Skip to content

Commit

Permalink
Merge pull request #31 from wingkwong/develop
Browse files Browse the repository at this point in the history
release: 0.7.0
  • Loading branch information
wingkwong authored Aug 8, 2023
2 parents a7147f2 + 391c0cd commit bdbf0a3
Show file tree
Hide file tree
Showing 21 changed files with 1,101 additions and 519 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 0.7.0

- Refactor geodesy
- Support Class & Static methods

## 0.6.0

- Add findPolygonCentroid
Expand Down
223 changes: 84 additions & 139 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,197 +2,141 @@

[![pub package](https://img.shields.io/pub/v/geodesy.svg)](https://pub.dartlang.org/packages/geodesy)

A Dart library for implementing geodesic and trigonometric calculations based on a spherical Earth model for working with points and paths such as distances, bearings and destinations
## About

## Getting Started
A Dart library for implementing geodesic and trigonometric calculations based on a spherical Earth model for working with points and paths such as distances, bearings and destinations.

### Add the following line in your `pubspec.yml` file
## How to Use Geodesy

```dart
geodesy:<latest_version>
```

### Include the widget in your dart file

```dart
import 'package:geodesy/geodesy.dart';
```

## Usage

### Geodesy()

```dart
final Geodesy geodesy = Geodesy();
```

### LatLng(double latitude, double longitude)

```dart
final LatLng l = LatLng(22.308, 114.1716);
```

## Methods
### Commands

### destinationPointByDistanceAndBearing(LatLng l, num distance, num bearing, [num radius])

Calculate a destination point given the distance and bearing. If radius is not specified, Earth radius will be used.
#### For Dart

```dart
final LatLng destinationPoint = geodesy.destinationPointByDistanceAndBearing(l3, 2400, 420.2);
dart pub add geodesy
```

### midPointBetweenTwoGeoPoints(LatLng l1, LatLng l2)

Calculate the midpoint between teo geo points.
#### For Flutter

```dart
final LatLng midpoint = geodesy.midPointBetweenTwoGeoPoints(l1, l2);
flutter pub add geodesy
```

### distanceBetweenTwoGeoPoints(LatLng l1, LatLng l2, [num radius])

Calculate the distance in meters between two geo points. If radius is not specified, Earth radius will be used.
### Import the library in your dart file

```dart
final num distance = geodesy.distanceBetweenTwoGeoPoints(l1, l2);
```

### bearingBetweenTwoGeoPoints(LatLng l1, LatLng l2)

Calculate the bearing from point l1 to point l2.

```dart
final num finalBearing = geodesy.finalBearingBetweenTwoGeoPoints(l1, l2);
```

### finalBearingBetweenTwoGeoPoints(LatLng l1, LatLng l2)

Calculate the final bearing from point l1 to point l2.

```dart
final num finalBearing = geodesy.finalBearingBetweenTwoGeoPoints(l1, l2);
```

### degreesToRadians(num degrees)

Convert degrees to radians

```dart
final num l1LatRadians = degreesToRadians(l1.lat);
import 'package:geodesy/geodesy.dart';
```

### radiansToDegrees(num radians)

Convert degrees to radians
### Initialization

```dart
final num degrees = radiansToDegrees(latRadians);
final Geodesy geodesy = Geodesy();
```

### isGeoPointInBoundingBox(LatLng l, LatLng topLeft, LatLng bottomRight)
## Class

Check if a given geo point is in the bounding box
The Geodesy class provides a collection of methods for performing various geodetic calculations, including distance calculations, point intersections, and more. This class is designed to work with geographical coordinates in the form of latitude and longitude.

```dart
final bool inBoundingBox = geodesy.isGeoPointInBoundingBox(l1, l2, l3);
```
Please see the details [here](doc/CLASS.md).

### intersectionByPaths(LatLng l1, LatLng l2, num b1, num b2)
## Static Methods

Calculate the geo point of intersection of two given paths
Static methods are avilable without using Geodesy instance.

```dart
final LatLng intersectionByPaths = geodesy.intersectionByPaths(l1, l2, b1, b2);
```
Please see the details [here](doc/METHODS.md).

### crossTrackDistanceTo(LatLng l1, LatLng start, LatLng end, [num radius])
## Example - Geodesy Class

Calculate signed distance from a geo point to create circle with start and end points
Please check out [here](example/main.dart) for more.

```dart
final num distanceToGreatCircle = geodesy.crossTrackDistanceTo(l1, l2, l3);
```

### isGeoPointInPolygon(LatLng l, List<LatLng> polygon)

Check if a given geo point is in the a polygon using even-odd rule algorithm
import 'package:geodesy/geodesy.dart';
```dart
final bool isGeoPointInPolygon = geodesy.isGeoPointInPolygon(l, poly);
```
void main(){
final Geodesy geodesy = Geodesy();
// Calculate Bounding Box
// Example central position (San Francisco)
final centerPoint = const LatLng(37.7749, -122.4194);
// Example distance in kilometers
final distanceInKm = 1.0;
### pointsInRange(LatLng point, List<LatLng> pointsToCheck, num distance)
final boundingBox = geodesy.calculateBoundingBox(centerPoint, distanceInKm);
Get a list of points within a distance in meters from a given point
print('[calculateBoundingBox]: ');
print(' > Top Left: ${boundingBox[0]}');
print(' > Bottom Right: ${boundingBox[1]}');
```dart
final point = LatLng(51.0, 0);
final pointsToCheck = <LatLng>[/* points here */];
final distance = 10000;
List<LatLng> geoFencedPoints = geodesy.pointsInRange(point, pointsToCheck, distance);
```
// Polygon Centroid
List<LatLng> polygon = [
const LatLng(0, 0),
const LatLng(4, 0),
const LatLng(4, 4),
const LatLng(0, 4)
];
### getRectangleBounds(List<LatLng> polygonCoords)
LatLng centroid = geodesy.findPolygonCentroid(polygon);
Similar to PolygonEnvelop in Python
print("Centroid: ${centroid.latitude}, ${centroid.longitude}");
```dart
List<LatLng> polygonCoords = [
const LatLng(37.7749, -122.4194),
const LatLng(37.3382, -121.8863),
const LatLng(37.7749, -121.4194),
const LatLng(37.7749, -123.4194),
// Polygon Intersection
final List<LatLng> polygon1 = [
const LatLng(0, 0),
const LatLng(0, 2),
const LatLng(2, 2),
const LatLng(2, 0),
];
List<LatLng> rectangleBounds = geodesy.getRectangleBounds(polygonCoords);
```

### greatCircleDistanceBetweenTwoGeoPoints(num lat1, num lng1, num lat2, num lng2)

Calculate the Great-Circle Distance between two Geo points using the Haversine formula
final List<LatLng> polygon2 = [
const LatLng(1, 1),
const LatLng(1, 3),
const LatLng(3, 3),
const LatLng(3, 1),
];
```dart
num latitude1 = 37.7749;
num longitude1 = -122.4194;
num latitude2 = 37.3382;
num longitude2 = -121.8863;
final List<LatLng> intersectionPoints =
geodesy.getPolygonIntersection(polygon1, polygon2);
num greatCircleDistance = geodesy.greatCircleDistanceBetweenTwoGeoPoints(
latitude1, longitude1, latitude2, longitude2);
print('Intersection Points:');
for (final point in intersectionPoints) {
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
}
}
```

### calculateBoundingBox(LatLng centerPoint, num distanceInKm)

Given the Latitude and Longitude and distance in kilometers it calculate the bounding box value
## Example Static Methods

```dart
final centerPoint = const LatLng(
37.7749, -122.4194); // Example central position (San Francisco)
final distanceInKm = 1.0; // Example distance in kilometers
final boundingBox = geodesy.calculateBoundingBox(centerPoint, distanceInKm);
```

## findPolygonCentroid(List<LatLng> polygon)
import 'package:geodesy/geodesy.dart';
```dart
void main() {
// Calculate Bounding Box
// Example central position (San Francisco)
final centerPoint = const LatLng(37.7749, -122.4194);
// Example distance in kilometers
final distanceInKm = 1.0;
// Static Method
final boundingBox =
BoundingBox.calculateBoundingBox(centerPoint, distanceInKm);
print('[calculateBoundingBox]: ');
print(' > Top Left: ${boundingBox[0]}');
print(' > Bottom Right: ${boundingBox[1]}');
// Polygon Centroid
List<LatLng> polygon = [
const LatLng(0, 0),
const LatLng(4, 0),
const LatLng(4, 4),
const LatLng(0, 4)
];
// Static Method
final LatLng centroid = PolygonCentroid.findPolygonCentroid(polygon);
LatLng centroid = geodesy.findPolygonCentroid(polygon);
print("Centroid: ${centroid.latitude}, ${centroid.longitude}");
```

## getPolygonIntersection(List<LatLng> polygon1, List<LatLng> polygon2)
```dart
final List<LatLng> polygon1 = [
// Polygon Intersection
final List<LatLng> polygon1 = [
const LatLng(0, 0),
const LatLng(0, 2),
const LatLng(2, 2),
Expand All @@ -205,12 +149,13 @@ final List<LatLng> polygon1 = [
const LatLng(3, 3),
const LatLng(3, 1),
];
// Static Method
final List<LatLng> intersectionPoints =
geodesy.getPolygonIntersection(polygon1, polygon2);
PolygonIntersection.getPolygonIntersection(polygon1, polygon2);
print('Intersection Points:');
for (final point in intersectionPoints) {
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
}
}
```
Loading

0 comments on commit bdbf0a3

Please sign in to comment.