Giter VIP home page Giter VIP logo

geojson's Introduction

Geojson

pub package Build Status Coverage Status

Utilities to work with geojson data in Dart. Features:

  • Parser with a reactive api: streams are available to retrieve the geojson features as soon as they are parsed
  • Search: search for properties
  • Geofencing: geofence points in a polygon or from a distance

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

These functions are suitable for small data. Example:

final features = await featuresFromGeoJson(data);

Web support

featuresFromGeoJsonMainThread: as the web do not support isolates use this function to parse in the main thread. 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

Reactive api

Parse and listen

Typed streams are available to retrieve the features as soon as they are parsed. This is useful when the data is big.

  • 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

Example: add assets on a Flutter map:

  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 geo = GeoJson();
    geo.processedLines.listen((GeoJsonLine line) {
      /// when a line is parsed add it to the map right away
      setState(() => lines.add(Polyline(
          strokeWidth: 2.0, color: Colors.blue, points: line.geoSerie.toLatLng())));
    });
    geo.endSignal.listen((_) => geo.dispose());
    final data = await rootBundle
        .loadString('assets/railroads_of_north_america.geojson');
    await geo.parse(data, verbose: true);
  }

Data properties

After the data is parsed the GeoJson instance has properties to access the data:

List<GeoJsonFeature> features;
List<GeoJsonPoint> points;
List<GeoJsonMultiPoint> multipoints;
List<GeoJsonLine> lines;
List<GeoJsonMultiLine> multilines;
List<GeoJsonPolygon> polygons;
List<GeoJsonMultiPolygon> multipolygons;

Example:

final List<GeoJsonLine> lines = geo.lines;

Search

Search in a geojson file:

final geo = GeoJson();
await geo.searchInFile("countries.geojson",
    query: GeoJsonQuery(
        geometryType: GeoJsonFeatureType.multipolygon,
        matchCase: false,
        property: "name",
        value: "Zimbabwe"),
    verbose: true);
List<GeoJsonMultiPolygon> result = geo.multipolygons;

A search method is also available, taking string data in parameter instead of a file path. The streams are available to retrieve the data as soon as it is found

Geofencing

Geofence points within a distance of a given point:

final geo = GeoJson();
/// `point` is the [GeoJsonPoint] to search from
/// `points` is the list of [GeoJsonPoint] to search in
/// `distance` is the distance to search in meters
await geo.geofenceDistance(
      point: point, points: points, distance: distance);
 List<GeoPoint> foundPoints = geo.points;

Geofence points in a polygon:

final geo = GeoJson();
/// `polygon` is the [GeoJsonPolygon] to check
/// `points` is the list of [GeoJsonPoint] to search in
await geo.geofencePolygon(polygon: polygon, points: points);
 List<GeoPoint> foundPoints = geo.points;

Note: the processedPoints stream is available to retrieve geofenced points as soon as they are found

Maps

To draw geojson data on a map check the Map controller package

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

GeoJsonGeometryCollection:

  • String name
  • List<GeoJsonFeature> geometries

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

geojson's People

Contributors

airof98 avatar duzenko avatar synw avatar tuarrep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

geojson's Issues

function featuresFromGeoJsonMainThread is not working

Hello

I'm developing a proyect, and I need to represent on the map some lines that comes in GeoJson format.
In Android platform I can do this well, but in the Web this is not working.
I've implemented the featuresFromGeoJsonMainThread () funtion but returns empty values.
Please can you help me?

Web Support

I haven't tried this plugin yet but I would love to have something like this on web. If it is already compatible please update the docs so I can give it a try.

parsing geojson doesn't appear to work in web.

Whenever you call this on the web, while the code runs the features added to the sink don't appear to trigger the the listen.

I added a simple sample project for an example: https://github.com/ATeal/web_geojson

Additionally if you do a little hacking on the example project from the map_controller package and enable their implementation of the geojson read on web (they actually have it disabled on web, I'm assuming because it's not functioning) then you can see it not working there as well: https://github.com/synw/map_controller/tree/master/example

Feel free to let me know if I'm doing something wrong, or if I can help in anyway!

Latitude and longitude are inverted

From the RFC:

The first two elements are longitude and latitude, or
easting and northing, precisely in that order and using decimal
numbers.

