chuyentt / geojson_vi

An Open-Source Dart and Flutter Library for Efficiently Handling GeoJSON Data in Compliance with RFC 7946
https://pub.dev/packages/geojson_vi
MIT License
15 stars 10 forks source link

Load geojson from string and parse all features - functionality removed? #13

Closed giaur500 closed 3 years ago

giaur500 commented 3 years ago

Version 1.5 it was possible:

//Load geojson string:
GeoJSON geojson = GeoJSON.fromString(globals.city.mapBounds);

//Enumearate all geojson features:
var allFeatures = geojson.featureCollection.features;

After upgrading to version 2:

Without it, library is useless. Any advice?

giaur500 commented 3 years ago

Ok, I figured it out, need to use GeoJSONFeatureCollection and its fromJSON methods. But, it again fails on valid geojson, for example with json provided as follows:

{"type":"MultiPolygon","coordinates":[[[[22.605908299999999,52.974546799999999],[22.606422200000001,52.974650500000003],[22.608650699999998,52.975089799999999],[22.6098763,52.975354099999997],[22.6101156,52.975395399999996],[22.611150899999998,52.975740999999999],[22.611351899999999,52.975798699999999],[22.614527200000001,52.9768343],[22.614683100000001,52.976858100000001],[22.616637699999998,52.977156700000002],[22.617345700000001,52.9772648],[22.6192043,52.9772648],[22.625474400000002,52.975321600000001],[22.629048600000001,52.975112600000003],[22.6327657,52.975051100000002],[22.6347673,52.975137199999999],[22.636462399999999,52.975665999999997],[22.641609299999999,52.975051100000002],[22.644611600000001,52.974263999999998],[22.6452651,52.973944199999998],[22.647838499999999,52.974054899999999],[22.6522501,52.974423899999998],[22.655272799999999,52.974903500000003],[22.657294799999999,52.974854299999997],[22.6640959,52.9740672],[22.666730600000001,52.973107900000002],[22.669487799999999,52.973624399999999],[22.6773919,52.975776699999997],[22.679699800000002,52.976674500000001],[22.683641600000001,52.978666699999998],[22.6905857,52.978875700000003],[22.694956399999999,52.978617499999999],[22.6944458,52.971373700000001],[22.692219600000001,52.971115400000002],[22.692219600000001,52.968483200000001],[22.690892099999999,52.967314600000002],[22.689564499999999,52.966306000000003],[22.6874404,52.965137400000003],[22.685214200000001,52.964177800000002],[22.6798632,52.962775399999998],[22.671816199999999,52.961028499999998],[22.671693600000001,52.9611515],[22.663932599999999,52.959699800000003],[22.6638509,52.958740200000001],[22.662135299999999,52.958691000000002],[22.655089,52.959712099999997],[22.650391500000001,52.959146199999999],[22.651474,52.957546800000003],[22.651535299999999,52.9564764],[22.648614599999998,52.956414799999997],[22.6499013,52.953191099999998],[22.650207699999999,52.951296200000002],[22.6603788,52.951689899999998],[22.6750431,52.947604400000003],[22.674307899999999,52.943863100000002],[22.6778412,52.937290500000003],[22.6777187,52.935567200000001],[22.677330600000001,52.934016100000001],[22.677493999999999,52.932292699999998],[22.6785356,52.931098499999997],[22.6815584,52.928820899999998],[22.684581099999999,52.927602],[22.687113700000001,52.926259999999999],[22.6884412,52.925238100000001],[22.6933021,52.922898600000003],[22.707731800000001,52.9205112],[22.709945699999999,52.929006299999998],[22.715391400000001,52.934001299999998],[22.722049899999998,52.929301000000002],[22.724974199999998,52.930893599999997],[22.731385899999999,52.927660299999999],[22.735519,52.930337600000001],[22.742496899999999,52.925064499999998],[22.756043600000002,52.924861100000001],[22.7641089,52.925728399999997],[22.767697500000001,52.928534200000001],[22.767999400000001,52.932005699999998],[22.7702718,52.936762199999997],[22.767910400000002,52.941665800000003],[22.767158500000001,52.9458445],[22.769841400000001,52.951037100000001],[22.777074500000001,52.957186800000002],[22.7787106,52.9585857],[22.780200900000001,52.962218399999998],[22.782107700000001,52.963483799999999],[22.783398900000002,52.9640208],[22.785397199999998,52.964474500000001],[22.7880571,52.965909699999997],[22.786242600000001,52.967150099999998],[22.785574100000002,52.969217200000003],[22.784597900000001,52.971297499999999],[22.7800482,52.974936900000003],[22.777988100000002,52.977749099999997],[22.775713100000001,52.979664999999997],[22.773987900000002,52.980460899999997],[22.7687135,52.981943700000002],[22.769920599999999,52.983922800000002],[22.767962300000001,52.984285999999997],[22.767858199999999,52.985624899999998],[22.7693163,52.989982900000001],[22.762162199999999,52.991032599999997],[22.7641442,52.996696700000001],[22.7722327,52.993408100000003],[22.777449499999999,52.997734000000001],[22.775486000000001,52.998694800000003],[22.7779679,53.001535500000003],[22.770933599999999,53.001983699999997],[22.7656481,53.001140700000001],[22.762032999999999,53.002378299999997],[22.7624429,53.004947999999999],[22.760517700000001,53.006356500000003],[22.763419500000001,53.007612100000003],[22.768344200000001,53.010712400000003],[22.771187900000001,53.013429500000001],[22.774940900000001,53.015892999999998],[22.7792715,53.020696200000003],[22.786215599999998,53.031928899999997],[22.791747999999998,53.031208300000003],[22.791924900000001,53.031185299999997],[22.803834299999998,53.033162699999998],[22.807839999999999,53.036249099999999],[22.8156547,53.0382216],[22.822573599999998,53.041969399999999],[22.831210800000001,53.0472495],[22.854098199999999,53.052702699999998],[22.863260400000001,53.054946100000002],[22.868746000000002,53.073675700000003],[22.866414299999999,53.076783599999999],[22.860888899999999,53.075470500000002],[22.8559947,53.074955600000003],[22.852919799999999,53.073932399999997],[22.849141299999999,53.073381099999999],[22.8469862,53.0722156],[22.842238500000001,53.071246299999999],[22.8377965,53.071614400000001],[22.831750799999998,53.072820200000002],[22.8287394,53.074601700000002],[22.824599200000002,53.074173500000001],[22.8221153,53.075600999999999],[22.815689299999999,53.0788394],[22.817786900000002,53.081467099999998],[22.8162719,53.083312499999998],[22.816386000000001,53.088811200000002],[22.814706900000001,53.093020000000003],[22.809284999999999,53.094990600000003],[22.804177200000002,53.098410700000002],[22.8015081,53.097211100000003],[22.7904588,53.096561100000002],[22.7898256,53.095567699999997],[22.7787355,53.092930899999999],[22.775773999999998,53.092035500000001],[22.774671099999999,53.091459100000002],[22.769912300000001,53.087877400000004],[22.767665699999998,53.085399500000001],[22.765356100000002,53.0837699],[22.764377499999998,53.083093300000002],[22.761354699999998,53.082909299999997],[22.756943199999998,53.080823700000003],[22.7543902,53.079878999999998],[22.7505709,53.0781736],[22.748528499999999,53.076750400000002],[22.747037599999999,53.074959],[22.7460573,53.074235100000003],[22.7451586,53.072713499999999],[22.746016399999998,53.071388300000002],[22.745648800000001,53.070553799999999],[22.740277299999999,53.067350900000001],[22.732373200000001,53.062196299999997],[22.7320669,53.0616439],[22.734742399999998,53.058256200000002],[22.7298407,53.059103200000003],[22.722140899999999,53.0601956],[22.715931999999999,53.061398500000003],[22.711295799999998,53.0631536],[22.696876499999998,53.0649455],[22.6913825,53.063632300000002],[22.685602599999999,53.061717600000001],[22.6833764,53.061484399999998],[22.6834989,53.060993400000001],[22.679781800000001,53.061484399999998],[22.675186400000001,53.059238200000003],[22.676268799999999,53.058894500000001],[22.682252999999999,53.058157999999999],[22.680271900000001,53.056304500000003],[22.6772083,53.054057999999998],[22.672531299999999,53.050510099999997],[22.670059999999999,53.048877300000001],[22.666240699999999,53.046740900000003],[22.661910899999999,53.043880000000001],[22.662053799999999,53.043573100000003],[22.663381399999999,53.042959099999997],[22.666710500000001,53.042553900000001],[22.6646681,53.041375100000003],[22.665628000000002,53.037629600000002],[22.665934400000001,53.037826099999997],[22.6662611,53.036745400000001],[22.6643413,53.0357506],[22.6601748,53.034190899999999],[22.657846500000002,53.032815300000003],[22.656355600000001,53.031599399999998],[22.655722399999998,53.029474499999999],[22.653292,53.024892700000002],[22.6520461,53.023479899999998],[22.650412200000002,53.0222269],[22.648717000000001,53.021366899999997],[22.648185999999999,53.020654399999998],[22.644652700000002,53.019929500000003],[22.6391788,53.017742699999999],[22.638096300000001,53.017128300000003],[22.6281499,53.013110500000003],[22.625413099999999,53.013012199999999],[22.623125600000002,53.012520700000003],[22.620511400000002,53.010996900000002],[22.619612700000001,53.010148999999998],[22.622696699999999,53.008649800000001],[22.623064400000001,53.007900200000002],[22.6210016,53.006953899999999],[22.621307900000001,53.0063149],[22.6177542,53.005380799999998],[22.614996900000001,53.006339400000002],[22.610871299999999,53.004926099999999],[22.6097684,53.000304800000002],[22.609666300000001,52.999161700000002],[22.609911400000001,52.997785],[22.611320599999999,52.9977236],[22.610033900000001,52.995203600000004],[22.609176099999999,52.992622099999998],[22.6103199,52.990040399999998],[22.6101156,52.989142899999997],[22.6107488,52.985565000000001],[22.610830499999999,52.980080899999997],[22.605622400000001,52.977129499999997],[22.603518699999999,52.974719],[22.602722199999999,52.9744362],[22.602946800000002,52.973968800000002],[22.6051927,52.974414000000003],[22.605908299999999,52.974546799999999]]]]}

