#6721 closed enhancement (fixed)
Simplifing use of gdalwarp with cutline with non-georeferenced rasters
Reported by: | mj10777 | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | GDAL_Raster | Version: | unspecified |
Severity: | minor | Keywords: | |
Cc: |
Description
In the past I have had to deal with historical images with 'folds', which need to be cut out.
Upto now I have used gimp for this, that is however hard to use.
It would be nice to use a combination of QGIS and gdalwarp for this task.
At the moment the only way to do this is to create a world file in the form of:
1.00000000000000 0.00000000000000 0.00000000000000 -1.00000000000000 0.00000000000000 0.00000000000000
create the geometries in QGIS with a specific metric srid such as 3395 and call gdalwarp:
gdalwarp -s_srs epsg:3395 -t_srs epsg:3395 -crop_to_cutline -cutline cutline.gcp_mercator.db -csql "SELECT cutline_polygon FROM create_cutline_polygons WHERE (name = 'Petri_Gruenstrasse');" jpg/Straube_Blatt_III_A.1909.4000.300.jpg 1909.Petri_gruenstrasse.tif gdal_edit.py -unsetgt 1909.Petri_gruenstrasse.tif
This method brings the desired result, but the need for the world file is tedious.
While testing this, I ran into the message
Specify transformation option SRC_METHOD=NO_GEOTRANSFORM to bypass this check.
but found nothing the explain exactly what 'NO_GEOTRANSFORM' means.
Maybe 'SRC_METHOD' could be used to tell gdalwarp that this is a non-georeferenced image and
- to simulate a world file as above
- assuming the srid of the given cutline
- that the output should not contain georeferenced information
Attachments (3)
Change History (14)
by , 8 years ago
Attachment: | 1909.Petri_gruenstrasse.tif added |
---|
comment:1 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
gdalwarp -to SRC_METHOD=NO_GEOTRANSFORM
comment:2 by , 8 years ago
Could you give a practical sample that brings a valid result?
The following does not work:
Retrieve a small image
wget https://upload.wikimedia.org/wikipedia/commons/a/a0/Karte_berlin_akzisemauer.png -O 18550101.Karte_berlin_akzisemauer.wiki.png
Result is a black image.
echo "no_geotransform with: -te 220 -690 1160 -60 : results in a black image" gdalwarp -to SRC_METHOD=NO_GEOTRANSFORM -te 220 -690 1160 -60 18550101.Karte_berlin_akzisemauer.wiki.png 18550101.Karte_berlin_akzisemauer.cut.ref_minus.tif
Result invalid:
echo "no_geotransform with: -te 220 690 1160 60: results in illegal,sizes must be larger than zero" gdalwarp -to SRC_METHOD=NO_GEOTRANSFORM -te 220 690 1160 60 18550101.Karte_berlin_akzisemauer.wiki.png 18550101.Karte_berlin_akzisemauer.cut.ref_plus.tif
Where is SRC_METHOD=NO_GEOTRANSFORM documented
- with a practical sample showing how it is to be used?
comment:3 by , 8 years ago
Result is cut, but image is mirrored:
echo "no_geotransform with: -te 220 60 1160 690: result is mirrored" gdalwarp -to SRC_METHOD=NO_GEOTRANSFORM -te 20 60 1160 690 18550101.Karte_berlin_akzisemauer.wiki.png 18550101.Karte_berlin_akzisemauer.cut.ref_plus_mirrored.tif
comment:5 by , 8 years ago
The following works:
$ gdalwarp -to SRC_METHOD=NO_GEOTRANSFORM -to DST_METHOD=NO_GEOTRANSFORM -te 220 60 1160 690 18550101.Karte_berlin_akzisemauer.wiki.png out.tif -overwrite
I've just added some doc about that
comment:6 by , 8 years ago
by , 8 years ago
Attachment: | 18550101.Karte_berlin_akzisemauer.cut.ref_3395.jpg added |
---|
Expected result of 2nd with a world file and -s_srs epsg:3395 -t_srs epsg:3395 -te 220 -690 1160 -60
by , 8 years ago
Attachment: | 18550101.Karte_berlin_akzisemauer.cut.ref_no_geotransform_overwite.jpg added |
---|
Incorrect result (Top/Left is 0,0) for 2nd sample using: -to SRC_METHOD=NO_GEOTRANSFORM -to DST_METHOD=NO_GEOTRANSFORM -overwrite -te 220 60 1160 690
comment:7 by , 8 years ago
What is expected to be in cutline.csv?
gdalwarp -overwrite -to SRC_METHOD=NO_GEOTRANSFORM -to DST_METHOD=NO_GEOTRANSFORM -te 220 60 1160 690 -cutline cutline.csv in.png out.tif
At one point I attempted to use a Spatialite command directly, but that did not work:
-csql "SELECT GeomFromEWKT('SRID=3395;POLYGON((220 60,1160 60,1160 690,220 690,220 60))')"
comment:9 by , 8 years ago
I've reverted the example since indeed that does not work. Not sure how to fix that.
The CSV might be something like:
id,WKT 1,"POLYGON((....))"
comment:10 by , 8 years ago
When using -cutline with:
18550101.Karte_berlin_akzisemauer.cutline.csv
id,WKT 1,"POLYGON((220 60,1160 60,1160 690,220 690,220 60))"
and a command without -te
gdalwarp -to SRC_METHOD=NO_GEOTRANSFORM -to DST_METHOD=NO_GEOTRANSFORM -overwrite -crop_to_cutline -cutline 18550101.Karte_berlin_akzisemauer.cutline.csv 18550101.Karte_berlin_akzisemauer.wiki.png 18550101.Karte_berlin_akzisemauer.cut.ref_no_geotransform_overwite_cutline.tif
the area outside of the cutline is cutout properly (i.e. black).
The same command with -te 220 60 1160 690
- brings the following error:
ERROR 1: Cannot compute bounding box of cutline.
Test result for lower right for ungeoreferenced image.