根据dataFrame的结果,有效地更新地理框架中值的方法。Within方法
我有两个大的GeodataFrame:
一个来自一个ShapeFile,每个多边形具有称为“ Asapp”的浮子值。
其次是带有3x3米的渔网网格的质心和圆柱“ Asapp”零。
我需要的是填充第二个基数的“ asapp”,其中质心位于第一个基数内。
下面的代码执行此操作,但嘲笑的速度低15个多边形(最小的Shapefile之一具有更多的THA 20000多边形)。
# fishnet_grid is a dict created by GDAL with a raster with 3m pixel size
cells_in_wsg = np.array([(self.__convert_geom_sirgas(geom, ogr_transform), int(fid), 0.0) for fid, geom in fishnet_grid.items()])
# transforming the grid raster (which are square polygons) in a GeoDataframe of point using the centroids of the cells
fishnet_base = gpd.GeoDataFrame({'geometry': cells_in_wsg[..., 0], 'id': cells_in_wsg[..., 1], 'asapp': cells_in_wsg[..., 2]})
fishnet = gpd.GeoDataFrame({'geometry': fishnet_base.centroid, 'id': fishnet_base['id'], 'asapp': fishnet_base['asapp']})
# as_applied_data is the polygons GeoDataFrame
# the code below takes a lot of time to complete
for as_applied in as_applied_data.iterrows():
fishnet.loc[fishnet.within(as_applied[1]['geometry']), ['asapp']] += [as_applied[1]['asapp']]
还有另一种方法可以更好地做到这一点吗?
tys!
I have two large GeoDataFrame:
One came from a shapefile where each polygons has a float value called 'asapp'.
Second are the centroids of a fishnet grid with 3x3 meters and a column 'asapp' zeroed.
What I need is to fill the 'asapp' of the second one base where the centroid is within the polygons of the first.
The code below do this but with a ridiculos low rate of 15 polygons per sec (One of the smallest shapefile has more tha 20000 polygons).
# fishnet_grid is a dict created by GDAL with a raster with 3m pixel size
cells_in_wsg = np.array([(self.__convert_geom_sirgas(geom, ogr_transform), int(fid), 0.0) for fid, geom in fishnet_grid.items()])
# transforming the grid raster (which are square polygons) in a GeoDataframe of point using the centroids of the cells
fishnet_base = gpd.GeoDataFrame({'geometry': cells_in_wsg[..., 0], 'id': cells_in_wsg[..., 1], 'asapp': cells_in_wsg[..., 2]})
fishnet = gpd.GeoDataFrame({'geometry': fishnet_base.centroid, 'id': fishnet_base['id'], 'asapp': fishnet_base['asapp']})
# as_applied_data is the polygons GeoDataFrame
# the code below takes a lot of time to complete
for as_applied in as_applied_data.iterrows():
fishnet.loc[fishnet.within(as_applied[1]['geometry']), ['asapp']] += [as_applied[1]['asapp']]
There is another way to do this with better performance?
Tys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了问题。
我阅读了有关使用
geopandas.overlay
( htttps:/htttps:/ /geopandas.org/en/stable/docs/user_guide/set_operations.html )与许多多边形一起工作,但问题是它仅适用于多边形,我有多边形和点。因此,我的解决方案是从点创建非常小的多边形(2厘米侧正方形),然后使用覆盖层。
最终代码:
效果很好!
I solved the problem.
I readed about using
geopandas.overlay
(https://geopandas.org/en/stable/docs/user_guide/set_operations.html) with work with a lot of polygons, but the problem is that it work only with polygons and I had polygons and points.So, my solution, was to create very small polygons (2cm side squares) from the points and then using the overlay.
The final code:
Its worked very fine!