Accessing gshhs database of world coastlines
Hi Roger, Le 05-10-17 ? 02:21, Roger Bivand a ?crit :
I have no access to OSX, I'm afraid. If you do setwd() to the directory where gshhs_land.shp is placed, and then list.files(pattern="shp"), is the file visible?`
Yes, I got > list.files(pattern="shp") [1] "gshhs_land.shp"
What does getwd() say when you are there? The error message is from:
> getwd() [1] "/Users/dchabot/Documents/Cartographie/Shapefiles/gshhs"
hSHP = SHPOpen(CHAR(STRING_ELT(shpnm,0)), "rb" );
if( hSHP == NULL )
error("unable to open file");
in src/Rshapeget.c, where shpnm is the file name given to read.shape
(). So
either the compilation failed, or the file isn't there. Try
getinfo.shape("gshhs_land.shp")
> getinfo.shape("gshhs_land.shp")
Erreur dans getinfo.shape("gshhs_land.shp") :
No such file
Wow, these were R commands I did not know! But I just found the
problem. OS X can "hide" the extension of file names. The names of
the 3 files appeared correct to me, but I fired Terminal and listed
the files that way (which I admit I don't do often), and here what I
got:
LAUchabotd-QC-DFO-MPO-GC-CA:~/Documents/Cartographie/Shapefiles/gshhs
dchabot$ ls -l
total 336928
-rw-r--r-- 1 dchabot dchabot 8823500 Oct 11 13:07
gshhs_land.dbf.txt
-rw-r--r-- 1 dchabot dchabot 162143644 Oct 11 13:07 gshhs_land.shp
-rw-r--r-- 1 dchabot dchabot 1534588 Oct 11 13:07
gshhs_land.shx.txt
2 of the files had a hidden ".txt" which I did not see, but R sure
did. I fixed these 2 file names and read.shape gave me the same
number of shapes you got, and it did not take so long. Sorry for this.
... It is not a shapefile, but in GSHHS format. It is formatted as polygons. The problem with the shapefile as lines is that it cannot be used for filling land or sea, just for drawing coastlines.
So you accessed it using gshhs programs? You mentioned you could work on a way to adapt gshhs programs so they'd be called from R, or bringing the same functionality in R, I'm not sure exactly what you meant. But you can save you the trouble for one program, "gshhs_dp". I think thinPolys, from PBSmapping, implements this already.
OK, so I'll follow this route as well.
Is there any use in writing an R function on top of the gshhs program for extracting polygons from the gshhs databases directly into sp class objects - it doesn't look too difficult, and would give direct access without having to use the shapefile?
I would love to have it. At a minimum, I'd need clear(er) instructions as to how to compile and use the programs provided on GSHHS's site. But until now I valued being able to work with my dataset in R as I am used to, and produce maps for the right subset of data I'm interested in. So I don't plan to use GMT any time soon and would much prefer R functions to access the very nice gshhs databases and take what I need out of them.
I think it can be done.
As an aside, to you know of a way to do map borders in R that look like those in GMT and many paper maps (thick borders, alternating from white to black from one degree of lat or long to the next)? This is a cosmetic issue only but it would be a nice touch to be able to do this in R.
For unprojected it could be done, for projected like GMT is more trouble. If anyone would like to contribute GMTaxis() to work like GMT, please say, contributions welcome!
I wish I could help, but I really do not have the background to do so. I will be happy to test for you though. Denis