as_sp: Convert osmar object to sp object

Description Usage Arguments Details Value Examples

View source: R/as-sp.R

Description

Convert an osmar object to a sp object.

Usage

1
2
  as_sp(obj, what = c("points", "lines", "polygons"),
    crs = osm_crs(), simplify = TRUE)

Arguments

obj

An osmar object

what

A string describing the sp-object; see Details section

crs

A valid CRS object; default value is given by osm_crs-function

simplify

Should the result list be simplified to one element if possible?

Details

Depending on the strings given in what the osmar object will be converted into in a list of objects given by the sp-package:

what = "points"

the object will be converted in a SpatialPointsDataFrame. The data slot is filled with the attrs slot of obj$nodes.

what = "lines"

the object will be converted in a SpatialLinesDataFrame. It is build with all possible elements which are in obj$ways obj$relations. The data slot is filled with elements of both.

what = "polygons"

the object will be converted in a SpatialPolygonsDataFrame. It consists of elements which are in obj$ways slot.

Every conversion needs at least a non-empty obj$nodes$attrs-slot because spatial information are stored in there.

Value

A list of one or more sp objects; see Details section.

Examples

1
2
3
4
5
6
data("muc", package = "osmar")
  muc_points <- as_sp(muc, "points")
  muc_lines <- as_sp(muc, "lines")
  muc_polygons <- as_sp(muc, "polygons")

  bbox(muc_points)

Example output

Loading required package: XML
Loading required package: RCurl
Loading required package: bitops
Loading required package: geosphere
Loading required package: sp

Attaching package: 'osmar'

The following object is masked from 'package:utils':

    find

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
Warning message:
In Polygon(geo) : less than 4 coordinates in polygon
         min      max
lon 11.56647 11.58206
lat 48.13488 48.14304

osmar documentation built on May 1, 2019, 7:33 p.m.

Related to as_sp in osmar...