Constructing geography Instances
You can construct instances of the geography data type by inputting data either in Well-Known Text (WKT) or Well-Known Binary (WKB) format.
Constructing an Instance Using Well-Known Text Input
The geography data type provides several built-in methods that generate a geography from the Open Geospatial Consortium (OGC) WKT representation. The WKT standard is a text string that allows geography data to be exchanged in textual form.
To construct any type of geography instance from WKT input
To construct a geography Point instance from WKT input
To construct a geography MultiPoint instance from WKT input
To construct a geography LineString instance from WKT input
To construct a geography MultiLineString instance from WKT input
To construct a geography Polygon instance from WKT input
To construct a geography MultiPolygon instance from WKT input
To construct a geography GeometryCollection instance from WKT input
Constructing an Instance Using Well-Known Binary Input
WKB is a binary format specified by the OGC that permits geography data to be exchanged between a client application and an SQL database. The following functions accept WKB input to construct geography instances:
To construct any type of geography instance from WKB input
To construct a geography Point instance from WKB input
To construct a geography MultiPoint instance from WKB input
To construct a geography LineString instance from WKB input
To construct a geography MultiLineString instance from WKB input
To construct a geography Polygon instance from WKB input
To construct a geography MultiPolygon instance from WKB input
To construct a geography GeometryCollection instance from WKB input
Constructing an Instance Using GML Text Input
The geography data type provides a method that generates a geography instance from GML, an XML representation of a geography instance. SQL Server supports a subset of GML.
For more information on Geography Markup Language, see the OGC Specification: OGC Specifications, Geography Markup Language.
To construct any type of geography instance from GML input
Returning Well-Known Text and Well-Known Binary from an Instance
You can use the following methods to return either the WKT or WKB format of a geography instance:
To return the WKT representation of a geography instance
STAsText (geography Data Type)
ToString (geography Data Type)
To return the WKT representation of a geography instance including any Z and M values
AsTextZM (geography Data Type)
To return the WKB representation of a geography instance
STAsBinary (geography Data Type)
To return a GML representation of a geography instance
Querying Instance Type and GeometryCollection Information
Once a geography instance is constructed, you can use the following methods to return the instance type, or if it is a GeometryCollection instance, return a specific geography instance.
To return the instance type of a geography
STGeometryType (geography Data Type)
To determine if a geography is a given instance type
InstanceOf (geometry Data Type)
To determine if a geography instance is well-formed for its instance type
STNumGeometries (geography Data Type)
To return a specific geography in a GeometryCollection instance
See Also