Hi I can update new column with area of a polygon object, but don't know, how to update new column in polyline layer with length of polyline.

This works very well for AREA:

for %%f in (*.tab) do (
   ogrinfo %%f -sql "ALTER TABLE %%~nf DROP COLUMN PLO1"
   ogr2ogr %%~nf_new%%~xf %%f -sql "SELECT *, OGR_GEOM_AREA AS PLO1 FROM %%~nf" -f "MapInfo file"
   del %%~nf.* /Q
   ren %%~nf_new.* %%~nf.*

How to update Object LENGTH the same way, please?

I can do it in MapInfo:

Update tblnm Set Plo1 = ObjectLen(obj, "m")

But update with OGR would be more usefull for me in this case.


In order to access geometry characteristics in ogr2ogr you should force using SQLite by adding -dialect SQLite. Then the function for obtaing line/linestring length is ST_Length(geometry_field_name)

So try changing the third line of your Area solution into:

ogr2ogr %%~nf_new%%~xf %%f -dialect SQLite -sql "SELECT *, ST_Length(geom) AS PLO1 FROM %%~nf" -f "MapInfo file"

Be sure to pass the right geometry field name to ST_Length function.

  • Thanks for Your advice. I've tried this yesterday too. But the problem is the right name of the geom field. Is there some rule for it, or some function which returns name of geometry field? Please. – Pepa Beneš Jul 4 '17 at 12:30
  • 1
    ogr2ogr %%~nf_new%%~xf %%f -dialect SQLite -sql "SELECT *, ST_Length(geometry) AS PLO1 FROM %%~nf" -f "MapInfo file" IS THE RIGHT WAY :-) – Pepa Beneš Jul 4 '17 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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