Is there a PostGIS solution to a 3D intersection between a DEM raster (with elevation in band 1) and a 3D line?

Here are some facts:

  • Rasters only support 2D processing so I can't use ST_3DIntersects directly unless I could convert the rater to a 3D TIN or some other 3D geometry. If I could do this I could use ST_3DIntersects.
  • However there isn't a raster to TIN method and the only potential option to convert a raster to 3D Geometry (ST_DRAPE https://trac.osgeo.org/postgis/ticket/2327) is not yet implemented in PostGIS.

Here are two potential solutions that would be desirable but do not seem available:

  • a custom 3D raster intersection OR
  • a raster to 3d geomtery conversion so I could use ST_3DIntersects.
  • I have edited the question for clarity. This is a 3D intersection problem which postgis can handle but the raster format is still new so the postgis dev's haven't gotten around to supporting it. – dem246 Oct 7 '16 at 23:29
  • Changed the second paragraph to be an explicit statement of fact. Changed the third paragraph to be an explicit statement of two potential solutions. The single question is clearly asked in the first sentence. – dem246 Oct 8 '16 at 2:52
  • Your first sentence was a statement, and your last was part of the first posed as a question. I hope you don't mind that I have rearranged your content in a way that I think makes it an easier read. – PolyGeo Oct 8 '16 at 3:19
  • 1
    I have the exact same challenge which I've been posting a couple of questions about here but so far I'm also out of luck. I'm totally green when it comes to PostGIS and it seems like am only pissing people of by asking. gis.stackexchange.com/questions/267276/… you been able to find a work-around to this problem? – johlund Jan 8 '18 at 23:25
  • We solved the problem without PostGIS. We used BitMiracle.LibTiff.NET (FOSS) to read the DEM Tiffs with wrappers to determine which USGS files to extract points from. The FOSS lib was capable of reading a hundred thousand points from numerous Tiffs in less than a second so we estimated a max intersection area & then extracted elevation values. Then we used the 3D data to calculate the precise intersection using C#. This solution worked well as we had to handle large areas of the US so we threw all of the Tiffs in a folder and read them directly rather than trying to load them all into PostGIS. – dem246 Jan 10 '18 at 1:37

have a look at this, I kind of did the same thing in php.

  1. first I get the height of point 1 and point 2 from the dem.
  2. I calculated the slope between the two points by creating a triangle between the two points, and calculated tan0 (someone helped me with this part so I'm unable to explain this properly)
  3. created sample points,(use ST_Line_Interpolate_Point) of equal distance along the line between point 1 and 2.
  4. use tan0 to calculate the height, of each sample point, relativist to the line between point 1 and 2. So if you know sample point 8 is 12.5m away from point 1, the height is tan0 * 12.5m
  5. sample the heights of the dem for each sample point. And now you have the DEM Heights and line of sight height for each sample location. If the DEM value, for any one of the sample points, is greater than the line of sight value it is blocked.

I know I'm not very clear, English isn't first language. I will try to spend some time to do a proper write up and post it on a blog, will let you know.

By the way I have to agree with johlund. I found that if you ask some question as a new bee people get pissed off at you and criticize your intelligence and/or writing skills instead of tying to solve the problem, it's very strange.

I hope I could at least be of some help to you.


A possible workaround may be:

  1. Convert your raster to points using ST_PixelAsCentroid function
  2. Make a ST_Union on the the raster points to have one multipont geometry
  3. Use ST_DelaunayTriangles to generate TIN on the multipoint geometry
  4. Use ST_3DIntersection to get intersections

Drawbacks of this method:

  • No data values are dropped by ST_PixelAsCentroid

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.