如何使用QGIS或python gdal库转换ESRI shapefile格式以提取lat lon

时间:2016-12-22 08:18:38

标签: python esri qgis

我有ESRI Shapefile格式的文件。我可以知道如何使用QGIS或python gdal库来提取纬度和经度吗?我已经安装了QGIS并在其中添加了shapefile层,我可以在地图上查看(lat,long)但我不知道如何提取(lat,long)...请教我如何提取( lat,long)out。 TQ

2 个答案:

答案 0 :(得分:1)

右键单击图层,选择“另存为”。将打开“将矢量图层另存为...”对话框。选择以下选项:

格式:逗号分隔值[CSV]
文件名:选择文件名
CRS:EPSG:4326,WGS84

在下半部分,展开“选择要导出的字段”,如果只需要坐标,请单击“取消全选”,或者如果需要地名等,请选中可用项目(属性表中的列)。 WGS84作为输出CRS,您将收到十进制度(纬度,经度)的坐标。

Screenshot for 'Save vector layer as'

示例输出:

X,Y
12.4533865449718,41.9032821799601
12.4417701578001,43.936095834768
9.51666947290727,47.1337237742936

答案 1 :(得分:1)

如果你想用python做,你不需要gdal。我发现geopandas(使用Shapely)是一个更简单的库,用于处理shapefile。虽然起初它可能比点击QGIS界面要花几分钟,但从长远来看,学习如何在Python中操作shapefile是非常强大的知识。以下是使用python执行的任务示例:

import geopandas as gpd

# read shapefile (attributes and geometry) into geodataframe
shp = gpd.read_file("sample_shapefile.shp")

# convert "geometry" field into separate X and Y fields
shp["X"]=shp["geometry"].apply(lambda geom: geom.x)
shp["Y"]=shp["geometry"].apply(lambda geom: geom.y)

#save X,Y into csv file
shp[["X","Y"]].to_csv("coords.csv",header=True,index=False,sep=",")

Whick将在coords.csv中生成所需的输出:

X,Y
425070.0,80330.0
408390.0,81150.0
405370.0,85860.0
410880.0,82850.0
415310.0,80630.0
418610.0,80350.0