Skip to content

Commit 1d1ad6c

Browse files
authored
Release: 0.10.0 (#39)
- Geodesy Refactoring - Implement Geodesic Measurements - Calculate the length of a polyline formed by connecting multiple points - Calculate the area of a polygon defined by a set of points using Shoelace formula - Implement Intersection and Projection - Calculate intersection points of two geodesic lines - Project a point onto a geodesic line
1 parent 9bf0a10 commit 1d1ad6c

36 files changed

+919
-337
lines changed

CHANGELOG.md

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

3+
## 0.10.0
4+
5+
- Geodesy Refactoring
6+
- Implement Geodesic Measurements
7+
- Calculate the length of a polyline formed by connecting multiple points
8+
- Calculate the area of a polygon defined by a set of points using Shoelace formula
9+
- Implement Intersection and Projection
10+
- Calculate intersection points of two geodesic lines
11+
- Project a point onto a geodesic line
12+
313
## 0.9.0
414

515
- Implement DistanceCalculations: EquirectangularApproximation, and SphericalLawOfCosines

README.md

Lines changed: 6 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -40,163 +40,18 @@ The Geodesy class provides a collection of methods for performing various geodet
4040

4141
Please see the details [here](doc/CLASS.md).
4242

43+
### Example
44+
45+
Please check out [here](example/class_example.dart).
46+
4347
## Static Methods
4448

4549
Static methods are available without using Geodesy instance.
4650

4751
Please see the details [here](doc/METHODS.md).
52+
### Example
4853

49-
## Example - Geodesy Class
50-
51-
Please check out [here](example/main.dart) for more.
52-
53-
```dart
54-
import 'package:geodesy/geodesy.dart';
55-
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;
63-
64-
final boundingBox = geodesy.calculateBoundingBox(centerPoint, distanceInKm);
65-
66-
print('[calculateBoundingBox]: ');
67-
print(' > Top Left: ${boundingBox[0]}');
68-
print(' > Bottom Right: ${boundingBox[1]}');
69-
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-
];
77-
78-
LatLng centroid = geodesy.findPolygonCentroid(polygon);
79-
80-
print("Centroid: ${centroid.latitude}, ${centroid.longitude}");
81-
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),
88-
];
89-
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-
];
96-
97-
final List<LatLng> intersectionPoints =
98-
geodesy.getPolygonIntersection(polygon1, polygon2);
99-
100-
print('Intersection Points:');
101-
for (final point in intersectionPoints) {
102-
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
103-
}
104-
}
105-
106-
// Calculate Area
107-
final outerPolygon = [
108-
const LatLng(0.0, 0.0),
109-
const LatLng(0.0, 1.0),
110-
const LatLng(1.0, 1.0),
111-
const LatLng(1.0, 0.0),
112-
];
113-
114-
// Define a hole within the outer polygon
115-
final hole1 = [
116-
const LatLng(0.25, 0.25),
117-
const LatLng(0.25, 0.75),
118-
const LatLng(0.75, 0.75),
119-
const LatLng(0.75, 0.25),
120-
];
121-
122-
final holes = [hole1];
123-
final calculatedArea =
124-
geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
125-
```
126-
127-
## Example Static Methods
128-
129-
```dart
130-
import 'package:geodesy/geodesy.dart';
131-
132-
void main() {
133-
// Calculate Bounding Box
134-
// Example central position (San Francisco)
135-
final centerPoint = const LatLng(37.7749, -122.4194);
136-
// Example distance in kilometers
137-
final distanceInKm = 1.0;
138-
// Static Method
139-
final boundingBox =
140-
BoundingBox.calculateBoundingBox(centerPoint, distanceInKm);
141-
142-
print('[calculateBoundingBox]: ');
143-
print(' > Top Left: ${boundingBox[0]}');
144-
print(' > Bottom Right: ${boundingBox[1]}');
145-
146-
// Polygon Centroid
147-
List<LatLng> polygon = [
148-
const LatLng(0, 0),
149-
const LatLng(4, 0),
150-
const LatLng(4, 4),
151-
const LatLng(0, 4)
152-
];
153-
// Static Method
154-
final LatLng centroid = PolygonCentroid.findPolygonCentroid(polygon);
155-
156-
print("Centroid: ${centroid.latitude}, ${centroid.longitude}");
157-
158-
// Polygon Intersection
159-
final List<LatLng> polygon1 = [
160-
const LatLng(0, 0),
161-
const LatLng(0, 2),
162-
const LatLng(2, 2),
163-
const LatLng(2, 0),
164-
];
165-
166-
final List<LatLng> polygon2 = [
167-
const LatLng(1, 1),
168-
const LatLng(1, 3),
169-
const LatLng(3, 3),
170-
const LatLng(3, 1),
171-
];
172-
// Static Method
173-
final List<LatLng> intersectionPoints =
174-
PolygonIntersection.getPolygonIntersection(polygon1, polygon2);
175-
176-
print('Intersection Points:');
177-
for (final point in intersectionPoints) {
178-
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
179-
}
180-
}
181-
// Static Method
182-
final outerPolygon = [
183-
const LatLng(0.0, 0.0),
184-
const LatLng(0.0, 1.0),
185-
const LatLng(1.0, 1.0),
186-
const LatLng(1.0, 0.0),
187-
];
188-
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-
];
195-
196-
final holes = [hole1];
197-
final area = Polygon.calculatePolygonWithHolesArea(outerPolygon, holes);
198-
```
199-
54+
Please check out [here](example/static_example.dart).
20055
## Code of Conduct
20156

20257
See [here](doc/CODE_OF_CONDUCT.md).

analysis_options.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ analyzer:
77
missing_required_param: error
88
invalid_use_of_protected_member: error
99
dead_code: info
10-
sdk_version_async_exported_from_core: ignore
1110
linter:
1211
rules:
1312
- always_declare_return_types
@@ -16,12 +15,11 @@ linter:
1615
- one_member_abstracts
1716
- recursive_getters
1817
- null_closures
19-
- lines_longer_than_80_chars
2018
- prefer_conditional_assignment
2119
- prefer_const_constructors
2220
- prefer_final_fields
2321
- unnecessary_new
2422
- prefer_is_empty
2523
- prefer_is_not_empty
2624
- prefer_null_aware_operators
27-
- public_member_api_docs
25+
- public_member_api_docs

doc/CLASS.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,25 @@ LatLng midPointBetweenTwoPoints = geodesy.calculateMidpoint(bgPoint1, pFPoint2);
271271
List<LatLng> arcPoints = geodesy.calculatePointsAlongGreatCircle(startPoint, endPoint, numPoints);
272272
```
273273

274+
### PolyLine Length by multiple Points
275+
276+
```dart
277+
double length = PolyLine.calculatePolyLineLength(polyLinePoints);
278+
```
279+
280+
### Polygon Area Calculation using Shoelace formula
281+
282+
```dart
283+
double polygonArea = geodesy.calculatePolygonArea(polygonPoints);
284+
```
285+
286+
### Intersection points of two geodesic lines
287+
288+
```dart
289+
LatLng? intersection = geodesy.calculateGeodesicLineIntersection(
290+
start1, end1, start2, end2);
291+
```
292+
274293
---
275294

276295
This `Geodesy` class 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.

doc/CODE_OF_CONDUCT.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Code of Conduct
32

43
## Introduction

doc/METHODS.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,25 @@ List<LatLng> arcPoints = GreatCirclePoint.calculatePointsAlongGreatCircle(
254254
startPoint, endPoint, numPoints);
255255
```
256256

257+
### PolyLine Length by multiple Points
258+
259+
```dart
260+
double length = PolyLine.calculatePolyLineLength(polyLinePoints);
261+
```
262+
263+
### Polygon Area Calculation using Shoelace formula
264+
265+
```dart
266+
double polygonArea = PolygonArea.calculatePolygonArea(polygonPoints);
267+
```
268+
269+
### Intersection points of two geodesic lines
270+
271+
```dart
272+
LatLng? intersection = GeodesicLines.calculateGeodesicLineIntersection(
273+
start1, end1, start2, end2);
274+
```
275+
257276
---
258277

259278
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/main.dart renamed to example/class_example.dart

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,62 @@ void main() {
216216
for (var point in arcPoints) {
217217
print('${point.latitude}, ${point.longitude}');
218218
}
219+
220+
/// PolyLine Length Calculation
221+
// Create a list of LatLng points representing your polyLine
222+
List<LatLng> polyLinePoints = [
223+
const LatLng(42.345, -71.098), // Add your points here
224+
const LatLng(42.355, -71.108),
225+
const LatLng(42.365, -71.118),
226+
// Add more points as needed
227+
];
228+
229+
// Calculate the length of the polyLine
230+
double length = geodesy.calculatePolyLineLength(polyLinePoints);
231+
232+
print('Length of the polyLine: $length meters');
233+
234+
/// Polygon Area by Using Shoelace formula
235+
// Create a list of LatLng points representing your polygon
236+
List<LatLng> polygonPoints = [
237+
const LatLng(42.345, -71.098), // Add your points here
238+
const LatLng(42.355, -71.108),
239+
const LatLng(42.365, -71.118),
240+
// Add more points as needed
241+
];
242+
243+
// Calculate the area of the polygon
244+
double polygonArea = geodesy.calculatePolygonArea(polygonPoints);
245+
246+
print('Area of the polygon: $polygonArea square meters');
247+
248+
/// Calculate intersection points of two geodesic lines
249+
// Example geodesic lines
250+
LatLng start1 = const LatLng(42.345, -71.098);
251+
LatLng end1 = const LatLng(42.355, -71.108);
252+
LatLng start2 = const LatLng(42.355, -71.108);
253+
LatLng end2 = const LatLng(42.365, -71.118);
254+
255+
// Calculate intersection point
256+
LatLng? intersection =
257+
geodesy.calculateGeodesicLineIntersection(start1, end1, start2, end2);
258+
259+
if (intersection != null) {
260+
print(''''Intersection point: Latitude ${intersection.latitude},
261+
Longitude ${intersection.longitude}''');
262+
} else {
263+
print('No intersection found.');
264+
}
265+
266+
/// Project a point onto a geodesic line
267+
// Example geodesic line and point
268+
LatLng start = const LatLng(42.345, -71.098);
269+
LatLng end = const LatLng(42.355, -71.108);
270+
LatLng point = const LatLng(42.350, -71.103);
271+
272+
// Project the point onto the geodesic line
273+
LatLng projection = geodesy.projectPointOntoGeodesicLine(point, start, end);
274+
275+
print('''Projected Point: Latitude ${projection.latitude},
276+
Longitude ${projection.longitude}''');
219277
}

0 commit comments

Comments
 (0)