如无特殊说明,数据主要来自: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
'''