Skip to main content
Tweeted twitter.com/StackGIS/status/1105619580016312321
added 115 characters in body
Source Link
Alex R
  • 315
  • 1
  • 2
  • 9

Im learning to use shapely and have two shapefiles--forest, and basins. They are multipart. The two shapefiles clearly intersect (basins is completely within forest). But the way I've gone about it only gets the feature at index 0 of each shapefile, which don't intersect. I know where this is taking place in the script, but how do I get the whole polygon shape as wkt instead of just one record? Do I build a list of the wkt geometry one record at a time?

# Basins shapefile to wkt
basins = ogr.Open("data/Basins.shp")
basins_layer = basins.GetLayer(0)
basins_feature = basins_layer.GetFeature(0) # This is the line
# I'm thinking there should probably be a loop here to get the geometry of the whole shapefile
basins_geometry = basins_feature.GetGeometryRef()
basins_wkt = shapely.wkt.loads(basins_geometry.ExportToWkt())

How do I loop through the whole shapefile and build the outer polygon as wkt or is there another function to get the outer boundary of the shapefile? I guess this is called the outer ring. I want wkt of the whole shapefile exterior, rather than the individual polygons that make it up.

Im learning to use shapely and have two shapefiles--forest, and basins. They are multipart. The two shapefiles clearly intersect (basins is completely within forest). But the way I've gone about it only gets the feature at index 0 of each shapefile, which don't intersect. I know where this is taking place in the script, but how do I get the whole polygon shape as wkt instead of just one record? Do I build a list of the wkt geometry one record at a time?

# Basins shapefile to wkt
basins = ogr.Open("data/Basins.shp")
basins_layer = basins.GetLayer(0)
basins_feature = basins_layer.GetFeature(0) # This is the line
# I'm thinking there should probably be a loop here to get the geometry of the whole shapefile
basins_geometry = basins_feature.GetGeometryRef()
basins_wkt = shapely.wkt.loads(basins_geometry.ExportToWkt())

How do I loop through the whole shapefile and build the outer polygon as wkt or is there another function to get the outer boundary of the shapefile?

Im learning to use shapely and have two shapefiles--forest, and basins. The two shapefiles clearly intersect (basins is completely within forest). But the way I've gone about it only gets the feature at index 0 of each shapefile, which don't intersect. I know where this is taking place in the script, but how do I get the whole polygon shape as wkt instead of just one record? Do I build a list of the wkt geometry one record at a time?

# Basins shapefile to wkt
basins = ogr.Open("data/Basins.shp")
basins_layer = basins.GetLayer(0)
basins_feature = basins_layer.GetFeature(0) # This is the line
# I'm thinking there should probably be a loop here to get the geometry of the whole shapefile
basins_geometry = basins_feature.GetGeometryRef()
basins_wkt = shapely.wkt.loads(basins_geometry.ExportToWkt())

How do I loop through the whole shapefile and build the outer polygon as wkt or is there another function to get the outer boundary of the shapefile? I guess this is called the outer ring. I want wkt of the whole shapefile exterior, rather than the individual polygons that make it up.

Source Link
Alex R
  • 315
  • 1
  • 2
  • 9

How to return WKT of entire polygon with shapely?

Im learning to use shapely and have two shapefiles--forest, and basins. They are multipart. The two shapefiles clearly intersect (basins is completely within forest). But the way I've gone about it only gets the feature at index 0 of each shapefile, which don't intersect. I know where this is taking place in the script, but how do I get the whole polygon shape as wkt instead of just one record? Do I build a list of the wkt geometry one record at a time?

# Basins shapefile to wkt
basins = ogr.Open("data/Basins.shp")
basins_layer = basins.GetLayer(0)
basins_feature = basins_layer.GetFeature(0) # This is the line
# I'm thinking there should probably be a loop here to get the geometry of the whole shapefile
basins_geometry = basins_feature.GetGeometryRef()
basins_wkt = shapely.wkt.loads(basins_geometry.ExportToWkt())

How do I loop through the whole shapefile and build the outer polygon as wkt or is there another function to get the outer boundary of the shapefile?