geojson 0.2.2 geojson: ^0.2.2 copied to clipboard
Manipulate geojson data. Load and parse geojson from a string or a file.
import 'dart:io';
import 'package:geojson/geojson.dart';
// data is from http://www.naturalearthdata.com
void main() async {
multipolygons();
lines();
}
void multipolygons() async {
final file = File("lakes_of_europe.geojson");
final features = await featuresFromGeoJsonFile(file, nameProperty: "label");
for (final feature in features.collection) {
final geom = feature.geometry as MultiPolygon;
for (final polygon in geom.polygons) {
print("Polygon ${polygon.name}");
for (final geoSerie in polygon.geoSeries) {
print("- ${geoSerie.geoPoints.length} geopoints");
}
}
}
}
void lines() async {
final file = File("railroads_of_north_america.geojson");
final features = await featuresFromGeoJsonFile(file);
for (final feature in features.collection) {
print("${feature.geometry.geoSerie.name}: " +
"${feature.geometry.geoSerie.geoPoints.length} geopoints");
}
}