SQL Server 2008Spatial  Geography Implemented in ASP.net and Virtual Earth Michael StarkStarkNetwork.comMichael@starknetwork.comblog.starknetwork.com
OutlineBackgroundOverview Spatial in SQL 2008Creating a spatial Query in SSMSSpatial Query in ListView controlSpatial Query wired up to Virtual Earth 21 Other ideas for mappingImplementation IssuesThis session is …a quick tour of  the spatial features of  SQL Server 2008.This session is NOT …An in-depth study of the spatial features of SQL Server 2008An in-depth explanation of ListView ControlAn in-depth explanation of Virtual Earth
OverviewTyler’s ArticleSQL Server MagazineSQLMAG.com Instant Doc ID  100528Tyler Chessman's article in SQL Server Magazine's December 2008 issue is my primary source of information to implement my spatial solutions.  Visit sqlmag.com and search for instant doc ID 100528.  I have a link on my blog to the article.
OverviewWhat is Spatial Data?Example of Spatial DataSQL Server’s answerSpatial data represents the shape and physical location of an object.  The object can be a house, business, sub-division, or a county.  SQL Server 2008 has two new data types GEOMETRY and GEOGRAPHY.  GEOMETRY works with flat objects. GEOGRAPHY considers the shape of the earth.
GEOMETRYGEOGRAPHY	CLR Data TypesNo need to enable CLRMany MethodsOpen Geospatial ConsortiumGEOGRAPHY and GEOMETRY are CLR data types. You do not need to have CLR enabled on the SQL Server instance.  Microsoft has provided a long list of OGC methods.  These are methods that are part of the independent  Open Geospatial Consortium list of specifications.
OGC Methods	OGC Open Geospatial ConsortiumSQL Server 2008 supports  the Open Geospatial Consortium (OGC) methods on geometry instances.  These methods  make it very easy to perform  geospatial tasks that were once very difficult.STAreaSTAsTextSTBoundarySTBufferSTCentroidSTContainsSTConvexHullSTCrossesSTDifference
OGC Methods	OGC Open Geospatial ConsortiumSQL Server 2008 supports  the Open Geospatial Consortium (OGC) methods on geometry instances.  These methods  make it very easy to perform  geospatial tasks that were once very difficult.STDimensionSTDisJointSTDistanceSTEndPointSTEnvelopeSTEqualsSTExteriorRingSTGeometryNSTGeometryType
OGC Methods	OGC Open Geospatial ConsortiumSQL Server 2008 supports  the Open Geospatial Consortium (OGC) methods on geometry instances.  These methods  make it very easy to perform  geospatial tasks that were once very difficult.STInteriorRingSTIntersectionSTIntersectsSTIsClosedSTIsEmptySTIsRingSTIsSimpleSTIsValidSTLength
OGC Methods	OGC Open Geospatial ConsortiumSQL Server 2008 supports  the Open Geospatial Consortium (OGC) methods on geometry instances.  These methods  make it very easy to perform  geospatial tasks that were once very difficult.STNumGeometriesSTNumInteriorRingSTNumPointsSTOverlapsSTPointNSTPointOnSurfaceSTIsSimpleSTRelateSTSrid
OGC Methods	OGC Open Geospatial ConsortiumSQL Server 2008 supports  the Open Geospatial Consortium (OGC) methods on geometry instances.  These methods  make it very easy to perform  geospatial tasks that were once very difficult.STStartPointSTSymDifferenceSTTouchesSTUnionSTWithinSTXSTY
DEMONSTRATION	List of functions to demonstrateI will demonstrate STGeomFromTextSTDistanceAsGMLSTasTextSTGeometryTypeSTNumPoints.  The demonstration will return a list of stores within a provided distance of a given point.
STDistanceSTDistance( Point , SRID )The STDistance function requires an argument of the SQLgeometrytypeConvert the latitude and longitude to SQLgeometrytype. Declare a variable of the geography type.  Set the variable togeography::STGeomFromText('point(lon lat)',4326).Notice that  the point is a string.Notice there is no comma between lat and lon4326 is an SRID and is used to tell the function what method to use to calculate distance on a not-so-round planet.
SQL StatementDeclare @CodeGEOG  geography = geography::STGeomFromText('Point(-95.3410 29.7070)',4326);Select top(5) addr.AddressID as id ,addr.addressline1,addr.city,addr.SpatialLocation, -- Will show the raw dataaddr.SpatialLocation.AsGml() as SpationalGML,addr.SpatialLocation.STAsText() as SpatialText,addr.SpatialLocation.STGeometryType() as GeoType,addr.SpatialLocation.STNumPoints() as Points,addr.SpatialLocation.STDistance(@CodeGEOG) as distance_in_meters,addr.SpatialLocation.STDistance(@CodeGEOG)/1609.344 as distance_in_milesfrom dbo.AddressaddrWhereaddr.SpatialLocation.STDistance(@CodeGEOG)/1609.344 < 50  order by distance_in_miles
SSMSA demonstration of running a spatial queryDEMO
Into ActionA very quick run throughWire-up Spatial Query toList View ControlVirtual Earth
List View Control
Virtual Earth
21 WaysJohn O'Brien of the GEOWebGuru.com has compiled a list of 20 ways to use VirtualEarth.  See it here http://www.geowebguru.com/articles/86-twenty-ways-to-use-the-virtual-earth-platform-as-a-developer- Visit Weather.com to see this flash and VirtualEarth in actionhttp://www.weather.com/weather/map/interactive/33626?from=36hr_topnav_undeclared O’Brien lists 20 wayshttp://maps.live.comhttp://dev.live.com/virtualearthhttp://blogs.msdn.com/VirtualEarth3D/And moreI add one more way – Weather .comImplementationIssuesYou will find that the VE and Handler implementation returns a File Not Found Error when deployed to a web server.In IIS6 you right click on your App, go to properties, click Virtual Directory Tab, Configuration, Mapping Tab, Add, point the Executable to c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll and add the appropriate Extension ("georss") . VE Implementation works fine in developmentReturns File Not Found when deployed to IIS
ConclusionThis session was …a quick tour of  the spatial features of  SQL Server 2008.This session was NOT …An in-depth study of the spatial features of SQL Server 2008
An in-depth explanation of ListView Control
An in-depth explanation of Virtual EarthBackgroundOverview Spatial in SQL 2008Creating a spatial Query in SSMSSpatial Query in ListView controlSpatial Query wired up to Virtual Earth 21 Ways to implement VEDeployment Issues

