1 | .. _api-zoo-format-geojson: |
---|
2 | |
---|
3 | ZOO.Format.GeoJSON |
---|
4 | ================== |
---|
5 | |
---|
6 | Read and write GeoJSON. |
---|
7 | |
---|
8 | Inherits from |
---|
9 | |
---|
10 | - :ref:`ZOO.Format.JSON <api-zoo-format-json>` |
---|
11 | |
---|
12 | Properties |
---|
13 | ---------- |
---|
14 | |
---|
15 | .. list-table:: |
---|
16 | :widths: 20 50 |
---|
17 | :header-rows: 1 |
---|
18 | |
---|
19 | * - NAME |
---|
20 | - DESCRIPTION |
---|
21 | * - :ref:`ZOO.Format.GeoJSON <ZOO.Format.GeoJSON>` |
---|
22 | - Create a new parser for GeoJSON. |
---|
23 | * - :ref:`read <read>` |
---|
24 | - Deserialize a GeoJSON string. |
---|
25 | * - :ref:`isValidType <isValidType>` |
---|
26 | - Check if a GeoJSON object is a valid representative of the given type. |
---|
27 | * - :ref:`parseFeature <parseFeature>` |
---|
28 | - Convert a feature object from GeoJSON into an ZOO.Feature. |
---|
29 | * - :ref:`parseGeometry <parseGeometry>` |
---|
30 | - Convert a geometry object from GeoJSON into an ZOO.Geometry. |
---|
31 | |
---|
32 | parseCoords Properties |
---|
33 | ---------------------- |
---|
34 | |
---|
35 | .. list-table:: |
---|
36 | :widths: 20 50 |
---|
37 | :header-rows: 1 |
---|
38 | |
---|
39 | * - NAME |
---|
40 | - DESCRIPTION |
---|
41 | * - :ref:`parseCoords <parseCoords>` |
---|
42 | - Object with properties corresponding to the GeoJSON geometry types. |
---|
43 | |
---|
44 | parseCoords Functions |
---|
45 | --------------------- |
---|
46 | |
---|
47 | .. list-table:: |
---|
48 | :widths: 12 50 |
---|
49 | :header-rows: 1 |
---|
50 | |
---|
51 | * - NAME |
---|
52 | - DESCRIPTION |
---|
53 | * - :ref:`parseCoords.point <parseCoords.point>` |
---|
54 | - Convert a coordinate array from GeoJSON into an ZOO.Geometry.Point. |
---|
55 | * - :ref:`parseCoords.multipoint <parseCoords.multipoint>` |
---|
56 | - Convert a coordinate array from GeoJSON into an ZOO.Geometry.MultiPoint. |
---|
57 | * - :ref:`parseCoords.linestring <parseCoords.linestring>` |
---|
58 | - Convert a coordinate array from GeoJSON into an ZOO.Geometry.LineString. |
---|
59 | * - :ref:`parseCoords.multilinestring <parseCoords.multilinestring>` |
---|
60 | - Convert a coordinate array from GeoJSON into an ZOO.Geometry.MultiLineString. |
---|
61 | * - :ref:`parseCoords.polygon <parseCoords.polygon>` |
---|
62 | - Convert a coordinate array from GeoJSON into an ZOO.Geometry.Polygon. |
---|
63 | * - :ref:`parseCoords.multipolygon <parseCoords.multipolygon>` |
---|
64 | - Convert a coordinate array from GeoJSON into an ZOO.Geometry.MultiPolygon. |
---|
65 | * - :ref:`parseCoords.box <parseCoords.box>` |
---|
66 | - Convert a coordinate array from GeoJSON into an ZOO.Geometry.Polygon. |
---|
67 | * - :ref:`write <write>` |
---|
68 | - Serialize a feature, geometry, array of features into a GeoJSON string. |
---|
69 | * - :ref:`createCRSObject <createCRSObject>` |
---|
70 | - Create the CRS object for an object. |
---|
71 | |
---|
72 | extract Properties |
---|
73 | ------------------ |
---|
74 | |
---|
75 | .. list-table:: |
---|
76 | :widths: 20 50 |
---|
77 | :header-rows: 1 |
---|
78 | |
---|
79 | * - NAME |
---|
80 | - DESCRIPTION |
---|
81 | * - :ref:`extract <extract>` |
---|
82 | - Object with properties corresponding to the GeoJSON types. |
---|
83 | |
---|
84 | extract Functions |
---|
85 | ----------------- |
---|
86 | |
---|
87 | .. list-table:: |
---|
88 | :widths: 12 50 |
---|
89 | :header-rows: 1 |
---|
90 | |
---|
91 | * - NAME |
---|
92 | - DESCRIPTION |
---|
93 | * - :ref:`extract.feature <extract.feature>` |
---|
94 | - Return a partial GeoJSON object representing a single feature. |
---|
95 | * - :ref:`extract.geometry <extract.geometry>` |
---|
96 | - Return a GeoJSON object representing a single geometry. |
---|
97 | * - :ref:`extract.point <extract.point>` |
---|
98 | - Return an array of coordinates from a point. |
---|
99 | * - :ref:`extract.multipoint <extract.multipoint>` |
---|
100 | - Return an array of coordinates from a multipoint. |
---|
101 | * - :ref:`extract.linestring <extract.linestring>` |
---|
102 | - Return an array of coordinate arrays from a linestring. |
---|
103 | * - :ref:`extract.multilinestring <extract.multilinestring>` |
---|
104 | - Return an array of linestring arrays from a linestring. |
---|
105 | * - :ref:`extract.polygon <extract.polygon>` |
---|
106 | - Return an array of linear ring arrays from a polygon. |
---|
107 | * - :ref:`extract.multipolygon <extract.multipolygon>` |
---|
108 | - Return an array of polygon arrays from a multipolygon. |
---|
109 | * - :ref:`extract.collection <extract.collection>` |
---|
110 | - Return an array of geometries from a geometry collection. |
---|
111 | |
---|
112 | **Functions** |
---|
113 | |
---|
114 | .. _ZOO.Format.GeoJSON: |
---|
115 | |
---|
116 | ZOO.Format.GeoJSON |
---|
117 | Create a new parser for GeoJSON. |
---|
118 | |
---|
119 | |
---|
120 | *Parameters* |
---|
121 | |
---|
122 | ``options {Object}`` An optional object whose properties will be set on this instance. |
---|
123 | |
---|
124 | .. _read: |
---|
125 | |
---|
126 | read |
---|
127 | :: |
---|
128 | |
---|
129 | read: function(json,type,filter) |
---|
130 | |
---|
131 | Deserialize a GeoJSON string. |
---|
132 | |
---|
133 | *Parameters* |
---|
134 | |
---|
135 | | ``json {String}`` A GeoJSON string |
---|
136 | | ``type {String}`` Optional string that determines the structure of the output. Supported values are "Geometry", "Feature", and "FeatureCollection". If absent or null, a default of "FeatureCollection" is assumed. |
---|
137 | | ``filter {Function}`` A function which will be called for every key and value at every level of the final result. Each value will be replaced by the result of the filter function. This can be used to reform generic objects into instances of classes, or to transform date strings into Date objects. |
---|
138 | |
---|
139 | *Returns* |
---|
140 | |
---|
141 | ``{Object}`` The return depends on the value of the type argument. If type is "FeatureCollection" (the default), |
---|
142 | the return will be an array of :ref:`ZOO.Feature <api-zoo-feature>`. If type is "Geometry", the input json must |
---|
143 | represent a single geometry, and the return will be an :ref:`ZOO.Geometry <api-zoo-geometry>`. If type |
---|
144 | is "Feature", the input json must represent a single feature, and the return will be an :ref:`ZOO.Feature <api-zoo-feature>`. |
---|
145 | |
---|
146 | .. _isValidType: |
---|
147 | |
---|
148 | isValidType |
---|
149 | :: |
---|
150 | |
---|
151 | isValidType: function(obj,type) |
---|
152 | |
---|
153 | Check if a GeoJSON object is a valid representative of the given type. |
---|
154 | |
---|
155 | *Returns* |
---|
156 | |
---|
157 | ``{Boolean}`` The object is valid GeoJSON object of the given type. |
---|
158 | |
---|
159 | .. _parseFeature: |
---|
160 | |
---|
161 | parseFeature |
---|
162 | :: |
---|
163 | |
---|
164 | parseFeature: function(obj) |
---|
165 | |
---|
166 | Convert a feature object from GeoJSON into a :ref:`ZOO.Feature <api-zoo-feature>`. |
---|
167 | |
---|
168 | *Parameters* |
---|
169 | |
---|
170 | ``obj {Object}`` An object created from a GeoJSON object |
---|
171 | |
---|
172 | *Returns* |
---|
173 | |
---|
174 | :ref:`{ZOO.Feature} <api-zoo-feature>` A feature. |
---|
175 | |
---|
176 | .. _parseGeometry: |
---|
177 | |
---|
178 | parseGeometry |
---|
179 | :: |
---|
180 | |
---|
181 | parseGeometry: function(obj) |
---|
182 | |
---|
183 | Convert a geometry object from GeoJSON into a :ref:`ZOO.Geometry <api-zoo-geometry>`. |
---|
184 | |
---|
185 | *Parameters* |
---|
186 | |
---|
187 | ``obj {Object}`` An object created from a GeoJSON object |
---|
188 | |
---|
189 | *Returns* |
---|
190 | |
---|
191 | :ref:`{ZOO.Geometry} <api-zoo-geometry>` A geometry. |
---|
192 | |
---|
193 | **parseCoords Properties** |
---|
194 | |
---|
195 | .. _parseCoords: |
---|
196 | |
---|
197 | parseCoords |
---|
198 | Object with properties corresponding to the GeoJSON geometry types. Property |
---|
199 | values are functions that do the actual parsing. |
---|
200 | |
---|
201 | **parseCoords Functions** |
---|
202 | |
---|
203 | .. _parseCoords.point: |
---|
204 | |
---|
205 | parseCoords.point |
---|
206 | Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.Point <api-zoo-geometry-point>`. |
---|
207 | |
---|
208 | *Parameters* |
---|
209 | |
---|
210 | ``array {Object}`` The coordinates array from the GeoJSON fragment. |
---|
211 | |
---|
212 | *Returns* |
---|
213 | |
---|
214 | :ref:`{ZOO.Geometry.Point} <api-zoo-geometry-point>` A geometry. |
---|
215 | |
---|
216 | .. _parseCoords.multipoint: |
---|
217 | |
---|
218 | parseCoords.multipoint |
---|
219 | Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.MultiPoint <api-zoo-geometry-multipoint>`. |
---|
220 | |
---|
221 | *Parameters* |
---|
222 | |
---|
223 | ``array {Object}`` The coordinates array from the GeoJSON fragment. |
---|
224 | |
---|
225 | *Returns* |
---|
226 | |
---|
227 | :ref:`{ZOO.Geometry.MultiPoint} <api-zoo-geometry-multipoint>` A geometry. |
---|
228 | |
---|
229 | .. _parseCoords.linestring: |
---|
230 | |
---|
231 | parseCoords.linestring |
---|
232 | Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.LineString <api-zoo-geometry-linestring>`. |
---|
233 | |
---|
234 | *Parameters* |
---|
235 | |
---|
236 | ``array {Object}`` The coordinates array from the GeoJSON fragment. |
---|
237 | |
---|
238 | *Returns* |
---|
239 | |
---|
240 | :ref:`{ZOO.Geometry.LineString} <api-zoo-geometry-linestring>` A geometry. |
---|
241 | |
---|
242 | .. _parseCoords.multilinestring: |
---|
243 | |
---|
244 | parseCoords.multilinestring |
---|
245 | Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.MultiLineString <api-zoo-geometry-multilinestring>`. |
---|
246 | |
---|
247 | *Parameters* |
---|
248 | |
---|
249 | ``array {Object}`` The coordinates array from the GeoJSON fragment. |
---|
250 | |
---|
251 | *Returns* |
---|
252 | |
---|
253 | :ref:`{ZOO.Geometry.MultiLineString} <api-zoo-geometry-multilinestring>` A geometry. |
---|
254 | |
---|
255 | .. _parseCoords.polygon: |
---|
256 | |
---|
257 | parseCoords.polygon |
---|
258 | Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.Polygon <api-zoo-geometry-polygon>`. |
---|
259 | |
---|
260 | *Parameters* |
---|
261 | |
---|
262 | ``array {Object}`` The coordinates array from the GeoJSON fragment. |
---|
263 | |
---|
264 | *Returns* |
---|
265 | |
---|
266 | :ref:`{ZOO.Geometry.Polygon} <api-zoo-geometry-polygon>` A geometry. |
---|
267 | |
---|
268 | .. _parseCoords.multipolygon: |
---|
269 | |
---|
270 | parseCoords.multipolygon |
---|
271 | Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.MultiPolygon <api-zoo-geometry-multipolygon>`. |
---|
272 | |
---|
273 | *Parameters* |
---|
274 | |
---|
275 | ``array {Object}`` The coordinates array from the GeoJSON fragment. |
---|
276 | |
---|
277 | *Returns* |
---|
278 | |
---|
279 | :ref:`{ZOO.Geometry.MultiPolygon} <api-zoo-geometry-multipolygon>` A geometry. |
---|
280 | |
---|
281 | .. _parseCoords.box: |
---|
282 | |
---|
283 | parseCoords.box |
---|
284 | Convert a coordinate array from GeoJSON into a :ref:`ZOO.Geometry.Polygon <api-zoo-geometry-polygon>`. |
---|
285 | |
---|
286 | *Parameters* |
---|
287 | |
---|
288 | ``array {Object}`` The coordinates array from the GeoJSON fragment. |
---|
289 | |
---|
290 | *Returns* |
---|
291 | |
---|
292 | :ref:`{ZOO.Geometry.Polygon} <api-zoo-geometry-polygon>` A geometry. |
---|
293 | |
---|
294 | .. _write: |
---|
295 | |
---|
296 | write |
---|
297 | :: |
---|
298 | |
---|
299 | write: function(obj,pretty) |
---|
300 | |
---|
301 | Serialize a feature, geometry, array of features into a GeoJSON string. |
---|
302 | |
---|
303 | *Parameters* |
---|
304 | |
---|
305 | | ``obj {Object}`` A :ref:`{ZOO.Feature} <api-zoo-feature>`, :ref:`{ZOO.Geometry} <api-zoo-geometry>`, or an array of features. |
---|
306 | | ``pretty {Boolean}`` Structure the output with newlines and indentation. Default is false. |
---|
307 | |
---|
308 | *Returns* |
---|
309 | |
---|
310 | ``{String}`` The GeoJSON string representation of the input geometry, features, or array of features. |
---|
311 | |
---|
312 | .. _createCRSObject: |
---|
313 | |
---|
314 | createCRSObject |
---|
315 | :: |
---|
316 | |
---|
317 | createCRSObject: function(object) |
---|
318 | |
---|
319 | Create the CRS object for an object. |
---|
320 | |
---|
321 | *Parameters* |
---|
322 | |
---|
323 | ``object`` :ref:`{ZOO.Feature} <api-zoo-feature>` |
---|
324 | |
---|
325 | *Returns* |
---|
326 | |
---|
327 | ``{Object}`` An object which can be assigned to the crs property of a GeoJSON object. |
---|
328 | |
---|
329 | **extract Properties** |
---|
330 | |
---|
331 | .. _extract: |
---|
332 | |
---|
333 | extract |
---|
334 | Object with properties corresponding to the GeoJSON types. Property values are |
---|
335 | functions that do the actual value extraction. |
---|
336 | |
---|
337 | **extract Functions** |
---|
338 | |
---|
339 | .. _extract.feature: |
---|
340 | |
---|
341 | extract.feature |
---|
342 | Return a partial GeoJSON object representing a single feature. |
---|
343 | |
---|
344 | |
---|
345 | *Parameters* |
---|
346 | |
---|
347 | ``feature`` :ref:`{ZOO.Feature} <api-zoo-feature>` |
---|
348 | |
---|
349 | *Returns* |
---|
350 | |
---|
351 | ``{Object}`` An object representing the point. |
---|
352 | |
---|
353 | .. _extract.geometry: |
---|
354 | |
---|
355 | extract.geometry |
---|
356 | Return a GeoJSON object representing a single geometry. |
---|
357 | |
---|
358 | *Parameters* |
---|
359 | |
---|
360 | ``geometry`` :ref:`{ZOO.Geometry} <api-zoo-geometry>` |
---|
361 | |
---|
362 | *Returns* |
---|
363 | |
---|
364 | ``{Object}`` An object representing the geometry. |
---|
365 | |
---|
366 | .. _extract.point: |
---|
367 | |
---|
368 | extract.point |
---|
369 | Return an array of coordinates from a point. |
---|
370 | |
---|
371 | *Parameters* |
---|
372 | |
---|
373 | ``point`` :ref:`{ZOO.Geometry.Point} <api-zoo-geometry-point>` |
---|
374 | |
---|
375 | *Returns* |
---|
376 | |
---|
377 | ``{Array}`` An array of coordinates representing the point. |
---|
378 | |
---|
379 | .. _extract.multipoint: |
---|
380 | |
---|
381 | extract.multipoint |
---|
382 | Return an array of coordinates from a multipoint. |
---|
383 | |
---|
384 | *Parameters* |
---|
385 | |
---|
386 | ``multipoint`` :ref:`{ZOO.Geometry.MultiPoint} <api-zoo-geometry-multipoint>` |
---|
387 | |
---|
388 | *Returns* |
---|
389 | |
---|
390 | ``{Array}`` An array of point coordinate arrays representing the multipoint. |
---|
391 | |
---|
392 | .. _extract.linestring: |
---|
393 | |
---|
394 | extract.linestring |
---|
395 | Return an array of coordinate arrays from a linestring. |
---|
396 | |
---|
397 | *Parameters* |
---|
398 | |
---|
399 | ``linestring`` :ref:`{ZOO.Geometry.LineString} <api-zoo-geometry-linestring>` |
---|
400 | |
---|
401 | *Returns* |
---|
402 | |
---|
403 | ``{Array}`` An array of coordinate arrays representing the linestring. |
---|
404 | |
---|
405 | .. _extract.multilinestring: |
---|
406 | |
---|
407 | extract.multilinestring |
---|
408 | Return an array of linestring arrays from a linestring. |
---|
409 | |
---|
410 | *Parameters* |
---|
411 | |
---|
412 | ``multilinestring`` :ref:`{ZOO.Geometry.MultiLineString} <api-zoo-geometry-multilinestring>` |
---|
413 | |
---|
414 | *Returns* |
---|
415 | |
---|
416 | ``{Array}`` An array of linestring arrays representing the multilinestring. |
---|
417 | |
---|
418 | .. _extract.polygon: |
---|
419 | |
---|
420 | extract.polygon |
---|
421 | Return an array of linear ring arrays from a polygon. |
---|
422 | |
---|
423 | *Parameters* |
---|
424 | |
---|
425 | ``polygon`` :ref:`{ZOO.Geometry.Polygon} <api-zoo-geometry-polygon>` |
---|
426 | |
---|
427 | *Returns* |
---|
428 | |
---|
429 | ``{Array}`` An array of linear ring arrays representing the polygon. |
---|
430 | |
---|
431 | .. _extract.multipolygon: |
---|
432 | |
---|
433 | extract.multipolygon |
---|
434 | Return an array of polygon arrays from a multipolygon. |
---|
435 | |
---|
436 | *Parameters* |
---|
437 | |
---|
438 | ``multipolygon`` :ref:`{ZOO.Geometry.MultiPolygon} <api-zoo-geometry-multipolygon>` |
---|
439 | |
---|
440 | *Returns* |
---|
441 | |
---|
442 | ``{Array}`` An array of polygon arrays representing the multipolygon |
---|
443 | |
---|
444 | .. _extract.collection: |
---|
445 | |
---|
446 | extract.collection |
---|
447 | Return an array of geometries from a geometry collection. |
---|
448 | |
---|
449 | *Parameters* |
---|
450 | |
---|
451 | ``collection`` :ref:`{ZOO.Geometry.Collection} <api-zoo-geometry-collection>` |
---|
452 | |
---|
453 | *Returns* |
---|
454 | |
---|
455 | ``{Array}`` An array of geometry objects representing the geometry collection. |
---|