qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.62k stars 3.01k forks source link

Error using QGIS 3.2.2 Warp (Reproject) tool with custom coordinate system #27679

Closed qgib closed 6 years ago

qgib commented 6 years ago

Author Name: Mario Reyes (@ernesto561) Original Redmine Issue: 19855 Affected QGIS version: 3.2.2 Redmine category:processing/gdal


I'm using the QGIS Warp (Reproject) tool to reproject a raster from WGS84 to a Lambert Conformal Conic custom projection in QGIS 3.2.2. The call to the GDAL/OGR console is the following:

gdalwarp -t_srs "+proj=lcc  +lat_1=13.31666666666667  +lat_2=14.25  +lat_0=13.783333  +lon_0=-89 +x_0=500000 +y_0=295809.184 +ellps=clrk66 +units=m +no_defs +towgs84=0,125,194,0,0,0,0 +wktext" -r near -ot Int16 -of GTiff C:/n13_w090_1arc_v3.tif "C:/Users/HP COREi5/Documents/n13_w090_1arc_v3_nad27.tif"

When I run the tool this is the result:

Processing algorithm…
Algorithm 'Warp (reproject)' starting…
Input parameters:
{ 'DATA_TYPE' : 1, 'INPUT' : 'C:/n13_w090_1arc_v3.tif', 'MULTITHREADING' : 
False, 'NODATA' : None, 'OPTIONS' : '', 'OUTPUT' : 'C:/Users/HP 
COREi5/Documents/n13_w090_1arc_v3_nad27.tif', 'RESAMPLING' : 0, 'SOURCE_CRS' 
: None, 'TARGET_CRS' : 'USER:100057', 'TARGET_EXTENT' : None, 
'TARGET_EXTENT_CRS' : None, 'TARGET_RESOLUTION' : None }

GDAL command:
gdalwarp -t_srs "+proj=lcc +lat_1=13.31666666666667 +lat_2=14.25 
+lat_0=13.783333 +lon_0=-89 
+x_0=500000 +y_0=295809.184 +ellps=clrk66 +units=m +no_defs 
+towgs84=0,125,194,0,0,0,0 
+wktext" -r near -ot Int16 -of GTiff C:/n13_w090_1arc_v3.tif "C:/Users/HP 
COREi5/Documents/n13_w090_1arc_v3_nad27.tif"
GDAL command output:

FAILURE: No target filename specified.

Usage: gdalwarp [--help-general] [--formats]

[-s_srs srs_def] [-t_srs srs_def] [-to "NAME=VALUE"] [-novshiftgrid]

[-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]

[-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, mode, max, 
min, med, Q1, Q3.

Execution completed in 0.18 seconds
Results:
{'OUTPUT': <QgsProcessingOutputLayerDefinition {'sink':C:/Users/HP 
COREi5/Documents/n13_w090_1arc_v3_nad27.tif, 'createOptions': 
{'fileEncoding': 'System'}}>}

Loading resulting layers
The following layers were not correctly generated.<ul><li>C:/Users/HP 
COREi5/Documents/n13_w090_1arc_v3_nad27.tif</li></ul>You can check the 'Log 
Messages Panel' in QGIS main window to find more information about the 
execution of the algorithm.

If I copy and paste the command in the OSGeo4W console, editing spaces, runs without problems. It seems the problem is the custom coordinate system. If is too long, like in this case, the command is split in several lines and only the first line is passed to the gdalwarp command. It doesn't matter if the path has spaces. If I use a predefined CRS, like UTM I have no problems.


qgib commented 6 years ago

Author Name: Nyall Dawson (@nyalldawson)


Can you confirm that the issue here is the newline characters in the definition of the custom projection? I.e. if you remove these, does everything work as expected?


qgib commented 6 years ago

Author Name: Mario Reyes (@ernesto561)


Nyall Dawson wrote:

Can you confirm that the issue here is the newline characters in the definition of the custom projection? I.e. if you remove these, does everything work as expected?

Yes, it seems that is the problem. When I run gdalwarp in the OSGeo4W console everything is fine if I slightly edit the command to get rid of those newline characters. This problem is not present in QGIS 2.18.x with GDAL Tools nor with the Warp tool for that version.

qgib commented 6 years ago

Author Name: Andre Joost (Andre Joost)


I just tried this in QGIS 3.2.2 form OSGEO4W on Windows 7 and it works for me. The output is:

Algorithm 'Warp (reproject)' starting…
Input parameters:
{ 'DATA_TYPE' : 5, 'INPUT' : 'D:/Download/NEU/Elsalvador.tif', 'MULTITHREADING' : False, 'NODATA' : None, 'OPTIONS' : '', 'OUTPUT' : 'D:/Download/NEU/ElSalvador-lcc.tif', 'RESAMPLING' : 0, 'SOURCE_CRS' : None, 'TARGET_CRS' : 'USER:100001', 'TARGET_EXTENT' : None, 'TARGET_EXTENT_CRS' : None, 'TARGET_RESOLUTION' : None }

GDAL command:
gdalwarp -t_srs "+proj=lcc +lat_1=13.31666666666667 +lat_2=14.25 +lat_0=13.783333 +lon_0=-89 +x_0=500000 +y_0=295809.184 +ellps=clrk66 +units=m +no_defs +towgs84=0,125,194,0,0,0,0 +wktext" -r near -ot Float32 -of GTiff D:\Download\NEU\Elsalvador.tif D:/Download/NEU/ElSalvador-lcc.tif
GDAL command output:
0...10...20...30...40...50...60...70...80...90...100 - done.

Execution completed in 0.66 seconds
Results:
{'OUTPUT': <QgsProcessingOutputLayerDefinition {'sink':D:/Download/NEU/ElSalvador-lcc.tif, 'createOptions': {'fileEncoding': 'System'}}>}

Loading resulting layers
Algorithm 'Warp (reproject)' finished

So no line breaks are inserted. I had defined the projection as Custom CRS before, and used the Raster menu.

qgib commented 6 years ago

Author Name: Mario Reyes (@ernesto561)


Andre Joost wrote:

I just tried this in QGIS 3.2.2 form OSGEO4W on Windows 7 and it works for me. The output is:

[...]

So no line breaks are inserted. I had defined the projection as Custom CRS before, and used the Raster menu.

I don't know if it's something specific in my computer. I installed QGIS using the stand alone installer. I attach a screenshot of my GDAL system call. In my case it works if I usea predefined CRS. Thanks.



qgib commented 6 years ago

Author Name: Mario Reyes (@ernesto561)


Mario Reyes wrote:

Andre Joost wrote:

I just tried this in QGIS 3.2.2 form OSGEO4W on Windows 7 and it works for me. The output is:

[...]

So no line breaks are inserted. I had defined the projection as Custom CRS before, and used the Raster menu.

I don't know if it's something specific in my computer. I installed QGIS using the stand alone installer. I attach a screenshot of my GDAL system call. In my case it works if I usea predefined CRS. Thanks.

Sorry, it seems that in the definition of my CRS there was a newline character. It didn't cause problems reprojecting vector files, but it seems when using a GDAL tool there are problems. Thanks for your help. This bug can be closed.

qgib commented 6 years ago

Author Name: Nyall Dawson (@nyalldawson)


It's still a valid bug -- we just need to strip out newline characters from the def when running gdal commands

qgib commented 6 years ago

Author Name: Nyall Dawson (@nyalldawson)


qgib commented 6 years ago

Author Name: Nyall Dawson (@nyalldawson)


Applied in changeset e005d6e2b9b84ecaf14a2290b58d7bc927ea3d08.