1

For now, I can use fiona to read one specific polygon and plot it like this:

## read the shapefile
import fiona
import shapely
from shapely.geometry import shape
c = fiona.open("xxx.shp")
pol = c.next()
geom = shape(pol['geometry'])
poly_data = pol["geometry"]["coordinates"][0]
poly = Polygon(poly_data)   

Output like this:

http://i13.tietuku.com/65d7d9d6a423a5d3.png

But when the shapefile is composed by several shapefile like this:

fig = plt.figure(figsize =(8,6))
ax = plt.gca()
map =   Basemap(llcrnrlon=114.3,llcrnrlat=37.95,urcrnrlon=114.75,urcrnrlat=38.2)
map.readshapefile("xxx",'xxx',zorder =1,)
patches=[]
cs=plt.cm.Blues_r(np.arange(21)/21.)
for info, shape in zip(map.xxx_info, map.xxx):
    x,y=zip(*shape)
    patches.append( Polygon(np.array(shape), True) )  # facecolor= '#6582B3'
ax.add_collection(PatchCollection(patches, facecolor= cs,edgecolor='none', linewidths=1.5, zorder=2,alpha = 0.8))

http://i13.tietuku.com/a331edcbeec29d5e.png

I can't use the similar code above to get 4 polygon represent the 4 different area.

My question

How to use fiona to read and transform it into several fiona.polygon(In my example, I want to get four polygon). And then, I can use each polygon to do more operation.

Han Zhengzu
  • 3,694
  • 7
  • 44
  • 94
  • 1
    "I can't use the similar code above to get 4 polygon represent the 4 different area." -- why not, what happens? – Brian Cain Feb 29 '16 at 05:08
  • 2
    Try calling 'next()' on 'c' multiple times to iterate the contents. Or try a 'for' loop to iterate the contents of 'c'. – songololo Feb 29 '16 at 06:34

0 Answers0