I'm trying to create a polygon shapefile from a bounding box in ogr but it creates an empty shapefile. Here's the code:
from osgeo import ogr
infc = r"C:\Temp\infc.shp"
layer_name = 'outfc_bbx'
driver = ogr.GetDriverByName("ESRI Shapefile")
vector = driver.Open(infc)
in_lyr = vector.GetLayer()
driver = ogr.GetDriverByName('ESRI Shapefile') # will select the driver foir our shp-file creation.
shapeData = driver.CreateDataSource(r"C:\Temp") #so there we will store our data
out_lyr = shapeData.CreateLayer(layer_name, in_lyr.GetSpatialRef(), ogr.wkbPolygon) #this will create a corresponding layer for our data with given spatial information.
out_lyr.CreateFields(in_lyr.schema)
out_defn = out_lyr.GetLayerDefn()
out_feat = ogr.Feature(out_defn)
feature = in_lyr.GetFeature(0)
geom = feature.GetGeometryRef()
geom.GetEnvelope()
(minX, maxX, minY, maxY) = geom.GetEnvelope()
ring = ogr.Geometry(ogr.wkbLinearRing)
ring.AddPoint(minX, minY)
ring.AddPoint(maxX, minY)
ring.AddPoint(maxX, maxY)
ring.AddPoint(minX, maxY)
ring.AddPoint(minX, minY)
polygon_env = ogr.Geometry(ogr.wkbPolygon)
#poly = polygon_env.GetGeometryRef(0)
out_feat.SetGeometry(polygon_env)
out_lyr.CreateFeature(out_feat)