Saturday, February 27, 2010

Spatial Data types

Sql Server 2008 introduced new types of spatial data including the following types:
1. Geometry data type.
A data type used to store two and three dimensional data coordinates. It is used to store planar (flat-earth) data. It is generally used to store XY coordinates that represent points, lines, and polygons in a two-dimensional space
2. Geography data type.
A data type used to store ellipsoidal data, such as latitude and longitude coordinates. It is used to store ellipsoidal (round-earth) data. It is used to store latitude and longitude coordinates that represent points, lines, and polygons on the earth’s surface

So by using the above types you can store data like latitude,lognlatitude,…which can be used in conjunction with for example Microsoft Virtual Earth to provide a visual representation of your geospatial data.

These types implemented by .Net CLR data types which mean they can support various properties and methods specific to the data.

Let's see examples:

USE TestDb
GO

CREATE TABLE EmployeesAddress
(EmployeeID int IDENTITY PRIMARY KEY,
AddressName NVARCHAR(50),
Location    GEOGRAPHY)
GO

--The Point extended static geography method constructs an
--instance representing a point that includes information 
--on the longitude, latitude, and SRID.
--The Parse extended static geography method returns a geography instance when the input
--is expressed in the OGC WKT representation.
INSERT INTO EmployeesAddress
VALUES
('ALRiyadh',
    GEOGRAPHY::Parse('POINT(-83.0086 39.95954)'));
GO    
    
SELECT * FROM EmployeesAddress
GO

--Other example use GEOMETRY data type
DECLARE @s GEOMETRY
SET @s = 'LINESTRING (  69 26, 69 23, 69 21, 67 20, 65 20, 
          63 18, 58 17, 52 17, 51 17, 49 17, 45 18, 44 20, 
          44 21, 42 26, 42 29, 42 32, 42 35, 43 35, 47 38, 
          50 41, 55 42, 58 42, 65 44, 66 44, 67 44, 68 45, 
          69 47, 70 48, 70 50, 71 51, 70 56, 68 60, 68 63, 
          66 65, 65 66, 63 68, 60 71, 59 71, 57 71, 55 71, 
          51 69, 45 65, 44 63, 42 62, 41 59, 41 57, 41 56, 
          41 54, 42 53 )'
          
SELECT @s



No comments: