read.coastline {oce} | R Documentation

## Scan a coastline data file

### Description

Read a coastline file in R, Splus, mapgen, shapefile, or openstreetmap format.

### Usage

    read.coastline(file, type=c("R","S","mapgen","shapefile","openstreetmap"),
      debug=getOption("oceDebug"), monitor=FALSE, processingLog)
    read.coastline.shapefile(file, lonlim=c(-180,180), latlim=c(-90,90),
      debug=getOption("oceDebug"), monitor=FALSE, processingLog)
    read.coastline.openstreetmap(file, lonlim=c(-180,180), latlim=c(-90,90),
      debug=getOption("oceDebug"), monitor=FALSE, processingLog)

### Arguments

`file` | name of file containing coastline data.
`type` | type of file, one of `"R"`, `"S"`, `"mapgen"`, `"shapefile"` or `"openstreetmap"`.
`debug` | set to TRUE to print information about the header, etc.
`latlim` | range of (signed) latitudes, used only for shapefiles. Regions that do not intersect this range are skipped.
`lonlim` | as `latlim`, but a signed longitude.
`monitor` | print a dot for every coastline segment read (ignored except for reading "shapefile" type)
`processingLog` | if provided, the action item to be stored in the log. (Typically only provided for internal calls; the default that it provides is better for normal calls by a user.)

### Details

The S and R formats are identical, and consist of two columns, lon and lat, with land-jump segments separated by lines with two NAs.

The MapGen format is of the form

    # -b
    -16.179081	28.553943
    -16.244793	28.563330

BUG: the 'arc/info ungenerate' format is not yet understood.

### Value

An object of `class` `"coastline"`, which is a `list` containing

``data``

: a list containing

longitude

  the longitude in decimal degrees positive east of Greenwich.

latitude

  the latitude in decimal degrees positive north of the equator.

``metadata`` | : a NULL item that may be used in a future version.
``processingLog`` | : a log of processing, in the standard `oce` format.

### A hack for depth contours

The following demonstrates that this code is getting close to working with depth contours. But this should be handled more internally, and a new object for depth contours should be constructed, of which coastlines could be a subset.

            library(oce)
            d <- read.coastline.shapefile("~/Dropbox/DepthContours/DepthContours.shp")
            isna <- is.na(d[["latitude"]])
            idx <- 1 + cumsum(isna)
            lat <- split(d[["latitude"]][!isna], idx[!isna])
            lon <- split(d[["longitude"]][!isna], idx[!isna])
            depths <- d[["depths"]]
            n <- length(depths)
            D <- 200
            plot(c(-180,180), c(-90,90), xlab="", ylab="", asp=1, type='n')
            for (i in 1:n) {
                if (depths[i]==D)
                    lines(lon[[i]], lat[[i]])
            }

### Author(s)

Dan Kelley

### References

The “shapefile” format is described in ESRI Shapefile Technical Description, March 1998, available at http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf.

### See Also

The documentation for `coastline-class` explains the structure of coastline objects, outlines other functions dealing with them, and provides hints on data sources and archiving.

### Examples

    ## Not run:
    library(oce)
    cl <- read.coastline("7404.dat")
    # If no plot yet:
    plot(cl)
    # To add to an existing plot:
    lon <- longitude(cl)
    lat <- latitude(cl)
    lines(lon, lat)
    # Note: another trick is to do something like the following,
    # to get issues of whether longitude is defined in (-180,180)
    # or (0,360)
    lines(lon, lat)
    lines(lon-360, lat)

    ## End(Not run)

[Package oce version 0.9-18 Index]