Skip to content

Commit bdfa803

Browse files
authored
Merge pull request #6 from davidfauth/5.5
Updated for Neo4j 5.5 and new multiline function
2 parents 43a045c + b7aa6be commit bdfa803

File tree

8 files changed

+145
-35
lines changed

8 files changed

+145
-35
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ src/.DS_Store
99
src/.DS_Store
1010
src/.DS_Store
1111
src/.DS_Store
12+
src/.DS_Store
13+
src/.DS_Store

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# CHANGELOG - Neo4jH3
2+
3+
## 5.5 2023-02-24
4+
5+
* [Added] Tested through Neo4j versions 5.5
6+
* [Added] Added support for converting a MULTILINE geospatial object to H3 number - com.neo4jh3.multilineash3
7+
* [Added] Added support for converting a MULTILINE geospatial object to H3 string - com.neo4jh3.multilineash3String
8+
9+
10+

Documentation.md

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ If h3CellId1Expr or h3CellId2Expr is an invalid h3 address, the function returns
413413
Returns the grid distance of the two input H3 cells, that are expected to have the same resolution.
414414

415415
### Syntax
416-
RETURN com.neo4jh3. gridDistance( h3CellId1Expr, h3CellId2Expr ) AS value;
416+
RETURN com.neo4jh3.gridDistance( h3CellId1Expr, h3CellId2Expr ) AS value;
417417

418418
### Arguments
419419
* h3CellId1Expr: A hexadecimal LONG expression representing an H3 cell ID.
@@ -484,7 +484,6 @@ A value of the type of LONG representing, as a hexadecimal string, the H3 cell I
484484
RETURN com.neo4jh3.h3HexAddress( 97.8199, -122.4783, 13) AS value
485485
-3
486486
487-
488487

489488
##com.neo4jh3.h3HexAddressString( latitude, longitude, resolution )
490489
Returns the H3 cell ID (as a hexadecimal STRING) corresponding to the provided longitude and latitude at the specified resolution.
@@ -691,9 +690,7 @@ A value of the type of LONG representing, as a hexadecimal string, the H3 cell I
691690

692691
RETURN com.neo4jh3.latlongash3( 67.8199, -222.4783, 13) AS value
693692
-4
694-
695-
696-
693+
697694
##com.neo4jh3.latlongash3String( latitude, longitude, resolution )
698695
Returns the H3 cell ID (as a hexadecimal STRING) corresponding to the provided longitude and latitude at the specified resolution.
699696

@@ -726,8 +723,6 @@ A value of the type of STRING representing, as a hexadecimal string, the H3 cell
726723
RETURN com.neo4jh3.latlongash3String( 97.8199, -222.4783, 13) AS value
727724
-4
728725
729-
730-
731726
##com.neo4jh3.maxChild( h3CellIdExpr, resolutionExpr )
732727
Returns the child of minimum value of the input H3 cell at the specified resolution.
733728

@@ -826,7 +821,6 @@ A value of the same type as the type of the h3CellIdExpr expression, correspondi
826821
If h3CellIdExpr is an invalid h3 address, the function returns -1.
827822
If resolutionExpr is an invalid resolution or smaller than h3_resolution(h3CellIdExpr), the function returns -2.
828823

