Skip to content

Commit bdbf0a3

Browse files
authored
Merge pull request #31 from wingkwong/develop
release: 0.7.0
2 parents a7147f2 + 391c0cd commit bdbf0a3

21 files changed

+1101
-519
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 0.7.0
4+
5+
- Refactor geodesy
6+
- Support Class & Static methods
7+
38
## 0.6.0
49

510
- Add findPolygonCentroid

README.md

Lines changed: 84 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -2,197 +2,141 @@
22

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

5-
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
5+
## About
66

7-
## Getting Started
7+
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.
88

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

11-
```dart
12-
geodesy:<latest_version>
13-
```
14-
15-
### Include the widget in your dart file
16-
17-
```dart
18-
import 'package:geodesy/geodesy.dart';
19-
```
20-
21-
## Usage
22-
23-
### Geodesy()
24-
25-
```dart
26-
final Geodesy geodesy = Geodesy();
27-
```
28-
29-
### LatLng(double latitude, double longitude)
30-
31-
```dart
32-
final LatLng l = LatLng(22.308, 114.1716);
33-
```
34-
35-
## Methods
11+
### Commands
3612

37-
### destinationPointByDistanceAndBearing(LatLng l, num distance, num bearing, [num radius])
38-
39-
Calculate a destination point given the distance and bearing. If radius is not specified, Earth radius will be used.
13+
#### For Dart
4014

4115
```dart
42-
final LatLng destinationPoint = geodesy.destinationPointByDistanceAndBearing(l3, 2400, 420.2);
16+
dart pub add geodesy
4317
```
4418

45-
### midPointBetweenTwoGeoPoints(LatLng l1, LatLng l2)
46-
47-
Calculate the midpoint between teo geo points.
19+
#### For Flutter
4820

4921
```dart
50-
final LatLng midpoint = geodesy.midPointBetweenTwoGeoPoints(l1, l2);
22+
flutter pub add geodesy
5123
```
5224

53-
### distanceBetweenTwoGeoPoints(LatLng l1, LatLng l2, [num radius])
54-
55-
Calculate the distance in meters between two geo points. If radius is not specified, Earth radius will be used.
25+
### Import the library in your dart file
5626

5727
```dart
58-
final num distance = geodesy.distanceBetweenTwoGeoPoints(l1, l2);
59-
```
60-
61-
### bearingBetweenTwoGeoPoints(LatLng l1, LatLng l2)
62-
63-
Calculate the bearing from point l1 to point l2.
64-
65-
```dart
66-
final num finalBearing = geodesy.finalBearingBetweenTwoGeoPoints(l1, l2);
67-
```
68-
69-
### finalBearingBetweenTwoGeoPoints(LatLng l1, LatLng l2)
70-
71-
Calculate the final bearing from point l1 to point l2.
72-
73-
```dart
74-
final num finalBearing = geodesy.finalBearingBetweenTwoGeoPoints(l1, l2);
75-
```
76-
77-
### degreesToRadians(num degrees)
78-
79-
Convert degrees to radians
80-
81-
```dart
82-
final num l1LatRadians = degreesToRadians(l1.lat);
28+
import 'package:geodesy/geodesy.dart';
8329
```
8430

85-
### radiansToDegrees(num radians)
86-
87-
Convert degrees to radians
31+
### Initialization
8832

8933
```dart
90-
final num degrees = radiansToDegrees(latRadians);
34+
final Geodesy geodesy = Geodesy();
9135
```
9236

93-
### isGeoPointInBoundingBox(LatLng l, LatLng topLeft, LatLng bottomRight)
37+
## Class
9438

95-
Check if a given geo point is in the bounding box
39+
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.
9640

97-
```dart
98-
final bool inBoundingBox = geodesy.isGeoPointInBoundingBox(l1, l2, l3);
99-
```
41+
Please see the details [here](doc/CLASS.md).
10042

101-
### intersectionByPaths(LatLng l1, LatLng l2, num b1, num b2)
43+
## Static Methods
10244

103-
Calculate the geo point of intersection of two given paths
45+
Static methods are avilable without using Geodesy instance.
10446

105-
```dart
106-
final LatLng intersectionByPaths = geodesy.intersectionByPaths(l1, l2, b1, b2);
107-
```
47+
Please see the details [here](doc/METHODS.md).
10848

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

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

