- Notifications
You must be signed in to change notification settings - Fork5
Geospatial data structures, tools and utilities for Dart and Flutter.
License
navibyte/geospatial
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Geospatial data structures, tools and utilities forDart andFlutter - coordinates,geometries, feature objects, metadata, spherical geodesy, projections, tilingschemes, vector data models and formats, and geospatial Web APIs.
Read the docs 👉geospatial.navibyte.dev!
🗺️Roadmap 2025: The current state and candidate issues for the geobase package.
✨ New (2025-03-11): The stable version 1.5.0 withglobal grids, better WGS84projection support andunit conversions.
✨ New (2024-11-10): The stable release withellipsoidal geodesy functions letting you calculate distances, bearings, destination positions and intermediate points along the Earth surface accurately.
✨ New (2024-07-26): The stable version 1.3.0 with centroid, polylabel, point-in-polygon and other cartesian 2D calculations enhanced -read more!
Dart code packages published atpub.dev:
Code | Package | Description |
---|---|---|
🌐geobase | Geospatial data structures (coordinates, geometries, features, metadata), ellipsoidal and spherical geodesy, projections and tiling schemes. Vector data format support forGeoJSON,WKT andWKB. | |
🌎geodata | Geospatial feature service Web APIs with support forGeoJSON andOGC API Features clients. |
Comprehensive guidance on how to use package and aboutGeospatial tools for Dart is available on thegeospatial.navibyte.dev website.
Overview topics aboutGeospatial tools for Dart:
Thegeobasepackage documentation by chapters:
- 📍 Coordinates
- 🧩 Simple geometries
- 📏 Geometry calculations
- 🔷 Geospatial features
- 📃 Vector formats
- 🔵 Ellipsoidal geodesy
- 📐 Spherical geodesy
- 📅 Metadata
- 🌐 Global grids
- 🗺️ Projections
- 🔢 Tiling schemes
- ⚖️ Unit conversions
Thegeodatapackage documentation by chapters:
Key features of thegeobase package:
- 🌐 geographic (longitude-latitude) and projected positions and bounding boxes
- 🧩 simple geometries (point, line string, polygon, multi point, multi line string, multi polygon, geometry collection)
- 📏 cartesian 2D calculations (centroid, polylabel, point-in-polygon, distance).
- 🔷 features (with id, properties and geometry) and feature collections
- 📐 ellipsoidal (vincenty) and spherical (great circle,rhumb line) geodesy tools, with ellipsoidal datum,UTM,MGRS and ECEF (earth-centric earth-fixed) support
- 📅 temporal data structures (instant, interval) and spatial extents
- 📃 vector data formats supported (GeoJSON,Newline-delimited GeoJSON,WKT,WKB)
- 🗺️ coordinate projections (built-in WGS84 based projections on geographic, geocentric, UTM and Web Mercator coordinates + externalproj4dart support)
- 🔢 tiling schemes and tile matrix sets (web mercator, global geodetic)
- ⚖️ unit conversions (angle, angular velocity, area, distance, speed and time)
Key features of thegeodata package:
- 🪄 Client-side data source abstraction for geospatial feature service Web APIs.
- 🌐 TheGeoJSON client to read features from static web resources and local files, supports alsoNewline-delimited GeoJSON data.
- 🌎 TheOGC API Features client to access metadata and feature items from a compliant geospatial Web API providing GeoJSON data.
Client-side support for the OGC API Features standard:
Standard part | Support in this package |
---|---|
OGC API - Features - Part 1: Core | Supported for accessing metadata and GeoJSON feature collections. |
OGC API - Features - Part 2: Coordinate Reference Systems by Reference | Supported. |
OGC API - Features - Part 3: Filtering Common Query Language (CQL2) | Partially supported (conformance classes, queryables, features filter). |
Ellipsoidal andspherical geodesy functions to calculate distances etc.:
final greenwich=Geographic.parseDms(lat:'51°28′40″ N', lon:'0°00′05″ W');final sydney=Geographic.parseDms(lat:'33.8688° S', lon:'151.2093° E');// How to calculate distances using ellipsoidal Vincenty, spherical// great-circle and spherical rhumb line methods is shown first.// The distance along a geodesic on the ellipsoid surface (16983.3 km). greenwich.vincenty().distanceTo(sydney);// By default the WGS84 reference ellipsoid is used but this can be changed. greenwich.vincenty(ellipsoid:Ellipsoid.GRS80).distanceTo(sydney);// The distance along a spherical great-circle path (16987.9 km). greenwich.spherical.distanceTo(sydney);// The distance along a spherical rhumb line path (17669.8 km). greenwich.rhumb.distanceTo(sydney);// Also bearings, destination points and mid points (or intermediate points)// are provided for all methods, but below shown only for great-circle paths.// Destination point (10 km to bearing 61°): 51° 31.3′ N, 0° 07.5′ E greenwich.spherical.initialBearingTo(sydney); greenwich.spherical.finalBearingTo(sydney);// Destination point: 51° 31.3′ N, 0° 07.5′ E greenwich.spherical.destinationPoint(distance:10000, bearing:61.0);// Midpoint: 28° 34.0′ N, 104° 41.6′ E greenwich.spherical.midPointTo(sydney);// Vincenty ellipsoidal geodesy functions provide also `inverse` and `direct`// methods to calculate shortest arcs along a geodesic on the ellipsoid. The// returned arc object contains origin and destination points, initial and// final bearings, and distance between points. greenwich.vincenty().inverse(sydney); greenwich.vincenty().direct(distance:10000, bearing:61.0);
As a quick sample, this is how geometry objects with 2D coordinate are createdusinggeobase:
Geospatial feature and feature collections can be instantiated easily too:
// A geospatial feature collection (with two features):FeatureCollection([Feature( id:'ROG',// a point geometry with a position (lon, lat, elev) geometry:Point.build([-0.0014,51.4778,45.0]), properties: {'title':'Royal Observatory','city':'London','isMuseum':true, }, ),Feature( id:'TB',// a point geometry with a position (lon, lat) geometry:Point.build([-0.075406,51.5055]), properties: {'title':'Tower Bridge','built':1886, }, ), ]);
More details in the article (2024-04-14)Decode and encode GeoJSON, WKT and WKB in Dart and Flutter apps.
GeoJSON, WKT and WKB formats are supported as input and output:
// Parse a geometry from GeoJSON text.final geometry=LineString.parse('{"type": "LineString", "coordinates": [[30,10],[10,30],[40,40]]}', format:GeoJSON.geometry, );// Encode a geometry as GeoJSON text.print(geometry.toText(format:GeoJSON.geometry));// Encode a geometry as WKT text.print(geometry.toText(format:WKT.geometry));// Encode a geometry as WKB bytes.final bytes= geometry.toBytes(format:WKB.geometry);// Decode a geometry from WKB bytes.LineString.decode(bytes, format:WKB.geometry);
A sample showing more deeply how to handle WKB and EWKB binary data:
// to get a sample point, first parse a 3D point from WKT encoded stringfinal p=Point.parse('POINT Z(-0.0014 51.4778 45)', format:WKT.geometry);// to encode a geometry as WKB/EWKB use toBytes() or toBytesHex() methods// encode as standard WKB data (format: `WKB.geometry`), prints:// 01e9030000c7bab88d06f056bfb003e78c28bd49400000000000804640final wkbHex= p.toBytesHex(format:WKB.geometry);print(wkbHex);// encode as Extended WKB data (format: `WKB.geometryExtended`), prints:// 0101000080c7bab88d06f056bfb003e78c28bd49400000000000804640final ewkbHex= p.toBytesHex(format:WKB.geometryExtended);print(ewkbHex);// otherwise encoded data equals, but bytes for the geometry type varies// there are some helper methods to analyse WKB/EWKB bytes or hex strings// (decodeFlavor, decodeEndian, decodeSRID and versions with hex postfix)// prints: "WkbFlavor.standard - WkbFlavor.extended"print('${WKB.decodeFlavorHex(wkbHex)} - ${WKB.decodeFlavorHex(ewkbHex)}');// when decoding WKB or EWKB data, a variant is detected automatically, so// both `WKB.geometry` and `WKB.geometryExtended` can be usedfinal pointFromWkb=Point.decodeHex(wkbHex, format:WKB.geometry);final pointFromEwkb=Point.decodeHex(ewkbHex, format:WKB.geometry);print(pointFromWkb.equals3D(pointFromEwkb));// prints "true"// SRID can be encoded only on EWKB data, this sample prints:// 01010000a0e6100000c7bab88d06f056bfb003e78c28bd49400000000000804640final ewkbHexWithSRID= p.toBytesHex(format:WKB.geometryExtended, crs:CoordRefSys.EPSG_4326);print(ewkbHexWithSRID);// if you have WKB or EWKB data, but not sure which, then you can fist check// a flavor and whether it contains SRID, prints: "SRID from EWKB data: 4326"if (WKB.decodeFlavorHex(ewkbHexWithSRID)==WkbFlavor.extended) {final srid=WKB.decodeSRIDHex(ewkbHexWithSRID);if (srid!=null) {print('SRID from EWKB data: $srid');// after finding out CRS, an actual point can be decoded// Point.decodeHex(ewkbHexWithSRID, format: WKB.geometry); } }
Using Newline-delimited GeoJSON (or "GeoJSONL") is as easy as using thestandard GeoJSON:
/// a feature collection encoded as GeoJSONL and containing two features that /// are delimited by the newline character \nconst sample=''' {"type":"Feature","id":"ROG","geometry":{"type":"Point","coordinates":[-0.0014,51.4778,45]},"properties":{"title":"Royal Observatory","place":"Greenwich"}} {"type":"Feature","id":"TB","geometry":{"type":"Point","coordinates":[-0.075406,51.5055]},"properties":{"title":"Tower Bridge","built":1886}} ''';// parse a FeatureCollection object using the decoder for the GeoJSONL formatfinal collection=FeatureCollection.parse(sample, format:GeoJSONL.feature);// ... use features read and returned in a feature collection object ...// encode back to GeoJSONL dataprint(collection.toText(format:GeoJSONL.feature, decimals:5));
Thegeodata package has the followingdiagram describing a decision flowchart how to select a client class to accessGeoJSON features:
Quick start code to access a Web API service conforming to OGC API Features:
// 1. Get a client instance for a Web API endpoint.final client=OGCAPIFeatures.http(endpoint:Uri.parse('...'));// 2. Access/check metadata (meta, OpenAPI, conformance, collections) as needed.final conformance=await client.conformance();if (!conformance.conformsToFeaturesCore(geoJSON:true)) {return;// not conforming to core and GeoJSON - so return}// 3. Get a feature source for a specific collection.final source=await client.collection('my_collection');// 4. Access (and check) metadata for this collection.final meta=await source.meta();print('Collection title: ${meta.title}');// 5. Access feature items.final items=await source.itemsAll(limit:100);// 6. Check response metadata.print('Timestamp: ${items.timeStamp}');// 7. Get an iterable of feature objects.final features= items.collection.features;// 8. Loop through features (each with id, properties and geometry)for (final featin features) {print('Feature ${feat.id} with geometry: ${feat.geometry}');}
More guidance and code examples are provided on thegeospatial.navibyte.dev documentation site.
✨ See also theGeospatial demos for Dart coderepository for demo and sample apps demonstrating the usage ofgeobase andgeodata packages along with other topics.
Code | Description |
---|---|
earthquake_map | Shows earthquakes fetched from theUSGS web service on a basic map view. The demo uses bothgeobase andgeodata packages for geospatial data accesss. Discusses also state management based onRiverpod. The map UI is based on theGoogle Maps Flutter plugin. |
2025-03-11
- ✨ The stable version 1.5.0 withglobal grids, better WGS84projection support andunit conversions.
- All docs:geospatial.navibyte.dev.
- Published packages at pub.dev:
2024-11-10
- ✨ The stable release withellipsoidal geodesy functions letting you calculate distances, bearings, destination positions and intermediate points along the Earth surface accurately.
- All docs:geospatial.navibyte.dev.
- Published packages at pub.dev:
2024-07-26
- ✨ Thestable version 1.3.0 with centroid, polylabel, point-in-polygon and other cartesian 2D calculations enhanced -read more!
- All docs:geospatial.navibyte.dev.
- Published packages at pub.dev:
2024-05-26
- ✨ The stable version 1.2.0 with the brand new documentation site published atgeospatial.navibyte.dev.
- Published packages at pub.dev:
2024-04-22
- ✨ Thestable version 1.1.0 adds support for Newline-delimited GeoJSON, EWKT and EWKB.
- See also the articleDecode and encode GeoJSON, WKT and WKB in Dart and Flutter apps.
- Published packages at pub.dev:
2023-10-29
- ✨ The stable version 1.0.0 is now ready. See also the articleGeospatial tools for Dart - version 1.0 published at Medium
- geobase version 1.0.0
- geodata version 1.0.0
See also older news in thechangelog of this repository.
🗺️Roadmap 2025: The current state and candidate issues for the geobase package.
🧩 Seeopen issues for planned features, requests for change, and observed bugs.
💡 Any comments, questions, suggestions of new features and other other contributions are welcome, of course!
📚 Documentation:geospatial.navibyte.dev
🪄 Active packages in this repository:
This project is authored byNavibyte.
This project is licensed under the "BSD-3-Clause"-style license.
Please see theLICENSE.
This project contains portions of derivative work:
- geobase: details aboutDERIVATIVE work.
Source repositories used when porting functionality to Dart and this project:
- geodesy by Chris Veness 2002-2024
- polylabel by Mapbox 2016-2024
- tinyqueue by Vladimir Agafonkin 2017-2024
Some external links and other resources.
Geospatial:
- GeoJSON based onRFC 7946
- Newline-delimited GeoJSON with variants specified elsewhere:
- Simple Feature Access - Part 1: Common Architecture
- WKT (Well-known text representation of geometry)
- WKB (Well-known binary)
- Coordinate Reference Systems by W3C
- EPSG (Geodetic Parameter Dataset)
- World Geodetic System, see alsoEPSG:4326 about WGS 84
- Web Mercator projection, see alsoEPSG:3857 andBing Maps Tile System
- Geographic coordinate conversion
- Geodetic datum
- Ellipsoid
- Geodesic
- Geodesic on ellipsoid
- Helmert transformation
- ECEF (Earth-centered, Earth-fixed coordinate system)
- UTM (Universal Transverse Mercator)
- MGRS (Military Grid Reference System)
- ISO 6709 on standard representation of geographic point location by coordinates
OGC (The Open Geospatial Consortium) related:
- OGC APIs
- OGC Web API Guidelines
- Simple Feature Access - Part 1: Common Architecture
- OGC Two Dimensional Tile Matrix Set
W3C
The OpenAPI Initiative (OAI)
SDKs:
Latest on Dart SDKs
- Dart 3.7 with developer productivity enhancements.
- Dart 3.6 with digit separators and new features in the pub ecosystem (pub download counts and pub workspaces)
- Dart 3.5 with improvements in interoperability and an update on the Dart roadmap.
- Dart 3.4 with WebAssembly (WASM) updates and the roadmap for Dartmacros.
- Dart 3.3 with extension types, evolving JavaScript-interoperability and experimental support for WebAssembly.
- Dart 3.2 with improved language & developer experience.
- Dart 3 with 100% sound null safety, new features (records, patterns, and class modifiers), and a peek into the future.
- Dart 3 alpha with records, patterns, access controls, portability advancements and the new Dart 3 type system (100% sound null safety)
- Dart 2.18 with Objective-C & Swift interop, and improved type inference
- Dart 2.17 with enum member support, parameter forwarding to super classes, flexibility for named parameters, and more
- Dart 2.16 with improved tooling and platform handling
- Dart 2.15 with fast concurrency, constructor tear-offs, improved enums, and more
- Dart 2.14 with Apple Silicon support, default lints etc.
- Dart 2.13 with new type aliases and more
- Dart 2.12 with sound null safety
Latest on Flutter SDKs
- Flutter 3.29 running on Dart 3.7 and with updates to Impeller, Cupertino and DevTools.
- Flutter 3.27 running on Dart 3.6 and with enhanced Impeller and improvements to Cupertino widgets.
- Flutter 3.24 running on Dart 3.5 and with Multi-View Embedding and preview on Flutter GPU.
- Flutter 3.22 running on Dart 3.4 and stable support for WebAssembly (WASM), Graphics rendering enhancements, and AI updates.
- Flutter 3.19 running on Dart 3.3 and Gemini API integration, Impeller updates, and Windows Arm64 support.
- Flutter 3.16 running on Dart 3.2 and with Material 3 by default, Impeller preview for Android, etc.
- Flutter 3.13 running on Dart 3.1 and with new 2D scrolling widgets and faster graphics.
- Flutter 3.10 running on Dart 3 and with seamless web and mobile integration, and stable Impleller for iOS.
- Flutter 3.7 with Material 3 updates and iOS improvements
- Flutter 3.3
- Flutter 3
Packages
Dart 3 migration
Null-safety (Dart 2):
- Dartnull-safety
- The officialnull-safety migration guide
- Preparing the Dart and Flutter ecosystem for null safety
Guidelines
Roadmaps
- Flutter roadmap
- The road to Dart 3: A fully sound, null safe language
- Dart language evolution
- Dart SDK milestones
- Waiting fornew features on the Dartlanguage too ...
There are thousands of excellent libraries available atpub.dev.
Here listed only those that are used (depended directly) by code packages ofthis repository (on the latest release):
Package @ pub.dev | Code @ GitHub | Description |
---|---|---|
http | dart-lang/http | A composable API for making HTTP requests in Dart. |
meta | dart-lang/sdk | This package defines annotations that can be used by the tools that are shipped with the Dart SDK. |
proj4dart | maRci002/proj4dart | Proj4dart is a Dart library to transform point coordinates from one coordinate system to another, including datum transformations (Dart version of proj4js/proj4js). |
very_good_analysis | VeryGoodOpenSource/very_good_analysis | Lint rules for Dart and Flutter. |
In some previous releases also following are utilized:
Package @ pub.dev | Code @ GitHub | Description |
---|---|---|
collection | dart-lang/collection | Collections and utilities functions and classes related to collections. |
equatable | felangel/equatable | Simplify Equality Comparisons |
synchronized | tekartik/synchronized.dart | Basic lock mechanism to prevent concurrent access to asynchronous code. |
About
Geospatial data structures, tools and utilities for Dart and Flutter.