[英]How do I find all the polygons of a GeoDataframe that contain any point of another GeoDataframe in GeoPandas?
[英]How do you store a tuple in a geopandas geodataframe?
我有
blocks["centroid"] = blocks.centroid
這樣做將存儲一個shapely.Point
到blocks["centroid"]
但是shp
格式在blocks.to_file()
時不接受兩個幾何。 所以我正在嘗試將值保存為元組或列表,但只是在做
blocks["centroid"] = (blocks.centroid.x, blocks.centroid.y)
不會工作,拋出。
Length of values does not match length of index
如何將點的緯度/經度存儲在單列中 ?
如何在geopandas地理數據框中存儲元組?
blocks['centroid'] = blocks.apply(
lambda row: (row['geometry'].centroid.x,
row['geometry'].centroid.y), axis=1)
結果:
> blocks['centroid']
0 (3.74932619950664, -3.54174728953859)
1 (3.83665124133256, -3.556156891148994)
..
但這不能讓您使用.to_file()
另存為ESRI Shapefile。 因為ESRI Shapefile不支持tuple
或list
。
如何將點的緯度/經度存儲在單列中並將其另存為ESRI Shapefile ?
ESRI Shapefile僅支持這些類型 。 我們可以將質心坐標另存為連接字符串。
blocks['centroid'] = blocks.apply(
lambda row: '{},{}'.format(row['geometry'].centroid.x,
row['geometry'].centroid.y), axis=1)
blocks.to_file(filename='blocks', driver='ESRI Shapefile')
結果
> blocks['centroid']
0 3.74932619950664,-3.54174728953859
1 3.83665124133256,-3.556156891148994
..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.