460 likes | 604 Views
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.
E N D
Spatial data types inSQL Server 2008: computation and visualization Marko Tintor DanicaPorobić Microsoft Development Center Serbia
What is Spatial about? • Traditional • GIS • Now • Consumer • Developing • LOB • Ubiquity
Spatial in SQL 2008 • 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)
What is Spatial Data? • Vector • Points • LineStrings • Polygons (Areas, Regions) • Raster • Satellite Imagery • Digitized Aerial Photos
Sample Query Which roads intersect Microsoft’s main campus? SELECT * FROM roads WHERE roads.geom.Intersects(@ms)=1
All Flat Maps Are Wrong • 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
Planar and Geodetic Cover Different Scenarios • 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
Planar Type • 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
Geodetic Type • 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
High Performance Spatial CapabilitiesSpatial Indexing • Spatial indexing is built into the query engine • Grid-based quad-tree index structure
Multi-Level Grid 42.3
Defining edges on round Earth • 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
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 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
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:
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
Numeric computations • Velocity vector: • Length of an edge: • Area: sum of integrals over edges • Computation using Gauss Legendre quadrature • Long edges broken into pieces
Boolean operations • 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
Simple gnomonic 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
Tiled projection • Map the scene with simple projections onto four facets of the tetrahedron • Affine projection along the axis into the plane
Visualization of geography • Building blocks • Points • LineStrings • Polygons • Points and LineStrings are easy to display • But, how to display the polygons?
Rendering polygons on Earth • Even polygons with small number of vertices can have unintuitive shape
Polygon rendering issues • 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
Possible solutions • Vector • Subdivide the polygon untilall parts are simple enough • Raster • Render the polygon to the textureand wrap that texture around sphere
Our idea • 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
Possible relations ofpatch and the polygon • Completely inside • On the border • Completely outside
Core algorithm FUNCRenderPatch(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
Best choice for patch shape • Triangle • Easy to render • Easy to subdivide • Easy to tile
How to subdivide the Earth? • Start from octahedron • Subdivide each triangle recursively
Resources • Sql Server Spatial http://www.microsoft.com/sqlserver/2008/en/us/spatial-data.aspx • Microsoft Development Center Serbia http://www.microsoft.com/scg/mdcs/default.mspx • Defining Edges on a Round EarthMichael Kallay, Microsoft Corporation ACM GIS ’07, Seattle, November 2007