0

The attempt is to change from multipolygon to polygon (shapefile) using:

ogrinfo tmpem122.shp -sql "alter table tmpem122 alter column OGR_GEOMETRY type geometry(polygon, 4326) using st_geometryn(geometry,1)"

I get this error message:

ERROR 1: alter table tmpem122 alter column OGR_GEOMETRY type geometry(polygon, 4326) using st_geometryn(geometry,1) failed, no such field as `OGR_GEOMETRY'.

but according to ogrinfo -sql "select * from tmpem122" tmpem122.shp, the geometry column is OGR_GEOMETRY (or _ogr_geometry_):

Layer name: tmpem122
Geometry: Polygon
Feature Count: 17
Extent: ...
...
...
Geometry Column = _ogr_geometry_
gid: String (10.0)
...

What would it be wrong? Please find the file sample here for your testing: https://file.io/U4XnvYSb69lp

4
  • I would expect a shapefile geometry column to be called the_geom
    – Ian Turton
    Commented Jul 30, 2021 at 10:03
  • Try replacing alter column OGR_GEOMETRY with alter column SHAPE ..or whatever the geometry field is named in your .shp file ..which probably should be SHAPE in order to avoid various oddball problems here and there. If your .shp file's geometry field is named something else, it's very possible this is the root of your issue.
    – elrobis
    Commented Jul 30, 2021 at 17:30
  • the same error message here after changing the column name, would you mind to test the sample file? here you can find it: file.io/U4XnvYSb69lp
    – Gery
    Commented Jul 30, 2021 at 19:23
  • Cross-posted as stackoverflow.com/q/68591393/820534
    – PolyGeo
    Commented Aug 1, 2021 at 10:52

1 Answer 1

2

There may be a solution to the no such field as OGR_GEOMETRY problem but that is irrelevant because it is not possible to do what you are trying. Shapefile specification does not make difference between polygons and multipolygons. ALTER TABLE will not work because it tries to change the field definitions of the table. What you seem to want to do is to update the geometries.

Try this instead

ogrinfo -sql "update polygonz set geometry=st_geometryn(geometry,1)" polygonz.shp -dialect sqlite

Notice that you must use the SQLite dialect because only that has the ST_GeometryN function and for SQLite dialect the name of the geometry field is usually geometry.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.