Skip to content

Commit

Permalink
Merge pull request #6 from davidfauth/5.5
Browse files Browse the repository at this point in the history
Updated for Neo4j 5.5 and new multiline function
  • Loading branch information
davidfauth authored Feb 24, 2023
2 parents 43a045c + b7aa6be commit bdfa803
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ src/.DS_Store
src/.DS_Store
src/.DS_Store
src/.DS_Store
src/.DS_Store
src/.DS_Store
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# CHANGELOG - Neo4jH3

## 5.5 2023-02-24

* [Added] Tested through Neo4j versions 5.5
* [Added] Added support for converting a MULTILINE geospatial object to H3 number - com.neo4jh3.multilineash3
* [Added] Added support for converting a MULTILINE geospatial object to H3 string - com.neo4jh3.multilineash3String



67 changes: 58 additions & 9 deletions Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ If h3CellId1Expr or h3CellId2Expr is an invalid h3 address, the function returns
Returns the grid distance of the two input H3 cells, that are expected to have the same resolution.

### Syntax
RETURN com.neo4jh3. gridDistance( h3CellId1Expr, h3CellId2Expr ) AS value;
RETURN com.neo4jh3.gridDistance( h3CellId1Expr, h3CellId2Expr ) AS value;

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


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

RETURN com.neo4jh3.latlongash3( 67.8199, -222.4783, 13) AS value
-4

##com.neo4jh3.latlongash3String( latitude, longitude, resolution )
Returns the H3 cell ID (as a hexadecimal STRING) corresponding to the provided longitude and latitude at the specified resolution.

Expand Down Expand Up @@ -726,8 +723,6 @@ A value of the type of STRING representing, as a hexadecimal string, the H3 cell
RETURN com.neo4jh3.latlongash3String( 97.8199, -222.4783, 13) AS value
-4


##com.neo4jh3.maxChild( h3CellIdExpr, resolutionExpr )
Returns the child of minimum value of the input H3 cell at the specified resolution.

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


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

##com.neo4jh3.multilineash3( geographyExpr, resolutionExpr )
Returns the H3 cell ID (as a LONG) corresponding to the provided MULTILINESTRING at the specified resolution.

### Syntax
RETURN com.neo4jh3.multilineash3( geographyExpr, resolutionExpr )

### Arguments
* geographyExpr: A STRING expression representing a MULTILINESTRING geography in WKT format
* resolutionExpr: An INT expression, whose value is expected to be between 0 and 15 inclusive, specifying the resolution of the child H3 cell ID.

### Returns
Returns the H3 cell ID (as a LONG) corresponding to the provided point at the specified resolution.

### Error conditions
If geographyExpr is of type STRING and the value is either an invalid WKT or does not represent a point, the function returns -1

If resolutionExpr is smaller than 0 or larger than 15, the function returns -2

### Example
RETURN com.neo4jh3.multilineash3('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',13) AS value
635714810904422079

RETURN com.neo4jh3.multilineash3('zzz(37.8199 -122.4783)',13) AS value
-1

RETURN com.neo4jh3.multilineash3('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',16) AS value
-2

##com.neo4jh3.multilineash3String( geographyExpr, resolutionExpr )
Returns the H3 cell ID (as a STRING) corresponding to the provided MULTILINESTRING at the specified resolution.

### Syntax
RETURN com.neo4jh3.multilineash3String( geographyExpr, resolutionExpr )

### Arguments
* geographyExpr: A STRING expression representing a MULTILINESTRING geography in WKT format
* resolutionExpr: An INT expression, whose value is expected to be between 0 and 15 inclusive, specifying the resolution of the child H3 cell ID.

### Returns
Returns the H3 cell ID (as a LONG) corresponding to the provided MULTILINESTRING at the specified resolution.

### Error conditions
If geographyExpr is of type STRING and the value is either an invalid WKT or does not represent a point, the function returns -1

If resolutionExpr is smaller than 0 or larger than 15, the function returns -2

### Example
RETURN com.neo4jh3.multilineash3String('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',13) AS value
8d283409a69a6bf

RETURN com.neo4jh3.multilineash3String('zzz(37.8199 -122.4783)',13) AS value
-1

RETURN com.neo4jh3.multilineash3String('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',16) AS value
-2

##com.neo4jh3.pointash3( geographyExpr, resolutionExpr )
Returns the H3 cell ID (as a LONG) corresponding to the provided point at the specified resolution.

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


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

Expand Down
28 changes: 4 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ project, simply package the project with maven:

mvn clean package

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

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


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

(Re)start Neo4j

# Functions
com.neo4jh3.uber.h3HexAddress(Double Lat, Double Long, Long Resolution) returns hexAddress;
com.neo4jh3.uber.h3HexAddressNumber(Double Lat, Double Long, Long Resolution) returns Long;
com.neo4jh3.uber.h3RingsForDistance(Double Resolution, Double Distance in KM) returns Long;
com.neo4jh3.gridDistance(String hexAddress, String hexAddress) returns int;
com.neo4jh3.gridDistanceNumber(Long hexAddress, Long hexAddress) returns int;
com.neo4jh3.cellToParent(String hexAddress, Long Resolution) returns String;
com.neo4jh3.cellToLatLng(String hexAddress) returns String;
com.neo4jh3.cellToLatLngNumber(Long hexAddress) returns String;
com.neo4jh3.distanceBetweenHexes(String hexAddress, String HexAddress) returns Long (km);
com.neo4jh3.distanceBetweenHexesNumber(String hexAddress, String HexAddress) returns Long (km);


