Skip to content

Commit 5ff01c8

Browse files
authored
Merge pull request #70 from isaacbrodsky/bump-3.7.0
Update to H3 v3.7.0
2 parents a500880 + dd65b70 commit 5ff01c8

File tree

9 files changed

+364
-2
lines changed

9 files changed

+364
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ pom.xml.releaseBackup
2424
pom.xml.versionsBackup
2525
pom.xml.next
2626
release.properties
27+
28+
.vscode/

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ file [H3Core.java](./src/main/java/com/uber/h3core/H3Core.java), and support
77
for the Linux x64 and Darwin x64 platforms.
88

99
## [Unreleased]
10+
## Added
11+
- Area and haversine distance functions (#70)
12+
- `cellArea`
13+
- `pointDist`
14+
- `exactEdgeLength`
15+
## Changed
16+
- Updated the core library to v3.7.1. (#70)
1017

1118
## [3.6.4] - 2020-06-29
1219
### Changed

h3version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
h3.git.reference=v3.6.4
1+
h3.git.reference=v3.7.1

src/main/c/h3-java/src/jniapi.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,106 @@ JNIEXPORT jint JNICALL Java_com_uber_h3core_NativeMethods_uncompact(
763763
return ret;
764764
}
765765

766+
/*
767+
* Class: com_uber_h3core_NativeMethods
768+
* Method: cellAreaRads2
769+
* Signature: (J)D
770+
*/
771+
JNIEXPORT jdouble JNICALL Java_com_uber_h3core_NativeMethods_cellAreaRads2(
772+
JNIEnv *env, jobject thiz, jlong h3) {
773+
return cellAreaRads2(h3);
774+
}
775+
776+
/*
777+
* Class: com_uber_h3core_NativeMethods
778+
* Method: cellAreaKm2
779+
* Signature: (J)D
780+
*/
781+
JNIEXPORT jdouble JNICALL Java_com_uber_h3core_NativeMethods_cellAreaKm2(
782+
JNIEnv *env, jobject thiz, jlong h3) {
783+
return cellAreaKm2(h3);
784+
}
785+
786+
/*
787+
* Class: com_uber_h3core_NativeMethods
788+
* Method: cellAreaM2
789+
* Signature: (J)D
790+
*/
791+
JNIEXPORT jdouble JNICALL Java_com_uber_h3core_NativeMethods_cellAreaM2(
792+
JNIEnv *env, jobject thiz, jlong h3) {
793+
return cellAreaM2(h3);
794+
}
795+
796+
/*
797+
* Class: com_uber_h3core_NativeMethods
798+
* Method: pointDistRads
799+
* Signature: (DDDD)D
800+
*/
801+
JNIEXPORT jdouble JNICALL Java_com_uber_h3core_NativeMethods_pointDistRads(
802+
JNIEnv *env, jobject thiz, jdouble lat1, jdouble lon1, jdouble lat2,
803+
jdouble lon2) {
804+
GeoCoord c1 = {.lat = lat1, .lon = lon1};
805+
GeoCoord c2 = {.lat = lat2, .lon = lon2};
806+
return pointDistRads(&c1, &c2);
807+
}
808+
809+
/*
810+
* Class: com_uber_h3core_NativeMethods
811+
* Method: pointDistKm
812+
* Signature: (DDDD)D
813+
*/
814+
JNIEXPORT jdouble JNICALL Java_com_uber_h3core_NativeMethods_pointDistKm(
815+
JNIEnv *env, jobject thiz, jdouble lat1, jdouble lon1, jdouble lat2,
816+
jdouble lon2) {
817+
GeoCoord c1 = {.lat = lat1, .lon = lon1};
818+
GeoCoord c2 = {.lat = lat2, .lon = lon2};
819+
return pointDistKm(&c1, &c2);
820+
}
821+
822+
/*
823+
* Class: com_uber_h3core_NativeMethods
824+
* Method: pointDistM
825+
* Signature: (DDDD)D
826+
*/
827+
JNIEXPORT jdouble JNICALL Java_com_uber_h3core_NativeMethods_pointDistM(
828+
JNIEnv *env, jobject thiz, jdouble lat1, jdouble lon1, jdouble lat2,
829+
jdouble lon2) {
830+
GeoCoord c1 = {.lat = lat1, .lon = lon1};
831+
GeoCoord c2 = {.lat = lat2, .lon = lon2};
832+
return pointDistM(&c1, &c2);
833+
}
834+
835+
/*
836+
* Class: com_uber_h3core_NativeMethods
837+
* Method: exactEdgeLengthRads
838+
* Signature: (J)D
839+
*/
840+
JNIEXPORT jdouble JNICALL
841+
Java_com_uber_h3core_NativeMethods_exactEdgeLengthRads(JNIEnv *env,
842+
jobject thiz, jlong h3) {
843+
return exactEdgeLengthRads(h3);
844+
}
845+
846+
/*
847+
* Class: com_uber_h3core_NativeMethods
848+
* Method: exactEdgeLengthKm
849+
* Signature: (J)D
850+
*/
851+
JNIEXPORT jdouble JNICALL Java_com_uber_h3core_NativeMethods_exactEdgeLengthKm(
852+
JNIEnv *env, jobject thiz, jlong h3) {
853+
return exactEdgeLengthKm(h3);
854+
}
855+
856+
/*
857+
* Class: com_uber_h3core_NativeMethods
858+
* Method: exactEdgeLengthM
859+
* Signature: (J)D
860+
*/
861+
JNIEXPORT jdouble JNICALL Java_com_uber_h3core_NativeMethods_exactEdgeLengthM(
862+
JNIEnv *env, jobject thiz, jlong h3) {
863+
return exactEdgeLengthM(h3);
864+
}
865+
766866
/*
767867
* Class: com_uber_h3core_NativeMethods
768868
* Method: hexAreaKm2

src/main/java/com/uber/h3core/AreaUnit.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
* Unit of measurement for areas.
2020
*/
2121
public enum AreaUnit {
22+
/**
23+
* Square radians on the WGS84 sphere
24+
*/
25+
rads2,
2226
/**
2327
* Square kilometers
2428
*/

src/main/java/com/uber/h3core/H3Core.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,88 @@ public long stringToH3(String h3Address) {
966966
return Long.parseUnsignedLong(h3Address, 16);
967967
}
968968

969+
/**
970+
* Calculates the area of the given H3 cell.
971+
*
972+
* @param h3Address Cell to find the area of.
973+
* @param unit Unit to calculate the area in.
974+
* @return Cell area in the given units.
975+
*/
976+
public double cellArea(String h3Address, AreaUnit unit) {
977+
return cellArea(stringToH3(h3Address), unit);
978+
}
979+
980+
/**
981+
* Calculates the area of the given H3 cell.
982+
*
983+
* @param h3 Cell to find the area of.
984+
* @param unit Unit to calculate the area in.
985+
* @return Cell area in the given units.
986+
*/
987+
public double cellArea(long h3, AreaUnit unit) {
988+
if (unit == AreaUnit.rads2)
989+
return h3Api.cellAreaRads2(h3);
990+
else if (unit == AreaUnit.km2)
991+
return h3Api.cellAreaKm2(h3);
992+
else if (unit == AreaUnit.m2)
993+
return h3Api.cellAreaM2(h3);
994+
else
995+
throw new IllegalArgumentException(String.format("Invalid unit: %s", unit));
996+
}
997+
998+
/**
999+
* Return the distance along the sphere between two points.
1000+
*
1001+
* @param a First point
1002+
* @param b Second point
1003+
* @param unit Unit to return the distance in.
1004+
* @return Distance from point <code>a</code> to point <code>b</code>
1005+
*/
1006+
public double pointDist(GeoCoord a, GeoCoord b, LengthUnit unit) {
1007+
double lat1 = toRadians(a.lat);
1008+
double lng1 = toRadians(a.lng);
1009+
double lat2 = toRadians(b.lat);
1010+
double lng2 = toRadians(b.lng);
1011+
1012+
if (unit == LengthUnit.rads)
1013+
return h3Api.pointDistRads(lat1, lng1, lat2, lng2);
1014+
else if (unit == LengthUnit.km)
1015+
return h3Api.pointDistKm(lat1, lng1, lat2, lng2);
1016+
else if (unit == LengthUnit.m)
1017+
return h3Api.pointDistM(lat1, lng1, lat2, lng2);
1018+
else
1019+
throw new IllegalArgumentException(String.format("Invalid unit: %s", unit));
1020+
}
1021+
1022+
/**
1023+
* Calculate the edge length of the given H3 edge.
1024+
*
1025+
* @param edgeAddress Edge to find the edge length of.
1026+
* @param unit Unit of measure to use.
1027+
* @return Length of the given edge.
1028+
*/
1029+
public double exactEdgeLength(String edgeAddress, LengthUnit unit) {
1030+
return exactEdgeLength(stringToH3(edgeAddress), unit);
1031+
}
1032+
1033+
/**
1034+
* Calculate the edge length of the given H3 edge.
1035+
*
1036+
* @param edge Edge to find the edge length of.
1037+
* @param unit Unit of measure to use.
1038+
* @return Length of the given edge.
1039+
*/
1040+
public double exactEdgeLength(long edge, LengthUnit unit) {
1041+
if (unit == LengthUnit.rads)
1042+
return h3Api.exactEdgeLengthRads(edge);
1043+
else if (unit == LengthUnit.km)
1044+
return h3Api.exactEdgeLengthKm(edge);
1045+
else if (unit == LengthUnit.m)
1046+
return h3Api.exactEdgeLengthM(edge);
1047+
else
1048+
throw new IllegalArgumentException(String.format("Invalid unit: %s", unit));
1049+
}
1050+
9691051
/**
9701052
* Returns the average area in <code>unit</code> for indexes at resolution <code>res</code>.
9711053
*

src/main/java/com/uber/h3core/LengthUnit.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
* Unit of measurement for lengths.
2020
*/
2121
public enum LengthUnit {
22+
/**
23+
* Radians on the WGS84 sphere
24+
*/
25+
rads,
2226
/**
2327
* Kilometers
2428
*/

src/main/java/com/uber/h3core/NativeMethods.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ final class NativeMethods {
6161
native int maxUncompactSize(long[] h3, int res);
6262
native int uncompact(long[] h3, int res, long[] results);
6363

64+
native double cellAreaRads2(long h3);
65+
native double cellAreaKm2(long h3);
66+
native double cellAreaM2(long h3);
67+
native double pointDistRads(double lat1, double lon1, double lat2, double lon2);
68+
native double pointDistKm(double lat1, double lon1, double lat2, double lon2);
69+
native double pointDistM(double lat1, double lon1, double lat2, double lon2);
70+
native double exactEdgeLengthRads(long h3);
71+
native double exactEdgeLengthKm(long h3);
72+
native double exactEdgeLengthM(long h3);
73+
6474
native double hexAreaKm2(int res);
6575
native double hexAreaM2(int res);
6676
native double edgeLengthKm(int res);

0 commit comments

Comments
 (0)