[gdal-dev] OGR support in gdal.x functions
Even Rouault
even.rouault at spatialys.com
Fri Oct 18 14:46:50 PDT 2024
Jesse,
Le 18/10/2024 à 21:15, Meyer, Jesse R. (GSFC-618.0)[SCIENCE SYSTEMS AND
APPLICATIONS INC] via gdal-dev a écrit :
>
> We have a bunch of legacy code that uses from osgeo import gdal, ogr,
> where raster datasets are created with gdal and vector datasets with
> ogr. However, these don’t mix well when, say, rasterizing a vector
> dataset with gdal.rasterize. The ‘workaround’ is to create a vector
> dataset using gdal:
>
> vector_ds = gdal.GetDriverByName("Memory").Create(“”, 0, 0, 0,
> gdal.GDT_Unknown)
>
> But this is arcane and quite unintuitive.
>
Admitedly true, although the "recommended" way since the GDAL 2.0 GDAL
and OGR unification, at least on the C/C++ side of things.
The good news is that in GDAL 3.10 in Python bindings as well,
ogr.DataSource is just now an alias of gdal.Dataset, so you can use
ogr.GetDriverByName(...).CreateDataSource(...) as a valid gdal.Dataset
>>> from osgeo import ogr
>>> ds = ogr.GetDriverByName('Memory').CreateDataSource('')
>>> ds
<osgeo.gdal.Dataset; proxy of <Swig Object of type 'GDALDatasetShadow *'
at 0x7fc32f3d9600> >
Even
--
http://www.spatialys.com
My software is free, but my time generally not.
Butcher of all kinds of standards, open or closed formats. At the end, this is just about bytes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20241018/285538db/attachment-0001.htm>
More information about the gdal-dev
mailing list