Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find if location is land or water in WorldWind

I know in WorldWind Java you can find out the elevation and a particular location with something like this:

public Double getPositionElevationMeters(Double lat, Double lon) {

    double elevation = getWorldWindCanvas().getModel().getGlobe()
            .getElevation(Angle.fromDegrees(lat), Angle.fromDegrees(lon));

    return elevation;
}

Is there a way to figure out if that lat/lon is actually a major body of water or land pro-grammatically? I've taken a "blind" approach of just considering elevation less than 0 to be water, but that's obviously not ideal.

I'd even use another library that would give me this information; I just need it to work offline.

like image 842
mainstringargs Avatar asked Jan 25 '15 05:01

mainstringargs


1 Answers

You could possibly use a data source such as this from which you should be able to determine the polygons for all countries on Earth. Antarctica has also been added to that data set. This would get you most of the way there, depending on what you define as a "major" body of water.

From there, you can use GeoTools to import the shape data and calculate which polygons a given lat/lon pair fall in to. If none, then it is probably an ocean.

The following pseudocode illustrates the logical flow:

// pseudocode, not the actual GeoTools API
boolean isWater(Coordinate point) 
{
    ShapeDataStore countryShapes = loadShapeData("world.shp");

    GeoShape shape = countryShapes.findShapeByPoint(point);

    if (shape == null)
        return true // not a country or Antarctica, must be international waters.
    else
        return false;
}

edit

See this answer for an answer to a similar question that describes this process in a bit more detail.

like image 178
Jeffrey Mixon Avatar answered Nov 13 '22 08:11

Jeffrey Mixon