Use of STDistance and difference between geometry and geography, stdistancegeometry
1. First, let's talk about the difference between geometry and geography in SQL Server:
Geometry: Planar plane coordinate system [supported by SQL Server conforms to the Open Geospatial consorures (OGC) Simple Features for SQL Specification version 1.1.0 .]
Geography: Terrestrial geographic coordinate system [stores ellipsoidal (round-earth) data, such as GPS latitude and longpolling coordinates .]
If you want to calculate the actual distance between two lat/lon points, you need to convert the geometry type to the geography type, otherwise the results will certainly be incorrect.
2. geometry to geography:
Geography: STGeomFromText (boundary. ToString (),4326)
Boundary is a geometry type, 4326 is a coordinate system parameter, 4326 represents the GCS-WGS-1984 coordinate system, is the system default coordinate system.
You can use this SQL statement to obtain the system coordinate system (in SQL server): Select * from sys. spatial_reference_systems where authorized_spatial_reference_id = 4326
3. STDistance usage:
Https://msdn.microsoft.com/zh-cn/library/bb933952 (v = SQL .110). aspx
The distance can be calculated according to the example in the preceding figure. However, if the input value is a longitude or latitude value, the result is always incorrect and the value is relatively small, in fact, the second step needs to be converted to geography type before calculation. By default, the unit of the distance returned in the 4326 coordinate system is meter ].
STDistance can also calculate the shortest distance from a vertex to a vertex.