829-
830824
### Example
831825
RETURN com.neo4jh3.minChildString('85283473fffffff', 10) AS value
832826
8a2834700007fff
@@ -837,6 +831,62 @@ If resolutionExpr is an invalid resolution or smaller than h3_resolution(h3CellI
837831
RETURN com.neo4jh3.minChildString('85283473fffffff',27) AS value
838832
-2
839833

834+
##com.neo4jh3.multilineash3( geographyExpr, resolutionExpr )
835+
Returns the H3 cell ID (as a LONG) corresponding to the provided MULTILINESTRING at the specified resolution.
836+
837+
### Syntax
838+
RETURN com.neo4jh3.multilineash3( geographyExpr, resolutionExpr )
839+
840+
### Arguments
841+
* geographyExpr: A STRING expression representing a MULTILINESTRING geography in WKT format
842+
* resolutionExpr: An INT expression, whose value is expected to be between 0 and 15 inclusive, specifying the resolution of the child H3 cell ID.
843+
844+
### Returns
845+
Returns the H3 cell ID (as a LONG) corresponding to the provided point at the specified resolution.
846+
847+
### Error conditions
848+
If geographyExpr is of type STRING and the value is either an invalid WKT or does not represent a point, the function returns -1
849+
850+
If resolutionExpr is smaller than 0 or larger than 15, the function returns -2
851+
852+
### Example
853+
RETURN com.neo4jh3.multilineash3('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',13) AS value
854+
635714810904422079
855+
856+
RETURN com.neo4jh3.multilineash3('zzz(37.8199 -122.4783)',13) AS value
857+
-1
858+
859+
RETURN com.neo4jh3.multilineash3('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',16) AS value
860+
-2
861+
862+
##com.neo4jh3.multilineash3String( geographyExpr, resolutionExpr )
863+
Returns the H3 cell ID (as a STRING) corresponding to the provided MULTILINESTRING at the specified resolution.
864+
865+
### Syntax
866+
RETURN com.neo4jh3.multilineash3String( geographyExpr, resolutionExpr )
867+
868+
### Arguments
869+
* geographyExpr: A STRING expression representing a MULTILINESTRING geography in WKT format
870+
* resolutionExpr: An INT expression, whose value is expected to be between 0 and 15 inclusive, specifying the resolution of the child H3 cell ID.
871+
872+
### Returns
873+
Returns the H3 cell ID (as a LONG) corresponding to the provided MULTILINESTRING at the specified resolution.
874+
875+
### Error conditions
876+
If geographyExpr is of type STRING and the value is either an invalid WKT or does not represent a point, the function returns -1
877+
878+
If resolutionExpr is smaller than 0 or larger than 15, the function returns -2
879+
880+
### Example
881+
RETURN com.neo4jh3.multilineash3String('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',13) AS value
882+
8d283409a69a6bf
883+
884+
RETURN com.neo4jh3.multilineash3String('zzz(37.8199 -122.4783)',13) AS value
885+
-1
886+
887+
RETURN com.neo4jh3.multilineash3String('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',16) AS value
888+
-2
889+
840890
##com.neo4jh3.pointash3( geographyExpr, resolutionExpr )
841891
Returns the H3 cell ID (as a LONG) corresponding to the provided point at the specified resolution.
842892

@@ -865,7 +915,6 @@ If resolutionExpr is smaller than 0 or larger than 15, the function returns -2
865915
RETURN com.neo4jh3.maxChildString('POINT(37.8199 -122.4783)',16) AS value
866916
-2
867917

868-
869918
##com.neo4jh3.pointash3String( geographyExpr, resolutionExpr )
870919
Returns the H3 cell ID (as a STRING) corresponding to the provided point at the specified resolution.
871920

README.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ project, simply package the project with maven:
1111

1212
mvn clean package
1313

14-
This will produce a jar-file, `neo4jh3-0.9.1.jar `,
14+
This will produce a jar-file, `neo4jh3-5.5.0.jar`,
1515
that can be copied to the `plugin` directory of your Neo4j instance.
1616

17-
cp target/neo4jh3-0.9.1-SNAPSHOT.jar neo4j-enterprise-5.x.0/plugins/.
17+
cp target/neo4jh3-5.5.0.jar neo4j-enterprise-5.x.0/plugins/.
1818

1919

2020
Edit your Neo4j/conf/neo4j.conf file by adding this line:
@@ -25,26 +25,6 @@ Edit your Neo4j/conf/neo4j.conf file by adding this line:
2525

2626
(Re)start Neo4j
2727

28-
# Functions
29-
com.neo4jh3.uber.h3HexAddress(Double Lat, Double Long, Long Resolution) returns hexAddress;
30-
com.neo4jh3.uber.h3HexAddressNumber(Double Lat, Double Long, Long Resolution) returns Long;
31-
com.neo4jh3.uber.h3RingsForDistance(Double Resolution, Double Distance in KM) returns Long;
32-
com.neo4jh3.gridDistance(String hexAddress, String hexAddress) returns int;
33-
com.neo4jh3.gridDistanceNumber(Long hexAddress, Long hexAddress) returns int;
34-
com.neo4jh3.cellToParent(String hexAddress, Long Resolution) returns String;
35-
com.neo4jh3.cellToLatLng(String hexAddress) returns String;
36-
com.neo4jh3.cellToLatLngNumber(Long hexAddress) returns String;
37-
com.neo4jh3.distanceBetweenHexes(String hexAddress, String HexAddress) returns Long (km);
38-
com.neo4jh3.distanceBetweenHexesNumber(String hexAddress, String HexAddress) returns Long (km);
39-
40-
41-
# Procedures
42-
com.neo4jh3.gridDisk(String hexAddress, Long ringSize) returns String;
43-
com.neo4jh3.cellToChildren(String hexAddress, Long resolution) returns String;
44-
com.neo4jh3.returnHexAddress(Double Lat, Double Long, Long Resolution) returns String hexAddress;
45-
com.neo4jh3.returnLongAddress(Double Lat, Double Long, Long Resolution) returns Long hexAddress;
46-
com.neo4jh3.polygonToCells(List String(lat,lon), List String(lat,lon), Long resolution) returns String;
47-
com.neo4jh3.gridPathCells(Double latitude, Double longitude, Double latitude, Double longitude, Long resolution) return string;
48-
com.neo4jh3.gridPathCellsHexAddress(String hexAddress, String hexAddress, Long resolution) returns String;
49-
com.neo4jh3.lineHexAddresses(List String(lat,lon), Long resolution) returns String;
28+
# Documentation
29+
Refer to the Documentation.md file for detailed documenation on the functions / procedures.
5030

pom.xml

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
<groupId>com.neo4jh3</groupId>
88
<artifactId>neo4jh3</artifactId>
9-
<version>5.3.0</version>
9+
<version>5.3.1</version>
1010

1111
<properties>
12-
<neo4j.version>5.3.0</neo4j.version>
12+
<neo4j.version>5.5.0</neo4j.version>
1313
<csv.version>1.2</csv.version>
1414
<lang3.version>3.7</lang3.version>
1515
<uber.version>4.0.2</uber.version>

src/.DS_Store

0 Bytes
Binary file not shown.

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,69 @@ public String pointash3String(
738738
return h3Address;
739739
}
740740

741+
// Geography Functions
742+
@UserFunction(name = "com.neo4jh3.multilineash3")
743+
@Description("com.neo4jh3.multilineash3(wktString, resolution) - Provides the distance in grid cells between the two indexes.")
744+
public Long multilineash3(
745+
@Name("wktString") String wktString,
746+
@Name("h3Res") Long h3Res) throws InterruptedException
747+
{
748+
Long h3Address = 0L;
749+
if (h3 == null) {
750+
throw new InterruptedException("h3 failed to initialize");
751+
}
752+
753+
final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue();
754+
755+
try {
756+
if (h3Resolution > 0 && h3Resolution <= 15) {
757+
Geometry geometry = GeometryReader.readGeometry(wktString);
758+
//System.out.println(geometry.getGeometryType());
759+
if (geometry.getGeometryType().toString().equalsIgnoreCase("MultiLineString")){
760+
h3Address=h3.latLngToCell(geometry.getEnvelope().getMinX(), geometry.getEnvelope().getMinY(), h3Resolution);
761+
}
762+
} else {
763+
h3Address = -2L;
764+
}
765+
} catch (Exception e) {
766+
//System.out.println(e);
767+
h3Address = -1L;
768+
// TODO Auto-generated catch block
769+
//e.printStackTrace();
770+
}
771+
return h3Address;
772+
}
773+
@UserFunction(name = "com.neo4jh3.multilineash3String")
774+
@Description("com.neo4jh3.multilineash3String(wktString, resolution) - Provides the distance in grid cells between the two indexes.")
775+
public String multilineash3String(
776+
@Name("wktString") String wktString,
777+
@Name("h3Res") Long h3Res) throws InterruptedException
778+
{
779+
String h3Address = "";
780+
if (h3 == null) {
781+
throw new InterruptedException("h3 failed to initialize");
782+
}
783+
784+
final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue();
785+
786+
try {
787+
if (h3Resolution > 0 && h3Resolution <= 15) {
788+
Geometry geometry = GeometryReader.readGeometry(wktString);
789+
if (geometry.getGeometryType().toString().equalsIgnoreCase("MultiLineString")){
790+
h3Address=h3.latLngToCellAddress(geometry.getEnvelope().getMinX(), geometry.getEnvelope().getMinY(), h3Resolution);
791+
}
792+
} else {
793+
h3Address = "-2";
794+
}
795+
} catch (Exception e) {
796+
//System.out.println(e);
797+
h3Address = "-1";
798+
// TODO Auto-generated catch block
799+
//e.printStackTrace();
800+
}
801+
return h3Address;
802+
}
803+
741804
@UserFunction(name = "com.neo4jh3.centeraswkb")
742805
@Description("com.neo4jh3.centeraswkb(hexAddress) - Provides the distance in grid cells between the two indexes.")
743806
public String centeraswkb(

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ public void should_return_hex_address() throws InterruptedException {
300300
result = session.run("RETURN com.neo4jh3.pointash3('POINT(37.8199 -122.4783)',13) AS value");
301301
assertEquals(635714569676958015L, result.single().get("value").asLong(),0);
302302

303+
result = session.run("RETURN com.neo4jh3.multilineash3('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',13) AS value");
304+
assertEquals(635714810904422079L, result.single().get("value").asLong(),0);
305+
306+
result = session.run("RETURN com.neo4jh3.multilineash3('MULTILINESTRING((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018))',13) AS value");
307+
assertEquals(635747522315622719L, result.single().get("value").asLong(),0);
308+
303309
result = session.run("RETURN com.neo4jh3.centeraswkb(599686042433355775) AS value");
304310
assertEquals("\"00000000014042AC42F51330C7C05E7E7CF1A5AD49\"", result.single().get("value").toString());
305311

0 commit comments

Comments
 (0)