搜索插件、代码仓与 APP 分类

插件详情v1.0.0

geojson

用于处理 GeoJSON 数据的工具。具有响应式 API 的解析器、搜索和地理围栏功能

AndroidiOSmacOSWindowsLinux
近 30 天下载
1380
喜欢数
63
Pub 分数
140

安装插件

flutter pub add geojson

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

geojson 包为 Flutter 应用程序中的 GeoJSON 数据处理提供了实用工具。它包含一个响应式解析器,可实现实时处理 GeoJSON 结构,支持空间搜索操作,并提供基于位置的触发器的地理围栏功能。专为集成地图和地理空间功能的开发者设计,该包简化了在多个平台间解析和操作 GeoJSON 内容的过程。该包非常适合需要动态地图数据处理的应用程序,例如导航工具、位置跟踪或交互式地图。

适合场景

  • 交互式地图应用
  • 基于位置的通知
  • 地理空间数据可视化
  • 实时路线规划
  • 地图图层管理

主要特点

  • 响应式 GeoJSON 解析
  • 内置空间搜索
  • 地理围栏支持
  • 跨平台兼容性
  • 基于流的数据处理

适合对象

  • 移动和桌面地图应用
  • 位置感知服务
  • GIS 集成
  • 实时数据仪表板
  • 使用 Flutter 进行地理空间项目开发的团队

使用建议

  • 需要了解 GeoJSON 格式
  • 可能需要额外的依赖项才能完整渲染地图
  • 性能取决于数据大小
  • 限于基本的地理空间逻辑
  • 不是完整的GIS解决方案

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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

所属分类

依赖

依赖清单 4 项

  • geodesy^0.4.0-nullsafety.0
  • geopoint^1.0.0
  • iso^1.0.0
  • pedantic^1.11.1

源码仓库

使用此插件的项目