Search code examples
javacoordinatesgeotools

How to generate only-ocean coordinates and display them in a visual map in Java


I am making a kind of tracking app which requires to generate coordinates for different ships and visualize their position in a map.

I have research for similares questions, but there are all about land-only coordinates. Also, I have seen so different frameworks like GeoTools or Unfolding but the documentation is so large I cannot find what I'm looking for.

I just need to generate coordinates at the ocean, and then display the label in a map.

In Python there's a library that checks is a point is on land or not (so you can check if it is on ocean or not), and then with Folium you can add marks with aditional information.

No idea if there is a similar approach with Java.


Solution

  • Download my grid of oceans-only coordinates:

    https://djinesse.com/public/coordinates_ocean.json The file may be deleted in the near future.

    How to use it:

    String fromFile = FileUtils.readFileToString( new File( "c:/users/you/downloads/coordinates.json" ), "UTF-8" );
    JSONArray coordinates = new JSONArray( fromFile );
    // pull random coordinates from the array:
    int index = (int) (Math.random() * coordinates.length() );
    JSONObject randomCoordinate = coordinates.getJSONObject( index );
    double longitude = randomCoordinate.getDouble( "lo" );
    double latitude = randomCoordinate.getDouble( "la" );
    

    Required pom.xml dependencies:

    <dependencies>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20190722</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency> 
    </dependencies>