Sql Saturday Spatial Data Ss2008 Michael Stark Copy

  • 1.
    SQL Server 2008Spatial Geography Implemented in ASP.net and Virtual Earth Michael StarkStarkNetwork.comMichael@starknetwork.comblog.starknetwork.com
  • 2.
    OutlineBackgroundOverview Spatial inSQL 2008Creating a spatial Query in SSMSSpatial Query in ListView controlSpatial Query wired up to Virtual Earth 21 Other ideas for mappingImplementation IssuesThis session is …a quick tour of the spatial features of SQL Server 2008.This session is NOT …An in-depth study of the spatial features of SQL Server 2008An in-depth explanation of ListView ControlAn in-depth explanation of Virtual Earth
  • 3.
    OverviewTyler’s ArticleSQL ServerMagazineSQLMAG.com Instant Doc ID 100528Tyler Chessman's article in SQL Server Magazine's December 2008 issue is my primary source of information to implement my spatial solutions. Visit sqlmag.com and search for instant doc ID 100528. I have a link on my blog to the article.
  • 4.
    OverviewWhat is SpatialData?Example of Spatial DataSQL Server’s answerSpatial data represents the shape and physical location of an object. The object can be a house, business, sub-division, or a county. SQL Server 2008 has two new data types GEOMETRY and GEOGRAPHY. GEOMETRY works with flat objects. GEOGRAPHY considers the shape of the earth.
  • 5.
    GEOMETRYGEOGRAPHY CLR Data TypesNoneed to enable CLRMany MethodsOpen Geospatial ConsortiumGEOGRAPHY and GEOMETRY are CLR data types. You do not need to have CLR enabled on the SQL Server instance. Microsoft has provided a long list of OGC methods. These are methods that are part of the independent Open Geospatial Consortium list of specifications.
  • 6.
    OGC Methods OGC OpenGeospatial ConsortiumSQL Server 2008 supports the Open Geospatial Consortium (OGC) methods on geometry instances. These methods make it very easy to perform geospatial tasks that were once very difficult.STAreaSTAsTextSTBoundarySTBufferSTCentroidSTContainsSTConvexHullSTCrossesSTDifference
  • 7.
    OGC Methods OGC OpenGeospatial ConsortiumSQL Server 2008 supports the Open Geospatial Consortium (OGC) methods on geometry instances. These methods make it very easy to perform geospatial tasks that were once very difficult.STDimensionSTDisJointSTDistanceSTEndPointSTEnvelopeSTEqualsSTExteriorRingSTGeometryNSTGeometryType
  • 8.
    OGC Methods OGC OpenGeospatial ConsortiumSQL Server 2008 supports the Open Geospatial Consortium (OGC) methods on geometry instances. These methods make it very easy to perform geospatial tasks that were once very difficult.STInteriorRingSTIntersectionSTIntersectsSTIsClosedSTIsEmptySTIsRingSTIsSimpleSTIsValidSTLength
  • 9.
    OGC Methods OGC OpenGeospatial ConsortiumSQL Server 2008 supports the Open Geospatial Consortium (OGC) methods on geometry instances. These methods make it very easy to perform geospatial tasks that were once very difficult.STNumGeometriesSTNumInteriorRingSTNumPointsSTOverlapsSTPointNSTPointOnSurfaceSTIsSimpleSTRelateSTSrid
  • 10.
    OGC Methods OGC OpenGeospatial ConsortiumSQL Server 2008 supports the Open Geospatial Consortium (OGC) methods on geometry instances. These methods make it very easy to perform geospatial tasks that were once very difficult.STStartPointSTSymDifferenceSTTouchesSTUnionSTWithinSTXSTY
  • 11.
    DEMONSTRATION List of functionsto demonstrateI will demonstrate STGeomFromTextSTDistanceAsGMLSTasTextSTGeometryTypeSTNumPoints. The demonstration will return a list of stores within a provided distance of a given point.
  • 12.
    STDistanceSTDistance( Point ,SRID )The STDistance function requires an argument of the SQLgeometrytypeConvert the latitude and longitude to SQLgeometrytype. Declare a variable of the geography type. Set the variable togeography::STGeomFromText('point(lon lat)',4326).Notice that the point is a string.Notice there is no comma between lat and lon4326 is an SRID and is used to tell the function what method to use to calculate distance on a not-so-round planet.
  • 13.
    SQL StatementDeclare @CodeGEOG geography = geography::STGeomFromText('Point(-95.3410 29.7070)',4326);Select top(5) addr.AddressID as id ,addr.addressline1,addr.city,addr.SpatialLocation, -- Will show the raw dataaddr.SpatialLocation.AsGml() as SpationalGML,addr.SpatialLocation.STAsText() as SpatialText,addr.SpatialLocation.STGeometryType() as GeoType,addr.SpatialLocation.STNumPoints() as Points,addr.SpatialLocation.STDistance(@CodeGEOG) as distance_in_meters,addr.SpatialLocation.STDistance(@CodeGEOG)/1609.344 as distance_in_milesfrom dbo.AddressaddrWhereaddr.SpatialLocation.STDistance(@CodeGEOG)/1609.344 < 50 order by distance_in_miles
  • 14.
    SSMSA demonstration ofrunning a spatial queryDEMO
  • 15.
    Into ActionA veryquick run throughWire-up Spatial Query toList View ControlVirtual Earth
  • 16.
  • 17.
  • 18.
    21 WaysJohn O'Brienof the GEOWebGuru.com has compiled a list of 20 ways to use VirtualEarth.  See it here http://www.geowebguru.com/articles/86-twenty-ways-to-use-the-virtual-earth-platform-as-a-developer- Visit Weather.com to see this flash and VirtualEarth in actionhttp://www.weather.com/weather/map/interactive/33626?from=36hr_topnav_undeclared O’Brien lists 20 wayshttp://maps.live.comhttp://dev.live.com/virtualearthhttp://blogs.msdn.com/VirtualEarth3D/And moreI add one more way – Weather .comImplementationIssuesYou will find that the VE and Handler implementation returns a File Not Found Error when deployed to a web server.In IIS6 you right click on your App, go to properties, click Virtual Directory Tab, Configuration, Mapping Tab, Add, point the Executable to c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll and add the appropriate Extension ("georss") . VE Implementation works fine in developmentReturns File Not Found when deployed to IIS
  • 19.
    ConclusionThis session was…a quick tour of the spatial features of SQL Server 2008.This session was NOT …An in-depth study of the spatial features of SQL Server 2008
  • 20.
    An in-depth explanationof ListView Control
  • 21.
    An in-depth explanationof Virtual EarthBackgroundOverview Spatial in SQL 2008Creating a spatial Query in SSMSSpatial Query in ListView controlSpatial Query wired up to Virtual Earth 21 Ways to implement VEDeployment Issues
  • 22.
    SQL Server 2008Spatial Geography Implemented in ASP.net and Virtual Earth Michael StarkStarkNetwork.comMichael@starknetwork.comhttp://blog.starknetwork.com