December 30, 2012

“USGS Elevation Data with Java”

Grabbing elevation data from the USGS webservice is pretty straightforward – make an HTTP request to with the required parameters (X and Y coordinates, elevation units and the data source), and you get back some XML with the results.

In my case, my area of interest is in the US so the source layer is NED.CONUS_NED which is the National Elevation Dataset Contiguous U.S. 1 arc second elevation data. X and Y are provided in lon/lat format and in my case, I want the data back in feet. Another thing to note is the presence of the parameter “Elevation_Only” which is required when querying for elevation data.

String dataUrl = "" +
                 "/getElevation?X_Value=" + x +
                 "&Y_Value=" + y +
                 "&Elevation_Only=TRUE" +
                 "&Elevation_Units=FEET" +

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(dataUrl);

// normalize text representation
// The results are contained in a single <double> node
NodeList listOfDoubles = doc.getElementsByTagName("double");

if(listOfDoubles.getLength() > 0)
    Node elevationNode = listOfDoubles.item(0);
    Element elevationElement = (Element)elevationNode;
    Double elevation = Double.parseDouble(elevationElement.getFirstChild().getNodeValue());
    return elevation;

Custom Proj4 definition

<?xml version="1.0" encoding="utf-8"?>

XML response