Differences between revisions 2 and 3
Revision 2 as of 2014-04-01 13:00:45
Size: 1044
Editor: 71-87-247-191
Comment:
Revision 3 as of 2014-04-01 13:12:42
Size: 2000
Editor: 71-87-247-191
Comment:
Deletions are marked like this. Additions are marked like this.
Line 24: Line 24:
Methods of instantiating Spatial data from WKT: Methods of instantiating Spatial data from WKT for either geometry or geography
Line 35: Line 35:

{{{
--T-SQL
SELECT geography::STPointFromText('POINT(153 -27.5)', 4326);

SELECT geometry::STLineFromText('LINESTRING(300500 600150, 310200 602500)', 27700);

SELECT geography::STGeomFromText('POINT(153 -27.5)', 4326),
       geometry::STGeomFromText('LINESTRING(300500 600150, 310200 602500)', 27700);

//C#
SqlGeography Point = SqlGeography.STPointFromText(new SqlChars("POINT(153 -27.5)"),4326);
}}}

You can also use the Parse() method which does not require an SRID since it defaults to 4326 (WGS84) for geography or 0 for geometry. Assignment statements use Parse by default e.g.:

{{{
DECLARE @Delhi geography = 'POINT(77.25 28.5)';
--Equivalent to:
DECLARE @Delhi geography = geography::Parse('POINT(77.25 28.5)';
--Equivalent to:
DECLARE @Delhi geography = geography::STGeomFromText('POINT(77.25 28.5)', 4326);

Or in C#
SqlGeography Delhi = SqlGeography.Parse("POINT(77.25 28.5)");
}}}

Creating Spatial Data

SQL provides methods to create data in several formats:

Well-Known Text

Advantages:

  • Simple format
  • Human readable

Disadvantage:

  • loss of precision due to rounding of text-based representation of floating point coordinate values

  • SQL must parse All WKT into it's own internal binary format. Parsing takes additional time making this method slower than binary creation methods.

Methods of instantiating Spatial data from WKT for either geometry or geography

Geometry

Static Method

Point

STPointFromText()

LineString

STLineFromText()

Polygon

STPolyFromText()

MultiPoint

STMPointFromText()

MultiLineString

STMLineFromText()

MultiPolygon

STMPolyFromText()

GeometryCollection

STGeomCollFromText()

Any supported geometry

STGeomFromText() / Parse()

--T-SQL
SELECT geography::STPointFromText('POINT(153 -27.5)', 4326);

SELECT geometry::STLineFromText('LINESTRING(300500 600150, 310200 602500)', 27700);

SELECT geography::STGeomFromText('POINT(153 -27.5)', 4326),
       geometry::STGeomFromText('LINESTRING(300500 600150, 310200 602500)', 27700);

//C#
SqlGeography Point = SqlGeography.STPointFromText(new SqlChars("POINT(153 -27.5)"),4326);

You can also use the Parse() method which does not require an SRID since it defaults to 4326 (WGS84) for geography or 0 for geometry. Assignment statements use Parse by default e.g.:

DECLARE @Delhi geography = 'POINT(77.25 28.5)';
--Equivalent to:
DECLARE @Delhi geography = geography::Parse('POINT(77.25 28.5)';
--Equivalent to:
DECLARE @Delhi geography = geography::STGeomFromText('POINT(77.25 28.5)', 4326);

Or in C#
SqlGeography Delhi = SqlGeography.Parse("POINT(77.25 28.5)");

GeographicInformationSystems/CreatingSpatialData (last edited 2014-04-01 21:30:25 by 71-87-247-191)