Search code examples
windowscommand-linegdalwktogr2ogr

Command line issue with ogr2ogr and WKT


I want to clip a shapefile with ogr2ogr using a POLYGON defined as wkt.

According to the documentation it should be possible to use WKT as clipsrc [1]

But I cant get the syntax right, I the following there is some simplified commands, that gives me the error.

I have tried the following, all it does is resulting in

FAILURE: Invalid geometry. Must be a valid POLYGON or MULTIPOLYGON WKT

Commands I have used:

ogr2ogr -clipsrc "POLYGON ^(^(10 0, 2 10, 34 0^)^)"

ogr2ogr -clipsrc POLYGON ^(^(10 0, 2 10, 34 0^)^)

ogr2ogr -clipsrc "POLYGON ((10 0, 2 10, 34 0))"

ogr2ogr -clipsrc POLYGON ((10 0, 2 10, 34 0))

[1] http://www.gdal.org/ogr2ogr.html


Solution

  • See Well-known text to get an overview of the markup. Your last example is the closest resemblance to WKT. Closing the linear ring and enclosing the string with quotes, try:

    ogr2ogr -clipsrc "POLYGON ((10 0, 2 10, 34 0, 10 0))"
    

    which describes the shape of a triangle that looks like this:

    triangle