平滑 shapefile 输出 - 底图 python
Smoothing a shapefile output - Basemap python
我正在使用 shapefile。我没有任何问题阅读它,绘制它,并使地图看起来很漂亮。然而,当我绘制它时(在使用 QGIS 将其重新投影到正确的 EPSG 之后),边缘都是锯齿状的(如下所示)。有没有办法使用 Python?
来平滑它
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
import numpy as np
#insert code for basemap setup m = Basemap(...)
m.arcgisimage(service = 'ESRI_StreetMap_World_2D', xpixels = 1000, verbose = True)
states_info = m.readshapefile('shapefiles/states', 'states')
spc_info = m.readshapefile('shapefiles/corrected_epsg', 'spc', drawbounds = False)
patches = []
ax = plt.gca()
for info, shape in zip(m.spc_info, m.spc):
x, y = zip(*shape)
if info['DN'] == 2:
color = '#80c580'
zorder = 2
patches.append( Polygon(np.array(shape), True))
if info['DN'] == 5:
color = '#f7f780'
zorder = 3
patches.append( Polygon(np.array(shape), True))
ax.add_collection(PatchCollection(patches, facecolor= color, zorder=zorder, alpha = 0.7))
Source 对于这些 shapefile。
This question 的回答解释了 Shapely Package 如何具有基于 Douglas-Puecker 算法的 Simplify 方法。
我正在使用 shapefile。我没有任何问题阅读它,绘制它,并使地图看起来很漂亮。然而,当我绘制它时(在使用 QGIS 将其重新投影到正确的 EPSG 之后),边缘都是锯齿状的(如下所示)。有没有办法使用 Python?
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
import numpy as np
#insert code for basemap setup m = Basemap(...)
m.arcgisimage(service = 'ESRI_StreetMap_World_2D', xpixels = 1000, verbose = True)
states_info = m.readshapefile('shapefiles/states', 'states')
spc_info = m.readshapefile('shapefiles/corrected_epsg', 'spc', drawbounds = False)
patches = []
ax = plt.gca()
for info, shape in zip(m.spc_info, m.spc):
x, y = zip(*shape)
if info['DN'] == 2:
color = '#80c580'
zorder = 2
patches.append( Polygon(np.array(shape), True))
if info['DN'] == 5:
color = '#f7f780'
zorder = 3
patches.append( Polygon(np.array(shape), True))
ax.add_collection(PatchCollection(patches, facecolor= color, zorder=zorder, alpha = 0.7))
Source 对于这些 shapefile。
This question 的回答解释了 Shapely Package 如何具有基于 Douglas-Puecker 算法的 Simplify 方法。