spatial data types in sql server 2008: computation and visualization

46
Spatial data types in SQL Server 2008: computation and visualization Marko Tintor Danica Porobić Microsoft Development Center Serbia

Upload: major

Post on 10-Jan-2016

33 views

Category:

Documents


0 download

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 Presentation

TRANSCRIPT

Page 1: Spatial data types in SQL Server 2008: computation and visualization

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

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

Virtual Earth with SQL Server

Page 4: Spatial data types in SQL Server 2008: computation and visualization

What is Spatial about?

TraditionalGIS

NowConsumer

DevelopingLOBUbiquity

Page 5: Spatial data types in SQL Server 2008: computation and visualization

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

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

What is Spatial Data?Vector

PointsLineStringsPolygons (Areas, Regions)

RasterSatellite ImageryDigitized Aerial Photos

Page 8: Spatial data types in SQL Server 2008: computation and visualization

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

It’s a big problem…

Page 10: Spatial data types in SQL Server 2008: computation and visualization

It can be complex, too...

Page 11: Spatial data types in SQL Server 2008: computation and visualization

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
Page 13: Spatial data types in SQL Server 2008: computation and visualization

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

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

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

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

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

Demo Architecture

Web Server

Client

VirtualEarth

Service

SQL Server

Page 19: Spatial data types in SQL Server 2008: computation and visualization

Demo Data

Page 20: Spatial data types in SQL Server 2008: computation and visualization

E75 and Counties

Page 21: Spatial data types in SQL Server 2008: computation and visualization

Flood Analysis

Page 22: Spatial data types in SQL Server 2008: computation and visualization

Economic Development Analysis

Page 23: Spatial data types in SQL Server 2008: computation and visualization

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

Multi-Level Grid

42.3

Page 25: Spatial data types in SQL Server 2008: computation and visualization

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Danica Porobic
Jel' mozda ovde bolje tiles umesto patches?
Page 39: Spatial data types in SQL Server 2008: computation and visualization

Possible relations ofpatch and the polygon

Completely insideOn the borderCompletely outside

Page 40: Spatial data types in SQL Server 2008: computation and visualization

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

Best choice for patch shape

TriangleEasy to renderEasy to subdivideEasy to tile

Page 42: Spatial data types in SQL Server 2008: computation and visualization

How to subdivide the Earth?

Start from octahedronSubdivide each triangle recursively

Page 43: Spatial data types in SQL Server 2008: computation and visualization

End result in wireframe

Page 44: Spatial data types in SQL Server 2008: computation and visualization

Questions?

Page 45: Spatial data types in SQL Server 2008: computation and visualization

Thank you!

Page 46: Spatial data types in SQL Server 2008: computation and visualization

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