Get function with gdal / ogr
This looks like something the function should already be doing, but I can't find it.
What I am ultimately trying to do is: I have a shapefile with three functions that show the bounding boxes; I want to use one of these functions to select all the functions inside it in another shape file or polygons. I have this launch done with ogr2ogr using the -clipsrc and -clipsrcwhere flags to select my bounding box from my frame shapefile. This works great, but I can't include or exclude polygons that fall along the border, and I don't want them to be clipped. So, I figured I use the -spat flag instead and just import the scale of the polygon box.
I know I can get the size of my polygon with:
polygon = 'mouth'
inDriver = ogr.GetDriverByName("ESRI Shapefile")
inDataSource = inDriver.Open(extent_shpfile, 1)
inLayer = inDataSource.GetLayer()
select = "name = '" + polygon + "'"
inLayer.SetAttributeFilter(select)
for feature in inLayer: #inLayer is always of size one because polygon is a unique value
geom=feature.GetGeometryRef()
From here I can parse the geom values ββto get the min and max x and y values. Isn't there a call to ogr for this already (like inLayer.GetFeatureExtent () or inLayer.GetExtent (feature_fid)? The latter just returns the size of the layer and the former doesn't exist, but it needs to be parsed from the geometry of the object feels awkward.
source to share
It turns out there is a built-in function for this, my 4 hours of searching (before the original post) just couldn't bring it to light until I switched to working on something else and stumbled upon it by accident.
extent = geom.GetEnvelope()
Hopefully this post will save someone else a headache when trying to find this feature.
source to share