Skip to content

Commit 42f0f1d

Browse files
committed
Updated for Neo4j 5.8 / Uber 4.1.1
Updated for Neo4j 5.8 Updated Uber H3 library to 4.1.1 Added LINESTRING as a valid geo type
1 parent 7af478e commit 42f0f1d

File tree

15 files changed

+236
-154
lines changed

15 files changed

+236
-154
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ src/.DS_Store
1212
src/.DS_Store
1313
src/.DS_Store
1414
*.class
15+
.vscode/settings.json

CHANGELOG.md

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

3+
## 5.8 2023-0519
4+
5+
* [Added] Tested through Neo4j 5.7
6+
* [Added] Added support for converting a LINESTRING geospatial object to H3 number - com.neo4jh3.lineash3
7+
* [Added] Added support for converting a LINESTRING geospatial object to H3 string - com.neo4jh3.lineash3String
8+
* [Updated] Bumped H3 library to 4.1.1
9+
10+
311
## 5.7 2023-05-01
412

513
* [Added] Tested through Neo4j versions 5.7

Documentation.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,63 @@ A value of the type of STRING representing, as a hexadecimal string, the H3 cell
722722

723723
RETURN com.neo4jh3.latlongash3String( 97.8199, -222.4783, 13) AS value
724724
-4
725-
725+
726+
## com.neo4jh3.lineash3( geographyExpr, resolutionExpr )
727+
Returns the H3 cell ID (as a LONG) corresponding to the provided LINESTRING at the specified resolution.
728+
729+
### Syntax
730+
RETURN com.neo4jh3.lineash3( geographyExpr, resolutionExpr )
731+
732+
### Arguments
733+
* geographyExpr: A STRING expression representing a LINESTRING geography in WKT format
734+
* resolutionExpr: An INT expression, whose value is expected to be between 0 and 15 inclusive, specifying the resolution of the child H3 cell ID.
735+
736+
### Returns
737+
Returns the H3 cell ID (as a LONG) corresponding to the provided point at the specified resolution.
738+
739+
### Error conditions
740+
If geographyExpr is of type STRING and the value is either an invalid WKT or does not represent a point, the function returns -1
741+
742+
If resolutionExpr is smaller than 0 or larger than 15, the function returns -2
743+
744+
### Example
745+
RETURN com.neo4jh3.lineash3('LINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',13) AS value
746+
635714810904422079
747+
748+
RETURN com.neo4jh3.lineash3('zzz(37.8199 -122.4783)',13) AS value
749+
-1
750+
751+
RETURN com.neo4jh3.lineash3('LINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',16) AS value
752+
-2
753+
754+
## com.neo4jh3.lineash3String( geographyExpr, resolutionExpr )
755+
Returns the H3 cell ID (as a STRING) corresponding to the provided LINESTRING at the specified resolution.
756+
757+
### Syntax
758+
RETURN com.neo4jh3.lineash3String( geographyExpr, resolutionExpr )
759+
760+
### Arguments
761+
* geographyExpr: A STRING expression representing a LINESTRING geography in WKT format
762+
* resolutionExpr: An INT expression, whose value is expected to be between 0 and 15 inclusive, specifying the resolution of the child H3 cell ID.
763+
764+
### Returns
765+
Returns the H3 cell ID (as a LONG) corresponding to the provided LINESTRING at the specified resolution.
766+
767+
### Error conditions
768+
If geographyExpr is of type STRING and the value is either an invalid WKT or does not represent a point, the function returns -1
769+
770+
If resolutionExpr is smaller than 0 or larger than 15, the function returns -2
771+
772+
### Example
773+
RETURN com.neo4jh3.lineash3String('LINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',13) AS value
774+
8d283409a69a6bf
775+
776+
RETURN com.neo4jh3.lineash3String('zzz(37.8199 -122.4783)',13) AS value
777+
-1
778+
779+
RETURN com.neo4jh3.lineash3String('LINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',16) AS value
780+
-2
781+
726782
## com.neo4jh3.maxChild( h3CellIdExpr, resolutionExpr )
727783
Returns the child of minimum value of the input H3 cell at the specified resolution.
728784

