Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#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)

1909.Petri_gruenstrasse.tif (797.1 KB ) - added by mj10777 7 years ago.
Test result for lower right for ungeoreferenced image.
18550101.Karte_berlin_akzisemauer.cut.ref_3395.jpg (190.7 KB ) - added by mj10777 7 years ago.
Expected result of 2nd with a world file and -s_srs epsg:3395 -t_srs epsg:3395 -te 220 -690 1160 -60
18550101.Karte_berlin_akzisemauer.cut.ref_no_geotransform_overwite.jpg (193.2 KB ) - added by mj10777 7 years ago.
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

Download all attachments as: .zip

Change History (14)

by mj10777, 7 years ago

Attachment: 1909.Petri_gruenstrasse.tif added

Test result for lower right for ungeoreferenced image.

comment:1 by Even Rouault, 7 years ago

Resolution: invalid
Status: newclosed

gdalwarp -to SRC_METHOD=NO_GEOTRANSFORM

comment:2 by mj10777, 7 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 mj10777, 7 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:4 by Even Rouault, 7 years ago

In 36632:

(Lightly) document SRC_METHOD/DST_METHOD=NO_GEOTRANSFORM (refs #6721)

comment:5 by Even Rouault, 7 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 Even Rouault, 7 years ago

r36633 "gdalwarp doc: add an example for un-georeferenced images (#6721)"

by mj10777, 7 years ago

Expected result of 2nd with a world file and -s_srs epsg:3395 -t_srs epsg:3395 -te 220 -690 1160 -60

by mj10777, 7 years ago

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 mj10777, 7 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:8 by Even Rouault, 7 years ago

In 36635:

gdalwarp: comment out example added in r36633 since it does not work (refs #6721)

comment:9 by Even Rouault, 7 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 mj10777, 7 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.

comment:11 by Even Rouault, 7 years ago

Resolution: invalidfixed

In 36636:

gdalwarp: fix -to SRC_METHOD=NO_GEOTRANSFORM -to DST_METHOD=NO_GEOTRANSFORM mode (fixes #6721)

Note: See TracTickets for help on using tickets.