geo_utilities 0.0.1
geo_utilities: ^0.0.1 copied to clipboard
A comprehensive Dart package for geospatial and geometric calculations, suitable for Flutter and server-side applications.
Geo Utilities #
A comprehensive Dart package for geospatial and geometric calculations. geo_utilities provides a robust set of tools for working with geographic coordinates, including distance, area, and polygon calculations. It is written in pure Dart and is suitable for both Flutter and server-side applications.
The library primarily operates on JSON strings for coordinate data, making it easy to integrate with APIs and data sources.
Features #
- Calculate great-circle distance and bearing between two points.
- Calculate the spherical area and perimeter of polygons.
- Determine if a point lies within a polygon (point-in-polygon).
- Determine if a point lies within a circle.
- Calculate the centroid of a polygon.
- Compute the convex hull for a set of points.
- Expand a convex hull by a given distance.
- Find the intersection of two line segments (vectors).
- Find the center point of a line segment.
Getting Started #
Add geo_utilities to your pubspec.yaml file:
dependencies:
geo_utilities: ^0.0.1 # Replace with the latest version
Then, run flutter pub get or dart pub get.
Usage #
Import the package and instantiate the GeoUtilities class to access the methods.
import 'dart:convert';
import 'package:geo_utilities/geo_utilities.dart';
void main() {
final geo = GeoUtilities();
// --- Example: Calculate Distance and Bearing ---
final pointA = jsonEncode([{'lat': 0.0, 'long': 0.0}]);
final pointB = jsonEncode([{'lat': 0.0, 'long': 1.0}]);
final result = geo.distanceAndBearing(pointA, pointB);
print('Distance: ${result['distance']?.toStringAsFixed(2)} meters'); // ~111194.93 meters
print('Bearing: ${result['bearing']?.toStringAsFixed(2)} degrees'); // 90.00 degrees
// --- Example: Calculate Polygon Area ---
final polygon = jsonEncode([
{'lat': 0.0, 'long': 0.0},
{'lat': 1.0, 'long': 0.0},
{'lat': 1.0, 'long': 1.0},
{'lat': 0.0, 'long': 1.0},
{'lat': 0.0, 'long': 0.0},
]);
final double area = geo.polygonArea(polygon);
print('Polygon Area: $area square meters');
// --- Example: Check if a Point is in a Polygon ---
final pointInside = jsonEncode([{'lat': 0.5, 'long': 0.5}]);
final isInside = geo.pointInPolygon(polygon, pointInside);
print('Is the point inside the polygon? $isInside'); // true
// --- Example: Calculate Convex Hull ---
final points = jsonEncode([
{'lat': 0.0, 'long': 0.0},
{'lat': 2.0, 'long': 0.0},
{'lat': 1.0, 'long': 1.0},
{'lat': 0.0, 'long': 2.0},
{'lat': 2.0, 'long': 2.0},
]);
final List<Map<String, double>> hull = geo.convexHull(points);
print('Convex Hull Vertices: $hull');
}
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Additional Information #
To file issues, submit feature requests, or contribute to the package, please visit the project's repository.