David Skea is a longtime colleague, JTS contributor, and all-around geospatial guru. He's developing a
Slope/Aspect/Elevation service to be used in forestry-related applications here in British Columbia. His work is a nice example of using JTS to perform real-world spatial processing.
The key to computing slope, aspect and elevation is to have a
Digital Elevation Model (DEM) available for the terrain in the area of interest. In this case, the terrain data is provided by the
TRIM irregular DEM, which is a dataset of over 500 million mass points covering all of British Columbia. To compute the required values for a given polygon, the first step is to extract only the mass points in the immediate region of the polygon (i.e. using the polygon envelope with a suitable buffer distance. The JTS
Delaunay Triangulation API is used to compute a
TIN triangulation from the TRIM mass points.
Using a JTS
PointOnGeometryLocator, the triangles whose centroids lie in the polygon are selected. Since each mass point has an elevation value, each TIN triangle is located in 3D space. The normal vector can be computed for each triangle, which provides the slope and aspect values. The elevation is the height of the triangle centroid.
The SEA values for the triangles are averaged to compute the overall slope, aspect and elevation value for the polygon.
Here's a screenshot showing the results, using Google Earth as a convenient 3D visualization tool (click for full-size image).