1 IF OBJECT_ID ( 'dbo.SpatialTable', 'U' ) IS NOT NULL 2 DROP TABLE dbo.SpatialTable; 3 GO 4 5 CREATE TABLE SpatialTable 6 ( id int IDENTITY (1,1), 7 GeomCol1 geometry, 8 GeomCol2 AS GeomCol1.STAsText() ); 9 GO 10 11 INSERT INTO SpatialTable (GeomCol1) 12 VALUES (geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180)', 0)); 13 14 INSERT INTO SpatialTable (GeomCol1) 15 VALUES (geometry::STGeomFromText('POLYGON ((0 0, 150 0, 150 150, 0 150, 0 0))', 0)); 16 GO
17INSERT INTO SpatialTable (GeomCol1)
18VALUES (geometry::STGeomFromText('POINT (3,4)', 0));
以上是geometry数据的插入;修改也是类似,不赘述了;
查询同sql的普通查询,如果需要获取文本可以使用对应的方法,如下:
select GeomCol1.STAsText() from SpatialTable
sql的其他geometry处理的方法,请参考https://docs.microsoft.com/en-us/sql/t-sql/spatial-geography/ogc-methods-on-geography-instances?view=sql-server-ver15