Skip to content

Commit 9bf0a10

Browse files
Release: 0.9.0 (#36)
* feat: spherical law of cosines & equirectangular approximation (#35) * Updated README * Update LICENSE * docs: CODE_OF_CONDUCT * chore: dart format * docs: revise README.md * CODE & FEATURES * Little Changes * EquirectangularApproximation * Spherical Law of Cosines * GeodeticPointManipulation * MidpointBetweenTwoPoints * PointAlongGreatCircle * DONE * refactor: remove unwanted comments * refactor: format * fix: The line length exceeds the 80-character limit * Vincenty DOC --------- Co-authored-by: wingkwong <[email protected]> * docs: format code * docs: add 0.9.0 CHANGELOG * chore: bump to 0.9.0 --------- Co-authored-by: Ayoub Ali <[email protected]>
1 parent 6af10d5 commit 9bf0a10

19 files changed

+480
-26
lines changed

CHANGELOG.md

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

3+
## 0.9.0
4+
5+
- Implement DistanceCalculations: EquirectangularApproximation, and SphericalLawOfCosines
6+
- Implement GeodeticPointManipulation: DestinationPoint, MidPointBetweenTwoPoints, and GreatCirclePoint
7+
38
## 0.8.0
49

510
- Implement Calculating Polygon Area With Hole
@@ -18,48 +23,59 @@
1823
- Add getPolygonIntersection
1924

2025
## 0.5.0
26+
2127
- Add greatCircleDistanceBetweenTwoGeoPoints
2228
- Add getRectangleBounds
2329
- Add calculateBoundingBox
2430

2531
## 0.4.2
32+
2633
- Removed pedantic
2734
- Migrated to lints package with Dart 3 compatible
2835
- Refactored source code
29-
- Revised README.md
36+
- Revised README.md
3037

3138
## 0.4.1
39+
3240
- Fixed isGeoPointInBoundingBox typos & logic
3341

3442
## 0.4.0
43+
3544
- Added dart 3 compatible changes
3645
- Revised test cases
3746
- Bumped minimum Dart version to 3.0.
3847

3948
## 0.4.0-nullsafety.0
49+
4050
- Null Safety Upgrade
4151

4252
## 0.3.2
53+
4354
- Added tests
4455
- Added pointsInRange
4556

4657
## 0.3.1
58+
4759
- Applied strict static analysis
4860
- Made the radius parameter optional
4961

5062
## 0.3.0
63+
5164
- Added latlong package
5265
- Deprecated LatLng
5366
- Deprecated degreesToRadians & radiansToDegrees
5467

5568
## 0.2.0
69+
5670
- Added intersectionByPaths
57-
- Added crossTrackDistanceTo
71+
- Added crossTrackDistanceTo
5872
- Added isGeoPointInPolygon
5973

6074
## 0.1.1
75+
6176
- Added example
6277
- Reformatted with Dart Style
6378

6479
## 0.1.0
80+
6581
- Initial version, created by wingkwong

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Please see the details [here](doc/CLASS.md).
4242

4343
## Static Methods
4444

45-
Static methods are avilable without using Geodesy instance.
45+
Static methods are available without using Geodesy instance.
4646

4747
Please see the details [here](doc/METHODS.md).
4848

@@ -186,14 +186,14 @@ final outerPolygon = [
186186
const LatLng(1.0, 0.0),
187187
];
188188
189-
final hole1 = [
190-
const LatLng(0.25, 0.25),
191-
const LatLng(0.25, 0.75),
192-
const LatLng(0.75, 0.75),
193-
const LatLng(0.75, 0.25),
194-
];
189+
final hole1 = [
190+
const LatLng(0.25, 0.25),
191+
const LatLng(0.25, 0.75),
192+
const LatLng(0.75, 0.75),
193+
const LatLng(0.75, 0.25),
194+
];
195195
196-
final holes = [hole1];
196+
final holes = [hole1];
197197
final area = Polygon.calculatePolygonWithHolesArea(outerPolygon, holes);
198198
```
199199

@@ -203,4 +203,4 @@ See [here](doc/CODE_OF_CONDUCT.md).
203203

204204
## License
205205

206-
See [here](./LICENSE).
206+
See [here](./LICENSE).

doc/CLASS.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,44 @@ Returns a list of `LatLng` points representing the intersection polygon.
231231
### Vincenty formula for Geodesic Distance Calculation
232232

233233
```dart
234-
final double calculatedDistance = geodesy.vincentyDistance(
235-
point1.latitude, point1.longitude, point2.latitude, point2.longitude);
234+
final double calculatedDistance =
235+
geodesy.vincentyDistance(point1.latitude, point1.longitude, point2.latitude, point2.longitude);
236236
```
237237

238238
### Calculate Area of Polygon with Hole
239239

240240
```dart
241-
final calculatedArea =
242-
geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
241+
final calculatedArea = geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
242+
```
243+
244+
### Equirectangular Approximation Calculation
245+
246+
```dart
247+
double equirectangularDistance = geodesy.equirectangularDistance(firstPoint, secondPoint);
248+
```
249+
250+
### Spherical Law Of Cosines Distance
251+
252+
```dart
253+
double sLCDdistance = geodesy.sphericalLawOfCosinesDistance(bGPoint, pFPoint);
254+
```
255+
256+
### Geodetic Point Manipulation - Rhumb Line Destination Formula
257+
258+
```dart
259+
LatLng destinationPoints = geodesy.calculateDestinationPoint(initialPoint, bearingDegrees, distanceKm);
260+
```
261+
262+
### Geodetic Point Manipulation - Midpoint between two points
263+
264+
```dart
265+
LatLng midPointBetweenTwoPoints = geodesy.calculateMidpoint(bgPoint1, pFPoint2);
266+
```
267+
268+
### Geodetic Point Manipulation - Calculate Point Along Great Circle
269+
270+
```dart
271+
List<LatLng> arcPoints = geodesy.calculatePointsAlongGreatCircle(startPoint, endPoint, numPoints);
243272
```
244273

245274
---

doc/METHODS.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,41 @@ VincentyDistance.vincentyDistance(lat1, lon1, lat2, lon2);
219219
final area = Polygon.calculatePolygonWithHolesArea(outerPolygon, holes);
220220
```
221221

222+
### Equirectangular approximation Calculation
223+
224+
```dart
225+
double equirectangularDistance =
226+
EquirectangularApproximation.equirectangularDistance(firstPoint,secondPoint);
227+
```
228+
229+
### Spherical Law Of Cosines Distance
230+
231+
```dart
232+
double sLCDdistance =
233+
SphericalLawOfCosines.sphericalLawOfCosinesDistance(bGPoint, pFPoint);
234+
```
235+
236+
### Geodetic Point Manipulation - Rhumb Line Destination Formula
237+
238+
```dart
239+
LatLng destinationPoints = DestinationPoint.calculateDestinationPoint(
240+
initialPoint, bearingDegrees, distanceKm);
241+
```
242+
243+
### Geodetic Point Manipulation - Midpoint between two points
244+
245+
```dart
246+
LatLng midPointBetweenTwoPoints =
247+
MidPointBetweenTwoPoints.calculateMidpoint(bgPoint1, pFPoint2);
248+
```
249+
250+
### Geodetic Point Manipulation - Calculate Point Along Great Circle
251+
252+
```dart
253+
List<LatLng> arcPoints = GreatCirclePoint.calculatePointsAlongGreatCircle(
254+
startPoint, endPoint, numPoints);
255+
```
256+
222257
---
223258

224259
This `Geodesy` provides a comprehensive set of methods for performing various geodetic calculations and operations. You can use these methods to calculate distances, bearings, intersections, and more based on geographical coordinates.

example/example.dart

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import 'package:geodesy/geodesy.dart';
2+
import 'package:geodesy/src/core/GeodeticPointManipulation/calculate_destination_point.dart';
3+
import 'package:geodesy/src/core/GeodeticPointManipulation/calculate_points_along_great_circle.dart';
4+
import 'package:geodesy/src/core/GeodeticPointManipulation/mid_point_between_two_points.dart';
25
import 'package:geodesy/src/core/polygon_with_hole.dart';
36

47
void main() {
@@ -85,4 +88,60 @@ void main() {
8588

8689
final area = Polygon.calculatePolygonWithHolesArea(outerPolygon, holes);
8790
print("Area of polygon with holes: $area");
91+
92+
// Equirectangular approximation Calculation
93+
final firstPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
94+
final secondPoint = const LatLng(48.8566, 2.3522); // Paris, France
95+
96+
double equirectangularDistance =
97+
EquirectangularApproximation.equirectangularDistance(
98+
firstPoint, secondPoint);
99+
print(
100+
'''Equirectangular Distance: ${equirectangularDistance.toStringAsFixed(2)} km
101+
''');
102+
103+
/// Calculate Spherical Law Of Cosines Distance
104+
final bGPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
105+
final pFPoint = const LatLng(48.8566, 2.3522); // Paris, France
106+
107+
double sLCDdistance =
108+
SphericalLawOfCosines.sphericalLawOfCosinesDistance(bGPoint, pFPoint);
109+
print(
110+
'''Spherical Law of Cosines Distance: ${sLCDdistance.toStringAsFixed(2)} km
111+
''');
112+
113+
/// Geodetic Point Manipulation - Rhumb Line Destination Formula
114+
final initialPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
115+
final bearingDegrees = 45.0; // 45 degrees bearing (northeast)
116+
final distanceKm = 100.0; // 100 kilometers distance
117+
118+
LatLng destinationPoints = DestinationPoint.calculateDestinationPoint(
119+
initialPoint, bearingDegrees, distanceKm);
120+
121+
print('Initial Point: ${initialPoint.latitude}, ${initialPoint.longitude}');
122+
print('''Destination Point: ${destinationPoints.latitude},
123+
${destinationPoints.longitude}''');
124+
125+
/// Geodetic Point Manipulation - Midpoint between two points
126+
final bgPoint1 = const LatLng(52.5200, 13.4050); // Berlin, Germany
127+
final pFPoint2 = const LatLng(48.8566, 2.3522); // Paris, France
128+
129+
LatLng midPointBetweenTwoPoints =
130+
MidPointBetweenTwoPoints.calculateMidpoint(bgPoint1, pFPoint2);
131+
132+
print('''Midpoint: ${midPointBetweenTwoPoints.latitude},
133+
${midPointBetweenTwoPoints.longitude}''');
134+
135+
/// Geodetic Point Manipulation - Calculate Point Along Great Circle
136+
final startPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
137+
final endPoint = const LatLng(48.8566, 2.3522); // Paris, France
138+
final numPoints = 5; // Number of points along the arc
139+
140+
List<LatLng> arcPoints = GreatCirclePoint.calculatePointsAlongGreatCircle(
141+
startPoint, endPoint, numPoints);
142+
143+
print('Points along Great Circle Arc:');
144+
for (var point in arcPoints) {
145+
print('${point.latitude}, ${point.longitude}');
146+
}
88147
}

example/main.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,58 @@ void main() {
162162

163163
final area = geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
164164
print("Area of polygon with holes: $area");
165+
166+
// Equirectangular approximation Calculation
167+
final firstPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
168+
final secondPoint = const LatLng(48.8566, 2.3522); // Paris, France
169+
170+
double equirectangularDistance =
171+
geodesy.equirectangularDistance(firstPoint, secondPoint);
172+
print(
173+
'''Equirectangular Distance: ${equirectangularDistance.toStringAsFixed(2)} km
174+
''');
175+
176+
/// Calculate Spherical Law Of Cosines Distance
177+
final bGPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
178+
final pFPoint = const LatLng(48.8566, 2.3522); // Paris, France
179+
180+
double sLCDdistance = geodesy.sphericalLawOfCosinesDistance(bGPoint, pFPoint);
181+
print(
182+
'''Spherical Law of Cosines Distance: ${sLCDdistance.toStringAsFixed(2)} km
183+
''');
184+
185+
/// Geodetic Point Manipulation - Rhumb Line Destination Formula
186+
final initialPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
187+
final bearingDegrees = 45.0; // 45 degrees bearing (northeast)
188+
final distanceKm = 100.0; // 100 kilometers distance
189+
190+
LatLng destinationPoints = geodesy.calculateDestinationPoint(
191+
initialPoint, bearingDegrees, distanceKm);
192+
193+
print('Initial Point: ${initialPoint.latitude}, ${initialPoint.longitude}');
194+
print('''Destination Point: ${destinationPoints.latitude},
195+
${destinationPoints.longitude}''');
196+
197+
/// Geodetic Point Manipulation - Midpoint between two points
198+
final bgPoint1 = const LatLng(52.5200, 13.4050); // Berlin, Germany
199+
final pFPoint2 = const LatLng(48.8566, 2.3522); // Paris, France
200+
201+
LatLng midPointBetweenTwoPoints =
202+
geodesy.calculateMidpoint(bgPoint1, pFPoint2);
203+
204+
print('''Midpoint: ${midPointBetweenTwoPoints.latitude},
205+
${midPointBetweenTwoPoints.longitude}''');
206+
207+
/// Geodetic Point Manipulation - Calculate Point Along Great Circle
208+
final startPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
209+
final endPoint = const LatLng(48.8566, 2.3522); // Paris, France
210+
final numPoints = 5; // Number of points along the arc
211+
212+
List<LatLng> arcPoints =
213+
geodesy.calculatePointsAlongGreatCircle(startPoint, endPoint, numPoints);
214+
215+
print('Points along Great Circle Arc:');
216+
for (var point in arcPoints) {
217+
print('${point.latitude}, ${point.longitude}');
218+
}
165219
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import '../core.dart';
2+
3+
/// Equirectangular approximation Calculation
4+
class EquirectangularApproximation {
5+
/// EquirectangularDistance function takes two LatLng objects representing the
6+
/// latitude and longitude coordinates of two points. It calculates the
7+
/// distance between the points using the Equirectangular
8+
/// approximation formula and the Earth's radius.
9+
static double equirectangularDistance(LatLng point1, LatLng point2) {
10+
final double radius = 6371.0; // Earth's radius in kilometers
11+
12+
double lat1 = point1.latitude;
13+
double lon1 = point1.longitude;
14+
double lat2 = point2.latitude;
15+
double lon2 = point2.longitude;
16+
17+
double x = (lon2 - lon1) * (radius * cos((lat1 + lat2) / 2));
18+
double y = (lat2 - lat1) * radius;
19+
20+
// Calculate distance using Pythagorean theorem
21+
double distance = sqrt(x * x + y * y);
22+
23+
return distance;
24+
}
25+
}

lib/src/core/geo_points.dart renamed to lib/src/core/DistanceCalculations/geo_points.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import 'core.dart';
1+
import '../core.dart';
22

33
///
44
class GeoPoints {
5-
/// Calculate the distance in meters between two geo points
5+
/// Calculate the Distance in meters between two geo points
66
static num distanceBetweenTwoGeoPoints(LatLng l1, LatLng l2, [num? radius]) {
77
final R = radius ?? 6371e3;
88
final num l1LatRadians = degToRadian(l1.latitude);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import '../core.dart';
2+
3+
/// Calculate Spherical Law Of Cosines Distance
4+
class SphericalLawOfCosines {
5+
/// This function takes two LatLng objects representing the latitude and
6+
/// longitude coordinates of two points. It calculates the distance
7+
/// between the points using the Spherical Law of Cosines formula
8+
/// and the Earth's radius.
9+
static double sphericalLawOfCosinesDistance(LatLng point1, LatLng point2) {
10+
final double radius = 6371.0; // Earth's radius in kilometers
11+
12+
double lat1 = (point1.latitude).toRadians();
13+
double lon1 = (point1.longitude).toRadians();
14+
double lat2 = (point2.latitude).toRadians();
15+
double lon2 = (point2.longitude).toRadians();
16+
17+
double deltaLon = lon2 - lon1;
18+
19+
double distance =
20+
acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(deltaLon)) *
21+
radius;
22+
23+
return distance;
24+
}
25+
}

0 commit comments

Comments
 (0)