spatial data types in sql server 2008: computation and visualization
DESCRIPTION
Spatial data types in SQL Server 2008: computation and visualization. Marko Tintor Danica Porobi ć Microsoft Development Center Serbia. Agenda. Virtual Earth with SQL Server. What is Spatial about?. Traditional GIS Now Consumer Developing LOB Ubiquity. Spatial Data Scenarios. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/1.jpg)
Spatial data types inSQL Server 2008: computation and
visualizationMarko TintorDanica PorobićMicrosoft Development Center Serbia
![Page 2: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/2.jpg)
Agenda
Spatial in SQL Server 2008
• What is spatial about?• Applications• Types, operations and indexing
Computation on Earth surface
• Numerical operations• Set operations
Projections and visualization
• 3D visualization tool• Extensible projection framework
Q/A
![Page 3: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/3.jpg)
Virtual Earth with SQL Server
![Page 4: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/4.jpg)
What is Spatial about?
TraditionalGIS
NowConsumer
DevelopingLOBUbiquity
![Page 5: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/5.jpg)
Spatial Data ScenariosCustomer-base
management and development
Environmental-related data
impact, analysis, and planning
Financial and economic analysis in
communities
Government-based planning
and development analysis
Market segmentation and analysis
Scientific research study
design and analysis
Real-estate development and analysis
![Page 6: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/6.jpg)
Spatial in SQL 2008
We’re providing vector supportWe’re targeting geospatial...
Spatial data which is referenced to a location on the EarthTypically uses spherical coordinates or projected planar coordinates I’ll come back to this distinction in a moment
...but, there is no restriction that the data is actually geospatialOnly 2D for now (Geodetic is 2D)
![Page 7: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/7.jpg)
What is Spatial Data?Vector
PointsLineStringsPolygons (Areas, Regions)
RasterSatellite ImageryDigitized Aerial Photos
![Page 8: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/8.jpg)
Sample QueryWhich roads intersect Microsoft’s main campus?
SELECT * FROM roads WHERE roads.geom.Intersects(@ms)=1
![Page 9: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/9.jpg)
It’s a big problem…
![Page 10: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/10.jpg)
It can be complex, too...
![Page 11: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/11.jpg)
All Flat Maps Are Wrong
Flat maps are projections from the spheroid
Small areas don’t distort too muchLarge areas do, so no good global projectionStill very important for legislative and historical reasons
conic secant projection
![Page 12: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/12.jpg)
![Page 13: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/13.jpg)
Comprehensive Spatial SupportSpatial Data Types
geography data type• Geodetic (“Round Earth”)
geospatial model• Define points, lines, and areas
with longitude and latitude• Account for planetary
curvature and obtain accurate “great circle” distances
geometry data type• Planar (“Flat Earth”)
geospatial model• Define points, lines, and
areas with coordinates• Use for localized areas or
non-projected surfaces such as interior spaces
![Page 14: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/14.jpg)
Planar and Geodetic Cover Different Scenarios
Planar (flat-earth)Supports legacy and legal mapping requirements: surveyors and the specialist GIS crowdComputationally simplerConceptually more difficult for geospatial
Geodetic (round-earth)
Supports existing long-range mapping requirements: military, shipping, etc.Computationally more complexConceptually simpler for geospatial
![Page 15: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/15.jpg)
Spatial Operators World Class
Relationships
• Intersects• Touches• Disjoint
Constructions
• Intersection, Union, Difference
Numeric Computations
• Distance, Length• Area
Special Operations
• Point in polygon• Buffer• Reduce
![Page 16: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/16.jpg)
Planar TypeNew type: geometryBuilt on the same infrastructure Geometry can store instances of various types
PointsLine stringsPolygonsCollections of the above
Methods for computingSpatial relationships: intersects, disjoint, etc.Spatial constructions: intersection, union, etc.Metric functions: distance, area
![Page 17: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/17.jpg)
Geodetic Type
Second type: geographyVery similar interface to geometry
Some methods have different semanticsMost data commonly available user data is geodetic
Anything expressed as latitude/longitudeThis is the type we expect most people to be interested in
![Page 18: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/18.jpg)
Demo Architecture
Web Server
Client
VirtualEarth
Service
SQL Server
![Page 19: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/19.jpg)
Demo Data
![Page 20: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/20.jpg)
E75 and Counties
![Page 21: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/21.jpg)
Flood Analysis
![Page 22: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/22.jpg)
Economic Development Analysis
![Page 23: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/23.jpg)
High Performance Spatial CapabilitiesSpatial Indexing
Spatial indexing is built into the query engineGrid-based quad-tree index structure
![Page 24: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/24.jpg)
Multi-Level Grid
42.3
![Page 25: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/25.jpg)
Spatial Index Performance
Indexed Operations
• g1.STIntersects(geometry2) = 1• g1.STTouches(geometry2) = 1• g1.STEquals(geometry2) = 1• g1.STWithin(geometry2) = 1• g1.STContains(geometry2) = 1• g1.STDistance(geometry2) < number• No native support for nearest neighbor
![Page 26: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/26.jpg)
Defining edges on round Earth
Requirements:Locally: edge should appear straightPair of points should define unique edgeEdge should have differentiable parameterization
Possible solution: Geodesic curves (shortest path between points)
Not suitable for points that are not on surfaceTwo points define more than one edgeComputations are extremely difficult
![Page 27: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/27.jpg)
Definition in SQL Server Spatial
Space of directions:Geographic coordinates of a point on the globe are defined by the direction of a vector that is normal to the surface of the globe at that pointSpace of directions – nonzero normal vectors
Definition:An edge is the image under the Inverse Gaussian Mapping (IGM) of the short great circle arc on the sphere of directions between the unit normal vectors at its endpointsAn edge is the image under the IGM of a line segment in the space of directions
![Page 28: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/28.jpg)
Mapping from normal vectors to points on ellipsoid
Surface of rotational ellipsoid:
Let (u,v,w) be normal at the surface of (x,y,z), so under IGM:
Mapping is:
12
2
2
2
2
2
b
z
a
y
a
x
222
2,
2,
2),,(
b
z
a
y
a
xrwvu
222222
222 ),,(),,(
wbvaua
wbvauawvuE
![Page 29: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/29.jpg)
Parameterization of an edge
Great-circle arc on the sphere of unit normal vectors
Edge on ellipsoid
Linear parameterization of great circle arc’s chord
Parameterization
}10:))(),(),({( ttwtvtu
}10:))(),(),(({ ttwtvtuE
}10:)1()({ ttBAttL
}10:)({)( ttLEtX
![Page 30: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/30.jpg)
Numeric computations
Velocity vector:
Length of an edge:
Area: sum of integrals over edges
Computation using Gauss Legendre quadratureLong edges broken into pieces
))('),('),('()(' tztytxtX
1
)(')('o
tXtX
![Page 31: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/31.jpg)
Boolean operations
Spherical arcs projected to lines using gnomonic projectionsBoolean operations on sphere transform to their planar counterparts after projectionPlanar operations rely on geometric library from Windows VistaGnomonic projection works for smaller objectsLarger objects handled by tiled projection
![Page 32: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/32.jpg)
Simple gnomonic projection
Central projection from the origin to a plane that is tangent to the unit sphereThe image of a polygon on sphere is a polygon in the planeLet C be the point of tangencyBasis vectors: two mutually orthogonal unit vectors A and B, orthogonal to CProjection of vector U:
V = U/U∙CPlanar coordinates: (V-C)∙A and (V-C)∙B
![Page 33: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/33.jpg)
Tiled projection
Map the scene with simple projections onto four facets of the tetrahedronAffine projection along the axis into the plane
Crease
Tile
![Page 34: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/34.jpg)
Visualization of geography
Building blocksPointsLineStringsPolygons
Points and LineStrings are easy to displayBut, how to display the polygons?
![Page 35: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/35.jpg)
Rendering polygons on Earth
Even polygons with small number of vertices can have unintuitive shape
![Page 36: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/36.jpg)
Polygon rendering issues
curved (spherical) surfacepolygons can have holespolygons can be non-convexpolygons can be near / span over polespolygons can cross ±180 degrees meridian
![Page 37: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/37.jpg)
Possible solutions
VectorSubdivide the polygon untilall parts are simple enough
RasterRender the polygon to the textureand wrap that texture around sphere
![Page 38: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/38.jpg)
Our idea
Subdivide entire Earth into patchesRender only the patches that are on the inside of the polygonUse smaller patches near the border of polygon
![Page 39: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/39.jpg)
Possible relations ofpatch and the polygon
Completely insideOn the borderCompletely outside
![Page 40: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/40.jpg)
Core algorithm
FUNC RenderPatch(patch, polygon)IF patch is INSIDE the polygon
Render(patch)IF patch is ON BORDER of the polygon
AND patch is not too smallFOREACH piece IN
Subdivide(patch) RenderPatch(piece, polygon)
IF patch is OUTSIDE polygonignore it
![Page 41: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/41.jpg)
Best choice for patch shape
TriangleEasy to renderEasy to subdivideEasy to tile
![Page 42: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/42.jpg)
How to subdivide the Earth?
Start from octahedronSubdivide each triangle recursively
![Page 43: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/43.jpg)
End result in wireframe
![Page 44: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/44.jpg)
Questions?
![Page 45: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/45.jpg)
Thank you!
![Page 46: Spatial data types in SQL Server 2008: computation and visualization](https://reader037.vdocuments.net/reader037/viewer/2022110102/568141ff550346895daddf98/html5/thumbnails/46.jpg)
Resources
Sql Server Spatialhttp://
www.microsoft.com/sqlserver/2008/en/us/spatial-data.aspx
Microsoft Development Center Serbiahttp://www.microsoft.com/scg/mdcs/default.mspx
Defining Edges on a Round EarthMichael Kallay, Microsoft CorporationACM GIS ’07, Seattle, November 2007