问题描述
我有一个包含纬度和经度两个字段的视图,我想创建一个新视图,将这些纬度/经度字段转换为几何/地理字段(不确定哪个最适合 ArcGIS).原始视图中的字段是双类型的,我希望它们在我的新视图中转换为空间类型.
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 (unsure which is most appropriate for ArcGIS). The fields in the original view are of double type, and I would like them cast as a spatial type in my new view.
目前我不确定如何将这些字段转换为空间类型.Stack Overflow 上的所有其他类似问题都没有给我一个可行的解决方案,所以如果这个问题似乎是重复的,我深表歉意,但希望一个更清晰的例子也可以帮助其他人.
Currently I am unsure how to cast these fields as spatial types. All the other similar questions on Stack Overflow never got me a working solution, so I apologize if this question appears to be a duplicate, but hopefully a clearer example could help others as well.
我的新视图写得很简单-
My new view is written pretty simply-
SELECT * FROM view_name WHERE (latitude <> 0) AND (longitude <> 0)
如何基于现有视图创建这个新视图,并将这两个字段(或创建一个填充有纬度/经度值的新空间字段)转换为空间类型?
How can I create this new view, based on an existing view, and cast the two fields (or create a new spatial field populated with the lat/lon values) as a spatial type?
我使用的是 SQL Server Management Studio,2012 版.如果我遗漏了任何相关信息,请告诉我.我很乐意提供尽可能多的详细信息.
I am using the SQL Server Management Studio, 2012 edition. Please let me know if I omitted any pertinent information. I am happy to provide as many details as I can.
推荐答案
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)
这篇关于从纬度创建几何/地理字段 &经度字段 (SQL Server)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!