Use of STDistance and difference between geometry and geography, stdistancegeometry

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.