gearslaboratory / gdalUtils

R Wrappers for the Geospatial Data Abstraction Library (GDAL) Utilities
18 stars 12 forks source link

ogr2ogr parameter -clipdst duplicated #29

Open dschoenig opened 4 years ago

dschoenig commented 4 years ago

When trying to use ogr2ogr() with the clipdst parameter the resulting call to the ogr2ogr utility includes -clipdst twice, which results in an error.

Minimum example (adapted from the ogr2ogr() example):`

src_datasource_name <- system.file("external/tahoe_highrez_training.shp",
                                   package="gdalUtils")
dst_datasource_name <- paste(tempfile(),".shp",sep="")

# reproject and clip to destination bounding box
ogr2ogr(src_datasource_name, dst_datasource_name,
        t_srs="EPSG:3395",
        clipdst = "-13350800 4736200 -13350700 4736400",
        verbose = TRUE)
# Call provided -clipdest twice and fails with error:
# ERROR 6: Unknown option name '-13350800 4736200 -13350700 4736400'

# No output file
ogrinfo(dirname(dst_datasource_name),
        layer=remove_file_extension(basename(dst_datasource_name)))

# Corresponding system call results in expected behaviour (i.e. providing -clipdst only once):
system(paste("/usr/bin/ogr2ogr",
             "-t_srs EPSG:3395",
             "-clipdst -13350800 4736200 -13350700 4736400",
             dst_datasource_name,
             src_datasource_name))

# Output successfully created
ogrinfo(dirname(dst_datasource_name),
        layer=remove_file_extension(basename(dst_datasource_name)))

# Cleanup
file.remove(dst_datasource_name)

Tested with GDAL version 2.4.2 and R version 3.6.2