【问题标题】:How do I match the projection of my cartopy map with that of a shapefile?如何将我的 cartopy 地图的投影与 shapefile 的投影相匹配?
【发布时间】:2016-11-02 12:42:40
【问题描述】:

我正在尝试将 Coastlines() 地图的投影与 shapefile 的投影合成,其 .prj 文件显示:

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",
SPHEROID["WGS_1984",6378137.0,298.257223563]],
PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]

我的尝试是:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.io import shapereader

# set up a map with coastlines around Auckland:
plt.figure(figsize=(10, 10))
platecarree = ccrs.PlateCarree(globe=ccrs.Globe(datum='WGS84'))

ax = plt.axes(projection=platecarree)
extent = [174.25, 175.25, -37.5, -36.5]
ax.set_extent(extent)
ax.coastlines('10m',color='red')

# read in shapefile and plot the polygons:
shp2 = shapereader.Reader('auckland_geology_wgs84gcs.shp')
formations = shp2.records()

for formation in formations:
     # plot water blue, and all other rocks yellow
     if formation.attributes['MAIN_ROCK'] == b'                                ':
         ax.add_geometries(formation.geometry, ccrs.PlateCarree(),facecolor='blue',alpha=.1)
     else:
         ax.add_geometries(formation.geometry, ccrs.PlateCarree(), facecolor='yellow',alpha=.1)
plt.show()

我尝试在我的 platecarree 定义中为地球参数提供半径和 prj 文件中的反向展平,但如果我设置甚至更改这些数字,我没有看到输出有任何变化。

此外,使用定义的“platecarree”投影(使用 WGS84 调用地球)作为 add_geometries 调用中的 crs,我的输出为空白。

按原样,结果在我看来就像a projection mismatch

【问题讨论】:

    标签: matplotlib projection cartopy


    【解决方案1】:

    我尝试使用 QGIS 和从 Natural Earth(10m 海岸线)和 GADM(NZ adm0 级别)下载的数据来重现您的问题。看起来 NE10m 海岸线是罪魁祸首! GADM 与您的地质层完美对齐,而 NE10m 关闭(并变形)。 screenshot of QGIS with Geological map & coastlines

    【讨论】:

      猜你喜欢
      • 2017-02-17
      • 1970-01-01
      • 2017-04-24
      • 2017-02-20
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多