geojson 0.2.3 geojson: ^0.2.3 copied to clipboard
Manipulate geojson data. Load and parse geojson from a string or a file.
Geojson #
Utilities to work with geojson data in Dart.
Example #
import 'dart:io';
import 'package:geojson/geojson.dart';
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");
}
}
Api #
featuresFromGeoJson
: get a FeaturesCollection
from geojson string data. Parameters:
data
: a string with the geojson data, requirednameProperty
: the property used for the geoserie name, automaticaly set if nullverbose
: print data if true
featuresFromGeoJsonFile
: get a FeaturesCollection
from a geojson file. Parameters:
file
: the file to load, requirednameProperty
: the property used for the geoserie name, automaticaly set if nullverbose
: print data if true
Supported geojson features #
All the data structures use GeoPoint
and GeoSerie
from the GeoPoint package to store the geometry data. Data structures used:
FeatureCollection:
String
nameList<Feature>
collection
Feature:
FeatureType
type: one ofFeatureType.point
,FeatureType.multipoint
,FeatureType.line
,FeatureType.multiline
,FeatureType.polygon
,FeatureType.multipolygon
Map<String, dynamic>
properties: the json properties of the featuredynamic
geometry: the geometry data, depends on the feature type, see below
Point:
String
nameGeoPoint
geoPoint: the geometry data
MultiPoint:
String
nameGeoSerie
geoSerie: the geometry data: this will produce a geoSerie of typeGeoSerieType.group
Line:
String
nameGeoSerie
geoSerie: the geometry data: this will produce a geoSerie of typeGeoSerieType.line
MultiLine:
String
nameList<Line>
lines
Polygon:
String
nameList<GeoSerie>
geoSeries: the geometry data: this will produce a list of geoSerie of typeGeoSerieType.polygon
*
MultiPolygon:
String
nameList<Polygon>
polygons
Note: none of the parameters is final for all of these data structures