•••
SQL Server Spatial SummaryOVERVIEW                                            FEATURES• 2 Spatial Data Types (CLR UDT)    ...
2 Spatial Datatypes • Geography (Geodetic) • Geometry (Planar)Geography •   Ellipsoidal coordinate support only (e.g. WGS ...
POINT            MULTIPOINTLINESTRING       MULTILINESTRINGCIRCULARSTRING   COMPOUNDCURVEPOLYGON          MULTIPOLYGON    ...
Spatial Data Type Support Spatial Methods• Retrieving Properties of Geometry Objects• Constructing Geometry Objects• Retur...
Vector Data
• Redmond to Belgrade• Does it go through France?
Shortest path is a Great Circle…
What is the distance from Anchorage to Tokyo?
••••
Geometry Data Type                Geography Data Type       STIntersects()=1                  STIntersects()=1       STOve...
••••
•    −    −•    −    −••    −    −•
Auto Grid Spatial Index                           Index ConstructionCREATE SPATIAL INDEX idxGeog        CREATE SPATIAL IND...
New Spatial Index HintSPATIAL_WINDOW_MAX_CELLSFine tuning at runtime for spatial indexes SELECT *   FROM table t     WITH ...
Relative Performance
•                                 Optimal value (theoretical) is                                somewhere between two extr...
Spatial Index CompressionCREATE SPATIAL INDEX idxGeog  ON table(geography column)  USING GEOGRAPHY_GRID  WITH (    DATA_CO...
••
••••
•            •••
LINESTRING (0 50, 90 50, 180 50,270 50, 0 50)  Linestring segments in the  geography type define the  minimum distance pat...
Circular ArcsGeography Type Considerations                                CIRCULARSTRING                                (0...
New Methods for Circular Arcs                                BufferWithCurves()                                This method...
New Methods for Circular Arcscontinued…   • STNumCurves()     Returns the number of curves in an object   • STCurveN()    ...
Existing Methods And Circular Arcs         All existing method work on circular arcs                     STIntersects() ex...
New and Updated Methods and Aggregates forall Types ShortestLineTo(); returns a linestring which represents the shortest d...
New and Updated Methods and Aggregates for allTypesUnionAggregate()EnvelopeAggregate()CollectionAggregate()ConvexHullAggre...
The following aggregate examples will use this core dataSELECT geog FROM Counties WHERE name_1 = Washington„--Results: 39 ...
Definition: Combines multiple spatial objects into a single spatial object,removing interior boundaries, where applicable....
Definition: Returns a bounding circular object as a CurvePolygon which encloses     one or more spatial objects.    SELECT...
Definition: Returns a 5 point polygon (rectangle) which encloses one or    more spatial objects.    SELECT Geometry::Envel...
Definition: Returns a geometry collection with one geometry part for each sp  object(s) in the selection set.  SELECT Geog...
Definition: Returns a convex hull polygon which encloses one or more spatialobjects.SELECT Geography::ConvexHullAggregate(...
••
•••
• STLength()       Now works on both valid and invalid linestrings; STLength now       works on invalid linestrings. Typic...
   24400: Valid   24401: Not valid, reason unknown.   24402: Not valid because point ({0}) is an isolated point, which ...
declare @p geography = Polygon((2 2, 4 4, 4 2, 2 4, 2 2))select @p.IsValidDetailed()--Results: 24409: Not valid because so...
All constructions and relations are now done with 48 bits of precision inDenali, compared to 27 bits used in SQL Server 20...
••••••
••
Full GlobeGeography Type Enhancement                             CURVEPOLYGON                             (CIRCULARSTRING ...
Full GlobeGeography Type Enhancement                  CURVEPOLYGON                  (CIRCULARSTRING (0 50, 90 50,         ...
••    −    −••
•    −    −    −    −
••    −    −    −    −
SELECT GEOGRAPHY::STGeomFromText(FULLGLOBE, 4326) -- WGS84SELECT GEOGRAPHY::STGeomFromText(FULLGLOBE, 4326).STArea() -- WG...
On March 20, 2010, the trimaran, Groupama 3,became the fastest boat to circumnavigate theEarth non-stop, ever (including p...
DECLARE @t GEOGRAPHY = (SELECT Track FROM Groupama_Track7)         SELECT TOP 16 CNTRY_NAME, SOVEREIGN,           POP_CNTR...
New Geography Methods                        ReorientObject()                        • This method will reverse the       ...
••
••*Average time for NN query is ~236ms
SELECT TOP(5) *  FROM Restaurants r    WHERE r.type = ‘Italian’      AND r.position.STDistance(@me) IS NOT NULL    ORDER B...
•    −    −    −    −    −•    −    −
•••
Two new helper methods are available:• sp_help_spatial_geography_histogram• sp_help_spatial_geometry_histogramThey can be ...
•    CREATE TABLE location (           id int primary key,           x float(max),           y float(max),           range...
Client Side Library Changes New sink interfaces are available IGeometrySink110 and IGeographySink110. They should be used ...
•    −    −•    −        −        −    −        −        −    −
SQL Server 2008 Spatial Data http://www.microsoft.com/sqlserver/2008/en/us/spatial-data.aspx•                            h...
•                              http://social.msdn.microsoft.com/Forums/en-US/sqlspatial/threads•                          ...
•USE Sample_USAGO--Update database compatibilityALTER DATABASE Sample_USA SET COMPATIBILITY_LEVEL = 110;GO
•    USE World;    GO    --Update database compatibility    ALTER DATABASE World     SET COMPATIBILITY_LEVEL = 110;    GO
•    −    −    −    −    −    −    −
•    −
•    −
•    −
•    −
•    −
•DECLARE @g GEOGRAPHY;SET @g = GEOGRAPHY::STGeomFromText(  CIRCULARSTRING(0 -23.43778, 0 0, 0 23.43778),4326);SELECT @g;GO
•DECLARE @g GEOGRAPHY;SET @g = GEOGRAPHY::STGeomFromText(  COMPOUNDCURVE(   CIRCULARSTRING(0 -23.43778, 0 0, 0 23.43778), ...
•DECLARE @g GEOGRAPHY;SET @g = GEOGRAPHY::STGeomFromText( COMPOUNDCURVE(   (0 -23.43778, 0 23.43778),   CIRCULARSTRING(0 2...
•DECLARE @a GEOGRAPHY = LineSTring(-118 34, -119 35)DECLARE @b GEOGRAPHY = Polygon((-120 22, -119 22, -119 23, -120 23, -1...
•    DECLARE @g GEOGRAPHY;    SET @g = GEOGRAPHY::STGeomFromText(      CURVEPOLYGON(        COMPOUNDCURVE(          (0 -23...
••DECLARE @g GEOGRAPHYSET @g = GEOGRAPHY::STGeomFromText(  GEOMETRYCOLLECTION(    COMPOUNDCURVE(       CIRCULARSTRING(0 23...
•USE Sample_USA;GO--Union Aggregates - GeographySELECT Geography::UnionAggregate(geog) FROM Counties WHERE NAME_1 = Washin...
•USE Sample_USA;GO--Envelope Aggregate - GeographySELECT Geography::EnvelopeAggregate(geog) FROM Counties WHERE NAME_1 = W...
•USE Sample_USA;GO--Collection AggregateSELECT Geography::CollectionAggregate(geog) FROM Counties WHERE NAME_1 = Washingto...
•    USE Sample_USA;    GO    --Convex Hull - Geography    SELECT Geography::ConvexHullAggregate(geog) FROM Counties     W...
•DECLARE @p geography = Polygon((2 2, 4 4, 4 2, 2 4, 2 2))SELECT @p.IsValidDetailed();GO--Results: 24409: Not valid becaus...
•--Invalid LineStrings - new behaviorDECLARE @line geometry = LineString(1 1, 2.1 1, 2.0 1, 4 1)SELECT @line.STIsValid();G...
•--You can still perform metric operationsDECLARE @line geometry = LineString(1 1, 2.1 1, 2.0 1, 4 1)SELECT @line.STLength...
•USE World;GODECLARE @g GEOGRAPHYSET @g = GEOGRAPHY::STGeomFromText(  CURVEPOLYGON(    CIRCULARSTRING(0 50, 90 50, 180 50,...
•USE World;GODECLARE @g GEOGRAPHYSET @g = GEOGRAPHY::STGeomFromText(  CURVEPOLYGON(    CIRCULARSTRING(0 50, 90 50, 180 50,...
•--BufferDECLARE @g GEOGRAPHY =GEOGRAPHY::STGeomFromText(CIRCULARSTRING(0 50, 45 50, 90 50),4326)DECLARE @b GEOGRAPHY = @g...
•    −    −    −    −    −
GEOGRAPHY              GEOMETRY          Denali CTP   Minimum DB                                                      Comp...
GEOGRAPHY                 GEOMETRY            Denali CTP   Minimum DB                                                     ...
GEOGRAPHY                GEOMETRY              Denali CTP   Minimum DB                                                    ...
GEOGRAPHY                    GEOMETRY                     Denali CTP   Minimum DB                                         ...
GEOGRAPHY                     GEOMETRY                    Denali CTP   Minimum DB                                         ...
GEOGRAPHY              GEOMETRY               Denali CTP   Minimum DB                                                     ...
GEOGRAPHY                              GEOMETRY                Denali CTP   Minimum DB                                    ...
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Covering the earth and the cloud the next generation of spatial in sql server and sql azure
Upcoming SlideShare
Loading in …5
×

Covering the earth and the cloud the next generation of spatial in sql server and sql azure

1,351 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,351
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Covering the earth and the cloud the next generation of spatial in sql server and sql azure

  1. 1. •••
  2. 2. SQL Server Spatial SummaryOVERVIEW FEATURES• 2 Spatial Data Types (CLR UDT) • 2D Vector Data Support• Comprehensive set of Spatial Methods • Open Geospatial Consortium Simple• High Performance Spatial Indexes Features for SQL compatible• Spatial Industry Standards Support • Supported By Major GIS Vendors• Spatial Library ESRI, Intergraph, Autodesk, Pitney Bowes, Safe, etc.•Management Studio Integration • Standard feature in all SQL Server Editions• Cloud-enabled • Support for very large spatial objects (2GB) • Supported in SS Reporting Services • Redistributable Spatial LibraryDETAILS• Geography data type for geodetic data• Geometry data type for planar data• Standard spatial methods STIntersects, STBuffer, STLength, STArea, etc.• Standard spatial format support (WKT, WBK, GML)• Multiple spatial indexes per column• Multiple spatial columns per table• Create new CLR-based spatial functions with the Sink/Builder APIs• SQL Azure Spatial support• Support for circular (curve) spatial objects• Support for full globe geography objects• Optimized performance for the sphere Ed Katibah, SQL Server, July 1, 2008
  3. 3. 2 Spatial Datatypes • Geography (Geodetic) • Geometry (Planar)Geography • Ellipsoidal coordinate support only (e.g. WGS 84) • Core set of geospatial methods • No OGC/ISO standards compliance (though many standards components are there) • Geospatial index • Designed as a simple, straight-forward geospatial implementationGeometry • Planar coordinate support only (georeferenced and non-georeferenced) • Complete set of spatial methods • OGC/ISO standards compliance (OGC SFS v1.1, ISO 19125) • Spatial index • Comprehensive spatial/geospatial offering supporting 2D planimetric applications
  4. 4. POINT MULTIPOINTLINESTRING MULTILINESTRINGCIRCULARSTRING COMPOUNDCURVEPOLYGON MULTIPOLYGON GEOMETRYCOLLECCURVEPOLYGON TIONFULLGLOBE
  5. 5. Spatial Data Type Support Spatial Methods• Retrieving Properties of Geometry Objects• Constructing Geometry Objects• Returning WKT, WKB and GML• Querying Validity, Instance Type, and Geometry Collection Information• Determining the Relationship between Two Geometries• Creating New Geometries Spatial Indexes • 4 Spatial indexes, two for geometry and two for geography
  6. 6. Vector Data
  7. 7. • Redmond to Belgrade• Does it go through France?
  8. 8. Shortest path is a Great Circle…
  9. 9. What is the distance from Anchorage to Tokyo?
  10. 10. ••••
  11. 11. Geometry Data Type Geography Data Type STIntersects()=1 STIntersects()=1 STOverlaps()=1 STOverlaps()=1* STEquals() = 1 STEquals() = 1 STTouches() = 1 STWithin() = 1 STWithin() = 1* STContains() = 1 STContains() = 1* STDistance() < value** STDistance() < value** STDistance() <= value** STDistance() <= value** Filter() = 1 Filter() = 1*New to SQL Server Code-Named “Denali” CTP3**STDistance() also participates in the new “Denali” Nearest Neighbor (NN) query plan
  12. 12. ••••
  13. 13. • − −• − −•• − −•
  14. 14. Auto Grid Spatial Index Index ConstructionCREATE SPATIAL INDEX idxGeog CREATE SPATIAL INDEX idxGeom ON table(geography column) ON table(geometry column) USING GEOGRAPHY_AUTO_GRID; USING GEOMETRY_AUTO_GRID; or orCREATE SPATIAL INDEX idxGeog CREATE SPATIAL INDEX idxGeom ON table(geography column) ON table(geometry column) USING GEOGRAPHY_AUTO_GRID USING GEOMETRY_AUTO_GRID WITH (CELLS_PER_OBJECT = 32); WITH (CELLS_PER_OBJECT = 32);Geography Type: Geometry Type:Default Cells per Object: 12 Default Cells per Object: 8
  15. 15. New Spatial Index HintSPATIAL_WINDOW_MAX_CELLSFine tuning at runtime for spatial indexes SELECT * FROM table t WITH (SPATIAL_WINDOW_MAX_CELLS=32) WHERE t.geom.STIntersects(@window)=1; The default value is 512 for geometry and 768 for geography. In SQL Server 2008, this value was hardcoded at 1024.
  16. 16. Relative Performance
  17. 17. • Optimal value (theoretical) is somewhere between two extremes Default values: Time needed to 512 - Geometry AUTO grid process false positives 768 - Geography AUTO grid 1024 - MANUAL grids
  18. 18. Spatial Index CompressionCREATE SPATIAL INDEX idxGeog ON table(geography column) USING GEOGRAPHY_GRID WITH ( DATA_COMPRESSION = <page | row> );On the basis of internal tests, with compression:• 40%-50% smaller than uncompressed counterparts• 5%-10% performance overhead for small indexes• For large indexes, performance improvements are observed
  19. 19. ••
  20. 20. ••••
  21. 21. •   •••
  22. 22. LINESTRING (0 50, 90 50, 180 50,270 50, 0 50) Linestring segments in the geography type define the minimum distance path on the underlying ellipsoid.CIRCULARSTRING (0 50, 90 50,180 50, 270 50, 0 50) Circularstring segments in the geography type define a circular path. A good example is a latitude parallel.
  23. 23. Circular ArcsGeography Type Considerations CIRCULARSTRING (0 50, 90 50, 180 50, 270 50, 0 50) If a circular linestring is closed, a curve polygon can be created CURVEPOLYGON (CIRCULARSTRING (0 50, 90 50, 180 50, 270 50, 0 50)) Coordinate pair order is important for the geography type. This set of coordinates is ordered according to the “left foot rule” for exterior rings.
  24. 24. New Methods for Circular Arcs BufferWithCurves() This method will construct the resulting polygon with circular arcs, often resulting in a dramatically smaller spatial object. DECLARE @g GEOGRAPHY = GEOGRAPHY::STGeomFromText(CIRCULARSTRING(0 50, 45 50, 90 50),4326) DECLARE @b GEOGRAPHY = @g.BufferWithCurves(500000) SELECT @b.STNumPoints() --Number of vertices: 11 DECLARE @g GEOGRAPHY = GEOGRAPHY::STGeomFromText(CIRCULARSTRING(0 50, 45 50, 90 50),4326) DECLARE @b GEOGRAPHY = @g.STBuffer(500000) SELECT @b.STNumPoints() --Number of vertices: 257
  25. 25. New Methods for Circular Arcscontinued… • STNumCurves() Returns the number of curves in an object • STCurveN() Used for iteration through the list of the edges • STCurveToLine() Convert curve components to a linestring • CurveToLineWithTolerance() Same as above but with user specific tolerance
  26. 26. Existing Methods And Circular Arcs All existing method work on circular arcs STIntersects() example
  27. 27. New and Updated Methods and Aggregates forall Types ShortestLineTo(); returns a linestring which represents the shortest distance between 2 objects HasZ, HasM [boolean] returns 0 or 1 if object has Z or M-value components
  28. 28. New and Updated Methods and Aggregates for allTypesUnionAggregate()EnvelopeAggregate()CollectionAggregate()ConvexHullAggregate()
  29. 29. The following aggregate examples will use this core dataSELECT geog FROM Counties WHERE name_1 = Washington„--Results: 39 rows, 1 for each county in the State of Washington All aggregates are static methods which work for either the Geography or the Geometry data types. For instance, consider the geography aggregate: Geography::UnionAggregate(geog) and its counterpart for geometry: Geometry::UnionAggregate(geom)
  30. 30. Definition: Combines multiple spatial objects into a single spatial object,removing interior boundaries, where applicable.SELECT Geography::UnionAggregate(geog) FROM Counties WHERE name_1 = Washington;
  31. 31. Definition: Returns a bounding circular object as a CurvePolygon which encloses one or more spatial objects. SELECT Geography::EnvelopeAggregate(geog).STCurveToLine() FROM Counties WHERE name_1 = Washington;Notes: STCurveToLine() method employed to assist in circular object rendering with visualizationprograms which do not support curve objects.
  32. 32. Definition: Returns a 5 point polygon (rectangle) which encloses one or more spatial objects. SELECT Geometry::EnvelopeAggregate(geom) FROM Counties WHERE name_1 = Washington;Notes: County input objects are in a US-wide Albersprojection which accounts for the apparent datarotation.
  33. 33. Definition: Returns a geometry collection with one geometry part for each sp object(s) in the selection set. SELECT Geography::CollectionAggregate(geog) FROM Counties WHERE name_1 = Washington;Notes: Unlike the UnionAggregate, adjoininginterior boundaries are not removed for polygons
  34. 34. Definition: Returns a convex hull polygon which encloses one or more spatialobjects.SELECT Geography::ConvexHullAggregate(geog) FROM Counties WHERE name_1 = Washington;
  35. 35. ••
  36. 36. •••
  37. 37. • STLength() Now works on both valid and invalid linestrings; STLength now works on invalid linestrings. Typically a linestring is invalid due to overlapping segment caused by anomalies such as inaccurate GPS measurements.• MinDbCompatibilityLevel() Method used for backward compatibility; indicates if spatial objects can be recognized by SQL Server 2008 and SQL Server 2008 R2.• IsValidDetailed() Provides commentary on what is wrong with invalid objects
  38. 38.  24400: Valid 24401: Not valid, reason unknown. 24402: Not valid because point ({0}) is an isolated point, which is not valid in this type of object. 24403: Not valid because some pair of polygon edges overlap. 24404: Not valid because polygon ring ({0}) intersects itself or some other ring. 24405: Not valid because some polygon ring intersects itself or some other ring. 24406: Not valid because curve ({0}) degenerates to a point. 24407: Not valid because polygon ring ({0}) collapses to a line at point ({1}). 24408: Not valid because polygon ring ({0}) is not closed. 24409: Not valid because some portion of polygon ring ({0}) lies in the interior of a polygon. 24410: Not valid because ring ({0}) is the first ring in a polygon of which it is not the exterior ring. 24411: Not valid because ring ({0}) lies outside the exterior ring ({1}) of its polygon. 24412: Not valid because the interior of a polygon with rings ({0}) and ({1}) is not connected. 24413: Not valid because of two overlapping edges in curve ({0}). 24414: Not valid because an edge of curve ({0}) overlaps an edge of curve ({1}). 24415: Not valid some polygon has an invalid ring structure. 24416: Not valid because in curve ({0}) the edge that starts at point ({1}) is either a line or a degenerate arc with antipodal endpoints.
  39. 39. declare @p geography = Polygon((2 2, 4 4, 4 2, 2 4, 2 2))select @p.IsValidDetailed()--Results: 24409: Not valid because some portion of polygon ring (1)-- lies in the interior of a polygon.
  40. 40. All constructions and relations are now done with 48 bits of precision inDenali, compared to 27 bits used in SQL Server 2008 and 2008 R2.For example, consider the following coordinate which was processed using theSTUnion() method in SQL Server 2008-82.339026 29.661245 -82.339025999885052 29.662144999951124In Denali, the greater numerical precision typically maintains the precision of theoriginal coordinates. Here is the result of the same STUnion() method in Denali, asabove-82.339026 29.661245 82.339026 29.661245
  41. 41. ••••••
  42. 42. ••
  43. 43. Full GlobeGeography Type Enhancement CURVEPOLYGON (CIRCULARSTRING (0 50, 90 50, 180 50, 270 50, 0 50)) Coordinate pair order is important for the geography type. This set of coordinates is ordered according to the “left foot rule” for exterior rings. What happens if the coordinates defining the exterior ring are reversed?
  44. 44. Full GlobeGeography Type Enhancement CURVEPOLYGON (CIRCULARSTRING (0 50, 90 50, 180 50, 270 50, 0 50)) If we reverse the order of the coordinate pairs, using the “right foot rule” for interior rings, this curve polygon now represents “the rest of the globe”. CURVEPOLYGON (CIRCULARSTRING (0 50, 270 50, 180 50, 90 50, 0 50))
  45. 45. •• − −••
  46. 46. • − − − −
  47. 47. •• − − − −
  48. 48. SELECT GEOGRAPHY::STGeomFromText(FULLGLOBE, 4326) -- WGS84SELECT GEOGRAPHY::STGeomFromText(FULLGLOBE, 4326).STArea() -- WGS84--Results: 510065621710996SELECT GEOGRAPHY::STGeomFromText(FULLGLOBE, 4322).STArea() -- WGS72--Results: 510065312469083DECLARE @wgs84_area FLOAT = (SELECT GEOGRAPHY::STGeomFromText(FULLGLOBE, 4326).STArea()) -- WGS84DECLARE @wgs72_area FLOAT = (SELECT GEOGRAPHY::STGeomFromText(FULLGLOBE, 4322).STArea()) -- WGS72SELECT @wgs84_area - @wgs72_area AS [DIFFERENCE]--Results: 309241913.4375
  49. 49. On March 20, 2010, the trimaran, Groupama 3,became the fastest boat to circumnavigate theEarth non-stop, ever (including power boats)…in 48 days, 7 hours and 44 minutes… …and of course, it‟s GPS-equipped…
  50. 50. DECLARE @t GEOGRAPHY = (SELECT Track FROM Groupama_Track7) SELECT TOP 16 CNTRY_NAME, SOVEREIGN, POP_CNTRY, @t.STDistance(Geography) AS [DISTANCE FROM TRACK] FROM Countries ORDER BY @t.STDistance(Geography)CNTRY_NAME SOVEREIGN POP_CNTRY DISTANCE FROM TRACKFrance France 57757060 0New Zealand New Zealand 3528197 7115.41609170632Chile Chile 13772710 15409.5690252515Spain Spain 39267780 37144.5519830663Portugal Portugal 9625516 57621.7065806319Argentina Argentina 33796870 106198.966899358United Kingdom United Kingdom 56420180 158636.063519451Cape Verde Cape Verde 413573 165226.105053976Guernsey United Kingdom 62920 177654.285742873Jersey United Kingdom 87848 189169.527892158Brazil Brazil 151525400 205920.063533954Falkland Is. United Kingdom 2136 237487.364201179Fr. So. & Ant. Lands France -99999 397707.475465133Ireland Ireland 5015975 416683.669375291Australia Australia 17827520 418237.701906367South Africa South Africa 40634126 430605.825881581
  51. 51. New Geography Methods ReorientObject() • This method will reverse the order of coordinates which define polygon rings. • This method is a no-op on line strings, circular arcs and points. • This method does not work with the geometry type.
  52. 52. ••
  53. 53. ••*Average time for NN query is ~236ms
  54. 54. SELECT TOP(5) * FROM Restaurants r WHERE r.type = ‘Italian’ AND r.position.STDistance(@me) IS NOT NULL ORDER BY r.position.STDistance(@me)It can also be expressed with limited maximum distanceSELECT TOP(5) * FROM Restaurants r WHERE r.type = ‘Italian’ AND r.position.STDistance(@me) < @max_range ORDER BY r.position.STDistance(@me)
  55. 55. • − − − − −• − −
  56. 56. •••
  57. 57. Two new helper methods are available:• sp_help_spatial_geography_histogram• sp_help_spatial_geometry_histogramThey can be used for investigating spatial index efficiency or analyzing spatialdata in general. The histograms could be also shown on a SSMS map.The data can be used for external visualization:
  58. 58. • CREATE TABLE location ( id int primary key, x float(max), y float(max), range float(max), geom as geometry::Point(x, y, 0) .STBuffer(range) PERSISTED );•
  59. 59. Client Side Library Changes New sink interfaces are available IGeometrySink110 and IGeographySink110. They should be used in the future. They must be used for objects incompatible with SQL Server 2008: • Objects bigger than a logical hemisphere • Objects with circular arcs • Invalid geography However, the old sinks will continue to work for SQL Server 2008 compatible objects. Geometry and Geography builders (SqlGeometryBuilder and SqlGeographyBuilder) now support circular arc constructions. New method “Deserialize” is added on the client library to both types.
  60. 60. • − −• − − − − − − −
  61. 61. SQL Server 2008 Spatial Data http://www.microsoft.com/sqlserver/2008/en/us/spatial-data.aspx• http://sqlspatialtools.codeplex.com• http://dataconnector.codeplex.com/• http://blogs.msdn.com/b/isaac/• http://blogs.msdn.com/edkatibah/• http://www.sqlskills.com/BLOGS/BOBB/• http://social.technet.microsoft.com/wiki/contents/articles/4136.aspx• http://social.technet.microsoft.com/wiki/contents/articles/new-spatial-features-in-the-sql-azure-q2-2011-service-release.aspx
  62. 62. • http://social.msdn.microsoft.com/Forums/en-US/sqlspatial/threads• http://msdn.microsoft.com/en- us/library/ee320529.aspx• http://msdn.microsoft.com/en- us/library/ee642046(v=SQL.105).aspx• http://downloads.solidq.com/insidetsql/• http://www.apress.com/book/view/1430218290
  63. 63. •USE Sample_USAGO--Update database compatibilityALTER DATABASE Sample_USA SET COMPATIBILITY_LEVEL = 110;GO
  64. 64. • USE World; GO --Update database compatibility ALTER DATABASE World SET COMPATIBILITY_LEVEL = 110; GO
  65. 65. • − − − − − − −
  66. 66. • −
  67. 67. • −
  68. 68. • −
  69. 69. • −
  70. 70. • −
  71. 71. •DECLARE @g GEOGRAPHY;SET @g = GEOGRAPHY::STGeomFromText( CIRCULARSTRING(0 -23.43778, 0 0, 0 23.43778),4326);SELECT @g;GO
  72. 72. •DECLARE @g GEOGRAPHY;SET @g = GEOGRAPHY::STGeomFromText( COMPOUNDCURVE( CIRCULARSTRING(0 -23.43778, 0 0, 0 23.43778), CIRCULARSTRING(0 23.43778, -45 23.43778, -90 23.43778), CIRCULARSTRING(-90 23.43778, -90 0, -90 -23.43778), CIRCULARSTRING(-90 -23.43778, -45 -23.43778, 0 -23.43778)),4326);SELECT @g;GO
  73. 73. •DECLARE @g GEOGRAPHY;SET @g = GEOGRAPHY::STGeomFromText( COMPOUNDCURVE( (0 -23.43778, 0 23.43778), CIRCULARSTRING(0 23.43778, -45 23.43778, -90 23.43778), (-90 23.43778, -90 -23.43778), CIRCULARSTRING(-90 -23.43778, -45 -23.43778, 0 -23.43778)) ,4326);SELECT @g;GO
  74. 74. •DECLARE @a GEOGRAPHY = LineSTring(-118 34, -119 35)DECLARE @b GEOGRAPHY = Polygon((-120 22, -119 22, -119 23, -120 23, -120 22))SELECT @a.ShortestLineTo(@b)UNION ALLSELECT @aUNION ALLSELECT @bGO
  75. 75. • DECLARE @g GEOGRAPHY; SET @g = GEOGRAPHY::STGeomFromText( CURVEPOLYGON( COMPOUNDCURVE( (0 -23.43778, 0 23.43778), CIRCULARSTRING(0 23.43778, -45 23.43778, -90 23.43778), (-90 23.43778, -90 -23.43778), CIRCULARSTRING(-90 -23.43778, -45 -23.43778, 0 -23.43778) ) ) ,4326); SELECT @g; GO
  76. 76. ••DECLARE @g GEOGRAPHYSET @g = GEOGRAPHY::STGeomFromText( GEOMETRYCOLLECTION( COMPOUNDCURVE( CIRCULARSTRING(0 23.43778, -45 23.43778, -90 23.43778), (-90 23.43778, -90 -23.43778) ), COMPOUNDCURVE( CIRCULARSTRING(-90 -23.43778, -45 -23.43778, 0 -23.43778), (0 -23.43778, 0 23.43778) ) ),4326);SELECT @g;GO
  77. 77. •USE Sample_USA;GO--Union Aggregates - GeographySELECT Geography::UnionAggregate(geog) FROM Counties WHERE NAME_1 = Washington;GO--Union Aggregates - GeometrySELECT Geometry::UnionAggregate(geom) FROM Counties WHERE NAME_1 = Washington;GO
  78. 78. •USE Sample_USA;GO--Envelope Aggregate - GeographySELECT Geography::EnvelopeAggregate(geog) FROM Counties WHERE NAME_1 = WashingtonUNION ALLSELECT geog from Counties WHERE NAME_1 = WashingtonGO--Envelope Aggregate - Geometry (why are the county spatial objects "rotated")SELECT Geometry::EnvelopeAggregate(geom) FROM Counties WHERE NAME_1 = WashingtonUNION ALLSELECT geom from Counties WHERE NAME_1 = WashingtonGO
  79. 79. •USE Sample_USA;GO--Collection AggregateSELECT Geography::CollectionAggregate(geog) FROM Counties WHERE NAME_1 = Washington;GO--Is it really a single object - if so, how many parts does it have?DECLARE @a GEOGRAPHY = (SELECT Geography::CollectionAggregate(geog)FROM Counties WHERE NAME_1 = Washington);SELECT @a.STNumGeometries();GO--Results: 39--Coincidentally, this is exactly the same number of counties in the State ofWashington ;-)SELECT COUNT(*) FROM Counties WHERE NAME_1 = Washington;GO
  80. 80. • USE Sample_USA; GO --Convex Hull - Geography SELECT Geography::ConvexHullAggregate(geog) FROM Counties WHERE NAME_1 = Washington UNION ALL SELECT geog from Counties WHERE NAME_1 = Washington„ GO --Convex Hull - Geometry SELECT Geometry::ConvexHullAggregate(geom) FROM Counties WHERE NAME_1 = Washington UNION ALL SELECT geom from Counties WHERE NAME_1 = Washington„ GO
  81. 81. •DECLARE @p geography = Polygon((2 2, 4 4, 4 2, 2 4, 2 2))SELECT @p.IsValidDetailed();GO--Results: 24409: Not valid because some portion of polygon ring (1)-- lies in the interior of a polygon.
  82. 82. •--Invalid LineStrings - new behaviorDECLARE @line geometry = LineString(1 1, 2.1 1, 2.0 1, 4 1)SELECT @line.STIsValid();GO--Results: 0 (invalid)DECLARE @line geometry = LineString(1 1, 2.1 1, 2.0 1, 4 1)SELECT @line.IsValidDetailed();GO--Results: 24413: Not valid because of two overlapping edges in curve (1).
  83. 83. •--You can still perform metric operationsDECLARE @line geometry = LineString(1 1, 2.1 1, 2.0 1, 4 1)SELECT @line.STLength();GO--Results: 3.2--You cannot perform other operations, howeverDECLARE @line geometry = LineString(1 1, 2.1 1, 2.0 1, 4 1)SELECT @line.STBuffer(.5);GO--Results: 24144: This operation cannot be completed because the instance is notvalid.
  84. 84. •USE World;GODECLARE @g GEOGRAPHYSET @g = GEOGRAPHY::STGeomFromText( CURVEPOLYGON( CIRCULARSTRING(0 50, 90 50, 180 50, 270 50, 0 50) ),4326);SELECT @gUNION ALLSELECT geography from World.dbo.CountriesGO
  85. 85. •USE World;GODECLARE @g GEOGRAPHYSET @g = GEOGRAPHY::STGeomFromText( CURVEPOLYGON( CIRCULARSTRING(0 50, 90 50, 180 50, 270 50, 0 50) ),4326);SELECT @g.ReorientObject()UNION ALLSELECT geography from World.dbo.CountriesGO
  86. 86. •--BufferDECLARE @g GEOGRAPHY =GEOGRAPHY::STGeomFromText(CIRCULARSTRING(0 50, 45 50, 90 50),4326)DECLARE @b GEOGRAPHY = @g.STBuffer(500000)SELECT @b --.STNumPoints()UNION ALLSELECT geography from World.dbo.CountriesGO--Number of vertices: 257--BufferWithCurvesDECLARE @g GEOGRAPHY =GEOGRAPHY::STGeomFromText(CIRCULARSTRING(0 50, 45 50, 90 50),4326)DECLARE @b GEOGRAPHY = @g.BufferWithCurves(500000)SELECT @b --.STNumPoints()UNION ALLSELECT geography from World.dbo.CountriesGO--Number of vertices: 11
  87. 87. • − − − − −
  88. 88. GEOGRAPHY GEOMETRY Denali CTP Minimum DB Compatibility LevelOGC MethodsSTArea() STArea() 100STAsBinary() STAsBinary() 100STAsText() STAsText() 100 STBoundary() 100STBuffer() STBuffer() 100see EnvelopeCenter() STCentroid() 100STContains() STContains() CTP1 100STConvexHull() STConvexHull() CTP1 100 STCrosses() 100STCurveN() STCurveN() CTP1 110STCurveToLine() STCurveToLine() CTP1 110STDifference() STDifference() 100STDimension() STDimension() 100STDisjoint() STDisjoint() 100
  89. 89. GEOGRAPHY GEOMETRY Denali CTP Minimum DB Compatibility LevelOGC Methods, continuedsee EnvelopeAggregate() STEnvelope() 100STEquals() STEquals() 100na STExteriorRing() 100STGeometryN() STGeometryN() 100STGeometryType() STGeometryType() 100na STInteriorRingN() 100STIntersections() STIntersections() 100STIntersects() STIntersects() 100STIsClosed() STIsClosed() 100STIsEmpty() STIsEmpty() 100na STIsRing() 100 STIsSimple() 100STIsValid() STIsValid() CTP1 100
  90. 90. GEOGRAPHY GEOMETRY Denali CTP Minimum DB Compatibility LevelOGC Methods, continuedSTNumGeometries() STNumGeometries() 100na STNumInteriorRing() 100STNumPoints() STNumPoints() 100STOverlaps() STOverlaps() CTP1 100STPointN() STPointN() 100 STPointOnSurface() 100 STRelate() 100STSrid STSrid 100STStartPoint() STStartPoint() 100STSymDifference() STSymDifference() 100 STTouches() 100STUnion() STUnion() 100STWithin() STWithin() CTP1 100na STX 100na STY 100
  91. 91. GEOGRAPHY GEOMETRY Denali CTP Minimum DB Compatibility LevelExtended MethodsASTextZM() ASTextZM() 100BufferWithCurves() BufferWithCurves() CTP1 110BufferWithTolerance() BufferWithTolerance() 100CurveToLineWithTolerance() CurveToLineWithTolerance() CTP1 110EnvelopeAngle() na 100EnvelopeCenter() na 100Filter() Filter() 100HasM HasM CTP3 100HasZ HasZ CTP3 100InstanceOf() InstanceOf() 100IsNull() IsNull() 100IsValidDetailed() IsValidDetailed() CTP3 100Lat na 100Long na 100
  92. 92. GEOGRAPHY GEOMETRY Denali CTP Minimum DB Compatibility LevelExtended Methods, continuedMinDbCompatibilityLevel() MinDbCompatibilityLevel() CTP1 100Reduce() Reduce() 100ReorientObject() na CTP1 100NumRings() na 100RingN() na 100ShortestLineTo() ShortestLineTo() CTP1 100ToString() ToString() 100Z Z 100
  93. 93. GEOGRAPHY GEOMETRY Denali CTP Minimum DB Compatibility LevelOGC Static MethodsSTGeomCollFromText() STGeomCollFromText() 100STGeomFromText() STGeomFromText() 100STLineFromText() STLineFromText() 100STPointFromText() STPointFromText() 100STPolyFromText() STPolyFromText() 100STMLineFromText() STMLineFromText() 100STMPointFromText() STMPointFromText() 100STMPolyFromText() STMPolyFromText() 100STGeomCollFromWKB() STGeomCollFromWKB() 100STGeomFromWKB() STGeomFromWKB() 100STLineFromWKB() STLineFromWKB() 100STPointFromWKB() STPointFromWKB() 100STPolyFromWKB() STPolyFromWKB() 100STMLineFromWKB() STMLineFromWKB() 100STMPointFromWKB() STMPointFromWKB() 100STMPolyFromWKB() STMPolyFromWKB() 100
  94. 94. GEOGRAPHY GEOMETRY Denali CTP Minimum DB Compatibility LevelExtended Static MethodsGeomFromGML() GeomFromGML() 100Parse() Parse() 100Point() Point() 100Null() Null() 100Aggregates (Extended Static Methods)CollectionAggregate() CollectionAggregate() CTP1 100ConvexHullAggregate() ConvexHullAggregate() CTP1 100EnvelopeAggregate() EnvelopeAggregate() CTP1 100UnionAggregate() UnionAggregate() CTP1 100

×