3

I am using the Google Maps API, in which as of now we are plotting the track of a vessel track, but the system is now allowing us to update even a Lat/Long which is on land. Is there is any way to stop this and check that the system should allow only updates to a lat/long that is in the sea?

John Powell
  • 13,649
  • 5
  • 46
  • 62
Robinson C
  • 31
  • 1
  • 2

2 Answers2

1

As @blah238 wrote, several ideas can be found from https://stackoverflow.com/questions/9644452/verify-if-a-point-is-land-or-water-in-google-maps

If you trust on the map color then you could check if the place at each Lat/Long is painted with the sea color or something else. You can demonstrate this with gdallocationinfo and GDAL WMS driver. Read about these from

http://gdal.org/gdallocationinfo.html

http://www.gdal.org/frmt_wms.html

Save the Google Maps definition file from the WMS driver page on disk as "frmt_wms_googlemaps_tms.xml". I copied contents of the file here

<GDAL_WMS>

<!-- Data is subject to term of use detailed at http://code.google.com/intl/nl/apis/maps/terms.html and
     http://www.google.com/intl/en_ALL/help/terms_maps.html -->

    <Service name="TMS">
        <ServerUrl>http://mt.google.com/vt/lyrs=m&amp;x=${x}&amp;y=${y}&amp;z=${z}</ServerUrl> <!-- Map -->
        <!-- <ServerUrl>http://mt.google.com/vt/lyrs=s&amp;x=${x}&amp;y=${y}&amp;z=${z}</ServerUrl> --> <!-- Satellite -->
        <!-- <ServerUrl>http://mt.google.com/vt/lyrs=y&amp;x=${x}&amp;y=${y}&amp;z=${z}</ServerUrl> --> <!-- Hybrid -->
        <!-- <ServerUrl>http://mt.google.com/vt/lyrs=t&amp;x=${x}&amp;y=${y}&amp;z=${z}</ServerUrl> --> <!-- Terrain -->
        <!-- <ServerUrl>http://mt.google.com/vt/lyrs=p&amp;x=${x}&amp;y=${y}&amp;z=${z}</ServerUrl> --> <!-- Terrain, Streets and Water  -->
    </Service>
    <DataWindow>
        <UpperLeftX>-20037508.34</UpperLeftX>
        <UpperLeftY>20037508.34</UpperLeftY>
        <LowerRightX>20037508.34</LowerRightX>
        <LowerRightY>-20037508.34</LowerRightY>
        <TileLevel>20</TileLevel>
        <TileCountX>1</TileCountX>
        <TileCountY>1</TileCountY>
        <YOrigin>top</YOrigin>
    </DataWindow>
    <Projection>EPSG:900913</Projection>
    <BlockSizeX>256</BlockSizeX>
    <BlockSizeY>256</BlockSizeY>
    <BandsCount>3</BandsCount>
    <MaxConnections>5</MaxConnections>
    <Cache />
</GDAL_WMS>

Now you must just run gdallocationinfo from this Google Maps definition file. This example checks what is at WGS84 coordinates (0,0)

gdallocationinfo -wgs84 frmt_wms_googlemaps_tms.xml 0 0
Report:
Location: (134217728P,134217728L)
Band 1:
Value: 148
Band 2:
Value: 107
Band 3:
Value: 76

I have no idea if all that has RGB values (148,107,76) in Google Maps is sea. All that is sea does obviously has this value because of labels.

user30184
  • 65,331
  • 4
  • 65
  • 118
1

There is a free web API that solves exactly this problem called onwater.io. Given a latitude and longitude it will accurately return true or false via a get request.

Example on water: https://api.onwater.io/23.92323,-66.3

{
  lat: 23.92323,
  lon: -66.3,
  water: true
}

Example on land: https://api.onwater.io/42.35,-71.1

{
  lat: 42.35,
  lon: -71.1,
  water: false
}
stuyam
  • 121
  • 3
  • It not too accurate this states 'false' https://api.onwater.io/54.814527,-99.031095 see https://www.google.ca/maps/place/54%C2%B048'52.3%22N+99%C2%B001'51.9%22W/@54.8142908,-99.0344348,16.42z/data=!4m5!3m4!1s0x0:0x0!8m2!3d54.814527!4d-99.031095 – Mapperz Jul 14 '17 at 20:39
  • Thank you for the feedback @Mapperz! It's a very small lake which isn't in our current dataset but we are constantly updating it for more accurate results. – stuyam Jul 14 '17 at 21:15
  • Though there are lakes that dry up seasonal like in Ireland https://en.wikipedia.org/wiki/Turlough_(lake) https://www.google.ca/maps/place/Turlough/@53.7086592,-8.710895,17.21z/data=!4m5!3m4!1s0x485c016cae958499:0x4eb42f99f5ae5ccf!8m2!3d53.7087082!4d-8.7101739 can be hard to code for. – Mapperz Jul 14 '17 at 21:23