[GIS] Checking whether lat/long is in sea using Google Maps API

google-maps-api

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?

Best Answer

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.