MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Virtual Earth & SQL Server 2008 - Part 2: Spatial Data Management in SQL Server 2008 (1/3)

This is a discussion on Virtual Earth & SQL Server 2008 - Part 2: Spatial Data Management in SQL Server 2008 (1/3) within the Virtual Earth Blogs forums, part of the Blogs category; Spatial Data Management in SQL Server 2008 Spatial Data Types Since the Community Technology Preview (CTP) 5 which was released ...


Go Back   MapPoint Forums > Blogs > Virtual Earth Blogs

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-02-2008
Member
Green Belt
 
Join Date: Sep 2007
Posts: 50
Virtual Earth & SQL Server 2008 - Part 2: Spatial Data Management in SQL Server 2008 (1/3)

Spatial Data Management in SQL Server 2008

Spatial Data Types

Since the Community Technology Preview (CTP) 5 which was released in November 2007, SQL Server 2008 supports two spatial data types: geometry and geography. Both data types are implemented as .NET Common Language Runtime (CLR) data types. The geometry data type is compliant with the Simple Features for SQL Specification, Version 1.1.0 according to the Open Geospatial Consortium (OGC) and supports planar or Euclidean (flat-earth) data. It is best used if you describe positions in coordinate systems which have the same scale in X- and Y-direction, such as the OSGB36 coordinate system mentioned before. The geography data type, on the other side, stores ellipsoidal (round-earth) data, such as latitude and longitude coordinates; it is thus a natural fit for the requirements of Virtual Earth.

The difference becomes immediately clear if we have a look at the map. In the example below we see the different effects of a calling the STBuffer-function on a geometry…

SELECT Geometry.STAsText() 
FROM Test01
WHERE id=1
UNION
SELECT
Geometry.STBuffer(0.0001).STAsText()
FROM Test01
WHERE id=1

…and a geography…

SELECT Geography.STAsText() 
FROM Test01
WHERE id=1
UNION
SELECT
Geography.STBuffer(20).STAsText()
FROM Test01
WHERE id=1


...data type. The first thing you notice is, that we have to use the same units as used in the spatial reference system for the geometry data type, i.e. we have to enter the size of the buffer in decimal degrees. That is something that doesn’t make sense to most users. On the other side the geography data type takes the size of the buffer in meters. Since the scale for WGS84 coordinate systems is different in X- and Y-directions and furthermore even different depending on the latitude, you see a distortion when using ellipsoidal data such as WGS84 with the geometry data type:



Coming back to the units of our data, we see that a result in degrees is most of the times not reasonable when it comes to measuring distances and areas. If we use the geometry data type to measure the area of a building like this:

DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((
51.461408935417026 -0.9266281127929573,
51.46091427889742 -0.9263437986373904,
51.46108473546569 -0.9255471825599749,
51.46157939013779 -0.9258341789245446,
51.461408935417026 -0.9266281127929573))'
, 4326);
SELECT @g.STArea();

We get an unusable result of 4.420787637913E-07 “square degrees”. However, if we use the geography data type:

DECLARE @g geography;
SET @g = geography::STGeomFromText('POLYGON((
51.461408935417026 -0.9266281127929573,
51.46091427889742 -0.9263437986373904,
51.46108473546569 -0.9255471825599749,
51.46157939013779 -0.9258341789245446,
51.461408935417026 -0.9266281127929573))'
, 4326);
SELECT @g.STArea();

e get a perfectly reasonable result of 3418.3 square meters.

The bottom line: It makes more sense, in most cases, to use the geography data type if you use Virtual Earth.

Please note: not all spatial functions are supported for both geography and geometry data types. For further reference have a look at the documentation.

Supported Geometries


SQL Server supports all geometries as defined in the OGC Simple Feature Specification:

image

On the other side Virtual Earth only supports Points, Lines and Polygons. Thus we need to split all multi-geometries into their components. Fortunately SQL Server 2008 supports us here with the necessary spatial-functions, e.g. if we have a MULTIPOLYGON we can retrieve the individual POLYGONs which are part of it:

SELECT GeomCol1.STAsText() FROM FeatureDemo WHERE ID=6;
SELECT GeomCol1.STGeometryN(1).STAsText() FROM FeatureDemo WHERE ID=6

Here is the result of these sample queries:

MULTIPOLYGON (((...)), (()))
POLYGON ((...))




Click here to view the article.

Last edited by Eric Frost; 03-03-2008 at 08:21 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Virtual Earth & SQL Server 2008 - Part 2: Spatial Data Management in SQL Server 2008 (3/3) Johannes Kebeck's Blog Virtual Earth Blogs 0 03-02-2008 01:40 PM
Virtual Earth & SQL Server 2008 - Part 2: Spatial Data Management in SQL Server 2008 (2/3) Johannes Kebeck's Blog Virtual Earth Blogs 0 03-02-2008 01:40 PM
Virtual Earth & SQL Server 2008 - Part 1: Introduction (2/2) Johannes Kebeck's Blog Virtual Earth Blogs 0 03-02-2008 07:30 AM
Virtual Earth & SQL Server 2008 - Part 1: Introduction (1/2) Johannes Kebeck's Blog Virtual Earth Blogs 0 03-02-2008 07:30 AM
MapDotNet Server 6.5 Supports SQL Server 2008 and New Virtual Earth Features VE For Government Virtual Earth Blogs 0 11-12-2007 05:42 PM


All times are GMT -5. The time now is 04:59 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5
MP2K Magazine
Visitor Map

Newcastle Flights
For details on Newcastle flights visit Holiday Hypermarket. We don't just book holidays, we provide useful information about airports too.

Turkey Holidays
Find and book Turkey Holidays with Travel Counsellors. Holiday destinations around the world including Turkey.

Portugal Holidays
Lisbon is perhaps Europe's most pleasant and affordable city. Check out the fantastic architecture, delicious seafood and non-stop night-life. Book Portugal Holidays with us.

Holidays in Cuba
Holidays in Cuba are an eclectic mix of golden beaches, rich, colourful scenery and a proud cultural heritage. Book a break in Cuba now!

Cheap Greece Holidays
For cheap Greece holidays make sure you know when to book and who to book with. Visit ulookubook.com to get help with doing both of those things. Why not time your visit with a Greek festival?

Holiday Comparison
We can help you with holiday comparison when you check out the options at Travel.co.uk

Holidays in Lanzarote
A quality luxury hotel awaits your patronage in the Canary Islands. Get information on holidays in Lanzarote at On The Beach.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47