从地geopandas dataFrame矢量化创建了外形多边形
我有一个带有点几何形状的GeodataFrame。 从点几何形状,我想以非常简单的方式定义一个方形多边形几何形状。
鉴于一个点,该点应为正方形的左下角,侧面为250个长度。 即,左下角是当前点,右下角是x轴上的当前点 + 250等。
我的天真方法是这样做: 在GeodataFrame中创建作为新列的角落:
之后,我尝试将新列定义为:
gdf['POLY'] = shapely.Geometry([gdf['BOTTOM_LEFT'], gdf['BOTTOM_RIGHT'], gdf['TOP_LEFT'], gdf['TOP_RIGHT']])
但是,这返回以下错误消息:
AttributeError: 'list' object has no attribute '__array_interface__'
I have a GeoDataFrame with a point geometry.
From the point geometry, I want to define a square polygon geometry in a quite straightforward manner.
Given a point, the point should be the left bottom corner in a square with sides 250 units of length.
I.e, left bottom corner is the current point, right bottom corner is the current point + 250 on the x axis etc.
My naive way of doing this is the following:
Create the corners as new columns in the GeoDataFrame:
After that, I try to define a new columns as:
gdf['POLY'] = shapely.Geometry([gdf['BOTTOM_LEFT'], gdf['BOTTOM_RIGHT'], gdf['TOP_LEFT'], gdf['TOP_RIGHT']])
But this returns the following error message:
AttributeError: 'list' object has no attribute '__array_interface__'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的实现是接近的,但是您无法将Shapely.deometry.polygon带有一系列点 - 只能一次完成。因此,诀窍是使用 在DataFrame的每一行上调用Polygon:
您可以使用
translate
:Your implementation is close, but you can't call shapely.geometry.Polygon with an array of points - it can only be done one at a time. So the trick is to use
df.apply
to call Polygon on every row of the DataFrame:You could do that with your original point using
translate
:假设您只有一个单点的GeodataFrame。它称为
gdf
,看起来如下:您可以使用以下lambda函数访问点的x和y组件:
现在您可以使用
shapely.polygon.polygon创建一个方形对象。
。您需要指定广场的四个顶点。您可以使用:您可以获取一个方形多边形对象,如下所示:

请注意,如果您在GeodataFrame中有很多点,请修改最后一个函数,以使其创建平方多边形,以逐步逐一为点。
Let's assume you have a GeoDataFrame with only single point. It is called
gdf
and it looks as follows:You can access the x and y components of the point using the following lambda function:
Now you can create a square object using
shapely.geometry.Polygon
. You need to specify the four vertices of the square. You can do it using:You can get a square polygon object as shown below:

Note that if you have many points in the GeoDataFrame, modify the last function such that it creates the square polygon for point in each row one by one.
就我而言,使用列表理解构建三角形的速度比使用geopandas。
In my case it was more than 5 times faster to build the triangles using list comprehension than using geopandas.apply :