SpatialLines2PolySet: Convert sp line and polygon objects to PBSmapping PolySet...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/sp2pbs.R

Description

Functions SpatialLines2PolySet and SpatialPolygons2PolySet convert objects of sp classes to PolySet class objects as defined in the PBSmapping package, and PolySet2SpatialLines and PolySet2SpatialPolygons convert in the opposite direction.

Usage

1
2
3
4

Arguments

SL

a SpatialLines object as defined in the sp package

SpP

a SpatialPolygons object as defined in the sp package

PS

a PolySet object

close_polys

should polygons be closed if open

Value

PolySet objects as defined in the PBSmapping package

Author(s)

Roger Bivand and Andrew Niccolai

See Also

PolySet, MapGen2SL

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
if(require(PBSmapping) && require(maps)) {
nor_coast_lines <- map("world", interior=FALSE, plot=FALSE, xlim=c(4,32),
 ylim=c(58,72))
nor_coast_lines <- pruneMap(nor_coast_lines, xlim=c(4,32), ylim=c(58,72))
nor_coast_lines_sp <- map2SpatialLines(nor_coast_lines,
 proj4string=CRS("+proj=longlat +datum=WGS84 +ellps=WGS84"))
nor_coast_lines_PS <- SpatialLines2PolySet(nor_coast_lines_sp)
summary(nor_coast_lines_PS)
plotLines(nor_coast_lines_PS)
o3 <- PolySet2SpatialLines(nor_coast_lines_PS)
plot(o3, axes=TRUE)
nor_coast_poly <- map("world", "norway", fill=TRUE, col="transparent",
 plot=FALSE, ylim=c(58,72))
IDs <- sapply(strsplit(nor_coast_poly$names, ":"), function(x) x[1])
nor_coast_poly_sp <- map2SpatialPolygons(nor_coast_poly, IDs=IDs,
 proj4string=CRS("+proj=longlat +datum=WGS84 +ellps=WGS84"))
nor_coast_poly_PS <- SpatialPolygons2PolySet(nor_coast_poly_sp)
summary(nor_coast_poly_PS)
plotPolys(nor_coast_poly_PS)
o1 <- PolySet2SpatialPolygons(nor_coast_poly_PS)
plot(o1, axes=TRUE)
}

Example output

Loading required package: sp
Checking rgeos availability: TRUE
Loading required package: PBSmapping
sh: 1: cannot create /dev/null: Permission denied

-----------------------------------------------------------
PBS Mapping 2.70.4 -- Copyright (C) 2003-2017 Fisheries and Oceans Canada

PBS Mapping comes with ABSOLUTELY NO WARRANTY;
for details see the file COPYING.
This is free software, and you are welcome to redistribute
it under certain conditions, as outlined in the above file.

A complete user guide 'PBSmapping-UG.pdf' is located at 
/usr/lib/R/site-library/PBSmapping/doc/PBSmapping-UG.pdf

Packaged on 2017-06-28
Pacific Biological Station, Nanaimo

All available PBS packages can be found at
https://github.com/pbs-software

To see demos, type '.PBSfigs()'.
-----------------------------------------------------------


Loading required package: maps
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files

maptools documentation built on Sept. 7, 2021, 5:09 p.m.