【发布时间】:2019-03-18 12:42:46
【问题描述】:
我有一个带有一列线串的数据框。我想将线串转换为其相应的纬度/经度,以便我可以用底图绘制它。我的代码如下:
gdf = gpd.read_file('./call2016.shp') #read the data into a variable
streetsaslinestring = gdf.loc[: , "geometry"] #getting the linestring column
接下来,我想将数据转换为 lon/lat。
streetsinlatlong = convert_etrs89_to_lonlat(streetsaslinestring)
streetsinlatlong.to_file('./streetslonglat.shp') #store it as .shp in order to plot it with basemap
m.readshapefile('./streetslonglat', 'streets') #read as shape file
几何列如下所示:geometry column
如何转换长字符串数据?
【问题讨论】:
-
“几何”列中的数据是什么样的?例如。
streetsaslinestring变量的内容是什么?此外,在第一行代码中,您使用gpd.read_file()读取 shapefile,但在最后一行代码中,您使用m.readshapefile()读取另一个 shapefile - 为什么? -
几何列由线串元素组成。因此,对于列中的每个条目,都存在一个线形。在第一行中,我读取了包含不同列的 shape 文件,例如街道名称、邮政编码等,在最后一列中,我使用
m.readshapefile()将转换后的 shapefile 绘制到使用底图的地图中。 -
您能否编辑您的问题以包含几何列内容的示例?
-
当然可以。它包含线串和多线串。可悲的是它们不可迭代......
-
更新:所以我使用了不同的方法:
stations = pd.read_csv(path)#将经度和纬度转换为另一个投影geometry = [Point(xy) for xy in zip(stations['lon'], stations['lat'])]crs = {'init': 'epsg:4326'}geoDF_stations = gpd.GeoDataFrame(stations, crs=crs, geometry=geometry)geoDF_stations_new = geoDF_stations.to_crs({'init': 'epsg:25830'})
标签: python matplotlib-basemap geopandas multilinestring