1

I'm working with some DEM data I've downloaded from the USGS and am trying to calculate the slope, aspect, and hillshade data of the TIFF file downloaded. Here is the code I'm using:

slope_cmd = "gdaldem slope clipped_by_coords.tif slope_clipped_1.tif"
os.system(slope_cmd)

slope = gdal.Open('slope_clipped_1.tif') slopeArray = slope.GetRasterBand(1).ReadAsArray()

But when I open the slopeArray array, it is filled with values of -9999. I know the clipped_by_coords.tif file is correct as I opened it in QGIS, so I'm not sure what is happening in between that is causing this issue. Any suggestions would be greatly appreciated!

EDIT

here's the test data I'm working with: https://drive.google.com/file/d/1O4MQhN8Qz8dQsMvDH7HZ_ZQ7K6B75IDn/view?usp=drive_link

1 Answers1

2

You need to read the documentation:

gdaldem generally assumes that x, y and z units are identical.

Your data is in a geographic coordinate system (CRS) - EPSG:4269. So the X, Y units are decimal degrees. Your elevation value are almost certainly not decimal degrees.

Either reproject it to a CRS that uses the same units as the elevation (either metres or feet) or use an appropriate -s scale parameter.

If x (east-west) and y (north-south) units are identical, but z (elevation) units are different, the scale (-s) option can be used to set the ratio of vertical units to horizontal

If your elevation units are metres, for latitude 46, the appropriate scale is 77329:

gdaldem slope -s 77329 clipped_by_coords.tif slope_clipped_metres.tif

For elevation in feet, multiply above by 3.28:

gdaldem slope -s 253640 clipped_by_coords.tif slope_clipped_feet.tif

enter image description here

enter image description here

enter image description here

enter image description here

user2856
  • 65,736
  • 6
  • 115
  • 196