It fails with message Invalid type. That geojson is valid, and it works with 1.5 version without any problems. On https://geojson.io/ it draws bounds correctly.

chuyentt commented 3 years ago

Ok, I figured it out, need to use GeoJSONFeatureCollection and its fromJSON methods. But, it again fails on valid geojson, for example with json provided as follows:

`{"type":"MultiPolygon","coordinates":[[[[22.605908299999999,52.974546799999999], ...

It fails with message Invalid type. That geojson is valid, and it works with 1.5 version without any problems. On https://geojson.io/ it draws bounds correctly.

If you already know its type 'MultiPolygon', then you can do like:

  final geometryFromJSON = GeoJSONMultiPolygon.fromJSON(jsonString);

or you can create a GeoJSON object from data without knowing its type:

  final geometryFromJSON = GeoJSON.fromJSON(jsonString);

please read more at README

giaur500 commented 3 years ago

Actually, I don't know type. There may be any type or multiple types included. That's what I need this library for - load geojson and extraxt all features into handy structures, used to draw on map.

When I know type or I have only single type, I don't need your lib. As everything is fine in old version, I think we can consider it as a bug.

steinmetz commented 3 years ago

Hi @giaur500, thanks for reporting this issue. I think my PR fixed this bug :) Can you please check if it is working now? @chuyentt published the updated: geojson_vi: ^2.0.2

giaur500 commented 3 years ago

Hi, I will try and let you know if problem is still there.