geojson
GeoJSON डेटा के साथ काम करने के लिए उपकरण। प्रतिक्रियाशील API के साथ पार्सर, खोज और भौगोलिक घेराव
Dart में GeoJSON डेटा के साथ काम करने के लिए उपकरण
यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
Utilities to work with geojson data in Dart. Features:
Note: the data is parsed in an isolate to avoid slowing down the main thread
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 the parsed data if truefeaturesFromGeoJsonFile: 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 the parsed data if trueThese functions are suitable for small data. Example:
final features = await featuresFromGeoJson(data);
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, requirednameProperty: the property used for the geoserie name, automaticaly set if nullverbose: print the parsed data if trueTyped 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 geometriesprocessedPoints: the parsed pointsprocessedMultipoints: the parsed multipointsprocessedLines: the parsed linesprocessedMultilines: the parsed multilinesprocessedPolygons: the parsed polygonsprocessedMultipolygons: the parsed multipolygonsendSignal: parsing is finished indicatorExample: 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);
}
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 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
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
To draw geojson data on a map check the Map controller package
All the data structures use GeoPoint and GeoSerie from the GeoPoint package to store the geometry data. Data structures used:
String nameList<GeoJsonFeature> collectionGeoJsonFeatureType type: types
Map<String, dynamic> properties: the json properties of the feature
dynamic geometry: the geometry data, depends on the feature type, see below
String nameGeoPoint geoPoint: the geometry dataString nameGeoSerie geoSerie: the geometry data: this will produce a geoSerie of type GeoSerieType.groupString nameGeoSerie geoSerie: the geometry data: this will produce a geoSerie of type GeoSerieType.lineString nameList<GeoJsonLine> linesString nameList<GeoSerie> geoSeries: the geometry data: this will produce a list of geoSerie of type GeoSerieType.polygon*String nameList<GeoJsonPolygon> polygonsString nameList<GeoJsonFeature> geometriesNote: none of the parameters is final for all of these data structures
निर्भरता सूची 6 आइटम
^0.4.0-nullsafety.0^1.0.0^1.0.0^1.11.1^1.4.0^1.17.4उपयोग के अनुसार छाँटें, गतिविधि की तुलना करें और अपनाने से पहले मूल प्रोजेक्ट की आवश्यकताएँ जाँचें।
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