Skip to content

Commit 128b9b8

Browse files
committed
degree and meter conversions, next version as 2.1.0
1 parent dcee86c commit 128b9b8

4 files changed

Lines changed: 92 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Adheres to [Semantic Versioning](http://semver.org/).
44

55
---
66

7-
## 2.0.7 (TBD)
7+
## 2.1.0 (TBD)
88

9-
* Line intersection geometry utility
10-
* GeometryEnvelope is empty and contains methods
9+
* Geometry utilities for line intersections and degree to/from meter conversions
10+
* GeometryEnvelope serializable and methods for mid values, is empty, and contains
1111

1212
## [2.0.6](https://github.com/ngageoint/simple-features-java/releases/tag/2.0.6) (04-18-2022)
1313

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>mil.nga</groupId>
55
<artifactId>sf</artifactId>
6-
<version>2.0.7</version>
6+
<version>2.1.0</version>
77
<packaging>jar</packaging>
88
<name>Simple Features</name>
99
<url>https://github.com/ngageoint/simple-features-java</url>

src/main/java/mil/nga/sf/GeometryEnvelope.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ public boolean isPoint() {
468468
* Get the envelope mid x
469469
*
470470
* @return mid x
471-
* @since 2.0.7
471+
* @since 2.1.0
472472
*/
473473
public double getMidX() {
474474
return (minX + maxX) / 2.0;
@@ -478,7 +478,7 @@ public double getMidX() {
478478
* Get the envelope mid y
479479
*
480480
* @return mid y
481-
* @since 2.0.7
481+
* @since 2.1.0
482482
*/
483483
public double getMidY() {
484484
return (minY + maxY) / 2.0;
@@ -498,7 +498,7 @@ public Point getCentroid() {
498498
* Determine if the envelope is empty
499499
*
500500
* @return true if empty
501-
* @since 2.0.7
501+
* @since 2.1.0
502502
*/
503503
public boolean isEmpty() {
504504
return getXRange() <= 0.0 || getYRange() <= 0.0;
@@ -599,7 +599,7 @@ public GeometryEnvelope union(GeometryEnvelope envelope) {
599599
* @param point
600600
* point
601601
* @return true if contains
602-
* @since 2.0.7
602+
* @since 2.1.0
603603
*/
604604
public boolean contains(Point point) {
605605
return contains(point.getX(), point.getY());
@@ -613,7 +613,7 @@ public boolean contains(Point point) {
613613
* @param y
614614
* y value
615615
* @return true if contains
616-
* @since 2.0.7
616+
* @since 2.1.0
617617
*/
618618
public boolean contains(double x, double y) {
619619
return x >= getMinX() && x <= getMaxX() && y >= getMinY()

src/main/java/mil/nga/sf/util/GeometryUtils.java

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ public class GeometryUtils {
5757
*/
5858
public static final double DEFAULT_EPSILON = 0.000000000000001;
5959

60+
/**
61+
* Half the world distance in either direction
62+
*
63+
* @since 2.1.0
64+
*/
65+
public static final double WEB_MERCATOR_HALF_WORLD_WIDTH = 20037508.342789244;
66+
6067
/**
6168
* Get the dimension of the Geometry, 0 for points, 1 for curves, 2 for
6269
* surfaces. If a collection, the largest dimension is returned.
@@ -178,9 +185,10 @@ public static Point getDegreesCentroid(Geometry geometry) {
178185
* Example: For WGS84 provide a max x of 180.0. Resulting x values will be
179186
* in the range: -540.0 &lt;= x &lt;= 540.0
180187
*
181-
* Example: For web mercator provide a world width of 20037508.342789244.
182-
* Resulting x values will be in the range: -60112525.028367732 &lt;= x
183-
* &lt;= 60112525.028367732
188+
* Example: For web mercator provide a world width of
189+
* {@link GeometryUtils#WEB_MERCATOR_HALF_WORLD_WIDTH}. Resulting x values
190+
* will be in the range: -60112525.028367732 &lt;= x &lt;=
191+
* 60112525.028367732
184192
*
185193
* @param geometry
186194
* geometry
@@ -369,9 +377,10 @@ private static void minimize(PolyhedralSurface polyhedralSurface,
369377
* Example: For WGS84 provide a max x of 180.0. Resulting x values will be
370378
* in the range: -180.0 &lt;= x &lt;= 180.0.
371379
*
372-
* Example: For web mercator provide a world width of 20037508.342789244.
373-
* Resulting x values will be in the range: -20037508.342789244 &lt;= x
374-
* &lt;= 20037508.342789244.
380+
* Example: For web mercator provide a world width of
381+
* {@link GeometryUtils#WEB_MERCATOR_HALF_WORLD_WIDTH}. Resulting x values
382+
* will be in the range: -20037508.342789244 &lt;= x &lt;=
383+
* 20037508.342789244.
375384
*
376385
* @param geometry
377386
* geometry
@@ -1149,7 +1158,7 @@ private static boolean pointOnPath(Point point, List<Point> points,
11491158
* @param line2
11501159
* second line
11511160
* @return intersection point or null if no intersection
1152-
* @since 2.0.7
1161+
* @since 2.1.0
11531162
*/
11541163
public static Point intersection(Line line1, Line line2) {
11551164
return intersection(line1.startPoint(), line1.endPoint(),
@@ -1168,7 +1177,7 @@ public static Point intersection(Line line1, Line line2) {
11681177
* @param line2Point2
11691178
* second point of the second line
11701179
* @return intersection point or null if no intersection
1171-
* @since 2.0.7
1180+
* @since 2.1.0
11721181
*/
11731182
public static Point intersection(Point line1Point1, Point line1Point2,
11741183
Point line2Point1, Point line2Point2) {
@@ -1194,6 +1203,72 @@ public static Point intersection(Point line1Point1, Point line1Point2,
11941203
return intersection;
11951204
}
11961205

1206+
/**
1207+
* Convert a point in degrees to a point in meters
1208+
*
1209+
* @param point
1210+
* point in degrees
1211+
* @return point in meters
1212+
* @since 2.1.0
1213+
*/
1214+
public static Point degreesToMeters(Point point) {
1215+
Point value = degreesToMeters(point.getX(), point.getY());
1216+
value.setZ(point.getZ());
1217+
value.setM(point.getM());
1218+
return value;
1219+
}
1220+
1221+
/**
1222+
* Convert a coordinate in degrees to a point in meters
1223+
*
1224+
* @param x
1225+
* x value in degrees
1226+
* @param y
1227+
* y value in degrees
1228+
* @return point in meters
1229+
* @since 2.1.0
1230+
*/
1231+
public static Point degreesToMeters(double x, double y) {
1232+
double xValue = x * WEB_MERCATOR_HALF_WORLD_WIDTH / 180;
1233+
double yValue = Math.log(Math.tan((90 + y) * Math.PI / 360))
1234+
/ (Math.PI / 180);
1235+
yValue = yValue * WEB_MERCATOR_HALF_WORLD_WIDTH / 180;
1236+
return new Point(xValue, yValue);
1237+
}
1238+
1239+
/**
1240+
* Convert a point in meters to a point in degrees
1241+
*
1242+
* @param point
1243+
* point in meters
1244+
* @return point in degrees
1245+
* @since 2.1.0
1246+
*/
1247+
public static Point metersToDegrees(Point point) {
1248+
Point value = metersToDegrees(point.getX(), point.getY());
1249+
value.setZ(point.getZ());
1250+
value.setM(point.getM());
1251+
return value;
1252+
}
1253+
1254+
/**
1255+
* Convert a coordinate in meters to a point in degrees
1256+
*
1257+
* @param x
1258+
* x value in meters
1259+
* @param y
1260+
* y value in meters
1261+
* @return point in degrees
1262+
* @since 2.1.0
1263+
*/
1264+
public static Point metersToDegrees(double x, double y) {
1265+
double xValue = x * 180 / WEB_MERCATOR_HALF_WORLD_WIDTH;
1266+
double yValue = y * 180 / WEB_MERCATOR_HALF_WORLD_WIDTH;
1267+
yValue = Math.atan(Math.exp(yValue * (Math.PI / 180))) / Math.PI * 360
1268+
- 90;
1269+
return new Point(xValue, yValue);
1270+
}
1271+
11971272
/**
11981273
* Determine if the geometries contain a Z value
11991274
*

0 commit comments

Comments
 (0)