1

I have had no luck creating rasters that are clipped from larger ones using gdal_translate. If I just do a simple conversion (no clipping) to .tif there is no problem However if I use -projwin and specify a smaller region I get a useless raster with naNs.

What is even more frustrating is that some raster files do work ok, especially if they are rgb. The raster files I have to clip/convert are single band Float32 grayscale.

I am running QGIS on my Windows 10PC with QGIS v2.18.13 and GDAL/OGR 2.2.2

Here is the actual command:

gdal_translate -projwin 711541.57665 20664.3625 712593.227737 20044.0065217 -of GTiff "D:/Composite Project/testin.tif" "D:/Composite Project/cliptest.tif" 

Likewise the info on this particular input file is below. BTW - this problem is not confined to just this file but a large collection of grayscale tif, cub and img files I have:

Driver: GTiff/GeoTIFF
Files: D:/Dropbox/Composite Project/testin.tif
       D:/Dropbox/Composite Project/testin.tif.aux.xml
Size is 10032, 55134
Coordinate System is:
PROJCS["EQUIRECTANGULAR MOON",
    GEOGCS["GCS_MOON",
    DATUM["D_MOON",
        SPHEROID["MOON_localRadius",1737400,0]],
    PRIMEM["Reference_Meridian",0],
    UNIT["degree",0.0174532925199433]],
    PROJECTION["Equirectangular"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",23],
    PARAMETER["standard_parallel_1",0.7],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
    AUTHORITY["EPSG","9001"]]]
Origin = (13140.399999999999636,27728.479999999999563)
Pixel Size = (0.520000000000000,-0.520000000000000)
Metadata:
  AREA_OR_POINT=Area
  DATA_SET_ID="LRO-L-LROC-5-RDR-V1.0"
  INSTRUMENT_ID="LROC"
  INSTRUMENT_NAME="LUNAR RECONNAISSANCE ORBITER CAMERA"
  PRODUCER_INSTITUTION_NAME="ARIZONA STATE UNIVERSITY"
  PRODUCT_CREATION_TIME=2013-05-30T01:32:18
  PRODUCT_ID="NAC_ROI_APOLLO11LOA_E004N0235"
  PRODUCT_TYPE="RDR"
  TARGET_NAME=MOON
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (   13140.400,   27728.480) ( 23d26' 0.15"E,  0d54'51.94"N)
Lower Left  (   13140.400,    -941.200) ( 23d26' 0.15"E,  0d 1'51.74"S)
Upper Right (   18357.040,   27728.480) ( 23d36'19.52"E,  0d54'51.94"N)
Lower Right (   18357.040,    -941.200) ( 23d36'19.52"E,  0d 1'51.74"S)
Center      (   15748.720,   13393.640) ( 23d31' 9.83"E,  0d26'30.10"N)
Band 1 Block=10032x1 Type=Float32, ColorInterp=Gray
  Min=-0.004 Max=0.048 
  Minimum=-0.004, Maximum=0.048, Mean=0.004, StdDev=0.003
  NoData Value=-3.40282265508890445e+38
  Metadata:
    STATISTICS_MAXIMUM=0.047876562923193
    STATISTICS_MEAN=0.0043105538663359
    STATISTICS_MINIMUM=-0.0035738591104746
    STATISTICS_STDDEV=0.0025277971613299
6
  • Please show gdalinfo report about your tiff file and the whole gdal_translate command.
    – user30184
    Oct 30, 2017 at 10:29
  • Sure. Here is the actual command: gdal_translate -projwin 711541.57665 20664.3625 712593.227737 20044.0065217 -of GTiff "D:/Composite Project/testin.tif" "D:/Composite Project/cliptest.tif"
    – monsenrm
    Oct 30, 2017 at 10:54
  • The info is too long for a comment. Here is the meat: Band 1 Block=10032x1 Type=Float32, ColorInterp=Gray Min=-0.004 Max=0.048 Minimum=-0.004, Maximum=0.048, Mean=0.004, StdDev=0.003 NoData Value=-3.40282265508890445e+38
    – monsenrm
    Oct 30, 2017 at 11:01
  • Welcome to GIS:SE @monsenrm! Could you please edit your question to include these new details instead of adding them as comments? :)
    – Joseph
    Oct 30, 2017 at 11:31
  • Are you requesting -projwin coordinates in the same CRS as the raster? The reported Corner Coordinates are not similar to those you're inputting. (This could be because gdalinfo provides these coordinates in some other CRS.)
    – Jon
    Oct 30, 2017 at 16:49

1 Answer 1

1

Solved! The problem was twofold: A newbie (me) to using gdal and a "bug" in gdal_translate.

I was picking coordinates off the screen from a different CRS than the layer I wanted to clip. The coordinates outside the limits of the layer but gdal_translate happily made a new raster but since there was no data in the region it was all nan. It seems to me gdal_translate should complain if you are trying to pick -projwin coordinates outside the limits of the layer.

I learned that I need to convert all layers (there are several) to the same CRS so I can uniformly clip them using the same coordinates.

3
  • In my experience gdal_translate does warn you if the coordinates are outside the layer. There are even options to prevent it from completing the operation in that case.
    – Jon
    Oct 31, 2017 at 13:49
  • Hmm.. I didn't see any warning. I ran the gdal_translate command inside QGIS and I have gotten error dialogs from other issues.. but not that one. Oh well. I know the problem now. Thanks.
    – monsenrm
    Nov 1, 2017 at 4:40
  • I got warnings using subprocess() to call gdal_translate and catching the output via piping. Not sure what happens if you call from command line. You can use the -eco switch to throw an error when the -projwin extents are completely beyond the raster extents.
    – Jon
    Nov 1, 2017 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.