However, you are using index 0 for latitude, and 1 for longitude here

GeoJsonFeatureType.point ignores properties when serializing

  String serialize() {
    assert(type != null, "The feature type can not be null for serialization");
    String featStr;
    switch (type) {
      case GeoJsonFeatureType.point:
        final geom = geometry as GeoJsonPoint;
        featStr = geom.serializeFeature();
        break;
      case GeoJsonFeatureType.multipoint:
        final geom = geometry as GeoJsonMultiPoint;
        featStr = geom.serializeFeature();
        break;
      case GeoJsonFeatureType.line:
        final geom = geometry as GeoJsonLine;
        featStr = geom.serializeFeature();
        break;
      case GeoJsonFeatureType.multiline:
        final geom = geometry as GeoJsonMultiLine;
        featStr = geom.serializeFeature(properties);
        break;
      case GeoJsonFeatureType.polygon:
        final geom = geometry as GeoJsonPolygon;
        featStr = geom.serializeFeature(properties);
        break;
      case GeoJsonFeatureType.multipolygon:
        final geom = geometry as GeoJsonMultiPolygon;
        featStr = geom.serializeFeature();
        break;
    }
    return featStr;
  }

You can see that only multiline and polygon make use of properties.
I do need them at least for point

Properly document nullable members or make them not nullable.

Some classes in this library have nullable type member variables, and it is not apparent why.

For example...

/// A line
class GeoJsonLine {
  /// Default constructor
  GeoJsonLine({this.geoSerie, this.name});

  /// The geometry data
  GeoSerie? geoSerie;

  /// The name of the line
  String? name;

  /// Serialize to a geojson feature string
  String? serializeFeature(Map<String, dynamic>? properties) =>
      geoSerie?.toGeoJsonFeatureString(properties);
}

Why is GeoSerie nullable? Does a GeoJsonLine make sense without a GeoSerie? Under what circumstances would this be null? Should this even be null?

If this member is never null, it should be typed as such. Libraries should try to never expose nullable types unless there is very good reason.

Empty Space in polygon

