7

I got the corner geo coordinates from a xml product file of a Sentinel-1 GRD SAR image. When looping through the pixels of the image I wish to check whether it represents land or sea.

I figured I could calculate the corresponding longtitude and latitude by using the corner longtitudes and latitudes and do the check. Looking into basemap from mpl_toolkits, i found an attribute .is_land(x, y) but this require a map projection which slows it down, which I want to avoid.

Is there an efficient and fast way to check whether a longtitude and latitude is land or ocean in python 3.x?

  • 1
    Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. What have you tried? What datasets have you got to perform your test? Please edit your question to include details about your data and what you've tried. – Midavalo Apr 7 '17 at 19:16
8

Basemap should fit your need. Its default projection is the raw use of (long, lat) for plotting/processing. In this case, it also takes projection='cyl' to conform with general uses. Here is the code to try:-

from mpl_toolkits.basemap import Basemap
bm = Basemap()   # default: projection='cyl'
print bm.is_land(99.675, 13.104)  #True
print bm.is_land(100.539, 13.104)  #False

Edit

Basemap's default parameters:

projection='cyl', which takes raw (long, lat) in degrees as input
resolution='c', which is 'crude' version (options are 'i': intermediate; 'f': fine)

Warning: 'i' and 'f' resolutions take much more time to process for results, use them only when you need more accurate result, and, appropriate lat-long extents should be specified when used.

Tips: To speed up the process, lat-long extents should be specified with these options:

llcrnrlon: lower-left corner longitude
llcrnrlat: lower-left corner latitude
urcrnrlon: upper-right corner longitude
urcrnrlat: upper-right corner latitude, all in degrees
-1

There's one problem with Basemap.is_land(): it's really slow! To solve this, I've written a small package with a much faster function: https://github.com/toddkarin/global-land-mask

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.