TO_GeoJson: converts data to a GeoJson object

Description Usage Value Methods Methods Examples

Description

converts data to a GeoJson object

converts data to a GeoJson object

Usage

1
# utl <- TO_GeoJson$new()

Value

a List

Methods

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)
--------------

Methods

Public methods


Method new()

Usage
TO_GeoJson$new()

Method Point()

Usage
TO_GeoJson$Point(data, stringify = FALSE)
Arguments
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)


Method MultiPoint()

Usage
TO_GeoJson$MultiPoint(data, stringify = FALSE)
Arguments
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)


Method LineString()

Usage
TO_GeoJson$LineString(data, stringify = FALSE)
Arguments
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)


Method MultiLineString()

Usage
TO_GeoJson$MultiLineString(data, stringify = FALSE)
Arguments
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)


Method Polygon()

Usage
TO_GeoJson$Polygon(data, stringify = FALSE)
Arguments
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)


Method MultiPolygon()

Usage
TO_GeoJson$MultiPolygon(data, stringify = FALSE)
Arguments
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)


Method GeometryCollection()

Usage
TO_GeoJson$GeometryCollection(data, stringify = FALSE)
Arguments
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)


Method Feature()

Usage
TO_GeoJson$Feature(data, stringify = FALSE)
Arguments
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)


Method FeatureCollection()

Usage
TO_GeoJson$FeatureCollection(data, stringify = FALSE)
Arguments
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)


Method clone()

The objects of this class are cloneable with this method.

Usage
TO_GeoJson$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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


# MultiPoint

multi_point_dat = list(c(100, 1.01), c(200, 2.01))

multi_point = init$MultiPoint(multi_point_dat, stringify = TRUE)
multi_point


# LineString

linestring_dat = list(c(100, 1.01), c(200, 2.01))

line_string = init$LineString(linestring_dat, stringify = TRUE)
line_string


# 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


# 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


# 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


# 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



# 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


# 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
cat(feature_obj$json_dump)



# 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


feature_collection_obj = init$FeatureCollection(feature_col_dat, stringify = TRUE)
feature_collection_obj
cat(feature_collection_obj$json_dump)

geojsonR documentation built on May 4, 2021, 9:06 a.m.