Skip to content

Commit

Permalink
Release: 0.10.0 (#39)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
wingkwong authored Sep 18, 2023
1 parent 9bf0a10 commit 1d1ad6c
Show file tree
Hide file tree
Showing 36 changed files with 919 additions and 337 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## 0.10.0

- 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

## 0.9.0

- Implement DistanceCalculations: EquirectangularApproximation, and SphericalLawOfCosines
Expand Down
157 changes: 6 additions & 151 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,163 +40,18 @@ The Geodesy class provides a collection of methods for performing various geodet

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

### Example

Please check out [here](example/class_example.dart).

## Static Methods

Static methods are available without using Geodesy instance.

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

## Example - Geodesy Class

Please check out [here](example/main.dart) for more.

```dart
import 'package:geodesy/geodesy.dart';
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;
final boundingBox = geodesy.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)
];
LatLng centroid = geodesy.findPolygonCentroid(polygon);
print("Centroid: ${centroid.latitude}, ${centroid.longitude}");
// Polygon Intersection
final List<LatLng> polygon1 = [
const LatLng(0, 0),
const LatLng(0, 2),
const LatLng(2, 2),
const LatLng(2, 0),
];
final List<LatLng> polygon2 = [
const LatLng(1, 1),
const LatLng(1, 3),
const LatLng(3, 3),
const LatLng(3, 1),
];
final List<LatLng> intersectionPoints =
geodesy.getPolygonIntersection(polygon1, polygon2);
print('Intersection Points:');
for (final point in intersectionPoints) {
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
}
}
// Calculate Area
final outerPolygon = [
const LatLng(0.0, 0.0),
const LatLng(0.0, 1.0),
const LatLng(1.0, 1.0),
const LatLng(1.0, 0.0),
];
// Define a hole within the outer polygon
final hole1 = [
const LatLng(0.25, 0.25),
const LatLng(0.25, 0.75),
const LatLng(0.75, 0.75),
const LatLng(0.75, 0.25),
];
final holes = [hole1];
final calculatedArea =
geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
```

## Example Static Methods

```dart
import 'package:geodesy/geodesy.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);
print("Centroid: ${centroid.latitude}, ${centroid.longitude}");
// Polygon Intersection
final List<LatLng> polygon1 = [
const LatLng(0, 0),
const LatLng(0, 2),
const LatLng(2, 2),
const LatLng(2, 0),
];
final List<LatLng> polygon2 = [
const LatLng(1, 1),
const LatLng(1, 3),
const LatLng(3, 3),
const LatLng(3, 1),
];
// Static Method
final List<LatLng> intersectionPoints =
PolygonIntersection.getPolygonIntersection(polygon1, polygon2);
print('Intersection Points:');
for (final point in intersectionPoints) {
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
}
}
// Static Method
final outerPolygon = [
const LatLng(0.0, 0.0),
const LatLng(0.0, 1.0),
const LatLng(1.0, 1.0),
const LatLng(1.0, 0.0),
];
final hole1 = [
const LatLng(0.25, 0.25),
const LatLng(0.25, 0.75),
const LatLng(0.75, 0.75),
const LatLng(0.75, 0.25),
];
final holes = [hole1];
final area = Polygon.calculatePolygonWithHolesArea(outerPolygon, holes);
```

Please check out [here](example/static_example.dart).
## Code of Conduct

See [here](doc/CODE_OF_CONDUCT.md).
Expand Down
4 changes: 1 addition & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ analyzer:
missing_required_param: error
invalid_use_of_protected_member: error
dead_code: info
sdk_version_async_exported_from_core: ignore
linter:
rules:
- always_declare_return_types
Expand All @@ -16,12 +15,11 @@ linter:
- one_member_abstracts
- recursive_getters
- null_closures
- lines_longer_than_80_chars
- prefer_conditional_assignment
- prefer_const_constructors
- prefer_final_fields
- unnecessary_new
- prefer_is_empty
- prefer_is_not_empty
- prefer_null_aware_operators
- public_member_api_docs
- public_member_api_docs
19 changes: 19 additions & 0 deletions doc/CLASS.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,25 @@ LatLng midPointBetweenTwoPoints = geodesy.calculateMidpoint(bgPoint1, pFPoint2);
List<LatLng> arcPoints = geodesy.calculatePointsAlongGreatCircle(startPoint, endPoint, numPoints);
```

### PolyLine Length by multiple Points

```dart
double length = PolyLine.calculatePolyLineLength(polyLinePoints);
```

### Polygon Area Calculation using Shoelace formula

```dart
double polygonArea = geodesy.calculatePolygonArea(polygonPoints);
```

### Intersection points of two geodesic lines

```dart
LatLng? intersection = geodesy.calculateGeodesicLineIntersection(
start1, end1, start2, end2);
```

---

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.
1 change: 0 additions & 1 deletion doc/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Code of Conduct

## Introduction
Expand Down
19 changes: 19 additions & 0 deletions doc/METHODS.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,25 @@ List<LatLng> arcPoints = GreatCirclePoint.calculatePointsAlongGreatCircle(
startPoint, endPoint, numPoints);
```

### PolyLine Length by multiple Points

```dart
double length = PolyLine.calculatePolyLineLength(polyLinePoints);
```

### Polygon Area Calculation using Shoelace formula

```dart
double polygonArea = PolygonArea.calculatePolygonArea(polygonPoints);
```

### Intersection points of two geodesic lines

```dart
LatLng? intersection = GeodesicLines.calculateGeodesicLineIntersection(
start1, end1, start2, end2);
```

---

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.
58 changes: 58 additions & 0 deletions example/main.dart → example/class_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,62 @@ void main() {
for (var point in arcPoints) {
print('${point.latitude}, ${point.longitude}');
}

/// PolyLine Length Calculation
// Create a list of LatLng points representing your polyLine
List<LatLng> polyLinePoints = [
const LatLng(42.345, -71.098), // Add your points here
const LatLng(42.355, -71.108),
const LatLng(42.365, -71.118),
// Add more points as needed
];

// Calculate the length of the polyLine
double length = geodesy.calculatePolyLineLength(polyLinePoints);

print('Length of the polyLine: $length meters');

/// Polygon Area by Using Shoelace formula
// Create a list of LatLng points representing your polygon
List<LatLng> polygonPoints = [
const LatLng(42.345, -71.098), // Add your points here
const LatLng(42.355, -71.108),
const LatLng(42.365, -71.118),
// Add more points as needed
];

// Calculate the area of the polygon
double polygonArea = geodesy.calculatePolygonArea(polygonPoints);

print('Area of the polygon: $polygonArea square meters');

/// Calculate intersection points of two geodesic lines
// Example geodesic lines
LatLng start1 = const LatLng(42.345, -71.098);
LatLng end1 = const LatLng(42.355, -71.108);
LatLng start2 = const LatLng(42.355, -71.108);
LatLng end2 = const LatLng(42.365, -71.118);

// Calculate intersection point
LatLng? intersection =
geodesy.calculateGeodesicLineIntersection(start1, end1, start2, end2);

if (intersection != null) {
print(''''Intersection point: Latitude ${intersection.latitude},
Longitude ${intersection.longitude}''');
} else {
print('No intersection found.');
}

/// Project a point onto a geodesic line
// Example geodesic line and point
LatLng start = const LatLng(42.345, -71.098);
LatLng end = const LatLng(42.355, -71.108);
LatLng point = const LatLng(42.350, -71.103);

// Project the point onto the geodesic line
LatLng projection = geodesy.projectPointOntoGeodesicLine(point, start, end);

print('''Projected Point: Latitude ${projection.latitude},
Longitude ${projection.longitude}''');
}
Loading

0 comments on commit 1d1ad6c

Please sign in to comment.