Access to GSHHG coastline data in pyGMT

Hello,

I am looking for access to longitude, latitude data of shoreline. In pyGMT documentation is totally clear how to achieve coast-plotting but I wonder if it is possible to only load this data in a variable to work with it.

I think that creating a direct method to do this, will be a really useful feature to access GSHHG coastlines from python environments. If you know about any other library to do that please let me know.

Many thanks in advance, best regards,

Does it mean you want to extract only the whole shoreline information into a dataframe or something else?

Yes the whole shoreline or a subset. I think that the method will be something like the one you have for strm data, I think that is the same but for the GSHHG dataset. something like:

coast = pygmt.datasets.load_coastline(resolution=‘f’ , region=‘ES’)

pygmt.datasets.load_earth_relief — PyGMT

In GMT it is straight-forward.
look at coast using the -E and -M options
It sometimes helps to read the man pages.

Thank you @biggle1856 it is a solution, but I have to implement this for operational tools coded in python so I rather prefer to use some python library wrappers if possible first, and then if it is no other way use external calls to another kind of software.

However, I think that the method that I suggest will be very useful for pyGMT users… if there is no way so far.

I see your point (and agree). If you want to give the Julia wrapper a shot you can do

D = coast(R="ES", dump=true, coast=true)
...
145×2 Matrix{Float64}:
 0.032578   40.0
 0.0470741  40.03
 0.148318   40.0838
 0.194553   40.1741
...

and have the data directly available in memory.

BUT. This is probably not what you expect. The GSHHG dataset has a particular memory organization (to be efficient 30 years ago) that makes contiguous by chunks (bins whose size depends on the resolution) but not between chunks.

The alternative is to use the DCW dataset, which is contiguous along the coast. Then you would use

D = coast(DCW=:ES, dump=true);

You can also access the GMT.jl from Python if you install the pyjulia package but have not tried this for a long time and not sure how it’s working now.

Thank you @Joaquim, that is exactly what I need. Indeed, I need a global coastline provider with good resolution but it has not to be GSHHG specifically.

Can anyone confirm that there is no similar method in python wrapper, pyGMT or similar? I think It would be a good feature request for pyGMT, what do you think?

Yes, this is not currently implemented. Thanks for submitting the feature request on GitHub.

1 Like

@aragong you have other options. Namely, the GSHHS coastlines are also distributed as shape files (not sure where but I know that Paul have made them) that you can read using some python package that can read the (awful) shapefile format.

Another alternative is like I said at the end of my post. With the pyjulia package you can run the Julia programs (i.e., GMT.jl), as well as the converse from Julia using the pycall package.

Sure, thank you again.
I downloaded GSHHS shp-files from GSHHG web and I’m gonna try to read them using geopandas to achieve the final pandas.dataframe. I think is the most “standard” way…

I’ve created a simple repository to process GSHHS from shapefiles. I share with all of you the link in case it could be helpful for anyone.

coastline-loader

best regards,

1 Like