1

I have some GeoTIFF files that contain elevation data. I have an area defined by latitude and longitude, and I would like to extract the elevation as a heightmap from the GeoTIFF files to use in Unity. Unity requires the heightmap to be both square and the dimensions to be 2^n + 1. The terrain is represented in Unity as a literal square mesh in x[0-2159.9], z[0-2159.9] with elevation in y dimension.

I've been able to import my files into QGIS 3.6 without any trouble and they all line up as expected (NOAA source and SRTM). I've even been able to use gdal_translate to convert to a raw heightmap (ENVI). What I'm struggling with is how to define a square region in QGIS (I can't even figure out how to add a layer that will let me add arbitrary shapes, let alone how to figure the dimensions of that shape). I can't just do delta latitude = delta longitude because that's really a parallelogram, or at least I assume it is.

UPDATE: to simplify things, I have updated the region of interest to be a square, and the lat/long is now:

  • NE: -82.67761,28.00410
  • SW: -82.69958,27.98470

Ultimately, what I'm trying to do is create a terrain in Unity that matches up exactly to the transformations that Mapbox does (the source of my coordinates is the the coordinates of the Mapbox tiles) so that I can map points of interest from Mapbox onto my terrain in the correct locations.

  • "Rectangular" areas in angular units are not rectangles, they're spheroidal trapezoids (or worst case, spheroidal triangles). You haven't specified the target coordinate system, which makes the problem indeterminate. – Vince Jun 1 at 11:55
  • I should have added to my question to feel free to assume that I'm dimwitted and slow :) GIS is not my forte. Target coordinate system is WGS 84 Web Mercator (that's what Mapbox uses), and ultimately projected onto a flat rectangle of 2159.9m square. – Colin Young Jun 1 at 14:12
  • Squares in Web Mercator aren't squares, either, but rectangles. The short answer is that you need to reproject then clip. You can pre-clip by deprojecting the target shape to geographic, then clip to a small buffer around that, but you'll need to clip again after projection. Please Edit the question to contain the target CS and what steps you have taken, and what problem you've encountered. – Vince Jun 1 at 14:56
0

I was able to solve this with the help of https://stackoverflow.com/questions/32112597/how-to-crop-polygon-with-latitude-and-longitude-coordinates-from-geotiff-image-i. Ultimately I used the following gdal command line utilities:

  1. Create crop shape GeoJson file. I used Mapbox Studio to create my GeoJson. I could have done it by hand, but Mapbox allowed me to verify I had done it correctly:
    • { "geometry": { "coordinates": [ [ [-82.69958, 28.0041], [-82.67761, 28.0041], [-82.67761, 27.9847], [-82.69958, 27.9847], [-82.69958, 28.0041] ] ], "type": "Polygon" }, "type": "Feature", "properties": {} }
  2. Crop to area of interest:
    • gdalwarp -of GTiff -crop_to_cutline -cutline SafetyHarborGeoExplorerBoundary.json Job472561_NOAA_SLR_DEM.tif heightmap.tif
  3. Get statistics to extract min and max height to input into Unity:
    • gdalinfo -mm heightmap.tif
  4. Convert to raw file for Unity:
    • gdal_translate heightmap.tif heightmap.raw –ot UInt16 –scale –of ENVI –outsize 2049 2049
  5. depending on size/location of original data, might need to do some edits in a paint program to make the final file actually square

The coordinate system doesn't enter into it. That is implicitly defined by the mapping that created the mesh target in my modeling program. Since I already had the model coordinates for each corner and their respective mapping to lat/long, it is a simple linear interpolation from the raster data to the model.

  • If you did a simple linear transform from degrees to Web Mercator you shouldn't expect accuracy in the northern 2/3rds of the extent. – Vince Jun 1 at 20:17
  • Are you referring to north-south stretching, or to the fact that a square at higher latitudes is going to deviate from the longitude lines more so than an lower latitudes? In my case, since I'm only dealing with 2000m at 28 degrees north, I don't think the difference is enough to worry about. – Colin Young Jun 1 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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