SQL Server Geography Point

≯℡__Kan透↙ 提交于 2019-12-08 05:06:27

问题


I have recently been researching the SQL Server spatial data types and have decided to try and store my long, lat points in a geography field.

However I cannot figure out how to insert the data into the field, I have tried using stuff like "POINT(double, double), 0" and weird stuff like that, but no success.

Also im curious as to what the purpose of the ID argument specified in the geography functions.

Thanks, Alex.


回答1:


Have you looked at the examples from MSDN?

From geography (Transact-SQL):

IF OBJECT_ID ( 'dbo.SpatialTable', 'U' ) IS NOT NULL 
    DROP TABLE dbo.SpatialTable;
GO

CREATE TABLE SpatialTable 
    ( id int IDENTITY (1,1),
    GeogCol1 geography, 
    GeogCol2 AS GeogCol1.STAsText() );
GO

INSERT INTO SpatialTable (GeogCol1)
VALUES (geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656 )', 4326));

INSERT INTO SpatialTable (GeogCol1)
VALUES (geography::STGeomFromText('POLYGON((-122.358 47.653 , -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326));
GO

And from Point:

DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POINT (3 4)', 0);
SET @g = geometry::Parse('POINT(3 4 7 2.5)');



回答2:


DECLARE @g geography;  
SET @g = geography::Point(4, 3, 4326);

Notice: Lat and Long are the other way around, compared to the POINT syntax above.



来源:https://stackoverflow.com/questions/4117979/sql-server-geography-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!