# Procedures
com.neo4jh3.gridDisk(String hexAddress, Long ringSize) returns String;
com.neo4jh3.cellToChildren(String hexAddress, Long resolution) returns String;
com.neo4jh3.returnHexAddress(Double Lat, Double Long, Long Resolution) returns String hexAddress;
com.neo4jh3.returnLongAddress(Double Lat, Double Long, Long Resolution) returns Long hexAddress;
com.neo4jh3.polygonToCells(List String(lat,lon), List String(lat,lon), Long resolution) returns String;
com.neo4jh3.gridPathCells(Double latitude, Double longitude, Double latitude, Double longitude, Long resolution) return string;
com.neo4jh3.gridPathCellsHexAddress(String hexAddress, String hexAddress, Long resolution) returns String;
com.neo4jh3.lineHexAddresses(List String(lat,lon), Long resolution) returns String;
# Documentation
Refer to the Documentation.md file for detailed documenation on the functions / procedures.

4 changes: 2 additions & 2 deletions pom.xml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

<groupId>com.neo4jh3</groupId>
<artifactId>neo4jh3</artifactId>
<version>5.3.0</version>
<version>5.3.1</version>

<properties>
<neo4j.version>5.3.0</neo4j.version>
<neo4j.version>5.5.0</neo4j.version>
<csv.version>1.2</csv.version>
<lang3.version>3.7</lang3.version>
<uber.version>4.0.2</uber.version>
Expand Down
Binary file modified src/.DS_Store
Binary file not shown.
63 changes: 63 additions & 0 deletions src/main/java/com/neo4jh3/uber/Uberh3.java
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,69 @@ public String pointash3String(
return h3Address;
}

// Geography Functions
@UserFunction(name = "com.neo4jh3.multilineash3")
@Description("com.neo4jh3.multilineash3(wktString, resolution) - Provides the distance in grid cells between the two indexes.")
public Long multilineash3(
@Name("wktString") String wktString,
@Name("h3Res") Long h3Res) throws InterruptedException
{
Long h3Address = 0L;
if (h3 == null) {
throw new InterruptedException("h3 failed to initialize");
}

final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue();

try {
if (h3Resolution > 0 && h3Resolution <= 15) {
Geometry geometry = GeometryReader.readGeometry(wktString);
//System.out.println(geometry.getGeometryType());
if (geometry.getGeometryType().toString().equalsIgnoreCase("MultiLineString")){
h3Address=h3.latLngToCell(geometry.getEnvelope().getMinX(), geometry.getEnvelope().getMinY(), h3Resolution);
}
} else {
h3Address = -2L;
}
} catch (Exception e) {
//System.out.println(e);
h3Address = -1L;
// TODO Auto-generated catch block
//e.printStackTrace();
}
return h3Address;
}
@UserFunction(name = "com.neo4jh3.multilineash3String")
@Description("com.neo4jh3.multilineash3String(wktString, resolution) - Provides the distance in grid cells between the two indexes.")
public String multilineash3String(
@Name("wktString") String wktString,
@Name("h3Res") Long h3Res) throws InterruptedException
{
String h3Address = "";
if (h3 == null) {
throw new InterruptedException("h3 failed to initialize");
}

final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue();

try {
if (h3Resolution > 0 && h3Resolution <= 15) {
Geometry geometry = GeometryReader.readGeometry(wktString);
if (geometry.getGeometryType().toString().equalsIgnoreCase("MultiLineString")){
h3Address=h3.latLngToCellAddress(geometry.getEnvelope().getMinX(), geometry.getEnvelope().getMinY(), h3Resolution);
}
} else {
h3Address = "-2";
}
} catch (Exception e) {
//System.out.println(e);
h3Address = "-1";
// TODO Auto-generated catch block
//e.printStackTrace();
}
return h3Address;
}

@UserFunction(name = "com.neo4jh3.centeraswkb")
@Description("com.neo4jh3.centeraswkb(hexAddress) - Provides the distance in grid cells between the two indexes.")
public String centeraswkb(
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/neo4jh3/Neo4jH3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ public void should_return_hex_address() throws InterruptedException {
result = session.run("RETURN com.neo4jh3.pointash3('POINT(37.8199 -122.4783)',13) AS value");
assertEquals(635714569676958015L, result.single().get("value").asLong(),0);

result = session.run("RETURN com.neo4jh3.multilineash3('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',13) AS value");
assertEquals(635714810904422079L, result.single().get("value").asLong(),0);

result = session.run("RETURN com.neo4jh3.multilineash3('MULTILINESTRING((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018))',13) AS value");
assertEquals(635747522315622719L, result.single().get("value").asLong(),0);

result = session.run("RETURN com.neo4jh3.centeraswkb(599686042433355775) AS value");
assertEquals("\"00000000014042AC42F51330C7C05E7E7CF1A5AD49\"", result.single().get("value").toString());

Expand Down

0 comments on commit bdfa803

Please sign in to comment.