2017-10-08 65 views
1

我正在使用shapefile。我没有任何问题阅读,绘制它,并使地图漂亮。但是,当我绘制它(使用QGIS将其重新投影到正确的EPSG之后)时,边缘都是锯齿状的(如下所示)。有没有办法使用Python来平滑它? enter image description here平滑shapefile输出 - 底图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这些shape文件。

回答

1

This question的答案解释了Shapely Package如何基于Douglas-Puecker算法提供简化方法。