Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining if a place (given coordinates) is on land or on ocean

I have some coordinates from the ISS (International Space Station) and I'd like to know whether when the coordinates were recorded the ISS was over land or ocean and I should do this offline, but I'm not sure what approach to use. A part from python standard library, I'm restricted to only using these libraries:

numpy
scipy
tensorflow
pandas
opencv-python
opencv-contrib-python
evdev
matplotlib
logzero
pyephem
scikit-image
scikit-learn
reverse-geocoder

If you know how to do this using some other libraries though, it'd be good anyway.

With this code I get the coordinates and write them to a file:

import logging
import logzero
from logzero import logger
import os
import ephem
import time

dir_path = os.path.dirname(os.path.realpath(__file__))
logzero.logfile(dir_path+"/coordinates.csv")

# Set a custom formatter
formatter = logging.Formatter('%(name)s - %(asctime)-15s - %(levelname)s: %(message)s');
logzero.formatter(formatter)

name = "ISS (ZARYA)"
line1 = "1 25544U 98067A   18282.18499736  .00001222  00000-0  25998-4 0  9992"
line2 = "2 25544  51.6418 170.6260 0003545 261.4423 234.4561 15.53790940136242"
iss = ephem.readtle(name, line1, line2)

iss.compute()

latitude = iss.sublat
longitude = iss.sublong

# Save the data to the file
logger.info("%s,%s", latitude, longitude )

Do you guys have any idea? Thanks in advance.

like image 317
Aezys Avatar asked Sep 13 '25 18:09

Aezys


2 Answers

global-land-mask from Karin Todd is extremely easy to use and efficient:

from global_land_mask import globe
print(globe.is_land(49.22, -2.23))
# → True
print(globe.is_land(49.22, -2.25))
# → False

It is available via pip, and its only dependency is numpy.

like image 128
Xavier Lamorlette Avatar answered Sep 15 '25 09:09

Xavier Lamorlette


mpl_toolkits.basemap may be able to help.

from mpl_toolkits.basemap import Basemap
bm = Basemap()   # default: projection='cyl'
print(bm.is_land(99.0, 13.0))  #True
print(bm.is_land(0.0, 0.0)) # False

Docs: here and relevant method below:

is_land(xpt, ypt) Returns True if the given x,y point (in projection coordinates) is over land, False otherwise. The definition of land is based upon the GSHHS coastline polygons associated with the class instance. Points over lakes inside land regions are not counted as land points.

Note: you may need to be careful with the projection that is being used with the Basemap object.

like image 24
tda Avatar answered Sep 15 '25 08:09

tda