0

I have some files in EPSG:4326 and some in "ESRI:102027". I use warping with -te argument in EPSG:4326:

gdalwarp -overwrite -of GTiff -t_srs srs -te xmin ymin xmax ymax -te_srs "EPSG:4326" $OUT/$file $OUT/${file}_test.tif

For files with EPSG:4326 the result is correct (srs=EPSG:4326), but for files with "ESRI:102027" (srs=ESRI:102027) I get a stripe with ll_x=xmin, ur_x=xmax (see the pic). enter image description here

What's the matter? In fact I need "crop to cutline" but not to a shp layer, but to coordinates written as an array. I would like to crop all these files undepending on their projection, but the window to crop to should be in EPSG:4326

UPD: It emerged that in my gdalwarp (GDAL 3.5.3, released 2022/10/21) there is no -te_srs argument.. so...

UPD2: If I change arguments to:

-s_srs $T_SRS -t_srs "EPSG:4326"

it works, so it lets me create the target only in target projection

But how can I createtarget file in target projection different from one -te xmin ymin xmax ymax are described with?

UPD3: the full result of gdalmerge --help (which shows, that my version has no -te_srs option:

gdalwarp --help
Usage: gdalwarp [--help-general] [--formats]
[-s_srs srs_def] [-t_srs srs_def] [-to "NAME=VALUE"]* [-vshift |   -novshift]
[[-s_coord_epoch epoch] | [-t_coord_epoch epoch]]
[-order n | -tps | -rpc | -geoloc] [-et err_threshold]
[-refine_gcps tolerance [minimum_gcps]]
[-te xmin ymin xmax ymax] [-tr xres yres] [-tap] [-ts width height]
[-ovr level|AUTO|AUTO-n|NONE] [-wo "NAME=VALUE"] [-ot Byte/Int16/...]  [-wt Byte/Int16]
[-srcnodata "value [value...]"] [-dstnodata "value [value...]"] -dstalpha
[-r resampling_method] [-wm memory_in_mb] [-multi] [-q]
[-cutline datasource] [-cl layer] [-cwhere expression]
[-csql statement] [-cblend dist_in_pixels] [-crop_to_cutline]
[-if format]* [-of format] [-co "NAME=VALUE"]* [-overwrite]
[-nomd] [-cvmd meta_conflict_value] [-setci] [-oo NAME=VALUE]*
[-doo NAME=VALUE]*
srcfile* dstfile

Available resampling methods:
near (default), bilinear, cubic, cubicspline, lanczos, average, rms,
mode,  max, min, med, Q1, Q3, sum.

UPD4: And now gdal writes me for

gdalwarp -overwrite -of GTiff -s_srs $T_SRS -t_srs "EPSG:4326" -te $tarray $OUT/${file}.map $OUT/${file}_test.tif

ERROR 6: Unknown option name '-te' Usage: gdalwarp [--help-general] [--formats] [-s_srs srs_def] [-t_srs srs_def] [-to "NAME=VALUE"]* [-vshift | -novshift] [[-s_coord_epoch epoch] | [-t_coord_epoch epoch]] [-order n | -tps | -rpc | -geoloc] [-et err_threshold] [-refine_gcps tolerance [minimum_gcps]] [-te xmin ymin xmax ymax]

Pay attention to the last [].. Whats? -te is also a wrong option (tarray is an array of xmin ymin xmax ymax)

1 Answer 1

1

My test file "Pk50095.tif" is included into the demo data that comes with GeoServer. It is in EPSG:32633 but GDAL does not recognize the .prj file. Therefore -s_srs must be set explicitly for GDAL. The lower left corner of the selection box in EPSG:4326 is (13.1 46.73), and upper right corner (13.2 46.83)

enter image description here

The command for warping image from EPSG:32633 into EPSG:32632 by defining the target extent in EPSG:4326 units is:

gdalwarp -s_srs EPSG:32633 -t_srs EPSG:32632 -te 13.1 46.73 13.2 46.83 -te_srs EPSG:4326 Pk50095.tif 32632.tif

The result looks like this:

enter image description here

Thus the answer is yes. It is possible to define the target extent for gdalwarp in other projection with the syntax that is documented in https://gdal.org/programs/gdalwarp.html.

Your GDAL version should have the option -te_srs because it was new in GDAL version 2.0 released in the summer of 2015 https://trac.osgeo.org/gdal/wiki/Release/2.0.0-News.

2

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.