2

I'm trying to clip a csv-file containing xyz-data (points) by an irregular shaped polygon in ogr2ogr. My code runs without any errors or warnings, but it returns an exact copy of the input-csv. What am I doing wrong?

My code is: ogr2ogr -f CSV output.csv -clipsrc clip_polygon.shp -clipsrclayer clip_polygon input.vrt

The vrt-file looks like:

<OGRVRTDataSource>
    <OGRVRTLayer name="test_layer">
       <SrcDataSource>input.csv</SrcDataSource>
       <GeometryType>wkbPoint</GeometryType>
       <LayerSRS>EPSG:25831</LayerSRS>
       <GeometryField encoding="PointFromColumns" x="field_1" y="field_2" z="field_3"/>
   </OGRVRTLayer>
</OGRVRTDataSource>
| improve this question | | | | |
  • Has the polygon shapefile the same CRS, and do the extents form ogrinfo and gdalinfo match? – AndreJ Apr 1 '15 at 14:47
  • Yes, both the .shp as the .vrt have the same EPSG-code. When I visualise the .csv and and .shp in ArcGIS, it is clear that they both have the same spatial extent. – daarende Apr 2 '15 at 8:59
  • I don't know if it makes a difference, but I put dst_datasource_name src_datasource_name always together behind the options. And I think to remember that csv, vrt and <OGRVRTLAYER name > should be the same. – AndreJ Apr 2 '15 at 9:28
  • I'm experiencing the same issue. If I set the output data type to GeoJSON, it filters correctly by my -clipsrc. I can then convert that output back to CSV. Seems like bug. – Charlie Hofmann Oct 16 '17 at 18:47
1

For some reason, adding -lco GEOMETRY=AS_WKT to my ogr2ogr command worked.

Here's my VRT (it's polygon data, not point):

<OGRVRTDataSource>
        <OGRVRTLayer name="data">
            <SrcDataSource relativeToVRT="1">data.csv</SrcDataSource>
            <SrcLayer>data</SrcLayer>
            <GeometryType>wkbPolygon</GeometryType>
            <GeometryField encoding="WKT" field='field_1'/>
        </OGRVRTLayer>
</OGRVRTDataSource>

This ogr2ogr command didn't filter the input CSV at all: ogr2ogr -f CSV output.csv data.vrt -clipsrc -50.0 -10.0 -40.0 0.0

But this one did: ogr2ogr -f CSV output.csv data.vrt -clipsrc -50.0 -10.0 -40.0 0.0 -lco GEOMETRY=AS_WKT

No idea why a layer creation option (-lco) would have this affect, but it seems to be working.

| improve this answer | | | | |

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.