常见空间数据格式包括:文本xy坐标(包括.dat, .csv, .xls, .txt)、.shp、GeoJson、图像(包括GeoTiff等)、netCDF。以上格式数据在Python中皆可处理,不过可能需要用到多个不同的工具包,本文将介绍作者所熟悉的几种除GDAL外的Python包供读者探讨。
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([70, 140, 15, 55])
ax.stock_img();
ax.scatter(data['经度'],data['纬度'],s=0.3,c='g');
plt.figure(figsize=(4,3))
ax = data['气压传感器拔海高度(米)'].plot(kind='hist');
ax.set_xlim([0,5000])
plt.xlabel('elevation (m)');
c_list = [country for country in countries if country.attributes['ADMIN']=='China']
countries = reader.records()
def get_record(key,value):
countries = reader.records()
result = [country for country in countries if country.attributes[key]==value]
countries = reader.records()
return result
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([45,90,35,55])
for r in cas:
ax.add_geometries(r.geometry,ccrs.PlateCarree(),
facecolor='green',edgecolor='black',alpha=0.2,linewidth=0.5)
ax.text(r.geometry.centroid.x,r.geometry.centroid.y,r.attributes['ADMIN'],
horizontalalignment='center',
verticalalignment='center',
transform=ccrs.Geodetic())
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([45,90,35,55])
for r in cas:
color = cm.Greens((r.attributes['POP_EST'] - pop_min) / (pop_max - pop_min))
ax.add_geometries(r.geometry,ccrs.PlateCarree(),
facecolor=color,edgecolor='black',linewidth=0.5)
ax.text(r.geometry.centroid.x,r.geometry.centroid.y,r.attributes['ADMIN'],
horizontalalignment='center',
verticalalignment='center',
transform=ccrs.Geodetic())
sm = plt.cm.ScalarMappable(cmap='Greens', norm=plt.Normalize(vmin=pop_min, vmax=pop_max))
# fake up the array of the scalar mappable. Urgh...
sm._A = []
plt.colorbar(sm);
plt.title('Population estimates');
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([45,90,35,55])
for r in cas:
color = cm.Greens((r.attributes['GDP_MD_EST'] - gdp_min) / (gdp_max - gdp_min))
ax.add_geometries(r.geometry,ccrs.PlateCarree(),
facecolor=color,edgecolor='black',linewidth=0.5)
ax.text(r.geometry.centroid.x,r.geometry.centroid.y,r.attributes['ADMIN'],
horizontalalignment='center',
verticalalignment='center',
transform=ccrs.Geodetic())
ax.set_xticks([45,55,65,75,85], crs=ccrs.PlateCarree())
ax.set_yticks([35,45,55], crs=ccrs.PlateCarree())
lon_formatter = LongitudeFormatter(zero_direction_label=True)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
plt.title('GDP estimates');