@@ -792,7 +848,7 @@ A value of the same type as the type of the h3CellIdExpr expression, correspondi
792848

793849
### Error conditions
794850
If h3CellIdExpr is an invalid h3 address, the function returns -1.
795-
If resolutionExpr is an invalid resolution or smaller than h3_resolution(h3CellIdExpr), the function returns -2.
851+
If resolutionExpr is an i nvalid resolution or smaller than h3_resolution(h3CellIdExpr), the function returns -2.
796852

797853
### Example
798854
RETURN com.neo4jh3.minChild(599686042433355775, 10) AS value

dependency-reduced-pom.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.neo4jh3</groupId>
55
<artifactId>neo4jh3</artifactId>
6-
<version>5.7.0</version>
6+
<version>5.8.0</version>
77
<build>
88
<plugins>
99
<plugin>
@@ -43,7 +43,7 @@
4343
<dependency>
4444
<groupId>org.neo4j</groupId>
4545
<artifactId>neo4j</artifactId>
46-
<version>5.7.0</version>
46+
<version>5.8.0</version>
4747
<scope>provided</scope>
4848
<exclusions>
4949
<exclusion>
@@ -58,6 +58,10 @@
5858
<artifactId>neo4j-fabric</artifactId>
5959
<groupId>org.neo4j</groupId>
6060
</exclusion>
61+
<exclusion>
62+
<artifactId>neo4j-query-router</artifactId>
63+
<groupId>org.neo4j</groupId>
64+
</exclusion>
6165
<exclusion>
6266
<artifactId>neo4j-procedure</artifactId>
6367
<groupId>org.neo4j</groupId>
@@ -119,7 +123,7 @@
119123
<dependency>
120124
<groupId>org.neo4j.test</groupId>
121125
<artifactId>neo4j-harness</artifactId>
122-
<version>5.7.0</version>
126+
<version>5.8.0</version>
123127
<scope>test</scope>
124128
<exclusions>
125129
<exclusion>
@@ -190,11 +194,11 @@
190194
</dependency>
191195
</dependencies>
192196
<properties>
193-
<neo4j.version>5.7.0</neo4j.version>
197+
<neo4j.version>5.8.0</neo4j.version>
194198
<commons.version>4.1</commons.version>
195199
<csv.version>1.2</csv.version>
196200
<lang3.version>3.7</lang3.version>
197-
<uber.version>4.0.2</uber.version>
201+
<uber.version>4.1.1</uber.version>
198202
</properties>
199203
</project>
200204

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
<groupId>com.neo4jh3</groupId>
88
<artifactId>neo4jh3</artifactId>
9-
<version>5.7.0</version>
9+
<version>5.8.0</version>
1010

1111
<properties>
12-
<neo4j.version>5.7.0</neo4j.version>
12+
<neo4j.version>5.8.0</neo4j.version>
1313
<csv.version>1.2</csv.version>
1414
<lang3.version>3.7</lang3.version>
15-
<uber.version>4.0.2</uber.version>
15+
<uber.version>4.1.1</uber.version>
1616
<commons.version>4.1</commons.version>
1717
</properties>
1818

src/main/java/com/neo4jh3/uber/Uberh3.java

Lines changed: 154 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,6 @@ public String pointash3String(
739739
return h3Address;
740740
}
741741

742-
// New Geo Functions
743742
@Procedure(name = "com.neo4jh3.multilineash3", mode = Mode.READ)
744743
@Description("com.neo4jh3.multilineash3(wktString, resolution) - Provides the distance in grid cells between the two indexes.")
745744
public Stream<H3LongAddress> multilineash3(
@@ -817,7 +816,7 @@ public Stream<H3LongAddress> multilineash3(
817816
return listh3Address.stream().map(H3LongAddress::of);
818817
}
819818

820-
// New Geo Functions
819+
// New Geo Procedures
821820
@Procedure(name = "com.neo4jh3.multilineash3String", mode = Mode.READ)
822821
@Description("com.neo4jh3.multilineash3String(wktString, resolution) - Provides the distance in grid cells between the two indexes.")
823822
public Stream<H3StringAddress> multilineash3String(
@@ -892,6 +891,159 @@ public Stream<H3StringAddress> multilineash3String(
892891
}
893892
return listh3Address.stream().map(H3StringAddress::of);
894893
}
894+
895+
@Procedure(name = "com.neo4jh3.lineash3", mode = Mode.READ)
896+
@Description("com.neo4jh3.lineash3(wktString, resolution) - Provides the distance in grid cells between the two indexes.")
897+
public Stream<H3LongAddress> lineash3(
898+
@Name("wktString") String wktString,
899+
@Name("h3Res") Long h3Res) throws InterruptedException
900+
{
901+
List<Long> listh3Address = new ArrayList<Long>();
902+
List<Long> gpCells = new ArrayList<Long>();
903+
Long h3Address = 0L;
904+
Long h3StartAddress = 0L;
905+
Long h3MidAddress = 0L;
906+
Long h3EndAddress = 0L;
907+
Double fromLat = 0.0;
908+
Double fromLon = 0.0;
909+
Double toLat = 0.0;
910+
Double toLon = 0.0;
911+
Double midLat = 0.0;
912+
Double midLon = 0.0;
913+
String mls = "";
914+
915+
if (h3 == null) {
916+
throw new InterruptedException("h3 failed to initialize");
917+
}
918+
919+
final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue();
920+
921+
try {
922+
if (h3Resolution > 0 && h3Resolution <= 15) {
923+
mls = wktString.replace("LINESTRING((", "");
924+
mls = mls.replace(" (","");
925+
mls = mls.replace(")","");
926+
mls = mls.replace("(","");
927+
String[] latlonPairs = mls.split(",");
928+
for (int i = 0; i < latlonPairs.length; i++) {
929+
if (i > 0){
930+
fromLat = Double.valueOf(latlonPairs[i-1].split(" ")[0]);
931+
fromLon = Double.valueOf(latlonPairs[i-1].split(" ")[1]);
932+
toLat = Double.valueOf(latlonPairs[i].split(" ")[0]);
933+
toLon = Double.valueOf(latlonPairs[i].split(" ")[1]);
934+
midLat = (fromLat + toLat) / 2;
935+
midLon = (fromLon + toLon) / 2;
936+
h3StartAddress = h3.latLngToCell(fromLat, fromLon, h3Resolution);
937+
h3MidAddress = h3.latLngToCell(midLat, midLon, h3Resolution);
938+
h3EndAddress = h3.latLngToCell(toLat, toLon, h3Resolution);
939+
try {
940+
gpCells = h3.gridPathCells(h3StartAddress, h3MidAddress);
941+
for (int j = 0; j < gpCells.size(); j++) {
942+
listh3Address.add(gpCells.get(j));
943+
}
944+
gpCells.clear();
945+
} catch (Exception e1){
946+
}
947+
try {
948+
gpCells = h3.gridPathCells((h3MidAddress), h3EndAddress);
949+
for (int j = 0; j < gpCells.size(); j++) {
950+
listh3Address.add(gpCells.get(j));
951+
}
952+
gpCells.clear();
953+
} catch (Exception e1){
954+
955+
}
956+
957+
}
958+
}
959+
} else {
960+
listh3Address = Collections.singletonList(-2L);
961+
962+
}
963+
} catch (Exception e) {
964+
//System.out.println(e);
965+
listh3Address = Collections.singletonList(-1L);
966+
// TODO Auto-generated catch block
967+
//e.printStackTrace();
968+
}
969+
return listh3Address.stream().map(H3LongAddress::of);
970+
}
971+
972+
// New Geo Procedures
973+
@Procedure(name = "com.neo4jh3.lineash3String", mode = Mode.READ)
974+
@Description("com.neo4jh3.lineash3String(wktString, resolution) - Provides the distance in grid cells between the two indexes.")
975+
public Stream<H3StringAddress> lineash3String(
976+
@Name("wktString") String wktString,
977+
@Name("h3Res") Long h3Res) throws InterruptedException
978+
{
979+
List<String> listh3Address = new ArrayList<String>();
980+
List<String> gpCells = new ArrayList<String>();
981+
String h3StartAddress = "";
982+
String h3MidAddress = "";
983+
String h3EndAddress = "";
984+
Double fromLat = 0.0;
985+
Double fromLon = 0.0;
986+
Double toLat = 0.0;
987+
Double toLon = 0.0;
988+
Double midLat = 0.0;
989+
Double midLon = 0.0;
990+
String mls = "";
991+
992+
if (h3 == null) {
993+
throw new InterruptedException("h3 failed to initialize");
994+
}
995+
996+
final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue();
997+
998+
try {
999+
if (h3Resolution > 0 && h3Resolution <= 15) {
1000+
mls = wktString.replace("LINESTRING((", "");
1001+
mls = mls.replace(" (","");
1002+
mls = mls.replace(")","");
1003+
mls = mls.replace("(","");
1004+
String[] latlonPairs = mls.split(",");
1005+
for (int i = 0; i < latlonPairs.length; i++) {
1006+
if (i > 0){
1007+
fromLat = Double.valueOf(latlonPairs[i-1].split(" ")[0]);
1008+
fromLon = Double.valueOf(latlonPairs[i-1].split(" ")[1]);
1009+
toLat = Double.valueOf(latlonPairs[i].split(" ")[0]);
1010+
toLon = Double.valueOf(latlonPairs[i].split(" ")[1]);
1011+
midLat = (fromLat + toLat) / 2;
1012+
midLon = (fromLon + toLon) / 2;
1013+
h3StartAddress = h3.latLngToCellAddress(fromLat, fromLon, h3Resolution);
1014+
h3MidAddress = h3.latLngToCellAddress(midLat, midLon, h3Resolution);
1015+
h3EndAddress = h3.latLngToCellAddress(toLat, toLon, h3Resolution);
1016+
try {
1017+
gpCells = h3.gridPathCells(h3StartAddress, h3MidAddress);
1018+
for (int j = 0; j < gpCells.size(); j++) {
1019+
listh3Address.add(gpCells.get(j));
1020+
}
1021+
gpCells.clear();
1022+
} catch (Exception e1){
1023+
//listh3Address = Collections.singletonList("-1");
1024+
}
1025+
try {
1026+
gpCells = h3.gridPathCells((h3MidAddress), h3EndAddress);
1027+
for (int j = 0; j < gpCells.size(); j++) {
1028+
listh3Address.add(gpCells.get(j));
1029+
}
1030+
gpCells.clear();
1031+
} catch (Exception e1){
1032+
//listh3Address = Collections.singletonList("-1");
1033+
}
1034+
}
1035+
}
1036+
} else {
1037+
listh3Address = Collections.singletonList("-2");
1038+
}
1039+
} catch (Exception e) {
1040+
//System.out.println(e);
1041+
listh3Address = Collections.singletonList("-1");
1042+
// TODO Auto-generated catch block
1043+
//e.printStackTrace();
1044+
}
1045+
return listh3Address.stream().map(H3StringAddress::of);
1046+
}
8951047
// Geography Functions
8961048

8971049
@UserFunction(name = "com.neo4jh3.centeraswkb")

src/test/java/com/neo4jh3/Neo4jH3Test.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ public void should_return_hex_address() throws InterruptedException {
311311
result = session.run("call com.neo4jh3.multilineash3('MULTILINESTRING((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018) , (40.93733046783797 -74.00265431029018))',17) yield value return value limit 1");
312312
assertEquals(-2L,result.single().get(0).asLong(),0);
313313

314+
result = session.run("call com.neo4jh3.lineash3('LINESTRING((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018) , (40.93733046783797 -74.00265431029018))',12) yield value return value limit 1");
315+
assertEquals(631243922688264703L, result.single().get(0).asLong(),0);
316+
314317
/* Geography tests */
315318
result = session.run("RETURN com.neo4jh3.pointash3('POINT(37.8199 -122.4783)',13) AS value");
316319
assertEquals(635714569676958015L, result.single().get("value").asLong(),0);

target/original-neo4jh3-5.3.1.jar

-19.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)