Create Geometry/Geography Field from Latitude & Longitude fields (SQL Server)

后端 未结 2 1435
野性不改
野性不改 2021-01-05 22:22

I have a view that contains two fields for latitude and longitude, and I would like to create a new view that converts these lat/lon fields into a geometry/geography field (

2条回答
  •  孤城傲影
    2021-01-05 23:13

      SELECT  *, 
              geography::STGeomFromText('POINT(' + 
                    CAST([Longitude] AS VARCHAR(20)) + ' ' + 
                    CAST([Latitude] AS VARCHAR(20)) + ')', 4326) as GEOM,
    
              geography::Point([Latitude], [Longitude], 4326) as SAME_GEOM
    
      FROM view_name 
      WHERE (latitude <> 0) AND (longitude <> 0)
    

提交回复
热议问题