TransWikia.com

Geometry buffer updating with ogr2ogr

Geographic Information Systems Asked on March 13, 2021

I am trying to modify a dataset by replacing the geometry of each feature by its buffer. I try to do it directly, in update mode (not very secure I know). Here is what I tried:

ogr2ogr -update test.gpkg test.gpkg -dialect sqlite -sql "UPDATE test SET geom = ST_buffer(geom,100000)"

but it does not work. No error is returned but the dataset has then empty geometries.

Any idea about something I missed ?

The geometry column is geom and the CRS is in meters, so that the distance 100000 is realistic.

One Answer

You are trying to use wrong tool for updating your GeoPackage. It is undefined what your ogr2ogr command does and it is not worth further investigations. It is just wrong tool.

Use ogrinfo instead. It works for me with GDAL 3.2 and with the following command.

I made this GeoPackage to start with:

ogrinfo polygon.gpkg -al
INFO: Open of `polygon.gpkg'
      using driver `GPKG' successful.

Layer name: polygon
Metadata:
  DBF_DATE_LAST_UPDATE=2020-11-06
Geometry: Polygon
Feature Count: 1
Extent: (665.000000, 155.000000) - (946.000000, 372.000000)
Layer SRS WKT:
(unknown)
FID Column = fid
Geometry Column = geom
OGRFeature(polygon):0
  POLYGON ((665 294,817 372,946 155,665 294))

Notice that the geometry type is Polygon. ST_Buffer function creates polygons as well so there will me no problem in updating the geometries. If I had geometry type Point then triggers would prevent the insertion of polygons into that table.

Then I run ogrinfo command with SQL dialect "indirect_SQLite" in order to get the SpatiaLite functions. Otherwise GDAL is running commands directly against GeoPackage with the standard functions without loading the mod_spatialite extension. In that case ST_Buffer is not found and GDAL errors out.

ogrinfo -dialect indirect_sqlite -sql "update polygon set geom=ST_Buffer(geom,10)" polygon.gpkg

The geometry of the only feature in the GeoPackage has been changed.

OGRFeature(polygon):0
  POLYGON ((660.566182558625 285.036671215639,660.101288123696 285.2820517349,659.649930712494 285.551523295949,659.213357599026 285.844341245292,658.792775202....

Correct answer by user30184 on March 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP