Marko Tintor Danica Porobić Microsoft Development Center Serbia
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
Traditional GIS Now Consumer Developing LOB Ubiquity
Customer-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
We’re providing vector support We’re targeting geospatial... Spatial data which is referenced to a location on the Earth Typically 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 geospatial Only 2D for now (Geodetic is 2D)
Vector Points LineStrings Polygons (Areas, Regions) Raster Satellite Imagery Digitized Aerial Photos
Which roads intersect Microsoft’s main campus? SELECT * FROM roads WHERE
Flat maps are projections from the spheroid Small areas don’t distort too much Large areas do, so no good global projection Still very important for legislative and historical reasons conic secant projection
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
Planar (flat-earth) Supports legacy and legal mapping requirements: surveyors and the specialist GIS crowd Computationally simpler Conceptually more difficult for geospatial Geodetic (round-earth) Supports existing long-range mapping requirements: military, shipping, etc. Computationally more complex Conceptually simpler for geospatial
Relationships Intersects Touches Disjoint Constructions Intersection, Union, Difference Numeric Computations Distance, Length Area Special Operations Point in polygon Buffer Reduce
New type: geometry Built on the same infrastructure Geometry can store instances of various types Points Line strings Polygons Collections of the above Methods for computing Spatial relationships: intersects, disjoint, etc. Spatial constructions: intersection, union, etc. Metric functions: distance, area
Second type: geography Very similar interface to geometry Some methods have different semantics Most data commonly available user data is geodetic Anything expressed as latitude/longitude This is the type we expect most people to be interested in
Web Server Client Virtual Earth Service SQL Server
Spatial indexing is built into the query engine Grid-based quad-tree index structure
42.3
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
Requirements: Locally: edge should appear straight Pair of points should define unique edge Edge should have differentiable parameterization Possible solution: Geodesic curves (shortest path between points) Not suitable for points that are not on surface Two points define more than one edge Computations are extremely difficult
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 point Space 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 endpoints An edge is the image under the IGM of a line segment in the space of directions
Surface of rotational ellipsoid: Let (u,v,w) be normal at the surface of (x,y,z), so under IGM: Mapping is:
Great-circle arc on the sphere of unit normal vectors Edge on ellipsoid Linear parameterization of great circle arc’s chord Parameterization
Velocity vector: Length of an edge: Area: sum of integrals over edges Computation using Gauss Legendre quadrature Long edges broken into pieces
Spherical arcs projected to lines using gnomonic projections Boolean operations on sphere transform to their planar counterparts after projection Planar operations rely on geometric library from Windows Vista Gnomonic projection works for smaller objects Larger objects handled by tiled projection
Central projection from the origin to a plane that is tangent to the unit sphere The image of a polygon on sphere is a polygon in the plane Let C be the point of tangency Basis vectors: two mutually orthogonal unit vectors A and B, orthogonal to C Projection of vector U: V = U/U∙C Planar coordinates: (V-C)∙A and (V-C)∙B
Map the scene with simple projections onto four facets of the tetrahedron Affine projection along the axis into the plane
Building blocks Points LineStrings Polygons Points and LineStrings are easy to display But, how to display the polygons?
Even polygons with small number of vertices can have unintuitive shape
curved (spherical) surface polygons can have holes polygons can be non-convex polygons can be near / span over poles polygons can cross ±180 degrees meridian
Vector Subdivide the polygon until all parts are simple enough Raster Render the polygon to the texture and wrap that texture around sphere
Subdivide entire Earth into patches Render only the patches that are on the inside of the polygon Use smaller patches near the border of polygon
Completely inside On the border Completely outside
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 small FOREACH piece IN Subdivide(patch) RenderPatch(piece, polygon) IF patch is OUTSIDE polygon ignore it
Triangle Easy to render Easy to subdivide Easy to tile
Start from octahedron Subdivide each triangle recursively
Sql Server Spatial data.aspx Microsoft Development Center Serbia Defining Edges on a Round Earth Michael Kallay, Microsoft Corporation ACM GIS ’07, Seattle, November 2007