In a nutshell
I'd like to compute the intersection of a 3D plane (defined by 3 points) and a terrain (given as a raster DEM GeoTIFF), and more particularly the part between two lines of that plane.
Inputs
I have a (GeoTIFF) raster DEM representing terrain height in a given projected (Cartesian) coordinate system.
Here's an hillshade representation of this DEM:
I have 3 points in space above this DEM representing an arbitrarily oriented plane. Each point has a known (x,y,z) position in the same coordinate system as the terrain. (These points are currently stored in a PostGIS database as POINT
geometries).
I want to compute the intersection of this plane with the terrain, especially the part (depicted in cyan in the image) between two of the three edges (depicted by yellow lines) of the triangle defined by these 3 points:
Upon some thoughts, it may not be so trivial.
What I'm 90% sure (based on intuitions) is that:
- I probably need to compute triangles from the raster DEM
- It's only the intersections (dark blue dots on the image below) between the plane and all the edges of these terrain triangles that is of interest (lines between these point can be interpolated; in cyan), as explained by this closeup on terrain triangles:
- It's probably totally useless to test each and every edge of the terrain triangles, over the whole DEM, as only a tiny set of these will actually intersect, but if you don't know them in advance, you probably have to establish kind of a (tricky?) optimized search procedure to quickly excludes the majority of them
- The computation time will certainly be proportional to the size of the DEM
- All these points make me think that I probably need a low-level implementation (languages of the C family or similar, a pure PostGIS implementation would be truly amazing) but an implementation that is "user friendly" (to be used by a non C-expert)
I'm 100% sure that:
- I need to run this computation on a headless Ubuntu machine
Directions I explored:
I've searched QGIS plugins deeply, but didn't found anything relevant enough to solve this.
I've also searched PostGIS functions without much success, except perhaps on the side of the sfcgal extension but I was not able to figure out a way to do such computation, especially when the terrain is stored as a file. And on the other hand, as the plane is not "outlined", standard functions such as ST_Intersection
could not help much.
I also looked a some viewshed algorithms (GDAL, SAGA), hoping to find some that could use a 3D line to delineate the result, without much success either.
And I lost myself in Python libraries...
I want to first turn the 90% of assumptions above into 100% certainty, and then find a friendly way to go? But which one and how; have you ever successfully managed such a calculation without implementing all the steps "by hand" (which in my case will certainly takes ~hours to run if I try in pure Python)?