Skip to content

Latest commit

 

History

History
 
 

geodata

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Geodata

pub package License

Geodata is a library package for Dart and Flutter mobile developers to help on accessing GeoJSON and other geospatial data sources.

Key features:

  • Client-side data source abstractions
    • common geospatial Web APIs
    • geospatial feature services
  • Data source implementations to read geospatial features
  • Also (partially) conforming to following standards

This package is at BETA stage, interfaces not fully final yet.

Usage

This sample shows to read GeoJSON features from a web resource using a HTTP fetcher, and from a local file using a file fetcher.

Please see other examples too.

import 'package:datatools/fetch_http.dart';
import 'package:datatools/fetch_file.dart';

import 'package:geodata/geojson_features.dart';

Future<void> main(List<String> args) async {
  // read GeoJSON for earthquakes from web using HTTP fetcher
  print('GeoJSON features from HTTP');
  await _readFeatures(
    HttpFetcher.simple(endpoints: [
      Uri.parse('https://earthquake.usgs.gov/earthquakes/feed/v1.0/')
    ]),
    'summary/2.5_day.geojson',
  );

  // same thing but files using a file fetcher to read a local file
  print('');
  print('GeoJSON features from file');
  await _readFeatures(
    FileFetcher.basePath('test/usgs'),
    'summary/2.5_day.geojson',
  );
}

Future<void> _readFeatures(Fetcher client, String collectionId) async {
  // create feature source using the given Fetch API client
  final source = FeatureSourceGeoJSON.of(
    client: client,
    meta: DataSourceMeta.collectionIds([collectionId], title: 'Earthquakes'),
  );

  // read features with error handling
  try {
    // get items or features from collection id, maximum 5 features returned
    final items = await source.items(
      collectionId,
      filter: FeatureFilter(limit: 5),
    );

    // do something with features, in this sample just print them out
    for (final f in items.features) {
      print('Feature with id: ${f.id}');
      print('  geometry: ${f.geometry}');
      print('  properties:');
      for (final key in f.properties.keys) {
        print('    $key: ${f.properties[key]}');
      }
    }
  } on OriginException catch (e) {
    final msg = e.isNotFound ? 'not found' : 'status code ${e.statusCode}';
    print('Origin exception: $msg');
  } on Exception catch (e) {
    print('Other exception: $e');
  }
}

Installing

The package supports Dart null-safety and using it requires at least Dart 2.12 from the stable channel. Please see the official null-safety migration guide.

In the pubspec.yaml of your project add the dependency:

dependencies:
  geodata: ^0.6.0  

All dependencies used by geodata are also ready for null-safety!

Package

This is a Dart code package named geodata under the geospatial repository.

The package is associated with and depending on the datatools package containing non-geospatial tools to fetch data from HTTP and file resources. The geodata package then provides client-side access for geospatial APIs and data sources.

This package also utilizes the geocore package for geometry, metadata and feature data structures and GeoJSON parser, and the attributes package for non-geospatial data structures.

Libraries

The package contains following mini-libraries:

Library Description
api_common Data source abstraction for client access of common geospatial Web APIs.
api_features Data source abstraction for client access of geospatial features Web APIs.
geojson_features A client-side data source to read GeoJSON features from a Web API or files.
oapi_common Data source abstraction for client access of OGC API Common based services.
oapi_features A client-side data source to read features from OGC API Features services.

For example to access a mini library you should use an import like:

import 'package:geodata/oapi_features.dart';

To use all libraries of the package:

import 'package:geodata/geodata.dart';

Authors

This project is authored by Navibyte.

More information and other links are available at the geospatial repository from GitHub.

License

This project is licensed under the "BSD-3-Clause"-style license.

Please see the LICENSE.