geopandas 笔记:geometry上的操作汇总

如无特殊说明,数据主要来自:GeoDataFrame 应用:公园分布映射至subzone_UQI-LIUWJ的博客-CSDN博客

0 读入数据

subzone = gpd.read_file('ura-mp19-subzone-no-sea-pl.geojson')
subzone

subzone_tst=subzone[0:5]
subzone_tst

subzone_tst.plot()

 

1 area 计算面积

subzone_tst.area
'''
0    0.000036
1    0.000033
2    0.000048
3    0.000003
4    0.000015
dtype: float64
'''

2 boundary 边界

subzone_tst.boundary
'''
0    LINESTRING Z (103.81454 1.28239 0.00000, 103.8...
1    LINESTRING Z (103.82209 1.28049 0.00000, 103.8...
2    LINESTRING Z (103.84375 1.28508 0.00000, 103.8...
3    LINESTRING Z (103.84962 1.28412 0.00000, 103.8...
4    LINESTRING Z (103.85253 1.28617 0.00000, 103.8...
dtype: geometry
'''


subzone_tst.boundary.plot()

3 centroid 中心点

subzone_tst.centroid
'''
0    POINT (103.80856 1.28222)
1    POINT (103.81859 1.28201)
2    POINT (103.84369 1.27997)
3    POINT (103.84865 1.28528)
4    POINT (103.85101 1.28372)
dtype: geometry
'''
ax=subzone_tst.plot()
subzone_tst.centroid.plot(ax=ax,color='red')

4 convex_hull 凸包

subzone_tst.convex_hull
'''
0    POLYGON Z ((103.81749 1.28004 0.00000, 103.813...
1    POLYGON Z ((103.82153 1.27882 0.00000, 103.821...
2    POLYGON Z ((103.84137 1.27415 0.00000, 103.841...
3    POLYGON Z ((103.84955 1.28391 0.00000, 103.847...
4    POLYGON Z ((103.85108 1.28077 0.00000, 103.849...
dtype: geometry
'''


ax=subzone_tst.convex_hull.plot()
subzone_tst.plot(ax=ax,color='red',alpha=0.2)

5 envelope 最小旋转矩形

subzone_tst.envelope
'''
0    POLYGON ((103.80126 1.28004, 103.81774 1.28004...
1    POLYGON ((103.81306 1.27882, 103.82372 1.27882...
2    POLYGON ((103.83960 1.27415, 103.84919 1.27415...
3    POLYGON ((103.84718 1.28391, 103.84995 1.28391...
4    POLYGON ((103.84852 1.28077, 103.85321 1.28077...
dtype: geometry
'''


ax=subzone_tst.envelope.plot()
subzone_tst.plot(ax=ax,color='red',alpha=0.2)

6 buffer 缓冲区

ax=subzone_tst.buffer(0.01,0.05).plot()
subzone_tst.plot(ax=ax,color='red',alpha=0.2)

7 intersects 是否与另一个几何形状相交

subzone_tst.intersects(subzone.at[5,'geometry'])
'''
0    False
1    False
2     True
3     True
4     True
dtype: bool
'''
ax=subzone_tst.plot(figsize=(10,7))
subzone_tst.boundary.plot(ax=ax,color='black')
gpd.GeoSeries(subzone.loc[5,'geometry']).plot(ax=ax,color='red',alpha=0.4)

8 contains  是否包含另一个几何形状

subzone_tst.contains(subzone.at[5,'geometry'])
'''
0    False
1    False
2    False
3    False
4    False
dtype: bool
'''

9 crosses 是否与另一个几何形状交叉

subzone_tst.crosses(subzone.at[5,'geometry'])
'''
0    False
1    False
2    False
3    False
4    False
dtype: bool
'''

