5

I am trying to replace a naïve bounding box clip when I download data for a study area using ogr2ogr, to one that uses a study area layer with an actual geometry.

ogr2ogr supports both -clipdst and -clipsrc arguments. The documentation gives this explantory text:

Clip geometries to one of the following:

  • the specified bounding box (expressed in source SRS)
  • a WKT geometry (POLYGON or MULTIPOLYGON expressed in source SRS)
  • one or more geometries selected from a datasource
  • the spatial extent of the -spat option if you use the spat_extent keyword.

When specifying a datasource, you will generally want to use -clipsrc in combination of the -clipsrclayer, -clipsrcwhere or -clipsrcsql options.

However, it is the same text for both -clipdst and -clipsrc. So I'm left wondering what the difference is. My assumption is that -clipsrc applies a clip (whether bbox, geom, etc.) to the source, whereas -clipdst applies to the output that is being written.

My situation is this: I'm using a layer (from PostgreSQL) to clip geometries being dowloaded from a WFS endpoint to a GPKG. Should I use -clipsrc or -clipdst?

Presumably -clipsrc might put the work onto the server, but -clipdst (without -clipsrc) would do it on the client end, but I don't know. I don't know if it's redundant to give both. None of the layers I'm downloading are so large that I can't download them in their entirety and then clip—presumably if that wasn't the case I'd need to -clipsrc.

1 Answer 1

7

If you read more carefully https://gdal.org/programs/ogr2ogr.html you will notice that the texts are not the same.

-clipsrc [xmin ymin xmax ymax]|WKT|datasource|spat_extent

  • the specified bounding box (expressed in source SRS)

  • a WKT geometry (POLYGON or MULTIPOLYGON expressed in source SRS)

-clipdst [ ]|WKT|datasource

  • the specified bounding box (expressed in destination SRS)

  • a WKT geometry (POLYGON or MULTIPOLYGON expressed in destination SRS)

If you do not re-project the data with -t_srs then the both options will give the same result.

Maybe the old documentation described the difference better. See for example https://manpages.ubuntu.com/manpages/xenial/man1/ogr2ogr.1.html

-clipdst xmin ymin xmax ymax

(starting with GDAL 1.7.0) clip geometries after reprojection to the specified bounding box (expressed in dest SRS), WKT geometry (POLYGON or MULTIPOLYGON) or from a datasource.

1
  • OK, good catch. I'm reprojecting as I download, so I should use -clipdst and ensure that my datasource used with that is in the same (i.e. destination) CRS. Commented Jun 20, 2023 at 7:54

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.