as.feature: Coerce character strings or JSON to GeoJSON Feature

View source: R/as.feature.R

as.featureR Documentation

Coerce character strings or JSON to GeoJSON Feature

Description

Coerce character strings or JSON to GeoJSON Feature

Usage

as.feature(x, ...)

Arguments

x

a character string or json class with a GeoJSON object, any of feature, point, multipoint, linestring, multilinestring, polygon, or multipolygon. featurecollection and geometrycollection simply returned without alteration

...

ignored

Value

a feature class object

Examples

poly <- '{
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [105.818939,21.004714],
      [105.818939,21.061754],
      [105.890007,21.061754],
      [105.890007,21.004714],
      [105.818939,21.004714]
     ]]
  }
}'
as.feature(poly)

pt <- '{"type":"Point","coordinates":[-75.343,39.984]}'
as.feature(pt)

line <- '{
  "type": "LineString",
  "coordinates": [
    [-77.031669, 38.878605],
    [-77.029609, 38.881946],
    [-77.020339, 38.884084],
    [-77.025661, 38.885821],
    [-77.021884, 38.889563],
    [-77.019824, 38.892368]
    ]
}'
as.feature(line)

# returns self if no match - note "Points" is not a GeoJSON type
pt <- '{"type":"Points","coordinates":[-75.343,39.984]}'
as.feature(pt)

ropensci/lawn documentation built on May 18, 2022, 9:58 a.m.