-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstatic_example.dart
202 lines (163 loc) · 6.55 KB
/
static_example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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 Methods
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}');
}
// Vincenty formula for Geodesic Distance Calculation
final LatLng point1 = const LatLng(37.7749, -122.4194); // San Francisco
final LatLng point2 = const LatLng(34.0522, -118.2437); // Los Angeles
final double calculatedDistance = VincentyDistance.vincentyDistance(
point1.latitude,
point1.longitude,
point2.latitude,
point2.longitude,
);
print(
'''Distance between San Francisco and Los Angeles: $calculatedDistance meters''',
);
// Define the outer polygon
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 area = PolygonHole.calculatePolygonWithHolesArea(outerPolygon, holes);
print("Area of polygon with holes: $area");
// Equirectangular approximation Calculation
final firstPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
final secondPoint = const LatLng(48.8566, 2.3522); // Paris, France
double equirectangularDistance =
EquirectangularApproximation.equirectangularDistance(
firstPoint, secondPoint);
print(
'''Equirectangular Distance: ${equirectangularDistance.toStringAsFixed(2)} km
''');
/// Calculate Spherical Law Of Cosines Distance
final bGPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
final pFPoint = const LatLng(48.8566, 2.3522); // Paris, France
double sLCDdistance =
SphericalLawOfCosines.sphericalLawOfCosinesDistance(bGPoint, pFPoint);
print(
'''Spherical Law of Cosines Distance: ${sLCDdistance.toStringAsFixed(2)} km
''');
/// Geodetic Point Manipulation - Rhumb Line Destination Formula
final initialPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
final bearingDegrees = 45.0; // 45 degrees bearing (northeast)
final distanceKm = 100.0; // 100 kilometers distance
LatLng destinationPoints = DestinationPoint.calculateDestinationPoint(
initialPoint, bearingDegrees, distanceKm);
print('Initial Point: ${initialPoint.latitude}, ${initialPoint.longitude}');
print('''Destination Point: ${destinationPoints.latitude},
${destinationPoints.longitude}''');
/// Geodetic Point Manipulation - Midpoint between two points
final bgPoint1 = const LatLng(52.5200, 13.4050); // Berlin, Germany
final pFPoint2 = const LatLng(48.8566, 2.3522); // Paris, France
LatLng midPointBetweenTwoPoints =
MidPointBetweenTwoPoints.calculateMidpoint(bgPoint1, pFPoint2);
print('''Midpoint: ${midPointBetweenTwoPoints.latitude},
${midPointBetweenTwoPoints.longitude}''');
/// Geodetic Point Manipulation - Calculate Point Along Great Circle
final startPoint = const LatLng(52.5200, 13.4050); // Berlin, Germany
final endPoint = const LatLng(48.8566, 2.3522); // Paris, France
final numPoints = 5; // Number of points along the arc
List<LatLng> arcPoints = GreatCirclePoint.calculatePointsAlongGreatCircle(
startPoint, endPoint, numPoints);
print('Points along Great Circle Arc:');
for (var point in arcPoints) {
print('${point.latitude}, ${point.longitude}');
}
/// PolyLine Length
// 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 = PolyLine.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 = PolygonArea.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 = GeodesicLines.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 =
GeodesicLines.projectPointOntoGeodesicLine(point, start, end);
print('''Projected Point: Latitude ${projection.latitude},
Longitude ${projection.longitude}''');
}