I can create a polygon with empty space. For create i use https://geoman.io/geojson-editor
created data
{ "type": "FeatureCollection", "features": [{ "id": "b30cc812-c8ba-41d0-98a7-76b3d7f5ec28", "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [-113.52572, 53.644638], [-113.593727, 53.623059], [-113.652804, 53.590059], [-113.661735, 53.5709], [-113.658987, 53.524799], [-113.661735, 53.482325], [-113.655552, 53.474561], [-113.612275, 53.45862], [-113.592354, 53.432856], [-113.562128, 53.427128], [-113.505112, 53.436128], [-113.450844, 53.435719], [-113.372533, 53.43531], [-113.342307, 53.448398], [-113.343889, 53.510918], [-113.343681, 53.570492], [-113.345259, 53.592097], [-113.356046, 53.612062], [-113.372038, 53.625095], [-113.397446, 53.637311], [-113.449626, 53.647487], [-113.52572, 53.644638] ], [ [-113.537341, 53.53893], [-113.534078, 53.539899], [-113.52884, 53.53944], [-113.523001, 53.538828], [-113.519567, 53.537502], [-113.515445, 53.536176], [-113.511495, 53.534135], [-113.509263, 53.534135], [-113.509949, 53.531585], [-113.501105, 53.530003], [-113.502565, 53.526125], [-113.506171, 53.524289], [-113.511495, 53.524085], [-113.513127, 53.525411], [-113.517506, 53.526636], [-113.520082, 53.528166], [-113.524547, 53.529799], [-113.529871, 53.530513], [-113.538372, 53.532809], [-113.539831, 53.535411], [-113.537341, 53.53893] ] ], "city_id": 1, "city_name": "Edmonton" }, "properties": { "name": "Edmonton", "shape": "Polygon", "category": "default" } }, { "id": "83af9f01-abb7-458d-9f18-fe8dac645a89", "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [-113.705187, 53.535819], [-113.859748, 53.521533], [-113.892034, 53.477831], [-113.8886, 53.431628], [-113.808228, 53.409123], [-113.701752, 53.434901], [-113.695569, 53.488454], [-113.705187, 53.535819] ], [ [-113.842575, 53.479081], [-113.835706, 53.516185], [-113.745717, 53.519446], [-113.74709, 53.474186], [-113.842575, 53.479081] ], [ [-113.846009, 53.455343], [-113.762889, 53.463501], [-113.758277, 53.435567], [-113.841877, 53.42784], [-113.846009, 53.455343] ] ], "city_id": 1, "city_name": "Edmonton" }, "properties": { "name": "Unnamed Layer", "shape": "Polygon", "category": "default" } }, { "id": "5c988165-fad6-4726-a90d-fc3ddd8cd0f9", "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [-113.321896, 53.466796], [-113.18176, 53.466796], [-113.18176, 53.54398], [-113.321896, 53.54398], [-113.321896, 53.466796] ] ], "city_id": 1, "city_name": "Edmonton" }, "properties": { "name": "Unnamed Layer", "shape": "Rectangle", "category": "default" } }, { "id": "b8952823-dbd0-425a-99ec-a63037bdf3e3", "type": "Feature", "geometry": { "type": "Point", "coordinates": [-113.293045, 53.581092], "city_id": 1, "city_name": "Edmonton" }, "properties": { "name": "Unnamed Layer", "shape": "Circle", "radius": 2909.9754362977806, "category": "default" } }] }
In web page I see
image

code i use in my app:
geo.processedPolygons.listen((GeoJsonPolygon multiPolygon) { geoJsonPolygons.add({ 'poligon': multiPolygon, 'city_id': cityId, }); for (final polygon in multiPolygon.geoSeries) { final geoSerie = GeoSerie( type: GeoSerieType.polygon, name: polygon.name, geoPoints: <GeoPoint>[]); geoSerie.geoPoints.addAll(polygon.geoPoints); Polygon poly = Polygon( consumeTapEvents: true, onTap: () { _onPolygonTapped(PolygonId( "${(math.Random().nextDouble() * 0xFFFFFF).toInt() << 0}")); }, strokeColor: Colors.orange, polygonId: PolygonId( "${(math.Random().nextDouble() * 0xFFFFFF).toInt() << 0}"), fillColor: Color.fromRGBO(75, 178, 68, 0.20), points: toLatLng(geoSerie.geoPoints, ignoreErrors: true), strokeWidth: 2, ); GeoJsonPolygon(geoSeries: [geoSerie]); polygons.add(poly); notifyListeners(); pointInsideCheck(); } }); for (var i = 0; i < polygonsData.length; i++) { if (polygonsData[i]['area_geojson'] != null) { var currentCityId = polygonsData[i]['city_id']; cityId = currentCityId; await geo.parse( json.encode(polygonsData[i]['area_geojson']), nameProperty: currentCityId.toString(), verbose: true, ); } }

in my app map look like this
image

GeoJson don't read GeometryCollection

Hi, I'm creating an app for my college work and I decided to use your library to be able to read a geojson. But when it comes to reading geojson when it comes to a part that has a type that the library can't understand inside geometry which is the GeometryCollection

It's all right when the type is Polygon, which I'm using. Is there any way to ignore this exception to continue running the application or any implementation for it?

{
    "type": "Feature",
    "geometry": {
        "geometries": [
            {
                "type": "Polygon",
                "coordinates": [
                    [
                        [coordinates]
                    ]
                ]
            },
            {
                "type": "Polygon",
                "coordinates": [
                    [
                        [morecoordinates]
                    ]
                ]
            },
            {
                "type": "Polygon",
                "coordinates": [
                    [
                        [anycoordinate]
                    ]
                ]
            },
            {
                "type": "Polygon",
                "coordinates": [
                    [
                        [coordinate]
                    ]
                ]
            }
        ],
        "type": "GeometryCollection"
    },
    "properties": {
        "name": "Inexistente ou Baixo"
    }
}

My code:

final polygons = <Polygon>[];

  Future<bool> processData() async {
    final geojson = GeoJson();
    geojson.processedPolygons.listen((GeoJsonPolygon multiPolygon) {
      for (final polygon in multiPolygon.geoSeries) {
        final geoSerie = GeoSerie(
            type: GeoSerieType.polygon,
            name: polygon.name,
            geoPoints: <GeoPoint>[]);

        geoSerie.geoPoints.addAll(polygon.geoPoints);
        final color =
        Color((math.Random().nextDouble() * 0xFFFFFF).toInt() << 0)
            .withOpacity(0.3);
        Polygon poly = Polygon(
          polygonId: PolygonId('Nice one'),
          fillColor: color,
          points: toLatLng(geoSerie.geoPoints, ignoreErrors: true),
        );
        setState(() => polygons.add(poly));
      }
    });
    geojson.endSignal.listen((bool _) => geojson.dispose());
    // The data is from https://datahub.io/core/geo-countries
    final data = await rootBundle.loadString('assets/coordinates/map.geojson');
    final nameProperty = "Name";
      await geojson.parse(data, nameProperty: nameProperty, verbose: true);


    return true;
  }

Creating geojson data

Does geojson package create new geojson file from points, or just parsing geojson files?

missing GeojsonGeometry class

all geometry classes (GeojsonPoint, GeojsonLine, GeojsonMultiLine, GeojsonPolygon, ...) should extend the same GeojsonGeometry abstract class to respect the geojson hierarchy and allow to point to a generic geojson geometry in our code if needed (for example if I want to define a class attribute as a geojson geometry without specifying the type because it is variable or unknown yet, I can't with the current lib implementation)

Flutter: search from an asset file

Hi, I'm little confused.
I've located my in assets folder and add to pubspec.yaml, when I try to load in it. I got error "The file does not exist". How to solve it? Thank you
image

[FEATURE] return future from featuresFromGeoJson

Execution time of featuresFromGeoJson may be very long if json will be too big.
Try to split internal body of featuresFromGeoJson to little futures to avoid freezing of main Isolate and also return Furute from featuresFromGeoJson in general.

Can't parse this geojson file

I created this from mapshaper and a 500m simplification and it won't parse with geojson. I did one with a 50m and the same workflow and it did work. Here is the one that doesn't work.

wmd-fast.json.zip

Name: "null"

class GeoJsonFeatureCollection {
...
  String serialize() {
    final buffer = StringBuffer()
      ..write('{"type": "FeatureCollection", "name": "$name",')
      ..write('"features": [');

If name is null (which is common) then the output json is polluted with meaningless "name": "null"
If we try to deserialize it again now we have name = `null' which is not good.

Proximity to polygon edge

I'd like to be able to query the two closest polygon edges to a single point. Any ideas?

Use case: tell the user which country border they are closest to. "You are 15km from the France/Germany border!"

Synchronous parsing

When dealing with a large geoJson having a way to fetch each feature after it's parsing is good, but when you deal on a very little geoJson (with only one feature, for instance) it's an overkill.

Can you add a way to parse the geoJson synchronously?

namespace exceptions

The exceptions have a generic name, I would like to request that we get them a more 'namespaced' name, such as GeoJsonFeatureNotSupported instead of FeatureNotSupported

I'm not be able to parse this json file into geojson.

{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"@id": "way/7976148"
},
"geometry": {
"type": "LineString",
"coordinates": [
[
21.7348336,
63.1817371
],
[
21.7340174,
63.1803407
],
[
21.7337985,
63.1798165
],
[
21.7336701,
63.1796189
],
[
21.7334107,
63.1794366
],
[
21.7330768,
63.1792931
],
[
21.7327166,
63.1791148
],
[
21.7324248,
63.1789103
],
[
21.7321882,
63.1786912
],
[
21.7320196,
63.1784645
],
[
21.7318318,
63.1781472
],
[
21.7318127,
63.1779711
],
[
21.7318692,
63.1776682
],
[
21.73197,
63.1772627
]
]
},
"id": "way/7976148"
},
{
"type": "Feature",
"properties": {
"@id": "way/18617780"
},
"geometry": {
"type": "LineString",
"coordinates": [
[
27.4328496,
68.446057
],
[
27.432846,
68.4458408
],
[
27.4327912,
68.4456453
],
[
27.4324782,
68.4450891
],
[
27.4322655,
68.4448676
],
[
27.4320019,
68.4446877
],
[
27.4218151,
68.4387766
],
[
27.4198287,
68.4376428
],
[
27.4178822,
68.436524
]
]
},
"id": "way/18617780"
},
]
}

Geofencing multiple polygons for a single point

I have found it very easy to filter a list of points using a geofence with geojson. Works great!

Unfortunately, my use case is trying to tell a user which geofence they are in. That means one point and multiple geo polygons. Best I've found so far is to search each geo polygon individually for the point using the filtering feature and see which one returns first.

Is there a better way to figure out which geofence a specific point is located in? We're seeing about a 0.8 second calculation time on a 27" iMac and we'd obviously like to bring that way down.

Is there a recommended way to achieve this with performance in mind?

Polygon & Point namespace confused by geojson

With the latest update I can't use Polygon from the poly package and neither Point from dart.math because geojson contains both of those Classes and thus confuses the namespace. This is my example script which worked fine before, but now don't. Could you make geojsons internal classes which are not part of the api private?

import 'dart:ffi';
import 'dart:io';
import 'package:geojson/geojson.dart';
import 'package:poly/poly.dart';

void main() async {
  polygons();
}

bool polygonContains(Polygon poli, Point target){
  return poli.contains(target.x, target.y);
}

void polygons() async {
  final file = File("ecorregiones.geojson");
  final geoSeries = await featuresFromGeoJsonFile(file);
  Point target = Point(-59.797841999254999, -19.72303808501668);
  List<Point> pointList = [];
  List<List<Point>> pointSeries = [];

  for (final geoSerie in geoSeries) {
    //print("${geoSerie.name}: ${geoSerie.geoPoints.length} geopoints");

    pointList = [];
    for (final geoPoint in geoSerie.geoPoints){
      double x = geoPoint.latitude;
      double y = geoPoint.longitude;
      Point p = Point(x, y);
      pointList.add(p);
    }

    Polygon poli = Polygon(pointList);
    bool contains = polygonContains(poli, target);
    if(contains){
      print('YES! $target is contained in ${geoSerie.name}.');
    }
    else print('nope!');
  }

}

Geojson data from api

i have multiple adresses from api with coordinates and i want to display their geojson data on the map like this
Screen Shot 2020-05-12 at 07 51 23

  • import 'package:flutter/material.dart';
    import 'package:flutter_map/flutter_map.dart';
    import 'package:latlong/latlong.dart';
    import 'package:promy_app/utilities/style.dart';
    import 'package:geojson/geojson.dart';

import 'dart:async';
import 'package:map_controller/map_controller.dart';
class Mapboxtest extends StatefulWidget {

final double lat;
final double lon;
final Object data;

Mapboxtest ({ Key key, @required this.lat,@required this.lon,this.data }): super(key: key);
@OverRide
_MapboxtestState createState() => new _MapboxtestState();
}

class _MapboxtestState extends State {

MapController mapController;
StatefulMapController statefulMapController;
StreamSubscription sub;
final lines = [];
Future parseAndDrawAssetsOnMap() async {
final geo = GeoJson();
geo.processedLines.listen((GeoJsonLine line) {
setState(() => lines.add(Polyline(
borderColor: Colors.red,
strokeWidth: 4.0, color: primarycolor, points: line.geoSerie.toLatLng())));
});
geo.endSignal.listen((_) => geo.dispose());
final data = widget.data;
await geo.parse(data, verbose: true);

}

@OverRide
void initState() {
mapController = MapController();
statefulMapController = StatefulMapController(mapController: mapController);
statefulMapController.onReady.then((_) => parseAndDrawAssetsOnMap());
sub = statefulMapController.changeFeed.listen((change) => setState(() {}));
super.initState();
}
@OverRide
Widget build(BuildContext context) {

return Scaffold(
    body: Stack(
      children: <Widget>[
        FlutterMap(
            options:
                MapOptions(
                  center: LatLng( widget.lon , widget.lat), zoom: 15,
            minZoom: 3.0,
           maxZoom: 20.0,
                  interactive: true, ),
            layers: [

          TileLayerOptions(
              urlTemplate:
              'https://api.mapbox.com/styles/v1/adnanefouham/cka1mwzas5g9k1iou3qn3odle/tiles/256/{z}/{x}/{y}@2x?access_token=TOKEN_KEY',              additionalOptions: {
                'accessToken':
                    'TOKEN_KEY',
                'id': 'mapbox.mapbox-stretts-v8',
              }),

          MarkerLayerOptions(markers: [
            Marker(
                width: 45.0,
                height: 45.0,
                point: LatLng(widget.lon , widget.lat),
                builder: (context) => Container(
                      child: IconButton(
                        icon: Icon(Icons.location_on),
                        color: primarycolor,
                        iconSize: 45.0,
                        onPressed: () {
                          parseAndDrawAssetsOnMap();
                          print('Marker tapped');
                        },
                      ),
                    ))
          ]),
              PolylineLayerOptions(
                polylines: statefulMapController.lines,
              ),
        ]),

      ],
    ));

}
}

Polygon type is not supported

Hello,

I have tried this library, but it seems that a NoSuchMethodError exception is thrown if the type of the geometry object is set to Polygon.
Looking at the code it seems that the only two supported types at this time are:

  • MultiPolygon
  • LineString

But the RFC spec states that there are seven:
"Point", "MultiPoint", "LineString",
"MultiLineString", "Polygon", "MultiPolygon", and
"GeometryCollection"

GeoJson used

{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[9.183021763511533,45.28718757700191],[9.184502342887754,45.28750460520285],[9.186154583640928,45.28422856168324],[9.184706190772886,45.28394925889815]]]}}]}

geojson validated with http://geojson.io

Please add a doc that state the current supported types and use an exception more meaningful (or do not return values for unsupported types, your choose)

Need latlong2 dependency in geopoint package upgraded

Hello, I am using flutter_map, wanting to upgrade from v4 > v6, but I am getting this error:

Because geojson >=1.0.0 depends on geopoint ^1.0.0 which depends on latlong2 ^0.8.0, geojson >=1.0.0 requires latlong2 ^0.8.0. So, because <project> depends on both geojson ^1.0.0 and latlong2 ^0.9.0, version solving failed.

Can the latlong2 package can be upgraded? The repository looks like it is archived. Not sure what that means in terms of further development.

Thank you.

Exception when trying to parse geojson

I am trying to load and parse simple geojson:

Future<void> parse() async {
    final geojson = GeoJson();

    String json="{\n" +
        "    \"type\": \"Point\",\n" +
        "    \"coordinates\": [\n" +
        "        -105.01621,\n" +
        "        39.57422\n" +
        "    ]\n" +
        "}";

    await geojson.parse(json);

  }

and I am getting exception:

NoSuchMethodError: The getter 'iterator' was called on null.
Receiver: null
Tried calling: iterator

JSON is valid, what am I doing wrong?

GeoJsonMultiLine serialized to type `Line`

I am new to GeoJson, but I notice that the GeoJsonFeature GeoJsonMultiLine when serialized the value of the Type is Line, however, when parsing a geojson collection that includes as feature with Type Line an exception is throw.

The serialization code is in src/models.dart at line 241:

  /// Serialize to a geojson feature string
  String serializeFeature(Map<String, dynamic>? properties) {
    final geoSeries = <GeoSerie?>[];
    for (final line in lines) {
      geoSeries.add(line.geoSerie);
    }
    return _buildGeoJsonFeature(
        geoSeries, "Line", properties ?? <String, dynamic>{"name": name});
  }

As you can notice, the type value is set to Line.

Looking at the code, in the file src/geojson.dart at line 498:

  case "MultiLineString":
    if (query != null) {
      if (query.geometryType != null) {
        if (query.geometryType != GeoJsonFeatureType.multiline) {
          continue;
        }
      }
    }
    feature = _processGeometry(geometry, properties, nameProperty);
    break;

A case for MultiLineString is evaluated but there is no case for Line type.

So, the questions are:

  • Why serialization of a GeoJson model (GeoJsonMultiLine) would set a type that doesn't fit to the GeoJson specifications, if it is not supported by the library? Is there a different way to generate GeoJson data?
  • Is it a bug? Can it be solved?
  • The generation of GeoJson data is not a recommended use case of this library?

Thanks in advance for your attention to this issue!!

Custom feature properties?

I need to send some decoration info for my polygons (e.g. color).
How can I do this with GeoJsonFeatureCollection.serialize?
image

JSON generation

How do I generate a new geojson from e.g. Google Map polygons?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.