Skip to content

Commit

Permalink
add nested geometry example
Browse files Browse the repository at this point in the history
  • Loading branch information
AFKessen committed Oct 14, 2020
1 parent c3d4a47 commit b87633b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
14 changes: 14 additions & 0 deletions example/dart/functions.dart
@@ -1,4 +1,5 @@
import 'dart:io';

import 'package:geojson/geojson.dart';

// data is from http://www.naturalearthdata.com
Expand All @@ -7,6 +8,7 @@ void main() async {
await multipolygons();
await lines();
await smallData();
await nestedGeometryCollection();
}

Future<void> smallData() async {
Expand Down Expand Up @@ -47,3 +49,15 @@ Future<void> lines() async {
"${feature.geometry.geoSerie.geoPoints.length} geopoints");
}
}

Future<void> nestedGeometryCollection() async {
final file = File("../data/nested_geometry_collection.geojson");
final features = await featuresFromGeoJsonFile(file, nameProperty: "name");
for (final feature in features.collection) {
final dynamic geometry = feature.geometry;

if (geometry is GeoJsonGeometryCollection) {
print("${geometry.name}: " + "${geometry.geometries.length} collections");
}
}
}
59 changes: 59 additions & 0 deletions example/data/nested_geometry_collection.geojson
@@ -0,0 +1,59 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "collection"
},
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [
0,
0
]
},
{
"type": "GeometryCollection",
"geometries": [
{
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [
0,
0
]
}
]
},
{
"type": "Point",
"coordinates": [
1,
1
]
}
]
}
]
},
{
"type": "Point",
"coordinates": [
1,
1
]
}
]
}
}
]
}

0 comments on commit b87633b

Please sign in to comment.