converts data to a GeoJson object
converts data to a GeoJson object
# utl <- TO_GeoJson$new()
a List
TO_GeoJson$new()
--------------
Point(data, stringify = FALSE)
--------------
MultiPoint(data, stringify = FALSE)
--------------
LineString(data, stringify = FALSE)
--------------
MultiLineString(data, stringify = FALSE)
--------------
Polygon(data, stringify = FALSE)
--------------
MultiPolygon(data, stringify = FALSE)
--------------
GeometryCollection(data, stringify = FALSE)
--------------
Feature(data, stringify = FALSE)
--------------
FeatureCollection(data, stringify = FALSE)
--------------
new()
TO_GeoJson$new()
Point()
TO_GeoJson$Point(data, stringify = FALSE)
data
a list specifying the geojson geometry object
stringify
either TRUE or FALSE, specifying if the output should also include a geojson-dump (as a character string)
MultiPoint()
TO_GeoJson$MultiPoint(data, stringify = FALSE)
data
a list specifying the geojson geometry object
stringify
either TRUE or FALSE, specifying if the output should also include a geojson-dump (as a character string)
LineString()
TO_GeoJson$LineString(data, stringify = FALSE)
data
a list specifying the geojson geometry object
stringify
either TRUE or FALSE, specifying if the output should also include a geojson-dump (as a character string)
MultiLineString()
TO_GeoJson$MultiLineString(data, stringify = FALSE)
data
a list specifying the geojson geometry object
stringify
either TRUE or FALSE, specifying if the output should also include a geojson-dump (as a character string)
Polygon()
TO_GeoJson$Polygon(data, stringify = FALSE)
data
a list specifying the geojson geometry object
stringify
either TRUE or FALSE, specifying if the output should also include a geojson-dump (as a character string)
MultiPolygon()
TO_GeoJson$MultiPolygon(data, stringify = FALSE)
data
a list specifying the geojson geometry object
stringify
either TRUE or FALSE, specifying if the output should also include a geojson-dump (as a character string)
GeometryCollection()
TO_GeoJson$GeometryCollection(data, stringify = FALSE)
data
a list specifying the geojson geometry object
stringify
either TRUE or FALSE, specifying if the output should also include a geojson-dump (as a character string)
Feature()
TO_GeoJson$Feature(data, stringify = FALSE)
data
a list specifying the geojson geometry object
stringify
either TRUE or FALSE, specifying if the output should also include a geojson-dump (as a character string)
FeatureCollection()
TO_GeoJson$FeatureCollection(data, stringify = FALSE)
data
a list specifying the geojson geometry object
stringify
either TRUE or FALSE, specifying if the output should also include a geojson-dump (as a character string)
clone()
The objects of this class are cloneable with this method.
TO_GeoJson$clone(deep = FALSE)
deep
Whether to make a deep clone.
library(geojsonR) # initialize class init = TO_GeoJson$new() # Examples covering all geometry-objects # Point point_dat = c(100, 1.01) point = init$Point(point_dat, stringify = TRUE) point#> $json_dump #> [1] "{\"coordinates\": [100, 1.01], \"type\": \"Point\"}" #> #> $type #> [1] "Point" #> #> $coordinates #> [1] 100.00 1.01 #># MultiPoint multi_point_dat = list(c(100, 1.01), c(200, 2.01)) multi_point = init$MultiPoint(multi_point_dat, stringify = TRUE) multi_point#> $json_dump #> [1] "{\"coordinates\": [[100, 1.01], [200, 2.0099999999999998]], \"type\": \"MultiPoint\"}" #> #> $type #> [1] "MultiPoint" #> #> $coordinates #> $coordinates[[1]] #> [1] 100.00 1.01 #> #> $coordinates[[2]] #> [1] 200.00 2.01 #> #># LineString linestring_dat = list(c(100, 1.01), c(200, 2.01)) line_string = init$LineString(linestring_dat, stringify = TRUE) line_string#> $json_dump #> [1] "{\"coordinates\": [[100, 1.01], [200, 2.0099999999999998]], \"type\": \"LineString\"}" #> #> $type #> [1] "LineString" #> #> $coordinates #> $coordinates[[1]] #> [1] 100.00 1.01 #> #> $coordinates[[2]] #> [1] 200.00 2.01 #> #># MultiLineString multilinestring_dat = list(list(c(100, 0.0), c(101, 1.0)), list(c(102, 2.0), c(103, 3.0))) multiline_string = init$MultiLineString(multilinestring_dat, stringify = TRUE) multiline_string#> $json_dump #> [1] "{\"coordinates\": [[[100, 0], [101, 1]], [[102, 2], [103, 3]]], \"type\": \"MultiLineString\"}" #> #> $type #> [1] "MultiLineString" #> #> $coordinates #> $coordinates[[1]] #> $coordinates[[1]][[1]] #> [1] 100 0 #> #> $coordinates[[1]][[2]] #> [1] 101 1 #> #> #> $coordinates[[2]] #> $coordinates[[2]][[1]] #> [1] 102 2 #> #> $coordinates[[2]][[2]] #> [1] 103 3 #> #> #># Polygon (WITHOUT interior rings) polygon_WITHOUT_dat = list(list(c(100, 1.01), c(200, 2.01), c(100, 1.0), c(100, 1.01))) polygon_without = init$Polygon(polygon_WITHOUT_dat, stringify = TRUE) polygon_without#> $json_dump #> [1] "{\"coordinates\": [[[100, 1.01], [200, 2.0099999999999998], [100, 1], [100, 1.01]]], \"type\": \"Polygon\"}" #> #> $type #> [1] "Polygon" #> #> $coordinates #> $coordinates[[1]] #> $coordinates[[1]][[1]] #> [1] 100.00 1.01 #> #> $coordinates[[1]][[2]] #> [1] 200.00 2.01 #> #> $coordinates[[1]][[3]] #> [1] 100 1 #> #> $coordinates[[1]][[4]] #> [1] 100.00 1.01 #> #> #># Polygon (WITH interior rings) polygon_WITH_dat = list(list(c(100, 1.01), c(200, 2.01), c(100, 1.0), c(100, 1.01)), list(c(50, 0.5), c(50, 0.8), c(50, 0.9), c(50, 0.5))) polygon_with = init$Polygon(polygon_WITH_dat, stringify = TRUE) polygon_with#> $json_dump #> [1] "{\"coordinates\": [[[100, 1.01], [200, 2.0099999999999998], [100, 1], [100, 1.01]], [[50, 0.5], [50, 0.80000000000000004], [50, 0.90000000000000002], [50, 0.5]]], \"type\": \"Polygon\"}" #> #> $type #> [1] "Polygon" #> #> $coordinates #> $coordinates[[1]] #> $coordinates[[1]][[1]] #> [1] 100.00 1.01 #> #> $coordinates[[1]][[2]] #> [1] 200.00 2.01 #> #> $coordinates[[1]][[3]] #> [1] 100 1 #> #> $coordinates[[1]][[4]] #> [1] 100.00 1.01 #> #> #> $coordinates[[2]] #> $coordinates[[2]][[1]] #> [1] 50.0 0.5 #> #> $coordinates[[2]][[2]] #> [1] 50.0 0.8 #> #> $coordinates[[2]][[3]] #> [1] 50.0 0.9 #> #> $coordinates[[2]][[4]] #> [1] 50.0 0.5 #> #> #># MultiPolygon # the first polygon is without interior rings and the second one is with interior rings multi_polygon_dat = list(list(list(c(102, 2.0), c(103, 2.0), c(103, 3.0), c(102, 2.0))), list(list(c(100, 0.0), c(101, 1.0), c(101, 1.0), c(100, 0.0)), list(c(100.2, 0.2), c(100.2, 0.8), c(100.8, 0.8), c(100.2, 0.2)))) multi_polygon = init$MultiPolygon(multi_polygon_dat, stringify = TRUE) multi_polygon#> $json_dump #> [1] "{\"coordinates\": [[[[102, 2], [103, 2], [103, 3], [102, 2]]], [[[100, 0], [101, 1], [101, 1], [100, 0]], [[100.2, 0.20000000000000001], [100.2, 0.80000000000000004], [100.8, 0.80000000000000004], [100.2, 0.20000000000000001]]]], \"type\": \"MultiPolygon\"}" #> #> $type #> [1] "MultiPolygon" #> #> $coordinates #> $coordinates[[1]] #> $coordinates[[1]][[1]] #> $coordinates[[1]][[1]][[1]] #> [1] 102 2 #> #> $coordinates[[1]][[1]][[2]] #> [1] 103 2 #> #> $coordinates[[1]][[1]][[3]] #> [1] 103 3 #> #> $coordinates[[1]][[1]][[4]] #> [1] 102 2 #> #> #> #> $coordinates[[2]] #> $coordinates[[2]][[1]] #> $coordinates[[2]][[1]][[1]] #> [1] 100 0 #> #> $coordinates[[2]][[1]][[2]] #> [1] 101 1 #> #> $coordinates[[2]][[1]][[3]] #> [1] 101 1 #> #> $coordinates[[2]][[1]][[4]] #> [1] 100 0 #> #> #> $coordinates[[2]][[2]] #> $coordinates[[2]][[2]][[1]] #> [1] 100.2 0.2 #> #> $coordinates[[2]][[2]][[2]] #> [1] 100.2 0.8 #> #> $coordinates[[2]][[2]][[3]] #> [1] 100.8 0.8 #> #> $coordinates[[2]][[2]][[4]] #> [1] 100.2 0.2 #> #> #> #># GeometryCollection (named list) Point = c(100, 1.01) MultiPoint = list(c(100, 1.01), c(200, 2.01)) MultiLineString = list(list(c(100, 0.0), c(101, 1.0)), list(c(102, 2.0), c(103, 3.0))) LineString = list(c(100, 1.01), c(200, 2.01)) MultiLineString = list(list(c(100, 0.0), c(101, 1.0)), list(c(102, 2.0), c(103, 3.0))) Polygon = list(list(c(100, 1.01), c(200, 2.01), c(100, 1.0), c(100, 1.01))) Polygon = list(list(c(100, 1.01), c(200, 2.01), c(100, 1.0), c(100, 1.01)), list(c(50, 0.5), c(50, 0.8), c(50, 0.9), c(50, 0.5))) MultiPolygon = list(list(list(c(102, 2.0), c(103, 2.0), c(103, 3.0), c(102, 2.0))), list(list(c(100, 0.0), c(101, 1.0), c(101, 1.0), c(100, 0.0)), list(c(100.2, 0.2), c(100.2, 0.8), c(100.8, 0.8), c(100.2, 0.2)))) geometry_collection_dat = list(Point = Point, MultiPoint = MultiPoint, MultiLineString = MultiLineString, LineString = LineString, MultiLineString = MultiLineString, Polygon = Polygon, Polygon = Polygon, MultiPolygon = MultiPolygon) geometry_col = init$GeometryCollection(geometry_collection_dat, stringify = TRUE) geometry_col#> $json_dump #> [1] "{\"geometries\": [{\"coordinates\": [100, 1.01], \"type\": \"Point\"}, {\"coordinates\": [[100, 1.01], [200, 2.0099999999999998]], \"type\": \"MultiPoint\"}, {\"coordinates\": [[[100, 0], [101, 1]], [[102, 2], [103, 3]]], \"type\": \"MultiLineString\"}, {\"coordinates\": [[100, 1.01], [200, 2.0099999999999998]], \"type\": \"LineString\"}, {\"coordinates\": [[[100, 0], [101, 1]], [[102, 2], [103, 3]]], \"type\": \"MultiLineString\"}, {\"coordinates\": [[[100, 1.01], [200, 2.0099999999999998], [100, 1], [100, 1.01]], [[50, 0.5], [50, 0.80000000000000004], [50, 0.90000000000000002], [50, 0.5]]], \"type\": \"Polygon\"}, {\"coordinates\": [[[100, 1.01], [200, 2.0099999999999998], [100, 1], [100, 1.01]], [[50, 0.5], [50, 0.80000000000000004], [50, 0.90000000000000002], [50, 0.5]]], \"type\": \"Polygon\"}, {\"coordinates\": [[[[102, 2], [103, 2], [103, 3], [102, 2]]], [[[100, 0], [101, 1], [101, 1], [100, 0]], [[100.2, 0.20000000000000001], [100.2, 0.80000000000000004], [100.8, 0.80000000000000004], [100.2, 0.20000000000000001]]]], \"type\": \"MultiPolygon\"}], \"type\": \"GeometryCollection\"}" #> #> $type #> [1] "GeometryCollection" #> #> $geometries #> $geometries$Point #> [1] 100.00 1.01 #> #> $geometries$MultiPoint #> $geometries$MultiPoint[[1]] #> [1] 100.00 1.01 #> #> $geometries$MultiPoint[[2]] #> [1] 200.00 2.01 #> #> #> $geometries$MultiLineString #> $geometries$MultiLineString[[1]] #> $geometries$MultiLineString[[1]][[1]] #> [1] 100 0 #> #> $geometries$MultiLineString[[1]][[2]] #> [1] 101 1 #> #> #> $geometries$MultiLineString[[2]] #> $geometries$MultiLineString[[2]][[1]] #> [1] 102 2 #> #> $geometries$MultiLineString[[2]][[2]] #> [1] 103 3 #> #> #> #> $geometries$LineString #> $geometries$LineString[[1]] #> [1] 100.00 1.01 #> #> $geometries$LineString[[2]] #> [1] 200.00 2.01 #> #> #> $geometries$MultiLineString #> $geometries$MultiLineString[[1]] #> $geometries$MultiLineString[[1]][[1]] #> [1] 100 0 #> #> $geometries$MultiLineString[[1]][[2]] #> [1] 101 1 #> #> #> $geometries$MultiLineString[[2]] #> $geometries$MultiLineString[[2]][[1]] #> [1] 102 2 #> #> $geometries$MultiLineString[[2]][[2]] #> [1] 103 3 #> #> #> #> $geometries$Polygon #> $geometries$Polygon[[1]] #> $geometries$Polygon[[1]][[1]] #> [1] 100.00 1.01 #> #> $geometries$Polygon[[1]][[2]] #> [1] 200.00 2.01 #> #> $geometries$Polygon[[1]][[3]] #> [1] 100 1 #> #> $geometries$Polygon[[1]][[4]] #> [1] 100.00 1.01 #> #> #> $geometries$Polygon[[2]] #> $geometries$Polygon[[2]][[1]] #> [1] 50.0 0.5 #> #> $geometries$Polygon[[2]][[2]] #> [1] 50.0 0.8 #> #> $geometries$Polygon[[2]][[3]] #> [1] 50.0 0.9 #> #> $geometries$Polygon[[2]][[4]] #> [1] 50.0 0.5 #> #> #> #> $geometries$Polygon #> $geometries$Polygon[[1]] #> $geometries$Polygon[[1]][[1]] #> [1] 100.00 1.01 #> #> $geometries$Polygon[[1]][[2]] #> [1] 200.00 2.01 #> #> $geometries$Polygon[[1]][[3]] #> [1] 100 1 #> #> $geometries$Polygon[[1]][[4]] #> [1] 100.00 1.01 #> #> #> $geometries$Polygon[[2]] #> $geometries$Polygon[[2]][[1]] #> [1] 50.0 0.5 #> #> $geometries$Polygon[[2]][[2]] #> [1] 50.0 0.8 #> #> $geometries$Polygon[[2]][[3]] #> [1] 50.0 0.9 #> #> $geometries$Polygon[[2]][[4]] #> [1] 50.0 0.5 #> #> #> #> $geometries$MultiPolygon #> $geometries$MultiPolygon[[1]] #> $geometries$MultiPolygon[[1]][[1]] #> $geometries$MultiPolygon[[1]][[1]][[1]] #> [1] 102 2 #> #> $geometries$MultiPolygon[[1]][[1]][[2]] #> [1] 103 2 #> #> $geometries$MultiPolygon[[1]][[1]][[3]] #> [1] 103 3 #> #> $geometries$MultiPolygon[[1]][[1]][[4]] #> [1] 102 2 #> #> #> #> $geometries$MultiPolygon[[2]] #> $geometries$MultiPolygon[[2]][[1]] #> $geometries$MultiPolygon[[2]][[1]][[1]] #> [1] 100 0 #> #> $geometries$MultiPolygon[[2]][[1]][[2]] #> [1] 101 1 #> #> $geometries$MultiPolygon[[2]][[1]][[3]] #> [1] 101 1 #> #> $geometries$MultiPolygon[[2]][[1]][[4]] #> [1] 100 0 #> #> #> $geometries$MultiPolygon[[2]][[2]] #> $geometries$MultiPolygon[[2]][[2]][[1]] #> [1] 100.2 0.2 #> #> $geometries$MultiPolygon[[2]][[2]][[2]] #> [1] 100.2 0.8 #> #> $geometries$MultiPolygon[[2]][[2]][[3]] #> [1] 100.8 0.8 #> #> $geometries$MultiPolygon[[2]][[2]][[4]] #> [1] 100.2 0.2 #> #> #> #> #># Feature (named list) # Empty 'properties' list feature_dat1 = list(id = 1, bbox = c(1,2,3,4), geometry = list(Point = c(100, 1.01)), properties = list()) # Nested 'properties' list feature_dat2 = list(id = "1", bbox = c(1,2,3,4), geometry = list(Point = c(100, 1.01)), properties = list(prop0 = 'value0', prop1 = 0.0, vec = c(1,2,3), lst = list(a = 1, d = 2))) feature_obj = init$Feature(feature_dat2, stringify = TRUE) feature_obj#> $id #> [1] "1" #> #> $bbox #> [1] 1 2 3 4 #> #> $geometry #> $geometry$Point #> [1] 100.00 1.01 #> #> #> $properties #> $properties$prop0 #> [1] "value0" #> #> $properties$prop1 #> [1] 0 #> #> $properties$vec #> [1] 1 2 3 #> #> $properties$lst #> $properties$lst$a #> [1] 1 #> #> $properties$lst$d #> [1] 2 #> #> #> #> $json_dump #> [1] "{\"bbox\": [1, 2, 3, 4], \"geometry\": {\"coordinates\": [100, 1.01], \"type\": \"Point\"}, \"id\": \"1\", \"properties\": {\"lst\": {\"a\": 1, \"d\": 2}, \"prop0\": \"value0\", \"prop1\": 0, \"vec\": [1, 2, 3]}, \"type\": \"Feature\"}" #> #> $type #> [1] "Feature" #>#> {"bbox": [1, 2, 3, 4], "geometry": {"coordinates": [100, 1.01], "type": "Point"}, "id": "1", "properties": {"lst": {"a": 1, "d": 2}, "prop0": "value0", "prop1": 0, "vec": [1, 2, 3]}, "type": "Feature"}# FeatureCollection (named list) # takes as input the previously created 'feature_dat1', 'feature_dat2' feature_col_dat = list(bbox = c(-10.01, -10.01, 10.01, 10.01), features = list(Feature = feature_dat1, Feature = feature_dat2)) feature_col_dat#> $bbox #> [1] -10.01 -10.01 10.01 10.01 #> #> $features #> $features$Feature #> $features$Feature$id #> [1] 1 #> #> $features$Feature$bbox #> [1] 1 2 3 4 #> #> $features$Feature$geometry #> $features$Feature$geometry$Point #> [1] 100.00 1.01 #> #> #> $features$Feature$properties #> list() #> #> #> $features$Feature #> $features$Feature$id #> [1] "1" #> #> $features$Feature$bbox #> [1] 1 2 3 4 #> #> $features$Feature$geometry #> $features$Feature$geometry$Point #> [1] 100.00 1.01 #> #> #> $features$Feature$properties #> $features$Feature$properties$prop0 #> [1] "value0" #> #> $features$Feature$properties$prop1 #> [1] 0 #> #> $features$Feature$properties$vec #> [1] 1 2 3 #> #> $features$Feature$properties$lst #> $features$Feature$properties$lst$a #> [1] 1 #> #> $features$Feature$properties$lst$d #> [1] 2 #> #> #> #> #>feature_collection_obj = init$FeatureCollection(feature_col_dat, stringify = TRUE) feature_collection_obj#> $bbox #> [1] -10.01 -10.01 10.01 10.01 #> #> $features #> $features$Feature #> $features$Feature$id #> [1] 1 #> #> $features$Feature$bbox #> [1] 1 2 3 4 #> #> $features$Feature$geometry #> $features$Feature$geometry$Point #> [1] 100.00 1.01 #> #> #> $features$Feature$properties #> list() #> #> #> $features$Feature #> $features$Feature$id #> [1] "1" #> #> $features$Feature$bbox #> [1] 1 2 3 4 #> #> $features$Feature$geometry #> $features$Feature$geometry$Point #> [1] 100.00 1.01 #> #> #> $features$Feature$properties #> $features$Feature$properties$prop0 #> [1] "value0" #> #> $features$Feature$properties$prop1 #> [1] 0 #> #> $features$Feature$properties$vec #> [1] 1 2 3 #> #> $features$Feature$properties$lst #> $features$Feature$properties$lst$a #> [1] 1 #> #> $features$Feature$properties$lst$d #> [1] 2 #> #> #> #> #> #> $type #> [1] "FeatureCollection" #> #> $json_dump #> [1] "{\"bbox\": [-10.01, -10.01, 10.01, 10.01], \"features\": [{\"bbox\": [1, 2, 3, 4], \"geometry\": {\"coordinates\": [100, 1.01], \"type\": \"Point\"}, \"id\": 1, \"properties\": {}, \"type\": \"Feature\"}, {\"bbox\": [1, 2, 3, 4], \"geometry\": {\"coordinates\": [100, 1.01], \"type\": \"Point\"}, \"id\": \"1\", \"properties\": {\"lst\": {\"a\": 1, \"d\": 2}, \"prop0\": \"value0\", \"prop1\": 0, \"vec\": [1, 2, 3]}, \"type\": \"Feature\"}], \"type\": \"FeatureCollection\"}" #>#> {"bbox": [-10.01, -10.01, 10.01, 10.01], "features": [{"bbox": [1, 2, 3, 4], "geometry": {"coordinates": [100, 1.01], "type": "Point"}, "id": 1, "properties": {}, "type": "Feature"}, {"bbox": [1, 2, 3, 4], "geometry": {"coordinates": [100, 1.01], "type": "Point"}, "id": "1", "properties": {"lst": {"a": 1, "d": 2}, "prop0": "value0", "prop1": 0, "vec": [1, 2, 3]}, "type": "Feature"}], "type": "FeatureCollection"}