Opened 10 years ago

Closed 10 years ago

#5448 closed defect (worksforme)

ogr2ogr with -clipsrc and bounding box sometimes produces invalid output

Reported by: ysid Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: 1.9.1
Severity: normal Keywords:
Cc: abarton, Kyle Shannon

Description

When ogr2ogr is called with the "-clipsrc" argument, and the values passed into this argument are four numbers (a bounding box), and the output is a shapefile, the output is sometimes empty and/or corrupt. Since I am not at liberty to share the data being used, I have provided some details to illustrate the problem:

1 - Before calling ogr2ogr:

  • File "Acontours.shp" has been produced using gdal_contour from a DEM file. It is a 2-m contour file. The file size of the .shp file is 102 MB, and it looks good in ArcMap.

2 - ogr2ogr call to produce "Bcontours.shp":

ogr2ogr.exe -select elevation -clipsrc <minx> <miny> <maxx> <maxy> Bcontours.shp Acontours.shp

3 - After ogr2ogr call:

  • File "Bcontours.shp" is 4.98 MB. When viewing in ArcMap, there are no visible features, and the attribute table is empty. The DBF file seems to contain plenty of records. This shapefile is corrupt.

As a workaround, I seem to be able to write out my bounding box to a shapefile and use this as a clipping source with the -clipsrc argument. The output from this option looks correct in ArcMap.

If you need the source data, I will need to ask for permission to share it, but I understand you may need it in order to replicate the problem.

Change History (5)

comment:1 by Kyle Shannon, 10 years ago

Cc: Kyle Shannon added

comment:2 by Even Rouault, 10 years ago

Access to the source data and the exact command line you've used would be usefull. It is not obvious why -clipdst with the 4 values wouldn't work whereas it would work with a shapefile

comment:3 by ysid, 10 years ago

I got permission from the supplier to use their data for debugging purposes. Please destroy it once you are done. Here is the location of the data:

  • FTP site: ftp.i3.com
  • Login: GDALTrac
  • Password: ZvRzLI8e
  • Filename: ticket5448.zip

The file contains 3 items: the "A" shapefile, a text file with the command line used to generate the "B" shapefile, and the "B" shapefile which is corrupt.

comment:4 by Even Rouault, 10 years ago

I don't reproduce the issue. This generates a valid shapefile, that displays well in QGIS. Perhaps your GEOS version is too old ? I add to add -skip to your command line since the intersection generates a few degenerate non-line geometries (which is not unexpected):

ERROR 1: Attempt to write non-linestring (GEOMETRYCOLLECTION) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (GEOMETRYCOLLECTION) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (MULTIPOINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (MULTIPOINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (GEOMETRYCOLLECTION) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (GEOMETRYCOLLECTION) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (MULTIPOINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (MULTIPOINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (MULTIPOINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (GEOMETRYCOLLECTION) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (MULTIPOINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (MULTIPOINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Attempt to write non-linestring (MULTIPOINT) geometry to ARC type shapefile.

comment:5 by ysid, 10 years ago

Resolution: worksforme
Status: newclosed

OK, I understand now. I should have been using the "-skipfailures" flag. I got confused because my program that captures STOUT and STDERR wasn't reporting anything, so I didn't realize it was encountering an error early on. Just a suggestion: it's not very obvious how important "-skipfailures" is. It might be good to have that on by default, or give it more importance in the documentation.

Note: See TracTickets for help on using tickets.