11353
```dart
114-
final num distanceToGreatCircle = geodesy.crossTrackDistanceTo(l1, l2, l3);
115-
```
116-
117-
### isGeoPointInPolygon(LatLng l, List<LatLng> polygon)
118-
119-
Check if a given geo point is in the a polygon using even-odd rule algorithm
54+
import 'package:geodesy/geodesy.dart';
12055
121-
```dart
122-
final bool isGeoPointInPolygon = geodesy.isGeoPointInPolygon(l, poly);
123-
```
56+
void main(){
57+
final Geodesy geodesy = Geodesy();
58+
// Calculate Bounding Box
59+
// Example central position (San Francisco)
60+
final centerPoint = const LatLng(37.7749, -122.4194);
61+
// Example distance in kilometers
62+
final distanceInKm = 1.0;
12463
125-
### pointsInRange(LatLng point, List<LatLng> pointsToCheck, num distance)
64+
final boundingBox = geodesy.calculateBoundingBox(centerPoint, distanceInKm);
12665
127-
Get a list of points within a distance in meters from a given point
66+
print('[calculateBoundingBox]: ');
67+
print(' > Top Left: ${boundingBox[0]}');
68+
print(' > Bottom Right: ${boundingBox[1]}');
12869
129-
```dart
130-
final point = LatLng(51.0, 0);
131-
final pointsToCheck = <LatLng>[/* points here */];
132-
final distance = 10000;
133-
List<LatLng> geoFencedPoints = geodesy.pointsInRange(point, pointsToCheck, distance);
134-
```
70+
// Polygon Centroid
71+
List<LatLng> polygon = [
72+
const LatLng(0, 0),
73+
const LatLng(4, 0),
74+
const LatLng(4, 4),
75+
const LatLng(0, 4)
76+
];
13577
136-
### getRectangleBounds(List<LatLng> polygonCoords)
78+
LatLng centroid = geodesy.findPolygonCentroid(polygon);
13779
138-
Similar to PolygonEnvelop in Python
80+
print("Centroid: ${centroid.latitude}, ${centroid.longitude}");
13981
140-
```dart
141-
List<LatLng> polygonCoords = [
142-
const LatLng(37.7749, -122.4194),
143-
const LatLng(37.3382, -121.8863),
144-
const LatLng(37.7749, -121.4194),
145-
const LatLng(37.7749, -123.4194),
82+
// Polygon Intersection
83+
final List<LatLng> polygon1 = [
84+
const LatLng(0, 0),
85+
const LatLng(0, 2),
86+
const LatLng(2, 2),
87+
const LatLng(2, 0),
14688
];
14789
148-
List<LatLng> rectangleBounds = geodesy.getRectangleBounds(polygonCoords);
149-
```
150-
151-
### greatCircleDistanceBetweenTwoGeoPoints(num lat1, num lng1, num lat2, num lng2)
152-
153-
Calculate the Great-Circle Distance between two Geo points using the Haversine formula
90+
final List<LatLng> polygon2 = [
91+
const LatLng(1, 1),
92+
const LatLng(1, 3),
93+
const LatLng(3, 3),
94+
const LatLng(3, 1),
95+
];
15496
155-
```dart
156-
num latitude1 = 37.7749;
157-
num longitude1 = -122.4194;
158-
num latitude2 = 37.3382;
159-
num longitude2 = -121.8863;
97+
final List<LatLng> intersectionPoints =
98+
geodesy.getPolygonIntersection(polygon1, polygon2);
16099
161-
num greatCircleDistance = geodesy.greatCircleDistanceBetweenTwoGeoPoints(
162-
latitude1, longitude1, latitude2, longitude2);
100+
print('Intersection Points:');
101+
for (final point in intersectionPoints) {
102+
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
103+
}
104+
}
163105
```
164106

165-
### calculateBoundingBox(LatLng centerPoint, num distanceInKm)
166-
167-
Given the Latitude and Longitude and distance in kilometers it calculate the bounding box value
107+
## Example Static Methods
168108

169109
```dart
170-
final centerPoint = const LatLng(
171-
37.7749, -122.4194); // Example central position (San Francisco)
172-
173-
final distanceInKm = 1.0; // Example distance in kilometers
174-
175-
final boundingBox = geodesy.calculateBoundingBox(centerPoint, distanceInKm);
176-
```
177-
178-
## findPolygonCentroid(List<LatLng> polygon)
110+
import 'package:geodesy/geodesy.dart';
179111
180-
```dart
112+
void main() {
113+
// Calculate Bounding Box
114+
// Example central position (San Francisco)
115+
final centerPoint = const LatLng(37.7749, -122.4194);
116+
// Example distance in kilometers
117+
final distanceInKm = 1.0;
118+
// Static Method
119+
final boundingBox =
120+
BoundingBox.calculateBoundingBox(centerPoint, distanceInKm);
121+
122+
print('[calculateBoundingBox]: ');
123+
print(' > Top Left: ${boundingBox[0]}');
124+
print(' > Bottom Right: ${boundingBox[1]}');
125+
126+
// Polygon Centroid
181127
List<LatLng> polygon = [
182128
const LatLng(0, 0),
183129
const LatLng(4, 0),
184130
const LatLng(4, 4),
185131
const LatLng(0, 4)
186132
];
133+
// Static Method
134+
final LatLng centroid = PolygonCentroid.findPolygonCentroid(polygon);
187135
188-
LatLng centroid = geodesy.findPolygonCentroid(polygon);
189136
print("Centroid: ${centroid.latitude}, ${centroid.longitude}");
190-
```
191-
192-
## getPolygonIntersection(List<LatLng> polygon1, List<LatLng> polygon2)
193137
194-
```dart
195-
final List<LatLng> polygon1 = [
138+
// Polygon Intersection
139+
final List<LatLng> polygon1 = [
196140
const LatLng(0, 0),
197141
const LatLng(0, 2),
198142
const LatLng(2, 2),
@@ -205,12 +149,13 @@ final List<LatLng> polygon1 = [
205149
const LatLng(3, 3),
206150
const LatLng(3, 1),
207151
];
208-
152+
// Static Method
209153
final List<LatLng> intersectionPoints =
210-
geodesy.getPolygonIntersection(polygon1, polygon2);
154+
PolygonIntersection.getPolygonIntersection(polygon1, polygon2);
211155
212156
print('Intersection Points:');
213157
for (final point in intersectionPoints) {
214158
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
215159
}
160+
}
216161
```

0 commit comments

Comments
 (0)