9.1 crosses和intersects的区别

  •  intersects
    • 如果两个几何形状共享任何点、边或面,则它们相交
  • crosses
    • crosses 描述了一个几何形状与另一个不同维度的几何形状之间的关系
    • 如果一个几何形状(线或多边形)穿越另一个几何形状,但不完全包含在其中,那么它们就交叉

10 distance 距离

subzone_tst.distance(subzone.at[5,'geometry'])
'''
0    0.026645
1    0.020509
2    0.000000
3    0.000000
4    0.000000
dtype: float64
'''

11 union 并集

subzone_tst.union(subzone)
'''
0      POLYGON Z ((103.81774 1.28043 0.00000, 103.817...
1      POLYGON Z ((103.82210 1.28011 0.00000, 103.822...
2      POLYGON Z ((103.84400 1.28491 0.00000, 103.844...
3      POLYGON Z ((103.84955 1.28391 0.00000, 103.849...
4      POLYGON Z ((103.85253 1.28615 0.00000, 103.852...
                             ...                        
327                                                 None
328                                                 None
329                                                 None
330                                                 None
331                                                 None
Length: 332, dtype: geometry
'''

12 unary_union

合并所有几何形状为一个单一的几何形状

gpd.GeoSeries(subzone_tst.unary_union)
'''
0    MULTIPOLYGON Z (((103.84418 1.28480 0.00000, 1...
dtype: geometry
'''

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
将一个 `osg::Geometry` 对象拆分成多个 `osg::Geometry` 对象,可以通过以下步骤实现: 1. 遍历原始 `osg::Geometry` 对象的 `osg::PrimitiveSet`,并将其中不同类型的 `PrimitiveSet` 分别存储到不同的 `osg::PrimitiveSet` 容器中(如 `osg::DrawArrays` 存储到 `osg::DrawArrays` 容器中,`osg::DrawElementsUInt` 存储到 `osg::DrawElementsUInt` 容器中等等)。 2. 遍历存储不同类型的 `PrimitiveSet` 的容器,根据每个容器中存储的 `PrimitiveSet` 创建对应的 `osg::Geometry` 对象,并将这些 `osg::Geometry` 对象添加到场景图中。 以下是一个示例代码,可以将一个 `osg::Geometry` 对象拆分成多个 `osg::Geometry` 对象: ```cpp osg::ref_ptr<osg::Geometry> originalGeometry = ...; // 定义不同类型的 PrimitiveSet 容器 std::vector<osg::ref_ptr<osg::DrawArrays>> drawArraysList; std::vector<osg::ref_ptr<osg::DrawElementsUInt>> drawElementsList; // 遍历原始 Geometry 对象的 PrimitiveSet,将不同类型的 PrimitiveSet 存储到不同容器中 for (unsigned int i = 0; i < originalGeometry->getNumPrimitiveSets(); ++i) { osg::PrimitiveSet* primitiveSet = originalGeometry->getPrimitiveSet(i); if (primitiveSet->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) { drawArraysList.push_back(static_cast<osg::DrawArrays*>(primitiveSet)); } else if (primitiveSet->getType() == osg::PrimitiveSet::DrawElementsUIntPrimitiveType) { drawElementsList.push_back(static_cast<osg::DrawElementsUInt*>(primitiveSet)); } } // 创建多个 Geometry 对象,并将它们添加到场景图中 osg::ref_ptr<osg::Group> group = new osg::Group; for (unsigned int i = 0; i < drawArraysList.size(); ++i) { osg::ref_ptr<osg::Geometry> newGeometry = new osg::Geometry; newGeometry->addPrimitiveSet(drawArraysList[i].get()); group->addChild(newGeometry); } for (unsigned int i = 0; i < drawElementsList.size(); ++i) { osg::ref_ptr<osg::Geometry> newGeometry = new osg::Geometry; newGeometry->addPrimitiveSet(drawElementsList[i].get()); group->addChild(newGeometry); } ``` 请注意,这只是一个简单的示例代码,实际应用中可能需要更多的逻辑处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UQI-LIUWJ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值