python第三方库geopandas中的数据结构分为两种,分别是GeoSeries和GeoDataFrame ,这两个数据结构是不是在numpy中见过Series和DataFrame呢。
GeoSeries
是一个向量,其中向量中的每个条目是对应于一个观察的一组形状。一个条目可能只包含一个形状(如单个多边形)或多个形状,
geopandas有几个基本的几何对象类(实际上是形状对象):
- 积分/多点
- 线/多线
- 多边形/多边形
属性
area:形状区域(投影单位 - 见投影)bounds:每个形状的每个轴上的最大和最小坐标的元组total_bounds:整个GeoSeries的每个轴上的最大和最小坐标的元组geom_type:几何类型。is_valid:测试坐标是否形成合理几何形状的形状(根据此)
基本方法
distance(other):返回Series每个条目的最小距离othercentroid:GeoSeries质心的返回representative_point():GeoSeries保证在每个几何体内的点的返回。它不返回重心。to_crs():改变坐标参考系。看预测plot():情节GeoSeries。请参见映射。
关系测试
geom_almost_equals(other):形状几乎相同other(当浮点精度问题使形状略有不同时很好)contains(other):是包含在其中的形状otherintersects(other):形状相交other
GeoDataFrame
GeoDataFrame数据是包含GeoSeries的多维表格
An example using the worlds GeoDataFrame:
In [1]: world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
In [2]: world.head()
Out[2]:
pop_est ... geometry
0 28400000.0 ... POLYGON ((61.21081709172574 35.65007233330923,...
1 12799293.0 ... (POLYGON ((16.32652835456705 -5.87747039146621...
2 3639453.0 ... POLYGON ((20.59024743010491 41.85540416113361,...
3 4798491.0 ... POLYGON ((51.57951867046327 24.24549713795111,...
4 40913584.0 ... (POLYGON ((-65.50000000000003 -55.199999999999...
[5 rows x 6 columns]
#Plot countries
In [3]: world.plot();
Currently, the column named “geometry” with country borders is the active geometry column:
In [4]: world.geometry.name
Out[4]: 'geometry'
We can also rename this column to “borders”:
In [5]: world = world.rename(columns={'geometry': 'borders'}).set_geometry('borders')
In [6]: world.geometry.name
Out[6]: 'borders'
Now, we create centroids and make it the geometry:
In [7]: world['centroid_column'] = world.centroid
In [8]: world = world.set_geometry('centroid_column')
In [9]: world.plot();

上述均摘自http://geopandas.org/(geopamdas第三方库官方文档)
浙公网安备 33010602011771号