Skip to Content

Shapely-shpUtils

  1. >>> import shpUtils
  2. >>> from shapely.geometry import Polygon
  3. >>> shp = 'testpoly.shp'
  4. >>> polys = []
  5. >>> for element in shpUtils.loadShapefile(shp):
  6. ... for part in element['shp_data']['parts'] :
  7. ... poly=[]
  8. ... for pt in part['points'] :
  9. ... if pt.has_key('x') and pt.has_key('y') :
  10. ... poly.append((pt['x'], pt['y']))
  11. ... poly = tuple(poly)
  12. ... p = Polygon(poly)
  13. ... polys.append(p)
  14.  
  15. >>> for pol in polys:
  16. ... print pol.wkt
  17. ...
  18. POLYGON ((0.0909447004608295 0.8075576036866359, 0.1416359447004608 0.8014746543778801, 0.3606221198156682 0.7021198156682027, 0.2409907834101383 0.5480184331797234, 0.0868894009216590 0.5845161290322580, 0.0544470046082949 0.7426728110599077, 0.0909447004608295 0.8075576036866359))
  19. POLYGON ((0.2754608294930876 0.7933640552995391, 0.5370276497695853 0.8136405529953916, 0.4173963133640554 0.5926267281105990, 0.2267972350230415 0.6777880184331797, 0.2267972350230415 0.7447004608294931, 0.2754608294930876 0.7933640552995391))