Geometry Data Type Examples
STArea()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0),(2 2, 2 1, 1 1, 1 2, 2 2))', 0);
SELECT @g, @g.STArea() as [AreaInUnits], 0.1 as [Thickness];
STAsBinary()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 3)', 0);
SELECT @g, @g.STAsBinary(), 0.1 as [Thickness];
STAsText()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 3)', 0);
SELECT @g, @g.STAsText() as [WellKnownText], 0.1 as [Thickness];
STBoundary()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 2, 0 2, 2 0)', 0);
SELECT @g, @g.STBoundary(), 0.1 as [Thickness];
/*
Boundary is defined by the OGC as follows:
- Point and MultiPoint instances do not have a boundary.
- LineString and MultiLineString boundaries are formed by the start points and end points, removing those that occur an even number of times.
*/
STBuffer()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 4 0)', 0);
SELECT @g, @g.STBuffer(1), 0.1 as [Thickness];
STCentroid()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0),(2 2, 2 1, 1 1, 1 2, 2 2))', 0);
SELECT @g, @g.STCentroid(), 0.1 as [Thickness];
STContains()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))', 0);
SET @h = geometry::STGeomFromText('POINT(1 1)', 0);
SELECT @g, @h, @g.STContains(@h), 0.1 as [Thickness];
STConvexHull()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 0 2, 1 1, 2 2, 2 0, 0 0))', 0);
SELECT @g, 'Original' AS [Display], 'Blue' as [Color], 0.2 as [Thickness]
UNION ALL
SELECT @g.STConvexHull(), 'Hull', 'Green' as [Color], 0.1 as [Thickness];
STCrosses()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 2, 2 0)', 0);
SET @h = geometry::STGeomFromText('LINESTRING(0 0, 2 2)', 0);
SELECT @g, @h, @g.STCrosses(@h), 0.1 as [Thickness];
STDifference()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))', 0);
SET @h = geometry::STGeomFromText('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))', 0);
SELECT 'Original Polygons' as [Display], @g, @h, 'Green' as [Color], 0.2 as [Thickness]
UNION ALL
SELECT 'First minus second', null, @g.STDifference(@h), 'Blue' as [Color], 0.1 as [Thickness]
UNION ALL
SELECT 'Second minus first', null, @h.STDifference(@g), 'Orange' as [Color], 0.05 as [Thickness];
STDimension
DECLARE @temp table ([name] varchar(10), [geom] geometry);
INSERT INTO @temp values ('LineString', geometry::STGeomFromText('LINESTRING(0 0, 3 3)', 0));
INSERT INTO @temp values ('Polygon', geometry::STGeomFromText('POLYGON((0 0, 3 0, 0 3, 0 0))', 0));
INSERT INTO @temp values ('Point', geometry::STGeomFromText('POINT(3 3)', 0));
SELECT [name], [geom], [geom].STDimension() as [dim], 0.1 as [Thickness]
FROM @temp;
STDisjoint()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 2, 2 0, 4 2)', 0);
SET @h = geometry::STGeomFromText('POINT(1 1)', 0);
SELECT @g, @h, @g.STDisjoint(@h), 0.1 as [Thickness];
STDistance
DECLARE @g geometry;
DECLARE @h geometry;
DECLARE @i geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))', 0);
SET @h = geometry::STGeomFromText('POINT(10 10)', 0);
SET @i = geometry::STGeomFromText('LINESTRING(2 2,10 10)', 0);
SELECT @g, @g.STDistance(@h), 0.1 as [Thickness], 'Green' as [Color]
UNION ALL
SELECT @i, @i.STLength(), 0.1 as [Thickness], 'Gray' as [Color] -- demonstration line
UNION ALL
SELECT @h, null, 0.3 as [Thickness], 'Red' as [Color];
STEndPoint()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 2, 1 0)', 0);
SELECT @g, @g.STEndPoint(), 0.1 as [Thickness];
STEnvelope()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 3)', 0);
SELECT @g, @g.STEnvelope(), 0.1 as [Thickness];
STEquals()
DECLARE @g geometry
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 2, 2 0, 4 2)', 0);
SET @h = geometry::STGeomFromText('MULTILINESTRING((4 2, 2 0), (0 2, 2 0))', 0);
SELECT @h, @h.STEquals(@g), 'Blue' as [Color], 0.2 as [Thickness]
UNION ALL
SELECT @g, @g.STEquals(@h), 'Orange' as [Color], 0.1 as [Thickness];
STExteriorRing()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0),(2 2, 2 1, 1 1, 1 2, 2 2))', 0);
SELECT @g, 0.2 as [Thickness]
UNION ALL
SELECT @g.STExteriorRing(), 0.1 as [Thickness];
STGeometryN()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('MULTIPOINT(0 0, 13.5 2, 7 19)', 0);
SELECT @g, 'Red' AS [Color], 1.5 as [Thickness]
UNION ALL
SELECT @g.STGeometryN(2), 'Yellow' AS [Color], 0.75 as [Thickness];
STGeometryType()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0))', 0);
SELECT @g, @g.STGeometryType() as [GeometryType], 0.1 as [Thickness];
STInteriorRing()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0),(2 2, 2 1, 1 1, 1 2, 2 2))', 0);
SELECT @g, @g.STInteriorRingN(1) AS [FirstInteriorRing], 0.1 as [Thickness];
STIntersection()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))', 0);
SET @h = geometry::STGeomFromText('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))', 0);
SELECT @g, 'Blue' as [Color], 0.3 as [Thickness]
UNION ALL
SELECT @h, 'Green' as [Color], 0.2 as [Thickness]
UNION ALL
SELECT @g.STIntersection(@h), 'Orange' as [Color], 0.1 as [Thickness];
STIntersects()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 2, 2 0, 4 2)', 0);
SET @h = geometry::STGeomFromText('POINT(1 1)', 0);
SELECT @g, @h, @g.STIntersects(@h), 0.1 as [Thickness];
STIsClosed()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 2, 1 0)', 0);
SELECT @g, @g.STIsClosed() AS [IsClosed], 0.1 as [Thickness];
STIsEmpty()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON EMPTY', 0);
SELECT @g, @g.STIsEmpty(), 0.1 as [Thickness];
STIsRing()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 2, 1 0, 0 0)', 0);
SELECT @g, @g.STIsRing(), 0.1 as [Thickness];
STIsSimple()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 2, 0 2, 2 0)', 0);
SELECT @g, @g.STIsSimple(), 0.1 as [Thickness];
STIsValid()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 2, 1 0)', 0);
SELECT @g, @g.STIsValid(), 0.1 as [Thickness];
STLength()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 2, 1 0)', 0);
SELECT @g, @g.STLength(), 0.1 as [Thickness];
STNumGeometries()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('MULTIPOINT(0 0, 13.5 2, 7 19)', 0);
SELECT @g.STNumGeometries() as [NumberOfGeometries], @g, 1 as [Thickness];
STNumInteriorRing()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0),(2 2, 2 1, 1 1, 1 2, 2 2))', 0);
SELECT @g.STNumInteriorRing() as [NumberOfInteriorRings], @g, 0.1 as [Thickness];
STNumPoints()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 2, 1 0)', 0);
SELECT @g.STNumPoints() as [NumberOfPoints], @g, 0.1 as [Thickness];
STOverlaps()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))', 0);
SET @h = geometry::STGeomFromText('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))', 0);
SELECT @g, @h, @g.STOverlaps(@h) as [DoesItOverlap], 0.1 as [Thickness];
STPointN()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 2, 1 0)', 0);
SELECT @g, @g.STPointN(2), 0.1 as [Thickness];
STPointOnSurface()
-- Returns an arbitrary point located within the interior of a geometry instance
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0),(2 2, 2 1, 1 1, 1 2, 2 2))', 0);
SELECT @g, @g.STPointOnSurface(), 0.1 as [Thickness];
STRelate()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 2, 2 0, 4 2)', 0);
SET @h = geometry::STGeomFromText('POINT(5 5)', 0);
SELECT @g, @h, @g.STRelate(@h, 'FF*FF****'), 0.1 as [Thickness];
STSrid()
--The first example creates a geometry instance with the SRID value 13 and uses STSrid to confirm the SRID.
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0))', 13);
SELECT @g.STSrid
/*
--The second example uses STSrid to change the SRID value of the instance to 23 and then confirms the modified SRID value.
SET @g.STSrid = 23;
SELECT @g.STSrid;
*/
STStartPoint()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 2 2, 1 0)', 0);
SELECT @g, @g.STStartPoint(), 0.1 as [Thickness];
STSymDifference()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))', 0);
SET @h = geometry::STGeomFromText('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))', 0);
SELECT @g, 'Green' as [Color], 0.2 as [Thickness]
UNION ALL
SELECT @h, 'Green' as [Color], 0.2 as [Thickness]
UNION ALL
SELECT @g.STSymDifference(@h).STGeometryN(1), 'Blue' as [Color], 0.1 as [Thickness]
UNION ALL
SELECT @g.STSymDifference(@h).STGeometryN(2), 'DarkBlue' as [Color], 0.1 as [Thickness];
STTouches()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 2, 2 0, 4 2)', 0);
SET @h = geometry::STGeomFromText('POINT(1 1)', 0);
SELECT @g.STTouches(@h) as [DoesItTouch]
, @g.STIntersects(@h) as [DoesItIntersect]
, @g, @h, 0.1 as [Thickness];
--Two geometry instances touch if their point sets intersect, but their interiors do not intersect.
STUnion()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))', 0);
SET @h = geometry::STGeomFromText('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))', 0);
SELECT @g, @h, @g.STUnion(@h), 0.1 as [Thickness];
STWithin()
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))', 0);
SET @h = geometry::STGeomFromText('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))', 0);
SELECT @g, @h, @g.STWithin(@h), 0.1 as [Thickness];
STX()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POINT(3 8)', 0);
SELECT @g.STX, 0.1 as [Thickness];
STY()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POINT(3 8)', 0);
SELECT @g.STY, 0.1 as [Thickness];
BufferWithTolerance()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POINT(3 3)', 0);
SELECT @g, 0.1 as [Thickness], 'Red' as [Color]
UNION ALL
SELECT @g.BufferWithTolerance(1, .5, 0), 0.1 as [Thickness], 'Green' as [Color]
UNION ALL
SELECT @g.BufferWithTolerance(2, .5, 0), 0.05 as [Thickness], 'Blue' as [Color]
UNION ALL
SELECT @g.BufferWithTolerance(2, .2, 0), 0.05 as [Thickness], 'Orange' as [Color];
InstanceOf()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('MULTIPOINT(0 0, 13.5 2, 7 19)', 0);
SELECT @g, @g.InstanceOf('GEOMETRYCOLLECTION'), 2 as [Thickness];
Reduce()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 0 1, 1 0, 2 1, 3 0, 4 1)', 0);
SELECT @g, 'Original' as [Display], 'Blue' AS [Color], 0.2 AS [Thickness]
UNION ALL
SELECT @g.Reduce(.75), 'Reduced' as [Display], 'Red' AS [Color], 0.1 AS [Thickness]
ToString()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 0 1, 1 0)', 0);
SELECT @g, @g.ToString(), 0.1 as [Thickness];
Geography Data Type Examples
STArea()
DECLARE @g geography;
SET @g = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326);
SELECT @g, @g.STArea(), 'Blue' as [Color], 10 as [Thickness];
STAsBinary()
DECLARE @g geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
SELECT @g.STAsBinary();
STAsText()
DECLARE @g geography;
SET @g = geography::STGeomFromText('LINESTRING( -122.360 47.656, -122.343 47.656)', 4326);
SELECT @g.STAsText();
STBuffer()
DECLARE @h geography;
SET @h = geography::STGeomFromText('POINT(-118.24 33.56)', 4326);
SELECT @h, 8 as [Thickness], 'Green' AS [COLOR]
UNION ALL
SELECT @h.STBuffer(5100000), 1 as [Thickness], 'Blue' AS [COLOR];
/*
DECLARE @g geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
SELECT @g.STBuffer(1).ToString(); */
STDifference()
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POLYGON((122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326);
SET @h = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
SELECT @g, @h, @g.STDifference(@h), 4 AS [Thickness];
STDimension()
DECLARE @temp table ([name] varchar(10), [geom] geography);
INSERT INTO @temp values ('Point', geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326));
INSERT INTO @temp values ('LineString', geography::STGeomFromText('LINESTRING( -122.360 47.656, -122.343 47.656)', 4326));
INSERT INTO @temp values ('Polygon', geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326));
SELECT [name], [geom], [geom].STDimension() AS [dim], 4 AS [Thickness]
FROM @temp;
STDisjoint()
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
SET @h = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326);
SELECT @g, @h, @g.STDisjoint(@h);
STDistance()
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
SET @h = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326);
SELECT @g, @h, @g.STDistance(@h);
STEndPoint()
DECLARE @g geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
SELECT @g, @g.STEndPoint()
STEquals()
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('GEOMETRYCOLLECTION(POLYGON((-122.368 47.658, -122.338 47.649, -122.338 47.658, -122.368 47.658, -122.368 47.658)), LINESTRING(-122.360 47.656, -122.343 47.656), POINT (-122.35 47.656))', 4326);
SET @h = geography::STGeomFromText('POLYGON((-122.368 47.658, -122.338 47.649, -122.338 47.658, -122.368 47.658, -122.368 47.658))', 4326);
SELECT @g, @h, @g.STEquals(@h);
STGeometryN()
DECLARE @g geography;
SET @g = geography::STGeomFromText('MULTIPOINT(-122.360 47.656, -122.343 47.656)', 4326);
SELECT @g, @g.STGeometryN(2);
STGeometryType()
DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326);
SELECT @g, @g.STGeometryType();
STIntersection()
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326);
SET @h = geography::STGeomFromText('LINESTRING( -122.360 47.656, -122.343 47.656)', 4326);
SELECT @g, @h, @g.STIntersection(@h);
STIntersects()
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649 , -122.348 47.658 , -122.358 47.658 , -122.358 47.653 ))', 4326);
SET @h = geography::STGeomFromText('LINESTRING( -122.360 47.656, -122.343 47.656 )', 4326);
SELECT @g, @h, @g.STIntersects(@h);
-- note this example appears incomplete on the MSDN page
STIsClosed()
DECLARE @g geography;
SET @g = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649 , -122.348 47.658 , -122.358 47.658 , -122.358 47.653 ))', 4326);
SELECT @g, @g.STIsClosed();
STIsEmpty()
DECLARE @g geography;
SET @g = geography::STGeomFromText('POLYGON EMPTY', 4326);
SELECT @g, @g.STIsEmpty();
STLength()
DECLARE @g geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
SELECT @g, @g.STLength();
STNumGeometries()
DECLARE @g geography;
SET @g = geography::STGeomFromText('MULTIPOINT((-122.360 47.656), (-122.343 47.656 ))', 4326);
SELECT @g, @g.STNumGeometries();
STNumPoints()
DECLARE @g geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
SELECT @g, @g.STNumPoints();
STPointN()
DECLARE @g geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
SELECT @g, @g.STPointN(2)
STSrid()
DECLARE @g geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
SELECT @g.STSrid;
/*
--The second example uses STSrid to change the SRID value of the instance to 4267
--(NAD27) and then confirms the modified SRID value.
SET @g.STSrid = 4267;
SELECT @g.STSrid;*/
STStartPoint()
DECLARE @g geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);
SELECT @g, @g.STStartPoint()
STSymDifference()
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658 , -122.358 47.653 ))', 4326);
SET @h = geography::STGeomFromText('POLYGON((-122.351 47.656, -122.341 47.656, -122.341 47.661, -122.351 47.661, -122.351 47.656))', 4326);
SELECT @g, @h, @g.STSymDifference(@h)
STUnion()
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POLYGON(( -122.358 47.653, -122.348 47.649 , -122.348 47.658 , -122.358 47.658 , -122.358 47.653 ))', 4326);
SET @h = geography::STGeomFromText('POLYGON((-122.351 47.656, -122.341 47.656 , -122.341 47.661 , -122.351 47.661 , -122.351 47.656 ))', 4326);
SELECT @g, @h, @g.STUnion(@h)
AsGml()
DECLARE @g geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656 )', 4326);
SELECT @g.AsGml();
AsTextZM()
DECLARE @g geography;
SET @g = geography::STGeomFromText('POINT(-122.34900 47.65100 10.3 12)', 4326);
SELECT @g.STAsText();
SELECT @g.AsTextZM()
BufferWithTolerance()
DECLARE @g geography;
SET @g = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326);
SELECT @g, @g.BufferWithTolerance(1, .5, 0);
InstanceOf()
DECLARE @g geography;
SET @g = geography::STGeomFromText('MULTIPOINT(-122.360 47.656, -122.343 47.656)', 4326);
SELECT @g, @g.InstanceOf('GEOMETRYCOLLECTION');
IsNull()
/* IsNull can be used to test whether a geography instance is null. This can produce somewhat confusing results, returning 0 if the instance is not null, but null if the instance is null.
This method is primarily used by the SQL Server infrastructure; it is not recommended that you use IsNull to test whether a geography instance is null.*/
Lat()
DECLARE @g geography;
SET @g = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326);
SELECT @g, @g.Lat;
Long()
DECLARE @g geography;
SET @g = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326);
SELECT @g, @g.Long;
M (measure)
DECLARE @g geography;
SET @g = geography::STGeomFromText('POINT(-122.34900 47.65100 10.3 12)', 4326);
SELECT @g, @g.M;
NumRings()
DECLARE @g geography;
SET @g = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649 , -122.348 47.658 , -122.358 47.658 , -122.358 47.653 ), (-122.357 47.654 , -122.357 47.657 , -122.349 47.657 , -122.349 47.650 , -122.357 47.654 ))', 4326);
SELECT @g, @g.NumRings();
RingN()
DECLARE @g geography;
SET @g = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649 , -122.348 47.658 , -122.358 47.658 , -122.358 47.653 ), (-122.357 47.654 , -122.357 47.657 , -122.349 47.657 , -122.349 47.650 , -122.357 47.654 ))', 4326);
SELECT @g, @g.RingN(2)
ToString()
DECLARE @g geography;
SET @g = geography::STGeomFromText('LINESTRING( -122.360 47.656, -122.343 47.656 )', 4326);
SELECT @g, @g.ToString()
Z (elevation)
DECLARE @g geography;
SET @g = geography::STGeomFromText('POINT(-122.34900 47.65100 10.3 12)', 4326);
SELECT @g, @g.Z;
No comments:
Post a Comment