3

Trying to load and plot a raster (it's a DEM) in R, but having problems.

Using R I read in a raster file:

library(raster)

dem <- raster("DEM_Victoria.tif")  # >70 MB
print(dem)

class       : RasterLayer 
band        : 1  (of  3  bands)
dimensions  : 5444, 6007, 32702108  (nrow, ncol, ncell)
resolution  : 100, 100  (x, y)
extent      : 176615.6, 777315.6, 5650397, 6194797  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +no_defs 
data source : DEM_Victoria.tif
names       : DEM_Victoria
values      : 0, 255  (min, max)

My confusion here is the extent vs the CRS. The extent shows coordinates from a UTM Zone 55S system, while the CRS reports it as longlat.

Similarly, gdalinfo reports:

Driver: GTiff/GeoTIFF
Files:  DEM_Victoria.tif
Size is 6007, 5444
Coordinate System is:
GEOGCS["GDA94",
    DATUM["unknown",
        SPHEROID["unretrievable - using WGS84",6378137,298.257223563]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433]]
Origin = (176615.587999997427687,6194797.138000000268221)
Pixel Size = (100.000000000000000,-100.000000000000000)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (  176615.588, 6194797.138) (Invalid angle,Invalid angle)
Lower Left  (  176615.588, 5650397.138) (Invalid angle,Invalid angle)
Upper Right (  777315.588, 6194797.138) (Invalid angle,Invalid angle)
Lower Right (  777315.588, 5650397.138) (Invalid angle,Invalid angle)
Center      (  476965.588, 5922597.138) (Invalid angle,Invalid angle)
Band 1 Block=6007x1 Type=Byte, ColorInterp=Red
Band 2 Block=6007x1 Type=Byte, ColorInterp=Green
Band 3 Block=6007x1 Type=Byte, ColorInterp=Blue

Is this real? A problem? (well it is to me, but perhaps because I don't understand something) Fixable?

I tried 'Assign projection' in QGIS, which uses this command:

gdalwarp -t_srs EPSG:28355 -srcnodata -32768  DEM_Victoria.tif DEM_Victoria.tif.tmp

but it failed with:

ERROR 1: Too many points (12100 out of 12100) failed to transform, unable to compute output bounds.

3
  • 2
    gdalwarp is definitely not "assign". This is a serious problem, you need to figure out why this has been assigned incorrectly. There's no way (for us) to tell from the numbers that they are UTM, they could be VicGrid (or anything, but presumably you can confirm what they are). scruss' answer is the right one, as long as 28355 is actually correct.
    – mdsumner
    Sep 25, 2013 at 12:57
  • I didn't think of that - I suppose it could be Vicgrid, I don't know enough about the source to make sense of it. I also have double-checked QGIS (v1.8.0), and it is gdalwarp in the Assign dialogue box. Sep 25, 2013 at 23:35
  • You'll need to check with the provider/creator, it's their fault. No one can guess though you can get away with that as a last resort.
    – mdsumner
    Sep 26, 2013 at 1:32

2 Answers 2

7

If I understand this correctly, you're not translating the coordinates, you need to assign the correct CRS. gdal_translate can do this:

gdal_translate -a_srs EPSG:28355 DEM_Victoria.tif DEM_Victoria.tif.tmp
2
  • Thanks scruss. As it happens, gdal_translate borks at the srcnodata option, so I removed it, and it worked. I guess it just plays with the header or something and doesn't look at the values. Sep 25, 2013 at 23:39
  • I just put it in because it was in your example; I wasn't sure if you needed it or not. As you said, best not to have it, so I've taken it out for clarity.
    – scruss
    Sep 26, 2013 at 0:17
3

If you want a solution inside R, you can do:

library(raster)

dem <- raster("DEM_Victoria.tif")  # >70 MB
print(dem)
projection(dem) <- "+proj=utm +zone=55 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
print(dem)

Check if the proj4 string is correct, that one its for EPSG:28355 http://spatialreference.org/ref/epsg/28355/

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.