geojson 0.5.0 copy "geojson: ^0.5.0" to clipboard
geojson: ^0.5.0 copied to clipboard

outdated

Manipulate geojson data. Load and parse geojson from a string or a file.

Geojson #

pub package Build Status Coverage Status

Utilities to work with geojson data in Dart. Features:

  • Parser: simple functions are available to parse geojson
  • Reactive api: streams are available to retrieve the geojson features as soon as they are parsed

Note: the data is parsed in an isolate to avoid slowing down the main thread

Simple functions #

featuresFromGeoJson: get a FeaturesCollection from geojson string data. Parameters:

  • data: a string with the geojson data, required
  • nameProperty: the property used for the geoserie name, automaticaly set if null
  • verbose: print the parsed data if true

featuresFromGeoJsonFile: get a FeaturesCollection from a geojson file. Parameters:

  • file: the file to load, required
  • nameProperty: the property used for the geoserie name, automaticaly set if null
  • verbose: print the parsed data if true

Reactive api #

Typed streams are available to retrieve the features as soon as they are parsed. Example: add assets on a Flutter map:

  import 'dart:math' as math;
  import 'package:pedantic/pedantic.dart';
  import 'package:flutter/services.dart' show rootBundle;
  import 'package:geojson/geojson.dart';
  import 'package:flutter_map/flutter_map.dart';

  /// Data for the Flutter map polylines layer
  final lines = <Polyline>[];

  Future<void> parseAndDrawAssetsOnMap() async {
    final data = await rootBundle
        .loadString('assets/railroads_of_north_america.geojson');
    final geojson = GeoJson();
    geojson.processedLines.listen((GeoJsonLine line) {
      final color = Color((math.Random().nextDouble() * 0xFFFFFF).toInt() << 0)
          .withOpacity(0.3);
      setState(() => lines.add(Polyline(
          strokeWidth: 2.0, color: color, points: line.geoSerie.toLatLng())));
    });
    geojson.endSignal.listen((_) => geojson.dispose());
    unawaited(geojson.parse(data, verbose: true));
  }

Check the examples for more details

Available streams #

  • processedFeatures: the parsed features: all the geometries
  • processedPoints: the parsed points
  • processedMultipoints: the parsed multipoints
  • processedLines: the parsed lines
  • processedMultilines: the parsed multilines
  • processedPolygons: the parsed polygons
  • processedMultipolygons: the parsed multipolygons
  • endSignal: parsing is finished indicator

Supported geojson features #

All the data structures use GeoPoint and GeoSerie from the GeoPoint package to store the geometry data. Data structures used:

GeoJsonFeatureCollection:

  • String name
  • List<GeoJsonFeature> collection

GeoJsonFeature:

  • GeoJsonFeatureType type: types

  • Map<String, dynamic> properties: the json properties of the feature

  • dynamic geometry: the geometry data, depends on the feature type, see below

GeoJsonPoint:

  • String name
  • GeoPoint geoPoint: the geometry data

GeoJsonMultiPoint:

  • String name
  • GeoSerie geoSerie: the geometry data: this will produce a geoSerie of type GeoSerieType.group

GeoJsonLine:

  • String name
  • GeoSerie geoSerie: the geometry data: this will produce a geoSerie of type GeoSerieType.line

GeoJsonMultiLine:

  • String name
  • List<GeoJsonLine> lines

GeoJsonPolygon:

  • String name
  • List<GeoSerie> geoSeries: the geometry data: this will produce a list of geoSerie of type GeoSerieType.polygon*

GeoJsonMultiPolygon:

  • String name
  • List<GeoJsonPolygon> polygons

Note: none of the parameters is final for all of these data structures

61
likes
0
pub points
91%
popularity

Publisher

unverified uploader

Manipulate geojson data. Load and parse geojson from a string or a file.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

geopoint, iso, meta, pedantic

More

Packages that depend on geojson