Creating a geometry / geography field from latitude and longitude fields (SQL Server)

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 to a geometry / geography field (unsure which works best for ArcGIS). Fields in the original view are of a double type, and I would like them to display as a spatial type in my new view.

I am currently not sure how to use these fields as spatial types. All other similar questions about stack overflows never got me a working solution, so I apologize if this question seems to be a duplicate, but I hope a clearer example could help others.

My new view is written quite simply -

SELECT * FROM view_name WHERE (latitude <> 0) AND (longitude <> 0)

How can I create this new view based on an existing view and apply two fields (or create a new spatial field filled with lat / lon values) as a spatial type?

I am using SQL Server Management Studio, 2012. Please let me know if I omit any relevant information. I am happy to provide as many details as possible.

+2
source share
1 answer
  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)
+9
source

Source: https://habr.com/ru/post/1669753/


All Articles