Discussion:
[Gdal-dev] Change EXTENT of a shapefile
shortyII
2008-04-21 12:58:21 UTC
Permalink
Hi,
i am trying to change the EXTENT parameters of a shapefile with ogr2ogr:

ogr2ogr -update -spat 3500000 5300000 3540000 5400000 rastervorlage.shp
rastervorlage.shp
FAILED: Layer rastervorlage already exists, and -append not specified.
Consider using -append, or -overwrite.
ERROR 1: Terminating translation prematurely after failed
translation of layer rastervorlage

but it doesn't work. (-append and -overwrite also don't work)
Is it in principal possible to change the extent and how can i do it?
Thank you!

Stefan
--
View this message in context: http://www.nabble.com/Change-EXTENT-of-a-shapefile-tp16807475p16807475.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
Frank Warmerdam
2008-04-21 14:46:52 UTC
Permalink
Post by shortyII
Hi,
ogr2ogr -update -spat 3500000 5300000 3540000 5400000 rastervorlage.shp
rastervorlage.shp
FAILED: Layer rastervorlage already exists, and -append not specified.
Consider using -append, or -overwrite.
ERROR 1: Terminating translation prematurely after failed
translation of layer rastervorlage
but it doesn't work. (-append and -overwrite also don't work)
Is it in principal possible to change the extent and how can i do it?
Thank you!
Stefan,

You cannot subset the features within a shapefile with ogr2ogr, you need
to copy the subset to a new shapefile.

So instead use:

ogr2ogr -spat 3500000 5300000 3540000 5400000 out.shp rastervorlage.shp

Once complete you can delete the original, and rename the new to the
original if you want.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, ***@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | President OSGeo, http://osgeo.org
shortyII
2008-04-23 16:49:30 UTC
Permalink
Hi Frank
thank you. Now I don't get an error, but it still doesn't work.
The extent parameters have their old values. Is this a principal problem of
shapefiles?
Best regards,
Stefan
Post by Frank Warmerdam
ogr2ogr -spat 3500000 5300000 3540000 5400000 out.shp rastervorlage.shp
Once complete you can delete the original, and rename the new to the
original if you want.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam,
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | President OSGeo, http://osgeo.org
_______________________________________________
gdal-dev mailing list
http://lists.osgeo.org/mailman/listinfo/gdal-dev
--
View this message in context: http://www.nabble.com/Change-EXTENT-of-a-shapefile-tp16807475p16834680.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
Frank Warmerdam
2008-04-23 17:09:39 UTC
Permalink
Post by shortyII
Hi Frank
thank you. Now I don't get an error, but it still doesn't work.
The extent parameters have their old values. Is this a principal problem of
shapefiles?
Stefan,

Note that the -spat switch does not set the spatial extent of the new
shapefile - that is established by the cumulative bounds of all features
written to it. The -spat switch just requests only features which
intersect the indicated region should be transferred. If, for instance,
you have a "universe polygon" in your source file, then it will impact
the area, and will be copied to the output file, and you will get the
same output file bounds.

That is to say, -spat will *not* clip feature geometries.

There is no mechanism through OGR (or Shapelib for that matter) to
directly set the spatial extents in the shapefile header. It is always
computed as side effect of writing features.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, ***@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | President OSGeo, http://osgeo.org
Loading...