Skip to Content

Shapely-ogr

  1. >>> from osgeo import ogr
  2. >>> from shapely.wkb import loads
  3. >>> source = ogr.Open("testpoly.shp")
  4. >>> couche = source.GetLayerByName("testpoly")
  5. >>> for element in couche:
  6. ... geom = loads(element.GetGeometryRef().ExportToWkb())
  7. ... if geom.geom_type == 'Point':
  8. ... print geom.type
  9. ... print geom
  10. ... if geom.geom_type == 'LineString':
  11. ... print geom.type
  12. ... print geom
  13. ... if geom.geom_type == 'MultiLineString':
  14. ... print geom.type
  15. ... print geom
  16. ... if geom.geom_type == 'MultiPolygon':
  17. ... print geom.type
  18. ... print geom
  19. ... if geom.geom_type == 'Polygon':
  20. ... print geom.type
  21. ... print geom
  22. ...
  23. Polygon
  24. 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))
  25. Polygon
  26. 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))