How to use the SQL 2008 Geometry.

Playing a little with SQL 2008 geometry I thought to post the queries that insert point, lines and polygons for the world to copy and paste if you like

INSERT INTO [Test].[dbo].[GeometryTest]
           ([Name]
           ,[Shape])
     VALUES
           ('Test'
           ,'POLYGON ((5 4, 5.38924515247345 4.0785849690437317, 5.70710676908493 4.29289323091507, 5.9214150309562683 4.61075484752655, 6 5, 5.9214150309562683 5.38924515247345, 5.70710676908493 5.70710676908493, 5.38924515247345 5.9214150309562683, 5 6, 4.61075484752655 5.9214150309562683, 4.29289323091507 5.70710676908493, 4.0785849690437317 5.38924515247345, 4 5, 4.0785849690437317 4.61075484752655, 4.29289323091507 4.29289323091507, 4.61075484752655 4.0785849690437317, 5 4))')

or

Adding a Spatial Reference to the polygon with automatic convertion.

INSERT INTO [Test].[dbo].[GeometryTest] values ('Polygon2', geometry::STGeomFromText(
'POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326));

 

INSERT INTO [Test].[dbo].[GeometryTest] values ('Line', geometry::STGeomFromText(
'LINESTRING(-122.34799999 47.648999999, -122.34799999999814 47.658000000054017, -122.35 47.65800, -122.35800000000745 47.652999999932945, -123.999 44.999)', 4326));

 

Create a buffer from a geometry

SELECT     TOP (1) Shape.STBuffer(0.001) AS Expr1
FROM         dbo.GeometryTest

Get a centroid

SELECT     TOP (1) Shape.STCentroid() AS Expr1
FROM         dbo.GeometryTest

Get the boundary

SELECT     TOP (1) Shape.STBoundary() AS Expr1
FROM         dbo.GeometryTest

Resources

http://technet.microsoft.com/en-us/magazine/2008.04.datatypes.aspx?pr=blog

http://technet.microsoft.com/en-us/library/bb933985.aspx

http://sqlspatialtools.codeplex.com/Wiki/View.aspx?title=Current%20Contents

Published Monday, July 20, 2009 9:53 PM by albertpascual
Filed under:

Comments

# re: How to use the SQL 2008 Geometry.

Monday, April 11, 2011 6:39 AM by adam

hmm just i wanna tell that was not helping at all

Leave a Comment

(required) 
(required) 
(optional)
(required)