osgeo.ogr module

osgeo.ogr.ApproximateArcAngles(dfCenterX, dfCenterY, dfZ, dfPrimaryRadius, dfSecondaryAxis, dfRotation, dfStartAngle, dfEndAngle, dfMaxAngleStepSizeDegrees) Geometry
class osgeo.ogr.ArrowArray(*args)

Bases: object

Proxy of C++ ArrowArray class.

GetChildrenCount(self) GIntBig
GetLength(self) GIntBig
class osgeo.ogr.ArrowArrayStream(*args, **kwargs)

Bases: object

Proxy of C++ ArrowArrayStream class.

GetNextRecordBatch(self, options=None) ArrowArray
GetSchema(self) ArrowSchema
class osgeo.ogr.ArrowSchema(*args)

Bases: object

Proxy of C++ ArrowSchema class.

GetChild(self, iChild) ArrowSchema
GetChildrenCount(self) GIntBig
GetName(self) char const *
osgeo.ogr.BuildPolygonFromEdges(hLineCollection, bBestEffort=0, bAutoClose=0, dfTolerance=0) Geometry
osgeo.ogr.CreateGeomCoordinatePrecision() GeomCoordinatePrecision
osgeo.ogr.CreateGeometryFromEnvelope(xmin, ymin, xmax, ymax, reference=None) Geometry

Creates a rectangular, axis-aligned Polygon geometry.

Added in version 3.12.

Parameters:
  • xmin (float) -- minimum x coordinate value

  • ymin (float) -- minimum y coordinate value

  • xmax (float) -- maximum x coordinate value

  • ymax (float) -- maximum y coordinate value

  • srs (SpatialReference, optional) -- optional spatial reference to assign to the geometry

Return type:

Geometry

Examples

>>> g = ogr.CreateGeometryFromEnvelope(424788, 25211, 581555, 279799)
>>> g.ExportToWkt()
'POLYGON ((424788 25211,424788 279799,581555 279799,581555 25211,424788 25211))'
osgeo.ogr.CreateRangeFieldDomainDateTime(name, description, min, minIsInclusive, max, maxIsInclusive) FieldDomain
osgeo.ogr.DontUseExceptions()

Disable exceptions in all GDAL related modules (osgeo.gdal, osgeo.ogr, osgeo.osr, osgeo.gnm). Note: prior to GDAL 3.7, this only affected the calling module

class osgeo.ogr.ExceptionMgr(useExceptions=True)

Bases: object

Context manager to manage Python Exception state for GDAL/OGR/OSR/GNM.

Separate exception state is maintained for each module (gdal, ogr, etc), and this class appears independently in all of them. This is built in top of calls to the older UseExceptions()/DontUseExceptions() functions.

Example:

>>> print(gdal.GetUseExceptions())
0
>>> with gdal.ExceptionMgr():
...     # Exceptions are now in use
...     print(gdal.GetUseExceptions())
1
>>>
>>> # Exception state has now been restored
>>> print(gdal.GetUseExceptions())
0
osgeo.ogr.GT_GetSingle(eType) OGRwkbGeometryType
osgeo.ogr.GeneralCmdLineProcessor(papszArgv, nOptions=0) char **
class osgeo.ogr.GeomCoordinatePrecision(*args, **kwargs)

Bases: object

Proxy of C++ OGRGeomCoordinatePrecisionShadow class.

GetFormatSpecificOptions(self, formatName) char **
GetFormats(self) char **
GetMResolution(self) double
GetXYResolution(self) double
GetZResolution(self) double
Set(self, xyResolution, zResolution, mResolution)
SetFormatSpecificOptions(self, formatName, formatSpecificOptions)
SetFromMeter(self, srs, xyMeterResolution, zMeterResolution, mResolution)
class osgeo.ogr.GeomTransformer(*args)

Bases: object

Proxy of C++ OGRGeomTransformerShadow class.

Transform(self, src_geom) Geometry
osgeo.ogr.GetDriver(driver_number) OGRDriverShadow *
osgeo.ogr.GetDriverByName(name) OGRDriverShadow *

Get a vector driver. Like gdal.GetDriverByName(), but only returns drivers that handle vector data.

Parameters:

name (str) -- name of the driver to fetch

Return type:

Driver

Examples

>>> ogr.GetDriverByName('ESRI Shapefile').GetDescription()
'ESRI Shapefile'
>>> ogr.GetDriverByName('GTiff')
>>>
osgeo.ogr.GetDriverCount() int
osgeo.ogr.GetFieldSubtypeByName(subTypeName) OGRFieldSubType
osgeo.ogr.GetFieldTypeByName(typeName) OGRFieldType
osgeo.ogr.GetGEOSVersionMajor() int
osgeo.ogr.GetGEOSVersionMicro() int
osgeo.ogr.GetGEOSVersionMinor() int
osgeo.ogr.GetNonLinearGeometriesEnabledFlag() int
osgeo.ogr.GetOpenDS(ds_number) OGRDataSourceShadow *
osgeo.ogr.GetOpenDSCount() int
osgeo.ogr.GetUseExceptions() int
class osgeo.ogr.MajorObject(*args, **kwargs)

Bases: object

Proxy of C++ GDALMajorObjectShadow class.

GetDescription(self) char const *
GetMetadata(domain='')
GetMetadataDomainList(self) char **
GetMetadataItem(self, pszName, pszDomain='') char const *
GetMetadata_Dict(self, pszDomain='') char **
GetMetadata_List(self, pszDomain='') char **
SetDescription(self, pszNewDesc)
SetMetadata(self, papszMetadata, pszDomain='') CPLErr
SetMetadata(self, pszMetadataString, pszDomain='') CPLErr
SetMetadataItem(self, pszName, pszValue, pszDomain='') CPLErr
osgeo.ogr.Open(utf8_string, update=0) OGRDataSourceShadow *

Open a vector file as a gdal.Dataset. Equivalent to calling gdal.OpenEx() with the gdal.OF_VECTOR flag.

Parameters:

path (str) -- name of the file to open

Returns:

A dataset or None on failure.

Return type:

Dataset or None

Examples

>>> from osgeo import ogr
>>> ogr.GetDriverByName('ESRI Shapefile').GetDescription()
'ESRI Shapefile'
>>> ogr.GetDriverByName('GTiff')
>>>
osgeo.ogr.OpenShared(utf8_string, update=0) OGRDataSourceShadow *

Open a vector file as a gdal.Dataset. If the file has already been opened in the current thread, return a reference to the already-opened gdal.Dataset. Equivalent to calling gdal.OpenEx() with the gdal.OF_VECTOR and gdal.OF_SHARED flags.

Parameters:

path (str) -- name of the file to open

Returns:

A dataset or None on failure.

Return type:

Dataset or None

class osgeo.ogr.PreparedGeometry(*args, **kwargs)

Bases: object

Proxy of C++ OGRPreparedGeometryShadow class.

Contains(self, otherGeom) bool
Intersects(self, otherGeom) bool
osgeo.ogr.RegisterAll()
osgeo.ogr.SetGenerate_DB2_V72_BYTE_ORDER(bGenerate_DB2_V72_BYTE_ORDER) OGRErr
osgeo.ogr.SetNonLinearGeometriesEnabledFlag(bFlag)
osgeo.ogr.TermProgress_nocb(dfProgress, pszMessage=None, pData=None) int
osgeo.ogr.UseExceptions()

Enable exceptions in all GDAL related modules (osgeo.gdal, osgeo.ogr, osgeo.osr, osgeo.gnm). Note: prior to GDAL 3.7, this only affected the calling module