[gdal-dev] ogr2ogr.py sqlite dialect unsupported?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] ogr2ogr.py sqlite dialect unsupported?

Martin Lacayo-Emery
Hello,

I complied GDAL 3.0.1 from source with Python, SQLite, and SpatiLite
enabled. I am trying to dissolve polygons in a Shapefile with the
following command:

ogr2ogr output.shp input.shp -dialect sqlite -sql "SELECT
ST_Union(geometry) FROM input"

This works from the command line, but not as I would like from a
Python call to ogr2ogr.main, although other calls do work. I see from
the code that ogr2ogr.py does not support the dialect parameter, but
ogrinfo.py does.

Is there a way for me to do this from Python without a system call?

Should I report this a bug/feature request to the GitHub repository?

For my own enlightenment, does anyone understand why this command
works from the command line?

The full 32 line script I am working on is here:

https://github.com/mlacayoemery/esws/blob/master/tools/wy_preprocess.py

Thank you,
Martin
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: ogr2ogr.py sqlite dialect unsupported?

Even Rouault-2
ogr2ogr.py is a toy / sample file which receives little maintainance, and was
mostly a one-time port of the ogr2ogr.cpp source, which is the on used by the
command line utility.

You may use the 'librarified' ogr2ogr with the gdal.VectorTranslate() Python
function. Examples at
https://github.com/OSGeo/gdal/blob/master/autotest/utilities/
test_ogr2ogr_lib.py#L63

Even

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: ogr2ogr.py sqlite dialect unsupported?

Martin Lacayo-Emery
Thank you, the following code worked perfectly:

import os
import osgeo.gdal

name, ext = os.path.splitext(os.path.basename(in_path))
srcDS = osgeo.gdal.OpenEx(in_path)
ds = osgeo.gdal.VectorTranslate(out_path, srcDS, SQLStatement="SELECT
ST_Union(geometry) FROM " + name , SQLDialect='sqlite')

Cheers,
Martin

On Mon, Sep 2, 2019 at 6:19 PM Even Rouault <[hidden email]> wrote:

>
> ogr2ogr.py is a toy / sample file which receives little maintainance, and was
> mostly a one-time port of the ogr2ogr.cpp source, which is the on used by the
> command line utility.
>
> You may use the 'librarified' ogr2ogr with the gdal.VectorTranslate() Python
> function. Examples at
> https://github.com/OSGeo/gdal/blob/master/autotest/utilities/
> test_ogr2ogr_lib.py#L63
>
> Even
>
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev