diff --git a/CHANGELOG.md b/CHANGELOG.md index d860d25..43d4da2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# CHANGELOG - 5.19.1 - 2024-06-05 +* [Added] - Added two new procedures to read a WKT polygon file and return the Hex Addresss. These are com.neo4jh3.polygonash3 and com.neo4jh3.polygonash3String. These procedures expect the POLYGON in Longitude, Latitude order. +* [Updated] - Updated Documentation with bug fixes. +* [Updated] - Added optional LatLon argument to com.neo4jh3.multilineash3, com.neo4jh3.multilineash3String, com.neo4jh3.lineash3, and com.neo4jh3.lineash3String + # CHANGELOG - 5.19 - 2024-04-15 * [Updated] - Tested through Neo4j 5.19 diff --git a/Documentation.md b/Documentation.md index a44e0a3..e43be71 100644 --- a/Documentation.md +++ b/Documentation.md @@ -903,7 +903,7 @@ If resolutionExpr is an invalid resolution or smaller than h3_resolution(h3CellI Returns the H3 cell ID (as a LONG) corresponding to the provided point at the specified resolution. ### Syntax -RETURN com.neo4jh3.pointash3( geographyExpr, resolutionExpr ) +RETURN com.neo4jh3.pointash3( geographyExpr, resolutionExpr, LatLonOrder ) ### Arguments * geographyExpr: A LONG expression representing a point geography in WKT format @@ -932,7 +932,7 @@ If resolutionExpr is smaller than 0 or larger than 15, the function returns -2 Returns the H3 cell ID (as a STRING) corresponding to the provided point at the specified resolution. ### Syntax -RETURN com.neo4jh3.pointash3String( geographyExpr, resolutionExpr ) +RETURN com.neo4jh3.pointash3String( geographyExpr, resolutionExpr, LatLonOrder ) ### Arguments * geographyExpr: A STRING expression representing a point geography in WKT format @@ -980,6 +980,45 @@ If h3CellIdExpr is not a valid H3 cell ID, the function returns -1. -1 # Procedures +## com.neo4jh3.compact( h3CellIdsExpr ) +Compacts the input set of H3 cells. The compacted set covers the same set of H3 cells as the original one. + +### Syntax +CALL com.neo4jh3.compact( h3CellIdsExpr ); + +### Arguments +* h3CellIdsExpr: A LIST of LONG expressions representing H3 cell IDs. + +### Returns +An LIST of H3 cell IDs of the same type as the values in the input LIST expression h3CellIdsExpr. + +### Error conditions + + +### Example + CALL com.neo4jh3.compact([599686042433355775,599686030622195711,599686044580839423,599686038138388479,599686043507097599,599686015589810175,599686014516068351,599686034917163007,599686029548453887,599686032769679359,599686198125920255,599686040285872127,599686041359613951,599686039212130303,599686023106002943,599686027400970239,599686013442326527,599686012368584703,599686018811035647]) yield value return value; + 599686030622195711,599686015589810175,599686014516068351,599686034917163007,599686029548453887,599686032769679359,599686198125920255,599686023106002943,599686027400970239,599686013442326527,599686012368584703,599686018811035647,595182446027210751 + +## com.neo4jh3.compactString( h3CellIdsExpr ) +Compacts the input set of H3 cells. The compacted set covers the same set of H3 cells as the original one. + +### Syntax +CALL com.neo4jh3.compactString( h3CellIdsExpr ); + +### Arguments +* h3CellIdsExpr: A LIST of STRING expressions representing H3 cell IDs. + +### Returns +An LIST of H3 cell IDs of the same type as the values in the input LIST expression h3CellIdsExpr. + +### Error conditions + + +### Example + CALL com.neo4jh3.compactString(['85283473fffffff', '85283447fffffff', '8528347bfffffff', '85283463fffffff', '85283477fffffff', '8528340ffffffff', '8528340bfffffff', '85283457fffffff', '85283443fffffff', '8528344ffffffff', '852836b7fffffff', '8528346bfffffff', '8528346ffffffff', '85283467fffffff', '8528342bfffffff', '8528343bfffffff', '85283407fffffff', '85283403fffffff', '8528341bfffffff']) yield value return value; + + "85283447fffffff", "8528340ffffffff", "8528340bfffffff", "85283457fffffff", "85283443fffffff", "8528344ffffffff", "852836b7fffffff", "8528342bfffffff", "8528343bfffffff", "85283407fffffff", "85283403fffffff", "8528341bfffffff", "8428347ffffffff" + ## com.neo4jh3.gridDisk( h3CellIdExpr, kExpr ) Returns the H3 cells that are within (grid) distance k of the origin cell. The set of these H3 cells is called the k-ring of the origin cell. @@ -1049,7 +1088,7 @@ call com.neo4jh3.lineash3( geographyExpr, resolutionExpr ) yield value Returns a list of H3 cell IDs (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 geographyExpr is of type STRING and the value is either an invalid WKT or does not represent a LINESTRING, the function returns -1 If resolutionExpr is smaller than 0 or larger than 15, the function returns -2 @@ -1077,7 +1116,7 @@ RETURN com.neo4jh3.lineash3String( geographyExpr, resolutionExpr ) Returns a list of H3 cell IDs (as a STRING) corresponding to the provided LINESTRING 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 geographyExpr is of type STRING and the value is either an invalid WKT or does not represent a LINESTRING, the function returns -1 If resolutionExpr is smaller than 0 or larger than 15, the function returns -2 @@ -1091,7 +1130,7 @@ If resolutionExpr is smaller than 0 or larger than 15, the function returns -2 call com.neo4jh3.lineash3String('LINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',16) yield value return value -2 -## com.neo4jh3.multilineash3( geographyExpr, resolutionExpr ) +## com.neo4jh3.multilineash3( geographyExpr, resolutionExpr, LatLonOrder ) Returns the H3 cell ID (as a LONG) corresponding to the provided MULTILINESTRING at the specified resolution. ### Syntax @@ -1100,26 +1139,27 @@ 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. +* LatLonOrder A STRING that indicates the order of the geometry (latlon or lonlat) ### 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 geographyExpr is of type STRING and the value is either an invalid WKT or does not represent a MULTILINESTRING, the function returns -1 If resolutionExpr is smaller than 0 or larger than 15, the function returns -2 ### Example - CALL com.neo4jh3.multilineash3('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',6) yield value return value; + CALL com.neo4jh3.multilineash3('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',6, 'latlon') yield value return value; 604189629981130751, 604189629444259839, 604189629444259839 - call com.neo4jh3.multilineash3('ZZZ((37.271355 -121.915080), (37.353926 -121.862223))',7) yield value return value + call com.neo4jh3.multilineash3('ZZZ((37.271355 -121.915080), (37.353926 -121.862223))',7, 'latlon') yield value return value -1 - call com.neo4jh3.multilineash3('MULTILINESTRING((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018) , (40.93733046783797 -74.00265431029018))',17) yield value return value + call com.neo4jh3.multilineash3('MULTILINESTRING((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018) , (40.93733046783797 -74.00265431029018))',17, 'latlon') yield value return value -2 -## com.neo4jh3.multilineash3String( geographyExpr, resolutionExpr ) +## com.neo4jh3.multilineash3String( geographyExpr, resolutionExpr, LatLonOrder ) Returns the H3 cell ID (as a STRING) corresponding to the provided MULTILINESTRING at the specified resolution. ### Syntax @@ -1128,26 +1168,83 @@ call com.neo4jh3.multilineash3String( geographyExpr, resolutionExpr ) yield valu ### 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. +* LatLonOrder A STRING that indicates the order of the geometry (latlon or lonlat) + ### Returns Returns the H3 cell ID (as a STRING) 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 geographyExpr is of type STRING and the value is either an invalid WKT or does not represent a MULTILINESTRING, the function returns -1 If resolutionExpr is smaller than 0 or larger than 15, the function returns -2 ### Example - CALL com.neo4jh3.multilineash3String('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',6) yield value return value; + CALL com.neo4jh3.multilineash3String('MULTILINESTRING((37.2713558667319 -121.91508032705622), (37.353926450852256 -121.86222328902491))',6, 'latlon') yield value return value; '86283446fffffff', '86283444fffffff', '86283444fffffff' - call com.neo4jh3.multilineash3String('ZZZ((37.271355 -121.915080), (37.353926 -121.862223))',7) yield value return value + call com.neo4jh3.multilineash3String('ZZZ((37.271355 -121.915080), (37.353926 -121.862223))',7, 'latlon') yield value return value '-1' - call com.neo4jh3.multilineash3String('MULTILINESTRING((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018) , (40.93733046783797 -74.00265431029018))',17) yield value return value + call com.neo4jh3.multilineash3String('MULTILINESTRING((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018) , (40.93733046783797 -74.00265431029018))',17, 'latlon') yield value return value '-2' +## com.neo4jh3.polygonash3( geographyExpr, resolutionExpr ) +Returns a list of H3 cell IDs (as a LONG) corresponding to the provided POLYGON at the specified resolution. + +### Syntax +call com.neo4jh3. polygonash3( geographyExpr, resolutionExpr ) yield value + +### Arguments +* geographyExpr: A STRING expression representing a POLYGON geography in WKT format (Longitude and then Latitude) +* 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 a list of H3 cell IDs (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 POLYGON, the function returns -1 + +If resolutionExpr is smaller than 0 or larger than 15, the function returns -2 + +### Example + call com.neo4jh3.polygonash3('POLYGON((-77.436031 38.471420, -77.395123 38.536569, -77.294124 38.511703, -77.310611 38.395709, -77.436031 38.471420))',6) yield value return value + 604233031162527743, 604233025391165439, 604233031699398655 + + call com.neo4jh3.polygonash3('ZZZ((-77.436031 38.471420, -77.395123 38.536569, -77.294124 38.511703, -77.310611 38.395709, -77.436031 38.471420))',7) yield value return value + -1 + + call com.neo4jh3.polygonash3('POLYGON((-77.436031 38.471420, -77.395123 38.536569, -77.294124 38.511703, -77.310611 38.395709, -77.436031 38.471420))',16) yield value return value + -2 + +## com.neo4jh3.polygonash3String( geographyExpr, resolutionExpr ) +Returns a list of H3 cell IDs (as a STRING) corresponding to the provided POLYGON at the specified resolution. + +### Syntax +RETURN com.neo4jh3. polygonash3String( geographyExpr, resolutionExpr ) + +### Arguments +* geographyExpr: A STRING expression representing a POLYGON geography in WKT format (Longitude and then Latitude) +* 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 a list of H3 cell IDs (as a STRING) corresponding to the provided POLYGON 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 polygon, the function returns -1 + +If resolutionExpr is smaller than 0 or larger than 15, the function returns -2 +### Example + call com.neo4jh3.polygonash3String('POLYGON((-77.436031 38.471420, -77.395123 38.536569, -77.294124 38.511703, -77.310611 38.395709, -77.436031 38.471420))',6) yield value return value + '862aabd8fffffff','862aabc37ffffff','862aabdafffffff' + + call com.neo4jh3. polygonash3String('ZZZPOLYGON((-77.436031 38.471420, -77.395123 38.536569, -77.294124 38.511703, -77.310611 38.395709, -77.436031 38.471420))',7) yield value return value + -1 + + call com.neo4jh3.polygonash3String('POLYGON((-77.436031 38.471420, -77.395123 38.536569, -77.294124 38.511703, -77.310611 38.395709, -77.436031 38.471420))',16) yield value return value + -2 + ## com.neo4jh3.polygonToCells( ListOuterGeography, ListHoleGeography, resolutionExpr, LatLonOrder ) Returns a list of H3 cell IDs (represented as LONGs) corresponding to hexagons or pentagons, of the specified resolution, that are contained by the input area geography. @@ -1197,45 +1294,6 @@ If resolutionExpr is invalid, the function returns -2 call com.neo4jh3.polygonToCellsString(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],20,'latlon') yield value return value -2 - -## com.neo4jh3.compact( h3CellIdsExpr ) -Compacts the input set of H3 cells. The compacted set covers the same set of H3 cells as the original one. - -### Syntax -CALL com.neo4jh3.compact( h3CellIdsExpr ); - -### Arguments -* h3CellIdsExpr: A LIST of LONG expressions representing H3 cell IDs. - -### Returns -An LIST of H3 cell IDs of the same type as the values in the input LIST expression h3CellIdsExpr. - -### Error conditions - - -### Example - CALL com.neo4jh3.compact([599686042433355775,599686030622195711,599686044580839423,599686038138388479,599686043507097599,599686015589810175,599686014516068351,599686034917163007,599686029548453887,599686032769679359,599686198125920255,599686040285872127,599686041359613951,599686039212130303,599686023106002943,599686027400970239,599686013442326527,599686012368584703,599686018811035647]) yield value return value; - 599686030622195711,599686015589810175,599686014516068351,599686034917163007,599686029548453887,599686032769679359,599686198125920255,599686023106002943,599686027400970239,599686013442326527,599686012368584703,599686018811035647,595182446027210751 - -## com.neo4jh3.compactString( h3CellIdsExpr ) -Compacts the input set of H3 cells. The compacted set covers the same set of H3 cells as the original one. - -### Syntax -CALL com.neo4jh3.compactString( h3CellIdsExpr ); - -### Arguments -* h3CellIdsExpr: A LIST of STRING expressions representing H3 cell IDs. - -### Returns -An LIST of H3 cell IDs of the same type as the values in the input LIST expression h3CellIdsExpr. - -### Error conditions - - -### Example - CALL com.neo4jh3.compactString(['85283473fffffff', '85283447fffffff', '8528347bfffffff', '85283463fffffff', '85283477fffffff', '8528340ffffffff', '8528340bfffffff', '85283457fffffff', '85283443fffffff', '8528344ffffffff', '852836b7fffffff', '8528346bfffffff', '8528346ffffffff', '85283467fffffff', '8528342bfffffff', '8528343bfffffff', '85283407fffffff', '85283403fffffff', '8528341bfffffff']) yield value return value; - - "85283447fffffff", "8528340ffffffff", "8528340bfffffff", "85283457fffffff", "85283443fffffff", "8528344ffffffff", "852836b7fffffff", "8528342bfffffff", "8528343bfffffff", "85283407fffffff", "85283403fffffff", "8528341bfffffff", "8428347ffffffff" ## com.neo4jh3.gridpathcell( h3CellId1Expr, h3CellId2Expr ) Returns the line of indexes as LONGs between two H3 indexes (inclusive). @@ -1266,7 +1324,6 @@ Returns the line of indexes as STRINGs between two H3 indexes (inclusive). ### Syntax CALL com.neo4jh3.gridpathcellString( h3CellId1Expr, h3CellId2Expr ) yield value return value - ### Arguments * h3CellId1Expr: A hexadecimal STRING expression representing an H3 cell ID. * h3CellId2Expr: A hexadecimal STRING expression representing an H3 cell ID. diff --git a/README.md b/README.md index 2f5c2d9..d42a84a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Neo4j H3 Library -This library provides a set of H3 functions and procedures for Neo4j 5 +This library provides a set of H3 functions and procedures for Neo4j 5. + + H3 is a hexagonal hierarchical geospatial indexing system (https://h3geo.org) This library uses the H3 api which can be found at https://h3geo.org/docs/api/indexing @@ -11,10 +13,10 @@ project, simply package the project with maven: mvn clean package -This will produce a jar-file, `neo4jh3-5.15.0.jar`, +This will produce a jar-file, `neo4jh3-5.19.1.jar`, that can be copied to the `plugins` directory of your Neo4j instance. - cp target/neo4jh3-5.13.0.jar neo4j-enterprise-5.x.0/plugins/. + cp target/neo4jh3-5.19.1.jar neo4j-enterprise-5.x.0/plugins/. Edit your Neo4j/conf/neo4j.conf file by adding this line: diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 1bd8637..5044c1e 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.neo4jh3 neo4jh3 - 5.11.0 + 5.19.0 @@ -210,7 +210,7 @@ - 5.11.0 + 5.19.0 4.1 1.2 3.13.0 diff --git a/pom.xml b/pom.xml index 87cb39d..9b3f459 100644 --- a/pom.xml +++ b/pom.xml @@ -6,12 +6,11 @@ com.neo4jh3 neo4jh3 - 5.19.0 + 5.19.1 5.19.0 - 1.2 - 3.13.0 + 3.13.0 4.1.1 4.1 3.6.1 diff --git a/src/main/java/com/neo4jh3/uber/Uberh3.java b/src/main/java/com/neo4jh3/uber/Uberh3.java index bc43682..0de301e 100755 --- a/src/main/java/com/neo4jh3/uber/Uberh3.java +++ b/src/main/java/com/neo4jh3/uber/Uberh3.java @@ -33,7 +33,7 @@ public class Uberh3 { public Transaction tx; private final static int DEFAULT_H3_RESOLUTION = 9; - private final static String NEO4J_H3_VERSION = "5.16.0"; + private final static String NEO4J_H3_VERSION = "5.19.1"; private static H3Core h3 = null; @@ -89,6 +89,7 @@ public String h3ValidateString( } } + @SuppressWarnings("null") @UserFunction(name = "com.neo4jh3.h3HexAddress") @Description("com.neo4jh3.h3HexAddress(latitude, longitude, resolution) - return the hex address for a given latitude.") public Long h3HexAddress( @@ -301,6 +302,7 @@ public String latlongash3String( return returnString; } + @SuppressWarnings("null") @UserFunction(name = "com.neo4jh3.latlongash3") @Description("com.neo4jh3.latlongash3(latitude, longitude, resolution) - return the hex address for a given latitude.") public Long latlongash3( @@ -498,6 +500,7 @@ public String cellToLatLngString(@Name("hexAddress") String hexAddress) throws I } } + @SuppressWarnings("unused") @UserFunction(name = "com.neo4jh3.distanceBetweenHexes") @Description("CALL com.neo4jh3.distanceBetweenHexes(fromHexAddress, toHexAddress)") public double distanceBetweenHexes(@Name("fromHexAddress") Long fromHexAddress, @Name("toHexAddress") Long toHexAddress) throws InterruptedException { @@ -517,6 +520,7 @@ public double distanceBetweenHexes(@Name("fromHexAddress") Long fromHexAddress, } } + @SuppressWarnings("unused") @UserFunction(name = "com.neo4jh3.distanceBetweenHexesString") @Description("CALL com.neo4jh3.distanceBetweenHexesString(fromHexAddress, toHexAddress)") public double distanceBetweenHexesString(@Name("fromHexAddress") String fromHexAddress, @Name("toHexAddress") String toHexAddress) throws InterruptedException { @@ -697,7 +701,7 @@ public Double angleBetweenPoints( hasError = 1; } if (hasError < 1){ - return Precision.round(distance(lat1Value,lon1Value,lat2Value,lon2Value),6); + return Precision.round(angleDistance(lat1Value,lon1Value,lat2Value,lon2Value),6); } else { return returnValue; } @@ -705,7 +709,7 @@ public Double angleBetweenPoints( // Geography Functions @UserFunction(name = "com.neo4jh3.pointash3") - @Description("com.neo4jh3.pointash3(wktString, resolution, latlon order) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.pointash3(wktString, resolution, latlon order) - Loads a WKT POINT and returns H3 LONG values.") public Long pointash3( @Name("wktString") String wktString, @Name("h3Res") Long h3Res, @@ -742,7 +746,7 @@ public Long pointash3( return h3Address; } @UserFunction(name = "com.neo4jh3.pointash3String") - @Description("com.neo4jh3.pointash3String(wktString, resolution, latlon order) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.pointash3String(wktString, resolution, latlon order) - Loads a WKT POINT and returns H3 String values.") public String pointash3String( @Name("wktString") String wktString, @Name("h3Res") Long h3Res, @@ -789,310 +793,524 @@ public String neo4jH3Version() throws InterruptedException return h3Version; } - @Procedure(name = "com.neo4jh3.lineash3", mode = Mode.READ) - @Description("com.neo4jh3.lineash3(wktString, resolution) - Provides the distance in grid cells between the two indexes.") - public Stream lineash3( - @Name("wktString") String wktString, - @Name("h3Res") Long h3Res) throws InterruptedException - { - List listh3Address = new ArrayList(); - List gpCells = new ArrayList(); - Long h3StartAddress = 0L; - Long h3MidAddress = 0L; - Long h3EndAddress = 0L; - Double fromLat = 0.0; - Double fromLon = 0.0; - Double toLat = 0.0; - Double toLon = 0.0; - Double midLat = 0.0; - Double midLon = 0.0; - String mls = ""; - - 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) { - mls = wktString.replace("LINESTRING((", ""); - mls = mls.replace(" (",""); - mls = mls.replace(")",""); - mls = mls.replace("(",""); - String[] latlonPairs = mls.split(","); - for (int i = 0; i < latlonPairs.length; i++) { - if (i > 0){ - fromLat = Double.valueOf(latlonPairs[i-1].split(" ")[0]); - fromLon = Double.valueOf(latlonPairs[i-1].split(" ")[1]); - toLat = Double.valueOf(latlonPairs[i].split(" ")[0]); - toLon = Double.valueOf(latlonPairs[i].split(" ")[1]); - midLat = (fromLat + toLat) / 2; - midLon = (fromLon + toLon) / 2; - h3StartAddress = h3.latLngToCell(fromLat, fromLon, h3Resolution); - h3MidAddress = h3.latLngToCell(midLat, midLon, h3Resolution); - h3EndAddress = h3.latLngToCell(toLat, toLon, h3Resolution); - try { - gpCells = h3.gridPathCells(h3StartAddress, h3MidAddress); - for (int j = 0; j < gpCells.size(); j++) { - listh3Address.add(gpCells.get(j)); - } - gpCells.clear(); - } catch (Exception e1){ - } - try { - gpCells = h3.gridPathCells((h3MidAddress), h3EndAddress); - for (int j = 0; j < gpCells.size(); j++) { - listh3Address.add(gpCells.get(j)); - } - gpCells.clear(); - } catch (Exception e1){ - - } - - } - } - } else { - listh3Address = Collections.singletonList(-2L); - - } - } catch (Exception e) { - //System.out.println(e); - listh3Address = Collections.singletonList(-1L); - //e.printStackTrace(); - } - return listh3Address.stream().map(H3LongAddress::of); - } + // Procedures + + @Procedure(name = "com.neo4jh3.lineash3", mode = Mode.READ) + @Description("com.neo4jh3.lineash3(wktString, resolution, latlonorder) - Loads a WKT LINESTRING and returns H3 Long values.") + public Stream lineash3( + @Name("wktString") String wktString, + @Name("h3Res") Long h3Res, + @Name("latlonorder") String latlonorder) throws InterruptedException + { + List listh3Address = new ArrayList(); + List gpCells = new ArrayList(); + Long h3StartAddress = 0L; + Long h3MidAddress = 0L; + Long h3EndAddress = 0L; + Double fromLat = 0.0; + Double fromLon = 0.0; + Double toLat = 0.0; + Double toLon = 0.0; + Double midLat = 0.0; + Double midLon = 0.0; + String mls = ""; + + if (h3 == null) { + throw new InterruptedException("h3 failed to initialize"); + } + + if (latlonorder.isBlank()){ + latlonorder = "latlon"; + } + final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); + + try { + if (h3Resolution > 0 && h3Resolution <= 15) { + mls = wktString.replace("LINESTRING((", ""); + mls = mls.replace(" (",""); + mls = mls.replace(")",""); + mls = mls.replace("(",""); + String[] latlonPairs = mls.split(","); + String lonlat = ""; + for (int i = 0; i < latlonPairs.length; i++) { + if (i > 0){ + if (latlonorder.equalsIgnoreCase("latlon")){ + lonlat = latlonPairs[i-1].toString(); + lonlat = lonlat.trim(); + fromLat = Double.valueOf(lonlat.split("\\s+")[0]); + fromLon = Double.valueOf(lonlat.split("\\s+")[1]); + lonlat = latlonPairs[i].toString(); + lonlat = lonlat.trim(); + toLat = Double.valueOf(lonlat.split("\\s+")[0]); + toLon =Double.valueOf(lonlat.split("\\s+")[1]); + } else { + lonlat = latlonPairs[i-1].toString(); + lonlat = lonlat.trim(); + fromLat = Double.valueOf(lonlat.split("\\s+")[1]); + fromLon = Double.valueOf(lonlat.split("\\s+")[0]); + lonlat = latlonPairs[i].toString(); + lonlat = lonlat.trim(); + toLat = Double.valueOf(lonlat.split("\\s+")[1]); + toLon =Double.valueOf(lonlat.split("\\s+")[0]); + } + midLat = (fromLat + toLat) / 2; + midLon = (fromLon + toLon) / 2; + h3StartAddress = h3.latLngToCell(fromLat, fromLon, h3Resolution); + h3MidAddress = h3.latLngToCell(midLat, midLon, h3Resolution); + h3EndAddress = h3.latLngToCell(toLat, toLon, h3Resolution); + try { + gpCells = h3.gridPathCells(h3StartAddress, h3MidAddress); + for (int j = 0; j < gpCells.size(); j++) { + listh3Address.add(gpCells.get(j)); + } + gpCells.clear(); + } catch (Exception e1){ + } + try { + gpCells = h3.gridPathCells((h3MidAddress), h3EndAddress); + for (int j = 0; j < gpCells.size(); j++) { + listh3Address.add(gpCells.get(j)); + } + gpCells.clear(); + } catch (Exception e1){ + + } + + } + } + } else { + listh3Address = Collections.singletonList(-2L); + + } + } catch (Exception e) { + //System.out.println(e); + listh3Address = Collections.singletonList(-1L); + //e.printStackTrace(); + } + return listh3Address.stream().map(H3LongAddress::of); + } - // New Geo Procedures - @Procedure(name = "com.neo4jh3.lineash3String", mode = Mode.READ) - @Description("com.neo4jh3.lineash3String(wktString, resolution) - Provides the distance in grid cells between the two indexes.") - public Stream lineash3String( - @Name("wktString") String wktString, - @Name("h3Res") Long h3Res) throws InterruptedException - { - List listh3Address = new ArrayList(); - List gpCells = new ArrayList(); - String h3StartAddress = ""; - String h3MidAddress = ""; - String h3EndAddress = ""; - Double fromLat = 0.0; - Double fromLon = 0.0; - Double toLat = 0.0; - Double toLon = 0.0; - Double midLat = 0.0; - Double midLon = 0.0; - String mls = ""; - - 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) { - mls = wktString.replace("LINESTRING((", ""); - mls = mls.replace(" (",""); - mls = mls.replace(")",""); - mls = mls.replace("(",""); - String[] latlonPairs = mls.split(","); - for (int i = 0; i < latlonPairs.length; i++) { - if (i > 0){ - fromLat = Double.valueOf(latlonPairs[i-1].split(" ")[0]); - fromLon = Double.valueOf(latlonPairs[i-1].split(" ")[1]); - toLat = Double.valueOf(latlonPairs[i].split(" ")[0]); - toLon = Double.valueOf(latlonPairs[i].split(" ")[1]); - midLat = (fromLat + toLat) / 2; - midLon = (fromLon + toLon) / 2; - h3StartAddress = h3.latLngToCellAddress(fromLat, fromLon, h3Resolution); - h3MidAddress = h3.latLngToCellAddress(midLat, midLon, h3Resolution); - h3EndAddress = h3.latLngToCellAddress(toLat, toLon, h3Resolution); - try { - gpCells = h3.gridPathCells(h3StartAddress, h3MidAddress); - for (int j = 0; j < gpCells.size(); j++) { - listh3Address.add(gpCells.get(j)); - } - gpCells.clear(); - } catch (Exception e1){ - //listh3Address = Collections.singletonList("-1"); - } - try { - gpCells = h3.gridPathCells((h3MidAddress), h3EndAddress); - for (int j = 0; j < gpCells.size(); j++) { - listh3Address.add(gpCells.get(j)); - } - gpCells.clear(); - } catch (Exception e1){ - //listh3Address = Collections.singletonList("-1"); - } - } - } - } else { - listh3Address = Collections.singletonList("-2"); - } - } catch (Exception e) { - //System.out.println(e); - listh3Address = Collections.singletonList("-1"); - //e.printStackTrace(); - } - return listh3Address.stream().map(H3StringAddress::of); - } + // New Geo Procedures + @Procedure(name = "com.neo4jh3.lineash3String", mode = Mode.READ) + @Description("com.neo4jh3.lineash3String(wktString, resolution, latlonorder) - Loads a WKT LINESTRING and returns H3 String values.") + public Stream lineash3String( + @Name("wktString") String wktString, + @Name("h3Res") Long h3Res, + @Name("latlonorder") String latlonorder) throws InterruptedException + + { + List listh3Address = new ArrayList(); + List gpCells = new ArrayList(); + String h3StartAddress = ""; + String h3MidAddress = ""; + String h3EndAddress = ""; + Double fromLat = 0.0; + Double fromLon = 0.0; + Double toLat = 0.0; + Double toLon = 0.0; + Double midLat = 0.0; + Double midLon = 0.0; + String mls = ""; + + if (h3 == null) { + throw new InterruptedException("h3 failed to initialize"); + } + + if (latlonorder.isBlank()){ + latlonorder = "latlon"; + } + + final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); + + try { + if (h3Resolution > 0 && h3Resolution <= 15) { + mls = wktString.replace("LINESTRING((", ""); + mls = mls.replace(" (",""); + mls = mls.replace(")",""); + mls = mls.replace("(",""); + String[] latlonPairs = mls.split(","); + String lonlat = ""; + for (int i = 0; i < latlonPairs.length; i++) { + if (i > 0){ + if (latlonorder.equalsIgnoreCase("latlon")){ + lonlat = latlonPairs[i-1].toString(); + lonlat = lonlat.trim(); + fromLat = Double.valueOf(lonlat.split("\\s+")[0]); + fromLon = Double.valueOf(lonlat.split("\\s+")[1]); + lonlat = latlonPairs[i].toString(); + lonlat = lonlat.trim(); + toLat = Double.valueOf(lonlat.split("\\s+")[0]); + toLon =Double.valueOf(lonlat.split("\\s+")[1]); + } else { + lonlat = latlonPairs[i-1].toString(); + lonlat = lonlat.trim(); + fromLat = Double.valueOf(lonlat.split("\\s+")[1]); + fromLon = Double.valueOf(lonlat.split("\\s+")[0]); + lonlat = latlonPairs[i].toString(); + lonlat = lonlat.trim(); + toLat = Double.valueOf(lonlat.split("\\s+")[1]); + toLon =Double.valueOf(lonlat.split("\\s+")[0]); + } + midLat = (fromLat + toLat) / 2; + midLon = (fromLon + toLon) / 2; + h3StartAddress = h3.latLngToCellAddress(fromLat, fromLon, h3Resolution); + h3MidAddress = h3.latLngToCellAddress(midLat, midLon, h3Resolution); + h3EndAddress = h3.latLngToCellAddress(toLat, toLon, h3Resolution); + try { + gpCells = h3.gridPathCells(h3StartAddress, h3MidAddress); + for (int j = 0; j < gpCells.size(); j++) { + listh3Address.add(gpCells.get(j)); + } + gpCells.clear(); + } catch (Exception e1){ + //listh3Address = Collections.singletonList("-1"); + } + try { + gpCells = h3.gridPathCells((h3MidAddress), h3EndAddress); + for (int j = 0; j < gpCells.size(); j++) { + listh3Address.add(gpCells.get(j)); + } + gpCells.clear(); + } catch (Exception e1){ + //listh3Address = Collections.singletonList("-1"); + } + } + } + } else { + listh3Address = Collections.singletonList("-2"); + } + } catch (Exception e) { + //System.out.println(e); + listh3Address = Collections.singletonList("-1"); + //e.printStackTrace(); + } + return listh3Address.stream().map(H3StringAddress::of); + } @Procedure(name = "com.neo4jh3.multilineash3", mode = Mode.READ) - @Description("com.neo4jh3.multilineash3(wktString, resolution) - Provides the distance in grid cells between the two indexes.") - public Stream multilineash3( - @Name("wktString") String wktString, - @Name("h3Res") Long h3Res) throws InterruptedException - { - List listh3Address = new ArrayList(); - List gpCells = new ArrayList(); - Long h3StartAddress = 0L; - Long h3MidAddress = 0L; - Long h3EndAddress = 0L; - Double fromLat = 0.0; - Double fromLon = 0.0; - Double toLat = 0.0; - Double toLon = 0.0; - Double midLat = 0.0; - Double midLon = 0.0; - String mls = ""; + @Description("com.neo4jh3.multilineash3(wktString, resolution, latlonorder) - Provides the distance in grid cells between the two indexes.") + public Stream multilineash3( + @Name("wktString") String wktString, + @Name("h3Res") Long h3Res, + @Name("latlonorder") String latlonorder) throws InterruptedException + { + List listh3Address = new ArrayList(); + List gpCells = new ArrayList(); + Long h3StartAddress = 0L; + Long h3MidAddress = 0L; + Long h3EndAddress = 0L; + Double fromLat = 0.0; + Double fromLon = 0.0; + Double toLat = 0.0; + Double toLon = 0.0; + Double midLat = 0.0; + Double midLon = 0.0; + String mls = ""; - if (h3 == null) { - throw new InterruptedException("h3 failed to initialize"); + if (h3 == null) { + throw new InterruptedException("h3 failed to initialize"); + } + + if (latlonorder.isBlank()){ + latlonorder = "latlon"; + } + final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); + + try { + if (h3Resolution > 0 && h3Resolution <= 15) { + mls = wktString.replace("MULTILINESTRING((", ""); + mls = mls.replace(" (",""); + mls = mls.replace(")",""); + mls = mls.replace("(",""); + String[] latlonPairs = mls.split(","); + String lonlat = ""; + for (int i = 0; i < latlonPairs.length; i++) { + if (i > 0){ + if (latlonorder.equalsIgnoreCase("latlon")){ + lonlat = latlonPairs[i-1].toString(); + lonlat = lonlat.trim(); + fromLat = Double.valueOf(lonlat.split("\\s+")[0]); + fromLon = Double.valueOf(lonlat.split("\\s+")[1]); + lonlat = latlonPairs[i].toString(); + lonlat = lonlat.trim(); + toLat = Double.valueOf(lonlat.split("\\s+")[0]); + toLon =Double.valueOf(lonlat.split("\\s+")[1]); + } else { + lonlat = latlonPairs[i-1].toString(); + lonlat = lonlat.trim(); + fromLat = Double.valueOf(lonlat.split("\\s+")[1]); + fromLon = Double.valueOf(lonlat.split("\\s+")[0]); + lonlat = latlonPairs[i].toString(); + lonlat = lonlat.trim(); + toLat = Double.valueOf(lonlat.split("\\s+")[1]); + toLon =Double.valueOf(lonlat.split("\\s+")[0]); + } + midLat = (fromLat + toLat) / 2; + midLon = (fromLon + toLon) / 2; + h3StartAddress = h3.latLngToCell(fromLat, fromLon, h3Resolution); + h3MidAddress = h3.latLngToCell(midLat, midLon, h3Resolution); + h3EndAddress = h3.latLngToCell(toLat, toLon, h3Resolution); + try { + gpCells = h3.gridPathCells(h3StartAddress, h3MidAddress); + for (int j = 0; j < gpCells.size(); j++) { + listh3Address.add(gpCells.get(j)); + } + gpCells.clear(); + } catch (Exception e1){ + } + try { + gpCells = h3.gridPathCells((h3MidAddress), h3EndAddress); + for (int j = 0; j < gpCells.size(); j++) { + listh3Address.add(gpCells.get(j)); + } + gpCells.clear(); + } catch (Exception e1){ + + } + + } + } + } else { + listh3Address = Collections.singletonList(-2L); + } + } catch (Exception e) { + //System.out.println(e); + listh3Address = Collections.singletonList(-1L); + //e.printStackTrace(); + } + return listh3Address.stream().map(H3LongAddress::of); + } + + // New Geo Procedures + @Procedure(name = "com.neo4jh3.multilineash3String", mode = Mode.READ) + @Description("com.neo4jh3.multilineash3String(wktString, resolution, latlonorder) - Provides the distance in grid cells between the two indexes.") + public Stream multilineash3String( + @Name("wktString") String wktString, + @Name("h3Res") Long h3Res, + @Name("latlonorder") String latlonorder) throws InterruptedException + { + List listh3Address = new ArrayList(); + List gpCells = new ArrayList(); + String h3StartAddress = ""; + String h3MidAddress = ""; + String h3EndAddress = ""; + Double fromLat = 0.0; + Double fromLon = 0.0; + Double toLat = 0.0; + Double toLon = 0.0; + Double midLat = 0.0; + Double midLon = 0.0; + String mls = ""; + + if (h3 == null) { + throw new InterruptedException("h3 failed to initialize"); + } - final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); + if (latlonorder.isBlank()){ + latlonorder = "latlon"; + } + final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); - try { - if (h3Resolution > 0 && h3Resolution <= 15) { - mls = wktString.replace("MULTILINESTRING((", ""); - mls = mls.replace(" (",""); - mls = mls.replace(")",""); - mls = mls.replace("(",""); - String[] latlonPairs = mls.split(","); - for (int i = 0; i < latlonPairs.length; i++) { - if (i > 0){ - fromLat = Double.valueOf(latlonPairs[i-1].split(" ")[0]); - fromLon = Double.valueOf(latlonPairs[i-1].split(" ")[1]); - toLat = Double.valueOf(latlonPairs[i].split(" ")[0]); - toLon = Double.valueOf(latlonPairs[i].split(" ")[1]); - midLat = (fromLat + toLat) / 2; - midLon = (fromLon + toLon) / 2; - h3StartAddress = h3.latLngToCell(fromLat, fromLon, h3Resolution); - h3MidAddress = h3.latLngToCell(midLat, midLon, h3Resolution); - h3EndAddress = h3.latLngToCell(toLat, toLon, h3Resolution); - try { - gpCells = h3.gridPathCells(h3StartAddress, h3MidAddress); - for (int j = 0; j < gpCells.size(); j++) { - listh3Address.add(gpCells.get(j)); - } - gpCells.clear(); - } catch (Exception e1){ - } - try { - gpCells = h3.gridPathCells((h3MidAddress), h3EndAddress); - for (int j = 0; j < gpCells.size(); j++) { - listh3Address.add(gpCells.get(j)); - } - gpCells.clear(); - } catch (Exception e1){ + try { + if (h3Resolution > 0 && h3Resolution <= 15) { + mls = wktString.replace("MULTILINESTRING((", ""); + mls = mls.replace(" (",""); + mls = mls.replace(")",""); + mls = mls.replace("(",""); + String[] latlonPairs = mls.split(","); + String lonlat = ""; + for (int i = 0; i < latlonPairs.length; i++) { + if (i > 0){ + if (latlonorder.equalsIgnoreCase("latlon")){ + lonlat = latlonPairs[i-1].toString(); + lonlat = lonlat.trim(); + fromLat = Double.valueOf(lonlat.split("\\s+")[0]); + fromLon = Double.valueOf(lonlat.split("\\s+")[1]); + lonlat = latlonPairs[i].toString(); + lonlat = lonlat.trim(); + toLat = Double.valueOf(lonlat.split("\\s+")[0]); + toLon =Double.valueOf(lonlat.split("\\s+")[1]); + } else { + lonlat = latlonPairs[i-1].toString(); + lonlat = lonlat.trim(); + fromLat = Double.valueOf(lonlat.split("\\s+")[1]); + fromLon = Double.valueOf(lonlat.split("\\s+")[0]); + lonlat = latlonPairs[i].toString(); + lonlat = lonlat.trim(); + toLat = Double.valueOf(lonlat.split("\\s+")[1]); + toLon =Double.valueOf(lonlat.split("\\s+")[0]); + } + midLat = (fromLat + toLat) / 2; + midLon = (fromLon + toLon) / 2; + h3StartAddress = h3.latLngToCellAddress(fromLat, fromLon, h3Resolution); + h3MidAddress = h3.latLngToCellAddress(midLat, midLon, h3Resolution); + h3EndAddress = h3.latLngToCellAddress(toLat, toLon, h3Resolution); + try { + gpCells = h3.gridPathCells(h3StartAddress, h3MidAddress); + for (int j = 0; j < gpCells.size(); j++) { + listh3Address.add(gpCells.get(j)); + } + gpCells.clear(); + } catch (Exception e1){ + } + try { + gpCells = h3.gridPathCells((h3MidAddress), h3EndAddress); + for (int j = 0; j < gpCells.size(); j++) { + listh3Address.add(gpCells.get(j)); + } + gpCells.clear(); + } catch (Exception e1){ - } + } + + } + } + } else { + listh3Address = Collections.singletonList("-2"); + + } + } catch (Exception e) { + //System.out.println(e); + listh3Address = Collections.singletonList("-1"); + //e.printStackTrace(); + } + return listh3Address.stream().map(H3StringAddress::of); + } + + // TO DO + // Add MultiPolygon Support for WKT file + // Example: https://www.georgia811.com/wp-content/uploads/2022/06/Well_Known_Text.pdf + // Added 4 June 2024 + @Procedure(name = "com.neo4jh3.polygonash3", mode = Mode.READ) + @Description("com.neo4jh3.polygonash3(wktString, resolution) - Returns the hex addresses as a long from a WKT Polygon string.") + public Stream polygonash3( + @Name("wktString") String wktString, + @Name("h3Res") Long h3Res) throws InterruptedException + { + List listh3Address = new ArrayList(); + List hexPoints = new ArrayList<>(); + List hexHoles = new ArrayList<>(); + List> holesList = new ArrayList<>(); + String mls = ""; + + 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) { + mls = wktString.replace("POLYGON", ""); + mls = mls.replace(" (",""); + mls = mls.replace(")",""); + mls = mls.replace("(",""); + String[] lonlatPairs = mls.split(","); + for (int i = 0; i < lonlatPairs.length; i++) { + LatLng tmpGeoCoord = null; + tmpGeoCoord = returnLngLat(lonlatPairs[i]); + hexPoints.add(tmpGeoCoord); + } + + if (!hexHoles.isEmpty()) { + holesList.add(hexHoles); + listh3Address = h3.polygonToCells(hexPoints, holesList, h3Resolution); } else { - listh3Address = Collections.singletonList(-2L); - + listh3Address = h3.polygonToCells(hexPoints, null, h3Resolution); } - } catch (Exception e) { - //System.out.println(e); - listh3Address = Collections.singletonList(-1L); - //e.printStackTrace(); + + } else { + listh3Address = Collections.singletonList(-2L); + } - return listh3Address.stream().map(H3LongAddress::of); - } - - // New Geo Procedures - @Procedure(name = "com.neo4jh3.multilineash3String", mode = Mode.READ) - @Description("com.neo4jh3.multilineash3String(wktString, resolution) - Provides the distance in grid cells between the two indexes.") - public Stream multilineash3String( - @Name("wktString") String wktString, - @Name("h3Res") Long h3Res) throws InterruptedException - { - List listh3Address = new ArrayList(); - List gpCells = new ArrayList(); - String h3StartAddress = ""; - String h3MidAddress = ""; - String h3EndAddress = ""; - Double fromLat = 0.0; - Double fromLon = 0.0; - Double toLat = 0.0; - Double toLon = 0.0; - Double midLat = 0.0; - Double midLon = 0.0; - String mls = ""; - - 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) { - mls = wktString.replace("MULTILINESTRING((", ""); - mls = mls.replace(" (",""); - mls = mls.replace(")",""); - mls = mls.replace("(",""); - String[] latlonPairs = mls.split(","); - for (int i = 0; i < latlonPairs.length; i++) { - if (i > 0){ - fromLat = Double.valueOf(latlonPairs[i-1].split(" ")[0]); - fromLon = Double.valueOf(latlonPairs[i-1].split(" ")[1]); - toLat = Double.valueOf(latlonPairs[i].split(" ")[0]); - toLon = Double.valueOf(latlonPairs[i].split(" ")[1]); - midLat = (fromLat + toLat) / 2; - midLon = (fromLon + toLon) / 2; - h3StartAddress = h3.latLngToCellAddress(fromLat, fromLon, h3Resolution); - h3MidAddress = h3.latLngToCellAddress(midLat, midLon, h3Resolution); - h3EndAddress = h3.latLngToCellAddress(toLat, toLon, h3Resolution); - try { - gpCells = h3.gridPathCells(h3StartAddress, h3MidAddress); - for (int j = 0; j < gpCells.size(); j++) { - listh3Address.add(gpCells.get(j)); - } - gpCells.clear(); - } catch (Exception e1){ - //listh3Address = Collections.singletonList("-1"); - } - try { - gpCells = h3.gridPathCells((h3MidAddress), h3EndAddress); - for (int j = 0; j < gpCells.size(); j++) { - listh3Address.add(gpCells.get(j)); - } - gpCells.clear(); - } catch (Exception e1){ - //listh3Address = Collections.singletonList("-1"); - } - } - } - } else { - listh3Address = Collections.singletonList("-2"); - } - } catch (Exception e) { - //System.out.println(e); - listh3Address = Collections.singletonList("-1"); - //e.printStackTrace(); - } - return listh3Address.stream().map(H3StringAddress::of); - } + } catch (Exception e) { + System.out.println(e); + listh3Address = Collections.singletonList(-1L); + //e.printStackTrace(); + } + return listh3Address.stream().map(H3LongAddress::of); + } + + @Procedure(name = "com.neo4jh3.polygonash3String", mode = Mode.READ) + @Description("com.neo4jh3.polygonash3String(wktString, resolution) - Returns the hex addresses as a String from a WKT Polygon string") + public Stream polygonash3String( + @Name("wktString") String wktString, + @Name("h3Res") Long h3Res) throws InterruptedException + { + List listh3Address = new ArrayList(); + List hexPoints = new ArrayList<>(); + List hexHoles = new ArrayList<>(); + List> holesList = new ArrayList<>(); + String mls = ""; + + 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) { + mls = wktString.replace("POLYGON", ""); + mls = mls.replace(" (",""); + mls = mls.replace(")",""); + mls = mls.replace("(",""); + //System.out.println(mls); + String[] lonlatPairs = mls.split(","); + for (int i = 0; i < lonlatPairs.length; i++) { + LatLng tmpGeoCoord = null; + tmpGeoCoord = returnLngLat(lonlatPairs[i]); + hexPoints.add(tmpGeoCoord); + } + + if (!hexHoles.isEmpty()) { + holesList.add(hexHoles); + listh3Address = h3.polygonToCellAddresses(hexPoints, holesList, h3Resolution); + } else { + listh3Address = h3.polygonToCellAddresses(hexPoints, null, h3Resolution); + } + + } else { + listh3Address = Collections.singletonList("-2"); + + } + } catch (Exception e) { + System.out.println(e); + listh3Address = Collections.singletonList("-1"); + //e.printStackTrace(); + } + return listh3Address.stream().map(H3StringAddress::of); + } + // Stub procedure + @Procedure(name = "com.neo4jh3.multipolygonash3", mode = Mode.READ) + @Description("com.neo4jh3.multipolygonash3(wktString, resolution) - Returns the hex addresses as a long from a WKT Polygon string.") + public Stream multipolygonash3( + @Name("wktString") String wktString, + @Name("h3Res") Long h3Res) throws InterruptedException + { + List listh3Address = new ArrayList(); + List hexPoints = new ArrayList<>(); + List hexHoles = new ArrayList<>(); + List> holesList = new ArrayList<>(); + String mls = ""; + + if (h3 == null) { + throw new InterruptedException("h3 failed to initialize"); + } + + final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); + + return listh3Address.stream().map(H3LongAddress::of); + } + + + // Geography Functions @UserFunction(name = "com.neo4jh3.centeraswkb") - @Description("com.neo4jh3.centeraswkb(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.centeraswkb(hexAddress) - Returns the center of a hex address in WKB format.") public String centeraswkb( @Name("hexAddress") Long hexAddress) throws InterruptedException { @@ -1124,7 +1342,7 @@ public String centeraswkb( } @UserFunction(name = "com.neo4jh3.centeraswkbString") - @Description("com.neo4jh3.centeraswkbString(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.centeraswkbString(hexAddress) - Returns the center of a hex address in WKB format.") public String centeraswkbString( @Name("hexAddress") String hexAddress) throws InterruptedException { @@ -1155,7 +1373,7 @@ public String centeraswkbString( return geoJsonString; } @UserFunction(name = "com.neo4jh3.centeraswkt") - @Description("com.neo4jh3.centeraswkt(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.centeraswkt(hexAddress) - Returns the center of a hex address in WKT format.") public String centeraswkt( @Name("hexAddress") Long hexAddress) throws InterruptedException { @@ -1184,7 +1402,7 @@ public String centeraswkt( } @UserFunction(name = "com.neo4jh3.centeraswktString") - @Description("com.neo4jh3.centeraswktString(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.centeraswktString(hexAddress) - Returns the center of a hex address in WKT format.") public String centeraswktString( @Name("hexAddress") String hexAddress) throws InterruptedException { @@ -1213,7 +1431,7 @@ public String centeraswktString( } @UserFunction(name = "com.neo4jh3.boundaryaswkt") - @Description("com.neo4jh3.boundaryaswkt(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.boundaryaswkt(hexAddress) - Returns the boundary of a hex address in WKT format.") public String boundaryaswkt( @Name("hexAddress") Long hexAddress) throws InterruptedException { @@ -1256,7 +1474,7 @@ public String boundaryaswkt( } @UserFunction(name = "com.neo4jh3.boundaryaswktString") - @Description("com.neo4jh3.boundaryaswktString(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.boundaryaswktString(hexAddress) - Returns the boundary of a hex address in WKT format.") public String boundaryaswktString( @Name("hexAddress") String hexAddress) throws InterruptedException { @@ -1299,7 +1517,7 @@ public String boundaryaswktString( } @UserFunction(name = "com.neo4jh3.boundaryaswkb") - @Description("com.neo4jh3.boundaryaswkb(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.boundaryaswkb(hexAddress) - Returns the boundary of a hex address in WKB format.") public String boundaryaswkb( @Name("hexAddress") Long hexAddress) throws InterruptedException { @@ -1346,7 +1564,7 @@ public String boundaryaswkb( } @UserFunction(name = "com.neo4jh3.boundaryaswkbString") - @Description("com.neo4jh3.boundaryaswkbString(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.boundaryaswkbString(hexAddress) -- Returns the boundary of a hex address in WKB format.") public String boundaryaswkbString( @Name("hexAddress") String hexAddress) throws InterruptedException { @@ -1393,7 +1611,7 @@ public String boundaryaswkbString( } @UserFunction(name = "com.neo4jh3.centerasgeojson") - @Description("com.neo4jh3.centerasgeojson(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.centerasgeojson(hexAddress) - Returns the center of a hex address as a GeoJson string.") public String centerasgeojson( @Name("hexAddress") Long hexAddress) throws InterruptedException { @@ -1422,7 +1640,7 @@ public String centerasgeojson( } @UserFunction(name = "com.neo4jh3.centerasgeojsonString") - @Description("com.neo4jh3.centerasgeojsonString(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.centerasgeojsonString(hexAddress) - Returns the center of a hex address as a GeoJson string.") public String centerasgeojsonString( @Name("hexAddress") String hexAddress) throws InterruptedException { @@ -1451,7 +1669,7 @@ public String centerasgeojsonString( @UserFunction(name = "com.neo4jh3.boundaryasgeojson") - @Description("com.neo4jh3.boundaryasgeojson(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.boundaryasgeojson(hexAddress) - Returns the boundary of a hex address as a GeoJson string.") public String boundaryasgeojson( @Name("hexAddress") Long hexAddress) throws InterruptedException { @@ -1494,12 +1712,11 @@ public String boundaryasgeojson( } @UserFunction(name = "com.neo4jh3.boundaryasgeojsonString") - @Description("com.neo4jh3.boundaryasgeojsonString(hexAddress) - Provides the distance in grid cells between the two indexes.") + @Description("com.neo4jh3.boundaryasgeojsonString(hexAddress) - Returns the boundary of a hex address as a GeoJson string.") public String boundaryasgeojsonString( @Name("hexAddress") String hexAddress) throws InterruptedException { String geoJsonString = ""; - LatLng centerPoint = null; List hexPoints = new ArrayList<>(); if (h3 == null) { @@ -1581,8 +1798,9 @@ public Boolean ispentagonString( /* Neo4j H3 Procedures */ + @SuppressWarnings("null") @Procedure(name = "com.neo4jh3.gridDisk", mode = Mode.READ) - @Description("CALL com.neo4jh3.gridDisk(hexAddress, ringSize)") + @Description("CALL com.neo4jh3.gridDisk(hexAddress, ringSize) - Returns all H3 addresses around the hexAddress at the given ring size") public Stream gridDisk(@Name("hexAddress") Long hexAddress, @Name("ringSize") Long ringSize) throws InterruptedException { if (h3 == null) { @@ -1607,8 +1825,9 @@ public Stream gridDisk(@Name("hexAddress") Long hexAddress, @Name } } + @SuppressWarnings("null") @Procedure(name = "com.neo4jh3.gridDiskString", mode = Mode.READ) - @Description("CALL com.neo4jh3.gridDiskString(hexAddress, ringSize)") + @Description("CALL com.neo4jh3.gridDiskString(hexAddress, ringSize) - Returns all H3 addresses around the hexAddress at the given ring size") public Stream gridDiskString(@Name("hexAddress") String hexAddress, @Name("ringSize") Long ringSize) throws InterruptedException { if (h3 == null) { @@ -1634,6 +1853,7 @@ public Stream gridDiskString(@Name("hexAddress") String hexAddr } } + @SuppressWarnings("null") @Procedure(name = "com.neo4jh3.tochildren", mode = Mode.READ) @Description("CALL com.neo4jh3.tochildren(hexAddress, h3Resolution)") public Stream tochildren(@Name("hexAddress") Long hexAddress, @Name("h3Res") Long h3Res) throws InterruptedException { @@ -1661,6 +1881,7 @@ public Stream tochildren(@Name("hexAddress") Long hexAddress, @Na } } + @SuppressWarnings("null") @Procedure(name = "com.neo4jh3.tochildrenString", mode = Mode.READ) @Description("CALL com.neo4jh3.tochildrenString(hexAddress, h3Resolution)") public Stream tochildrenString(@Name("hexAddress") String hexAddress, @Name("h3Res") Long h3Res) throws InterruptedException { @@ -1801,242 +2022,241 @@ public Stream polygonToCellsString(@Name("polyEdges") List polygonIntersection(@Name("polyEdges") List polyEdges, @Name("polyEdgeHoles") List polyEdgeHoles, @Name("polyEdgesSecond") List polyEdgesSecond, @Name("polyEdgeHolesSecond") List polyEdgeHolesSecond, @Name("h3Res") Long h3Res, @Name("latlonorder") String latlonorder) throws InterruptedException { - if (h3 == null) { - return Stream.empty(); - } - if (polyEdges == null || polyEdgeHoles == null || polyEdgesSecond == null || polyEdgeHolesSecond == null) { - throw new InterruptedException("invalid arguments"); - } - - List hexPoints = new ArrayList<>(); - List hexHoles = new ArrayList<>(); - List> holesList = new ArrayList<>(); - List hexPointsSecond = new ArrayList<>(); - List hexHolesSecond = new ArrayList<>(); - List> holesListSecond = new ArrayList<>(); - - final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); - - if (h3Resolution >= 1 && h3Resolution <= 15) { - for (String mapEdges : polyEdges) { - final String[] latLonList = mapEdges.split(","); - LatLng tmpGeoCoord = null; - if (latlonorder.equalsIgnoreCase("latlon")){ - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); - } else { - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[0])); - } - hexPoints.add(tmpGeoCoord); - } - - for (String mapEdges : polyEdgeHoles) { - final String[] latLonList = mapEdges.split(","); - LatLng tmpGeoCoord = null; - if (latlonorder.equalsIgnoreCase("latlon")){ - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); - } else { - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[2])); - } - hexHoles.add(tmpGeoCoord); - } - - for (String mapEdges : polyEdgesSecond) { - final String[] latLonList = mapEdges.split(","); - LatLng tmpGeoCoord = null; - if (latlonorder.equalsIgnoreCase("latlon")){ - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); - } else { - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[0])); - } - hexPointsSecond.add(tmpGeoCoord); - } + @Procedure(name = "com.neo4jh3.polygonIntersection", mode = Mode.READ) + @Description("CALL com.neo4jh3.polygonIntersection(polyEdges, polyEdgeHoles, polyEdgesSecond, polyEdgeHolesSecond,resolution, latlon order)") + public Stream polygonIntersection(@Name("polyEdges") List polyEdges, @Name("polyEdgeHoles") List polyEdgeHoles, @Name("polyEdgesSecond") List polyEdgesSecond, @Name("polyEdgeHolesSecond") List polyEdgeHolesSecond, @Name("h3Res") Long h3Res, @Name("latlonorder") String latlonorder) throws InterruptedException { + if (h3 == null) { + return Stream.empty(); + } + if (polyEdges == null || polyEdgeHoles == null || polyEdgesSecond == null || polyEdgeHolesSecond == null) { + throw new InterruptedException("invalid arguments"); + } - for (String mapEdges : polyEdgeHolesSecond) { - final String[] latLonList = mapEdges.split(","); - LatLng tmpGeoCoord = null; - if (latlonorder.equalsIgnoreCase("latlon")){ - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); - } else { - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[2])); - } - hexHolesSecond.add(tmpGeoCoord); - } + List hexPoints = new ArrayList<>(); + List hexHoles = new ArrayList<>(); + List> holesList = new ArrayList<>(); + List hexPointsSecond = new ArrayList<>(); + List hexHolesSecond = new ArrayList<>(); + List> holesListSecond = new ArrayList<>(); + final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); - List hexList; - List hexListSecond; - List hexListFinal = new ArrayList(); - - if (!hexHoles.isEmpty()) { - holesList.add(hexHoles); - hexList = h3.polygonToCells(hexPoints, holesList, h3Resolution); + if (h3Resolution >= 1 && h3Resolution <= 15) { + for (String mapEdges : polyEdges) { + final String[] latLonList = mapEdges.split(","); + LatLng tmpGeoCoord = null; + if (latlonorder.equalsIgnoreCase("latlon")){ + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); } else { - hexList = h3.polygonToCells(hexPoints, null, h3Resolution); + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[0])); } - - if (!hexHolesSecond.isEmpty()) { - holesListSecond.add(hexHoles); - hexListSecond = h3.polygonToCells(hexPointsSecond, holesListSecond, h3Resolution); + hexPoints.add(tmpGeoCoord); + } + + for (String mapEdges : polyEdgeHoles) { + final String[] latLonList = mapEdges.split(","); + LatLng tmpGeoCoord = null; + if (latlonorder.equalsIgnoreCase("latlon")){ + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); } else { - hexListSecond = h3.polygonToCells(hexPointsSecond, null, h3Resolution); + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[2])); } - - for (Long secondHexList : hexListSecond){ - if (hexList.contains(secondHexList)){ - hexListFinal.add(secondHexList); - } + hexHoles.add(tmpGeoCoord); + } + + for (String mapEdges : polyEdgesSecond) { + final String[] latLonList = mapEdges.split(","); + LatLng tmpGeoCoord = null; + if (latlonorder.equalsIgnoreCase("latlon")){ + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); + } else { + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[0])); } - return hexListFinal.stream().map(H3LongAddress::of); - } else { - List ringList = null; - ringList = Collections.singletonList(-2L); - return ringList.stream().map(H3LongAddress::of); + hexPointsSecond.add(tmpGeoCoord); } + + for (String mapEdges : polyEdgeHolesSecond) { + final String[] latLonList = mapEdges.split(","); + LatLng tmpGeoCoord = null; + if (latlonorder.equalsIgnoreCase("latlon")){ + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); + } else { + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[2])); + } + hexHolesSecond.add(tmpGeoCoord); } - - @Procedure(name = "com.neo4jh3.polygonIntersectionString", mode = Mode.READ) - @Description("CALL com.neo4jh3.polygonIntersectionString(polyEdges, polyEdgeHoles, polyEdgesSecond, polyEdgeHolesSecond,resolution, latlon order)") - public Stream polygonIntersectionString(@Name("polyEdges") List polyEdges, @Name("polyEdgeHoles") List polyEdgeHoles, @Name("polyEdgesSecond") List polyEdgesSecond, @Name("polyEdgeHolesSecond") List polyEdgeHolesSecond, @Name("h3Res") Long h3Res, @Name("latlonorder") String latlonorder) throws InterruptedException { - if (h3 == null) { - return Stream.empty(); + List hexList; + List hexListSecond; + List hexListFinal = new ArrayList(); + + if (!hexHoles.isEmpty()) { + holesList.add(hexHoles); + hexList = h3.polygonToCells(hexPoints, holesList, h3Resolution); + } else { + hexList = h3.polygonToCells(hexPoints, null, h3Resolution); } - if (polyEdges == null || polyEdgeHoles == null || polyEdgesSecond == null || polyEdgeHolesSecond == null) { - throw new InterruptedException("invalid arguments"); + + if (!hexHolesSecond.isEmpty()) { + holesListSecond.add(hexHoles); + hexListSecond = h3.polygonToCells(hexPointsSecond, holesListSecond, h3Resolution); + } else { + hexListSecond = h3.polygonToCells(hexPointsSecond, null, h3Resolution); } - - List hexPoints = new ArrayList<>(); - List hexHoles = new ArrayList<>(); - List> holesList = new ArrayList<>(); - List hexPointsSecond = new ArrayList<>(); - List hexHolesSecond = new ArrayList<>(); - List> holesListSecond = new ArrayList<>(); - - final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); - - if (h3Resolution >= 1 && h3Resolution <= 15) { - for (String mapEdges : polyEdges) { - final String[] latLonList = mapEdges.split(","); - LatLng tmpGeoCoord = null; - if (latlonorder.equalsIgnoreCase("latlon")){ - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); - } else { - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[0])); - } - hexPoints.add(tmpGeoCoord); - } - - for (String mapEdges : polyEdgeHoles) { - final String[] latLonList = mapEdges.split(","); - LatLng tmpGeoCoord = null; - if (latlonorder.equalsIgnoreCase("latlon")){ - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); - } else { - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[2])); - } - hexHoles.add(tmpGeoCoord); - } - - for (String mapEdges : polyEdgesSecond) { - final String[] latLonList = mapEdges.split(","); - LatLng tmpGeoCoord = null; - if (latlonorder.equalsIgnoreCase("latlon")){ - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); - } else { - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[0])); - } - hexPointsSecond.add(tmpGeoCoord); - } - - for (String mapEdges : polyEdgeHolesSecond) { - final String[] latLonList = mapEdges.split(","); - LatLng tmpGeoCoord = null; - if (latlonorder.equalsIgnoreCase("latlon")){ - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); - } else { - tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[2])); - } - hexHolesSecond.add(tmpGeoCoord); + + for (Long secondHexList : hexListSecond){ + if (hexList.contains(secondHexList)){ + hexListFinal.add(secondHexList); } - - - List hexList; - List hexListSecond; - List hexListFinal = new ArrayList(); - - if (!hexHoles.isEmpty()) { - holesList.add(hexHoles); - hexList = h3.polygonToCellAddresses(hexPoints, holesList, h3Resolution); + } + return hexListFinal.stream().map(H3LongAddress::of); + } else { + List ringList = null; + ringList = Collections.singletonList(-2L); + return ringList.stream().map(H3LongAddress::of); + } + } + + @Procedure(name = "com.neo4jh3.polygonIntersectionString", mode = Mode.READ) + @Description("CALL com.neo4jh3.polygonIntersectionString(polyEdges, polyEdgeHoles, polyEdgesSecond, polyEdgeHolesSecond,resolution, latlon order)") + public Stream polygonIntersectionString(@Name("polyEdges") List polyEdges, @Name("polyEdgeHoles") List polyEdgeHoles, @Name("polyEdgesSecond") List polyEdgesSecond, @Name("polyEdgeHolesSecond") List polyEdgeHolesSecond, @Name("h3Res") Long h3Res, @Name("latlonorder") String latlonorder) throws InterruptedException { + if (h3 == null) { + return Stream.empty(); + } + if (polyEdges == null || polyEdgeHoles == null || polyEdgesSecond == null || polyEdgeHolesSecond == null) { + throw new InterruptedException("invalid arguments"); + } + + List hexPoints = new ArrayList<>(); + List hexHoles = new ArrayList<>(); + List> holesList = new ArrayList<>(); + List hexPointsSecond = new ArrayList<>(); + List hexHolesSecond = new ArrayList<>(); + List> holesListSecond = new ArrayList<>(); + + final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); + + if (h3Resolution >= 1 && h3Resolution <= 15) { + for (String mapEdges : polyEdges) { + final String[] latLonList = mapEdges.split(","); + LatLng tmpGeoCoord = null; + if (latlonorder.equalsIgnoreCase("latlon")){ + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); } else { - hexList = h3.polygonToCellAddresses(hexPoints, null, h3Resolution); + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[0])); } - - if (!hexHolesSecond.isEmpty()) { - holesListSecond.add(hexHoles); - hexListSecond = h3.polygonToCellAddresses(hexPointsSecond, holesListSecond, h3Resolution); + hexPoints.add(tmpGeoCoord); + } + + for (String mapEdges : polyEdgeHoles) { + final String[] latLonList = mapEdges.split(","); + LatLng tmpGeoCoord = null; + if (latlonorder.equalsIgnoreCase("latlon")){ + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); } else { - hexListSecond = h3.polygonToCellAddresses(hexPointsSecond, null, h3Resolution); - } - - for (String secondHexList : hexListSecond){ - if (hexList.contains(secondHexList)){ - hexListFinal.add(secondHexList); - } + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[2])); } - return hexListFinal.stream().map(H3StringAddress::of); - } else { - List ringList = null; - ringList = Collections.singletonList("-2"); - return ringList.stream().map(H3StringAddress::of); - } + hexHoles.add(tmpGeoCoord); } - - @Procedure(name = "com.neo4jh3.gridpathlatlon", mode = Mode.READ) - @Description("CALL com.neo4jh3.gridpathlatlon(latitude, longitude, latitude, longitude, h3Resolution)") - public Stream gridpathlatlon(@Name("startLat") Double startLat, @Name("startLong") Double startLong, @Name("endLat") Double endLat, @Name("endLong") Double endLong, @Name("h3Res") Long h3Res) throws InterruptedException { - if (startLat == null || startLong == null || endLat == null || endLong == null) { - throw new InterruptedException("invalid arguments"); + for (String mapEdges : polyEdgesSecond) { + final String[] latLonList = mapEdges.split(","); + LatLng tmpGeoCoord = null; + if (latlonorder.equalsIgnoreCase("latlon")){ + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); + } else { + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[0])); + } + hexPointsSecond.add(tmpGeoCoord); } - if (h3 == null) { - return Stream.empty(); + + for (String mapEdges : polyEdgeHolesSecond) { + final String[] latLonList = mapEdges.split(","); + LatLng tmpGeoCoord = null; + if (latlonorder.equalsIgnoreCase("latlon")){ + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[0]), Double.parseDouble(latLonList[1])); + } else { + tmpGeoCoord = new LatLng(Double.parseDouble(latLonList[1]), Double.parseDouble(latLonList[2])); + } + hexHolesSecond.add(tmpGeoCoord); } - List ringList = null; - int validLatLon = 1; - final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); - if (h3Resolution < 1 || h3Resolution > 15) { - ringList = Collections.singletonList(-2L); - } - - if ( startLat>90 || startLat<-90 || endLat>90 || endLat<-90 ){ - validLatLon = 0; - ringList = Collections.singletonList(-3L); - } - - if ( startLong>180 || startLong<-180 || endLong>180 || endLong<-180 ){ - validLatLon = 0; - ringList = Collections.singletonList(-4L); + List hexList; + List hexListSecond; + List hexListFinal = new ArrayList(); + + if (!hexHoles.isEmpty()) { + holesList.add(hexHoles); + hexList = h3.polygonToCellAddresses(hexPoints, holesList, h3Resolution); + } else { + hexList = h3.polygonToCellAddresses(hexPoints, null, h3Resolution); } - if (h3Resolution > 0 && h3Resolution <= 15 && validLatLon > 0){ - final String starthexAddr = h3.latLngToCellAddress(startLat, startLong, h3Resolution); - final String endhexAddr = h3.latLngToCellAddress(endLat, endLong, h3Resolution); - return h3.gridPathCells(starthexAddr, endhexAddr) - .stream() - .map(H3LongAddress::of); + if (!hexHolesSecond.isEmpty()) { + holesListSecond.add(hexHoles); + hexListSecond = h3.polygonToCellAddresses(hexPointsSecond, holesListSecond, h3Resolution); } else { - return ringList.stream().map(H3LongAddress::of); + hexListSecond = h3.polygonToCellAddresses(hexPointsSecond, null, h3Resolution); + } + + for (String secondHexList : hexListSecond){ + if (hexList.contains(secondHexList)){ + hexListFinal.add(secondHexList); + } } + return hexListFinal.stream().map(H3StringAddress::of); + } else { + List ringList = null; + ringList = Collections.singletonList("-2"); + return ringList.stream().map(H3StringAddress::of); + } + } + + @SuppressWarnings("null") + @Procedure(name = "com.neo4jh3.gridpathlatlon", mode = Mode.READ) + @Description("CALL com.neo4jh3.gridpathlatlon(latitude, longitude, latitude, longitude, h3Resolution)") + public Stream gridpathlatlon(@Name("startLat") Double startLat, @Name("startLong") Double startLong, @Name("endLat") Double endLat, @Name("endLong") Double endLong, @Name("h3Res") Long h3Res) throws InterruptedException { + if (startLat == null || startLong == null || endLat == null || endLong == null) { + throw new InterruptedException("invalid arguments"); + } + if (h3 == null) { + return Stream.empty(); + } + List ringList = null; + int validLatLon = 1; + + + final int h3Resolution = h3Res == null ? DEFAULT_H3_RESOLUTION : h3Res.intValue(); + if (h3Resolution < 1 || h3Resolution > 15) { + ringList = Collections.singletonList(-2L); + } + + if ( startLat>90 || startLat<-90 || endLat>90 || endLat<-90 ){ + validLatLon = 0; + ringList = Collections.singletonList(-3L); + } + + if ( startLong>180 || startLong<-180 || endLong>180 || endLong<-180 ){ + validLatLon = 0; + ringList = Collections.singletonList(-4L); + } + + if (h3Resolution > 0 && h3Resolution <= 15 && validLatLon > 0){ + final String starthexAddr = h3.latLngToCellAddress(startLat, startLong, h3Resolution); + final String endhexAddr = h3.latLngToCellAddress(endLat, endLong, h3Resolution); + return h3.gridPathCells(starthexAddr, endhexAddr) + .stream() + .map(H3LongAddress::of); + } else { + return ringList.stream().map(H3LongAddress::of); } + } + @SuppressWarnings("null") @Procedure(name = "com.neo4jh3.gridpathlatlonString", mode = Mode.READ) @Description("CALL com.neo4jh3.gridpathlatlonString(latitude, longitude, latitude, longitude, h3Resolution)") public Stream gridpathlatlonString(@Name("startLat") Double startLat, @Name("startLong") Double startLong, @Name("endLat") Double endLat, @Name("endLong") Double endLong, @Name("h3Res") Long h3Res) throws InterruptedException { @@ -2077,7 +2297,6 @@ public Stream gridpathlatlonString(@Name("startLat") Double sta } } - @Procedure(name = "com.neo4jh3.gridpathcell", mode = Mode.READ) @Description("CALL com.neo4jh3.gridpathcell(fromAddress, toAddress)") public Stream gridpathcell(@Name("fromAddress") Long fromAddress, @Name("toAddress") Long toAddress) throws InterruptedException { @@ -2202,7 +2421,6 @@ public Stream compactString(@Name("listCells") List lis return h3.compactCellAddresses(listCells) .stream() .map(H3StringAddress::of); - } // Compact @@ -2272,10 +2490,10 @@ public Stream lineash3( { List hexPoints = new ArrayList<>(); - List hexHoles = new ArrayList<>(); - List> holesList = new ArrayList<>(); - List hexList; - List hexListFinal = new ArrayList(); + List hexHoles = new ArrayList<>(); + List> holesList = new ArrayList<>(); + List hexList; + List hexListFinal = new ArrayList(); List listh3Address = new ArrayList(); List gpCells = new ArrayList(); Long h3StartAddress = 0L; @@ -2336,12 +2554,18 @@ public Stream lineash3( mls = mls.replace(")",""); mls = mls.replace("(",""); String[] latlonPairs = mls.split(","); + String lonlat = ""; for (int i = 0; i < latlonPairs.length; i++) { if (i > 0){ - fromLat = Double.valueOf(latlonPairs[i-1].split(" ")[0]); - fromLon = Double.valueOf(latlonPairs[i-1].split(" ")[1]); - toLat = Double.valueOf(latlonPairs[i].split(" ")[0]); - toLon = Double.valueOf(latlonPairs[i].split(" ")[1]); + lonlat = latlonPairs[i-1].toString(); + lonlat = lonlat.trim(); + fromLat = Double.valueOf(lonlat.split("\\s+")[0]); + fromLon = Double.valueOf(lonlat.split("\\s+")[1]); + lonlat = latlonPairs[i].toString(); + lonlat = lonlat.trim(); + toLat = Double.valueOf(lonlat.split("\\s+")[0]); + toLon =Double.valueOf(lonlat.split("\\s+")[1]); + midLat = (fromLat + toLat) / 2; midLon = (fromLon + toLon) / 2; h3StartAddress = h3.latLngToCell(fromLat, fromLon, h3Resolution); @@ -2426,6 +2650,7 @@ public Stream uncompactString(@Name("listCells") List l } // Experimental write to db procedure +@SuppressWarnings("unused") @Procedure(name = "com.neo4jh3.writeH3ToDB", mode = Mode.WRITE) @Description("CALL com.neo4jh3.writeH3ToDB(listCells, strLabel, strProperty, txSize)") public Stream writeH3ToDB(@Name("listCells") List listCells, @Name("strLabel") String strLabel, @Name("strProperty") String strProperty, @Name("txSize") Long txSize) throws InterruptedException { @@ -2474,6 +2699,7 @@ public Stream writeH3ToDB(@Name("listCells") List listCells, } // Experimental write to db procedure +@SuppressWarnings("unused") @Procedure(name = "com.neo4jh3.writeH3StringToDB", mode = Mode.WRITE) @Description("CALL com.neo4jh3.writeH3StringToDB(listCells, strLabel, strProperty, txSize)") public Stream writeH3StringToDB(@Name("listCells") List listCells, @Name("strLabel") String strLabel, @Name("strProperty") String strProperty, @Name("txSize") Long txSize) throws InterruptedException { @@ -2522,6 +2748,7 @@ public Stream writeH3StringToDB(@Name("listCells") List li } // Experimental write to db procedure + @SuppressWarnings("unused") @Procedure(name = "com.neo4jh3.writeH3NodesRelsToDB", mode = Mode.WRITE) @Description("CALL com.neo4jh3.writeH3NodesRelsToDB(From Node, List of H3 Cells, To Node Label, To Node Property Name, RelationshipType, Transaction Size)") public Stream writeH3NodesRelsToDB(@Name("fromNode") Node fromNode, @Name("listCells") List listCells, @Name("strLabel") String strLabel, @Name("strProperty") String strProperty, @Name("strRelationshipType") String strRelationshipType, @Name("txSize") Long txSize) throws InterruptedException { @@ -2708,7 +2935,7 @@ private static double distance(double lat1, double lon1, double lat2, double lon } } - private static double distance(double lat1, double lon1, double lat2, double lon2) { + private static double angleDistance(double lat1, double lon1, double lat2, double lon2) { if ((lat1 == lat2) && (lon1 == lon2)) { return 0; } @@ -2725,4 +2952,32 @@ private static double distance(double lat1, double lon1, double lat2, double lon } } + private static LatLng returnLatLng (String lonlatPairs) { + LatLng tmpGeoCoord = null; + Double polyLat = 0.0; + Double polyLon = 0.0; + if (!lonlatPairs.isBlank()){ + String lonlat = lonlatPairs.toString(); + lonlat = lonlat.trim(); + polyLat = Double.valueOf(lonlat.split("\\s+")[0]); + polyLon = Double.valueOf(lonlat.split("\\s+")[1]); + tmpGeoCoord = new LatLng(polyLat,polyLon); + } + return tmpGeoCoord; + } + + private static LatLng returnLngLat (String lonlatPairs) { + LatLng tmpGeoCoord = null; + Double polyLat = 0.0; + Double polyLon = 0.0; + if (!lonlatPairs.isBlank()){ + String lonlat = lonlatPairs.toString(); + lonlat = lonlat.trim(); + polyLat = Double.valueOf(lonlat.split("\\s+")[1]); + polyLon = Double.valueOf(lonlat.split("\\s+")[0]); + tmpGeoCoord = new LatLng(polyLat,polyLon); + } + return tmpGeoCoord; + } + } diff --git a/src/test/java/com/neo4jh3/Neo4jH3Test.java b/src/test/java/com/neo4jh3/Neo4jH3Test.java index 358e68f..1119db7 100644 --- a/src/test/java/com/neo4jh3/Neo4jH3Test.java +++ b/src/test/java/com/neo4jh3/Neo4jH3Test.java @@ -31,438 +31,454 @@ public void should_return_hex_address() throws InterruptedException { try (Session session = driver.session()) { Result result = null; - - /* result = session.run("call com.neo4jh3.compactNumber(['85283473fffffff','8528342bfffffff']) yield value return value limit 1"); assertEquals(599686042433355775L,result.single().get(0).asLong()); */ - if (System.getProperty("os.name").toLowerCase().equalsIgnoreCase("mac os x")){ - result = session.run("return com.neo4jh3.distanceBetweenHexes(599686042433355775,599686015589810175) as value"); - assertEquals(17.870163, result.single().get("value").asDouble(),0); + if (System.getProperty("os.name").toLowerCase().equalsIgnoreCase("mac os x")){ + result = session.run("return com.neo4jh3.distanceBetweenHexes(599686042433355775,599686015589810175) as value"); + assertEquals(17.870163, result.single().get("value").asDouble(),0); - result = session.run("RETURN com.neo4jh3.centeraswkb(599686042433355775) AS value"); - assertEquals("\"0000000001C05E7E7CF1C3265B4042AC42F1ED17C6\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.centeraswkb(599686042433355775) AS value"); + assertEquals("\"0000000001C05E7E7CF1C3265B4042AC42F1ED17C6\"", result.single().get("value").toString()); - result = session.run("RETURN com.neo4jh3.boundaryaswkt(599686042433355775) AS value"); - assertEquals("\"POLYGON ((-121.91508 37.271356, -121.862223 37.353926, -121.92355 37.428341, -122.037735 37.420129, -122.090429 37.337556, -122.029101 37.263198, -121.91508 37.271356))\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.boundaryaswkt(599686042433355775) AS value"); + assertEquals("\"POLYGON ((-121.91508 37.271356, -121.862223 37.353926, -121.92355 37.428341, -122.037735 37.420129, -122.090429 37.337556, -122.029101 37.263198, -121.91508 37.271356))\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.boundaryaswkt(111) AS value"); + assertEquals("\"-1\"", result.single().get("value").toString()); - result = session.run("RETURN com.neo4jh3.boundaryaswkt(111) AS value"); - assertEquals("\"-1\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.boundaryaswktString('822d57fffffffff') AS value"); - assertEquals("\"POLYGON ((38.777546 44.198571, 39.938746 42.736298, 42.150674 42.631271, 43.258395 44.047542, 42.146575 45.539505, 39.897167 45.559577, 38.777546 44.198571))\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.boundaryaswktString('111') AS value"); - assertEquals("\"-1\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.centeraswkt(599686042433355775) AS value"); - assertEquals("\"POINT (-121.976376 37.345793)\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.boundaryaswkb(599686042433355775) AS value"); - assertEquals("\"00000000030000000100000007C05E7A90ABB44E514042A2BBCB1CC964C05E772EA960B6FA4042AD4D72799A20C05E7B1B71758E224042B6D3E0BD449AC05E826A400FBA884042B5C6C97D8CF4C05E85C996B7670A4042AB3508F648C7C05E81DCCA70D1FA4042A1B078D92FB2C05E7A90ABB44E514042A2BBCB1CC964\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.boundaryaswkbString('8009fffffffffff') AS value"); - assertEquals("\"00000000030000000100000006C024E3D4280AE105404F8C2ABABEAD4F40161836EB4E9814404BDA775FB2EDFE4039152D44DCA8E3404D3365D3996FA8403FD4CEC41DD1A240513B846E8F29D43FD4D6CB5350092D405253DAB5C39BCCC024E3D4280AE105404F8C2ABABEAD4F\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.centeraswktString('8009fffffffffff') AS value"); - assertEquals("\"POINT (10.536199 64.7)\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.boundaryaswktString('822d57fffffffff') AS value"); + assertEquals("\"POLYGON ((38.777546 44.198571, 39.938746 42.736298, 42.150674 42.631271, 43.258395 44.047542, 42.146575 45.539505, 39.897167 45.559577, 38.777546 44.198571))\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.boundaryaswktString('111') AS value"); + assertEquals("\"-1\"", result.single().get("value").toString()); - result = session.run("RETURN com.neo4jh3.boundaryaswkbString('8009fffffffffff') AS value"); - assertEquals("\"00000000030000000100000006C024E3D4280AE105404F8C2ABABEAD4F40161836EB4E9814404BDA775FB2EDFE4039152D44DCA8E3404D3365D3996FA8403FD4CEC41DD1A240513B846E8F29D43FD4D6CB5350092D405253DAB5C39BCCC024E3D4280AE105404F8C2ABABEAD4F\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.centeraswkt(599686042433355775) AS value"); + assertEquals("\"POINT (-121.976376 37.345793)\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.boundaryaswkb(599686042433355775) AS value"); + assertEquals("\"00000000030000000100000007C05E7A90ABB44E514042A2BBCB1CC964C05E772EA960B6FA4042AD4D72799A20C05E7B1B71758E224042B6D3E0BD449AC05E826A400FBA884042B5C6C97D8CF4C05E85C996B7670A4042AB3508F648C7C05E81DCCA70D1FA4042A1B078D92FB2C05E7A90ABB44E514042A2BBCB1CC964\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.boundaryaswkbString('8009fffffffffff') AS value"); + assertEquals("\"00000000030000000100000006C024E3D4280AE105404F8C2ABABEAD4F40161836EB4E9814404BDA775FB2EDFE4039152D44DCA8E3404D3365D3996FA8403FD4CEC41DD1A240513B846E8F29D43FD4D6CB5350092D405253DAB5C39BCCC024E3D4280AE105404F8C2ABABEAD4F\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.centeraswktString('8009fffffffffff') AS value"); + assertEquals("\"POINT (10.536199 64.7)\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.boundaryaswkbString('8009fffffffffff') AS value"); + assertEquals("\"00000000030000000100000006C024E3D4280AE105404F8C2ABABEAD4F40161836EB4E9814404BDA775FB2EDFE4039152D44DCA8E3404D3365D3996FA8403FD4CEC41DD1A240513B846E8F29D43FD4D6CB5350092D405253DAB5C39BCCC024E3D4280AE105404F8C2ABABEAD4F\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.centerasgeojson(599686042433355775) AS value"); + assertEquals("\"{\\\"type\\\":\\\"Point\\\",\\\"coordinates\\\":[-121.976376,37.345793]}\"", result.single().get("value").toString()); - result = session.run("RETURN com.neo4jh3.centerasgeojson(599686042433355775) AS value"); - assertEquals("\"{\\\"type\\\":\\\"Point\\\",\\\"coordinates\\\":[-121.976376,37.345793]}\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.centerasgeojsonString('8009fffffffffff') AS value"); - assertEquals("\"{\\\"type\\\":\\\"Point\\\",\\\"coordinates\\\":[10.536199,64.7]}\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.centerasgeojsonString('8009fffffffffff') AS value"); + assertEquals("\"{\\\"type\\\":\\\"Point\\\",\\\"coordinates\\\":[10.536199,64.7]}\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.centerasgeojsonString('1234') AS value"); + assertEquals("\"-1\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.centerasgeojson(1234) AS value"); + assertEquals("\"-1\"", result.single().get("value").toString()); + } + + if (System.getProperty("os.name").toLowerCase().startsWith("wind")){ + result = session.run("return com.neo4jh3.distanceBetweenHexes(599686042433355775,599686015589810175) as value"); + assertEquals(17.870163466857125,result.single().get("value").asDouble(),0); + + result = session.run("RETURN com.neo4jh3.centeraswkb(599686042433355775) AS value"); + assertEquals("\"0000000001C05E7E7CF1C3265B4042AC42F1ED17C6\"", result.single().get("value").toString()); - result = session.run("RETURN com.neo4jh3.centerasgeojsonString('1234') AS value"); - assertEquals("\"-1\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.boundaryaswkt(599686042433355775) AS value"); + assertEquals("\"POLYGON ((-121.91508 37.271356, -121.862223 37.353926, -121.92355 37.428341, -122.037735 37.420129, -122.090429 37.337556, -122.029101 37.263198, -121.91508 37.271356))\"", result.single().get("value").toString()); - result = session.run("RETURN com.neo4jh3.centerasgeojson(1234) AS value"); - assertEquals("\"-1\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.centeraswkt(599686042433355775) AS value"); + assertEquals("\"POINT (-121.976376 37.345793)\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.boundaryaswktString('8009fffffffffff') AS value"); + assertEquals("\"POLYGON ((-10.444978 63.095054, 5.523647 55.706768, 25.082722 58.401545, 31.83128 68.929958, 0.32561 73.310224, -10.444978 63.095054))\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.boundaryaswkb(599686042433355775) AS value"); + assertEquals("\"00000000030000000100000007C05E7A90ABB44E514042A2BBCB1CC964C05E772EA960B6FA4042AD4D72799A20C05E7B1B71758E224042B6D3E0BD449AC05E826A400FBA884042B5C6C97D8CF4C05E85C996B7670A4042AB3508F648C7C05E81DCCA70D1FA4042A1B078D92FB2C05E7A90ABB44E514042A2BBCB1CC964\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.boundaryaswkbString('8009fffffffffff') AS value"); + assertEquals("\"00000000030000000100000006C024E3D4280AE105404F8C2ABABEAD4F40161836EB4E9814404BDA775FB2EDFE4039152D44DCA8E3404D3365D3996FA8403FD4CEC41DD1A240513B846E8F29D43FD4D6CB5350092D405253DAB5C39BCCC024E3D4280AE105404F8C2ABABEAD4F\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.centeraswktString('8009fffffffffff') AS value"); + assertEquals("\"POINT (10.536199 64.7)\"", result.single().get("value").toString()); + } - if (System.getProperty("os.name").toLowerCase().startsWith("wind")){ - result = session.run("return com.neo4jh3.distanceBetweenHexes(599686042433355775,599686015589810175) as value"); - assertEquals(17.870163466857125,result.single().get("value").asDouble(),0); - - result = session.run("RETURN com.neo4jh3.centeraswkb(599686042433355775) AS value"); - assertEquals("\"0000000001C05E7E7CF1C3265B4042AC42F1ED17C6\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.boundaryaswkt(599686042433355775) AS value"); - assertEquals("\"POLYGON ((-121.91508 37.271356, -121.862223 37.353926, -121.92355 37.428341, -122.037735 37.420129, -122.090429 37.337556, -122.029101 37.263198, -121.91508 37.271356))\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.centeraswkt(599686042433355775) AS value"); - assertEquals("\"POINT (-121.976376 37.345793)\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.boundaryaswktString('8009fffffffffff') AS value"); - assertEquals("\"POLYGON ((-10.444978 63.095054, 5.523647 55.706768, 25.082722 58.401545, 31.83128 68.929958, 0.32561 73.310224, -10.444978 63.095054))\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.boundaryaswkb(599686042433355775) AS value"); - assertEquals("\"00000000030000000100000007C05E7A90ABB44E514042A2BBCB1CC964C05E772EA960B6FA4042AD4D72799A20C05E7B1B71758E224042B6D3E0BD449AC05E826A400FBA884042B5C6C97D8CF4C05E85C996B7670A4042AB3508F648C7C05E81DCCA70D1FA4042A1B078D92FB2C05E7A90ABB44E514042A2BBCB1CC964\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.boundaryaswkbString('8009fffffffffff') AS value"); - assertEquals("\"00000000030000000100000006C024E3D4280AE105404F8C2ABABEAD4F40161836EB4E9814404BDA775FB2EDFE4039152D44DCA8E3404D3365D3996FA8403FD4CEC41DD1A240513B846E8F29D43FD4D6CB5350092D405253DAB5C39BCCC024E3D4280AE105404F8C2ABABEAD4F\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.centeraswktString('8009fffffffffff') AS value"); - assertEquals("\"POINT (10.536199 64.7)\"", result.single().get("value").toString()); - - } + result = session.run("RETURN com.neo4jh3.version() AS value"); + assertEquals("\"5.19.1\"", result.single().get("value").toString()); - result = session.run("RETURN com.neo4jh3.version() AS value"); - assertEquals("\"5.16.0\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.cellToLatLngString('892830926cfffff') AS value"); + assertEquals("\"37.564248,-122.325306\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.cellToLatLng(599686042433355775) AS value"); + assertEquals("\"37.345793,-121.976376\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.h3Validate(599686042433355775) AS value"); + assertEquals(599686042433355775L, result.single().get("value").asLong()); - result = session.run("RETURN com.neo4jh3.cellToLatLngString('892830926cfffff') AS value"); - assertEquals("\"37.564248,-122.325306\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.cellToLatLng(599686042433355775) AS value"); - assertEquals("\"37.345793,-121.976376\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.h3Validate(599686042433355775) AS value"); - assertEquals(599686042433355775L, result.single().get("value").asLong()); + result = session.run("RETURN com.neo4jh3.h3ValidateString('85283473fffffff') AS value"); + assertEquals("\"85283473fffffff\"", result.single().get("value").toString()); - result = session.run("RETURN com.neo4jh3.h3ValidateString('85283473fffffff') AS value"); - assertEquals("\"85283473fffffff\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.h3ValidateString('zzz1234a') AS value"); + assertEquals("\"-1\"", result.single().get("value").toString()); - result = session.run("RETURN com.neo4jh3.h3ValidateString('zzz1234a') AS value"); - assertEquals("\"-1\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.h3Validate(337) AS value"); + assertEquals(-1L, result.single().get("value").asLong()); - result = session.run("RETURN com.neo4jh3.h3Validate(337) AS value"); - assertEquals(-1L, result.single().get("value").asLong()); + result = session.run("RETURN com.neo4jh3.h3Validate(599686042433355775) AS value"); + assertEquals(599686042433355775L, result.single().get("value").asLong(),0); - result = session.run("RETURN com.neo4jh3.h3Validate(599686042433355775) AS value"); - assertEquals(599686042433355775L, result.single().get("value").asLong(),0); + result = session.run("RETURN com.neo4jh3.h3Validate(371) AS value"); + assertEquals(-1L, result.single().get("value").asLong(),0); - result = session.run("RETURN com.neo4jh3.h3Validate(371) AS value"); - assertEquals(-1L, result.single().get("value").asLong(),0); + result = session.run("RETURN com.neo4jh3.h3ValidateString('85283473fffffff') AS value"); + assertEquals("\"85283473fffffff\"", result.single().get("value").toString()); - result = session.run("RETURN com.neo4jh3.h3ValidateString('85283473fffffff') AS value"); - assertEquals("\"85283473fffffff\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.h3ValidateString('notvalidstring') AS value"); + assertEquals("\"-1\"", result.single().get("value").toString()); - result = session.run("RETURN com.neo4jh3.h3ValidateString('notvalidstring') AS value"); - assertEquals("\"-1\"", result.single().get("value").toString()); + result = session.run("call com.neo4jh3.compactString(['85283473fffffff', '85283447fffffff', '8528347bfffffff', '85283463fffffff', '85283477fffffff', '8528340ffffffff', '8528340bfffffff', '85283457fffffff', '85283443fffffff', '8528344ffffffff', '852836b7fffffff', '8528346bfffffff', '8528346ffffffff', '85283467fffffff', '8528342bfffffff', '8528343bfffffff', '85283407fffffff', '85283403fffffff', '8528341bfffffff']) yield value return value limit 1"); + assertEquals("\"85283447fffffff\"",result.single().get(0).toString()); - result = session.run("call com.neo4jh3.compactString(['85283473fffffff', '85283447fffffff', '8528347bfffffff', '85283463fffffff', '85283477fffffff', '8528340ffffffff', '8528340bfffffff', '85283457fffffff', '85283443fffffff', '8528344ffffffff', '852836b7fffffff', '8528346bfffffff', '8528346ffffffff', '85283467fffffff', '8528342bfffffff', '8528343bfffffff', '85283407fffffff', '85283403fffffff', '8528341bfffffff']) yield value return value limit 1"); - assertEquals("\"85283447fffffff\"",result.single().get(0).toString()); - - result=session.run("call com.neo4jh3.uncompact([599686030622195711,599686015589810175,599686014516068351,599686034917163007,599686029548453887,599686032769679359,599686198125920255,599686023106002943,599686027400970239,599686013442326527,599686012368584703,599686018811035647,595182446027210751], 5) yield value return value limit 1"); - assertEquals(599686030622195711L,result.single().get(0).asLong()); - - result=session.run("call com.neo4jh3.uncompact([599686030622195711,599686015589810175,599686014516068351,599686034917163007,599686029548453887,599686032769679359,599686198125920255,599686023106002943,599686027400970239,599686013442326527,599686012368584703,599686018811035647,595182446027210751], 1) yield value return value limit 1"); - assertEquals(-2L,result.single().get(0).asLong()); - - result = session.run("call com.neo4jh3.uncompactString(['85283447fffffff','8528340ffffffff','8528340bfffffff','85283457fffffff','85283443fffffff','8528344ffffffff','852836b7fffffff','8528342bfffffff','8528343bfffffff','85283407fffffff','85283403fffffff','8528341bfffffff','8428347ffffffff'],5) yield value return value limit 1"); - assertEquals("\"85283447fffffff\"",result.single().get(0).toString()); + result=session.run("call com.neo4jh3.uncompact([599686030622195711,599686015589810175,599686014516068351,599686034917163007,599686029548453887,599686032769679359,599686198125920255,599686023106002943,599686027400970239,599686013442326527,599686012368584703,599686018811035647,595182446027210751], 5) yield value return value limit 1"); + assertEquals(599686030622195711L,result.single().get(0).asLong()); + + result=session.run("call com.neo4jh3.uncompact([599686030622195711,599686015589810175,599686014516068351,599686034917163007,599686029548453887,599686032769679359,599686198125920255,599686023106002943,599686027400970239,599686013442326527,599686012368584703,599686018811035647,595182446027210751], 1) yield value return value limit 1"); + assertEquals(-2L,result.single().get(0).asLong()); + + result = session.run("call com.neo4jh3.uncompactString(['85283447fffffff','8528340ffffffff','8528340bfffffff','85283457fffffff','85283443fffffff','8528344ffffffff','852836b7fffffff','8528342bfffffff','8528343bfffffff','85283407fffffff','85283403fffffff','8528341bfffffff','8428347ffffffff'],5) yield value return value limit 1"); + assertEquals("\"85283447fffffff\"",result.single().get(0).toString()); - result = session.run("RETURN com.neo4jh3.h3HexAddressString( 37.8199, -122.4783, 13) AS value"); - assertEquals("\"8d283087022a93f\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.h3HexAddressString( 97.8199, -122.4783, 13) AS value"); - assertEquals("\"-3\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.h3HexAddressString( 37.8199, -122.4783, 16) AS value"); - assertEquals("\"-2\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.h3HexAddress( 37.8199, -122.4783, 13) AS value"); - assertEquals(635714569676958015L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.h3HexAddress( 37.8199, -122.4783, 16) AS value"); - assertEquals(-2L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.h3HexAddress( 37.8199, -222.4783, 13) AS value"); - assertEquals(-4L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.h3tostring(599686042433355775) AS value"); - assertEquals("\"85283473fffffff\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.h3tostring(22) AS value"); - assertEquals("\"-1\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.stringToH3('85283473fffffff') AS value"); - assertEquals(599686042433355775L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.stringToH3('invalidhex') AS value"); - assertEquals(-1L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.h3ResolutionString('85283473fffffff') AS value"); - assertEquals(5L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.h3ResolutionString('notavalidhex') AS value"); - assertEquals(-1L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.h3Resolution(599686042433355775) AS value"); - assertEquals(5L, result.single().get("value").asLong(),0); + result = session.run("RETURN com.neo4jh3.h3HexAddressString( 37.8199, -122.4783, 13) AS value"); + assertEquals("\"8d283087022a93f\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.h3HexAddressString( 97.8199, -122.4783, 13) AS value"); + assertEquals("\"-3\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.h3HexAddressString( 37.8199, -122.4783, 16) AS value"); + assertEquals("\"-2\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.h3HexAddress( 37.8199, -122.4783, 13) AS value"); + assertEquals(635714569676958015L, result.single().get("value").asLong(),0); + + result = session.run("RETURN com.neo4jh3.h3HexAddress( 37.8199, -122.4783, 16) AS value"); + assertEquals(-2L, result.single().get("value").asLong(),0); + + result = session.run("RETURN com.neo4jh3.h3HexAddress( 37.8199, -222.4783, 13) AS value"); + assertEquals(-4L, result.single().get("value").asLong(),0); + + result = session.run("RETURN com.neo4jh3.h3tostring(599686042433355775) AS value"); + assertEquals("\"85283473fffffff\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.h3tostring(22) AS value"); + assertEquals("\"-1\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.stringToH3('85283473fffffff') AS value"); + assertEquals(599686042433355775L, result.single().get("value").asLong(),0); + + result = session.run("RETURN com.neo4jh3.stringToH3('invalidhex') AS value"); + assertEquals(-1L, result.single().get("value").asLong(),0); + + result = session.run("RETURN com.neo4jh3.h3ResolutionString('85283473fffffff') AS value"); + assertEquals(5L, result.single().get("value").asLong(),0); + + result = session.run("RETURN com.neo4jh3.h3ResolutionString('notavalidhex') AS value"); + assertEquals(-1L, result.single().get("value").asLong(),0); + + result = session.run("RETURN com.neo4jh3.h3Resolution(599686042433355775) AS value"); + assertEquals(5L, result.single().get("value").asLong(),0); - result = session.run("RETURN com.neo4jh3.h3Resolution(337) AS value"); - assertEquals(-1L, result.single().get("value").asLong(),0); + result = session.run("RETURN com.neo4jh3.h3Resolution(337) AS value"); + assertEquals(-1L, result.single().get("value").asLong(),0); - result = session.run("RETURN com.neo4jh3.latlongash3String( 37.8199, -122.4783, 13) AS value"); - assertEquals("\"8d283087022a93f\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.latlongash3String( 107.8199, -122.4783, 13) AS value"); - assertEquals("\"-3\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.latlongash3String( 17.8199, -222.4783, 13) AS value"); - assertEquals("\"-4\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.latlongash3String( 17.8199, -122.4783, 22) AS value"); - assertEquals("\"-2\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.latlongash3( 37.8199, -122.4783, 13) AS value"); - assertEquals(635714569676958015L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.latlongash3( 107.8199, -122.4783, 13) AS value"); - assertEquals(-3L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.latlongash3( 17.8199, -222.4783, 13) AS value"); - assertEquals(-4L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.latlongash3( 17.8199, -122.4783, 22) AS value"); - assertEquals(-2L, result.single().get("value").asLong(),0); - - result = session.run("return com.neo4jh3.h3RingsForDistance(6,7) as value"); - assertEquals(3, result.single().get("value").asInt()); - - result = session.run("return com.neo4jh3.gridDistanceString('85283473fffffff','8528342bfffffff') as value"); - assertEquals(2L,result.single().get("value").asLong(),0); - - result = session.run("return com.neo4jh3.gridDistance(599686030622195711,599686015589810175) as value"); - assertEquals(2L,result.single().get("value").asLong(),0); + result = session.run("RETURN com.neo4jh3.latlongash3String( 37.8199, -122.4783, 13) AS value"); + assertEquals("\"8d283087022a93f\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.latlongash3String( 107.8199, -122.4783, 13) AS value"); + assertEquals("\"-3\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.latlongash3String( 17.8199, -222.4783, 13) AS value"); + assertEquals("\"-4\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.latlongash3String( 17.8199, -122.4783, 22) AS value"); + assertEquals("\"-2\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.latlongash3( 37.8199, -122.4783, 13) AS value"); + assertEquals(635714569676958015L, result.single().get("value").asLong(),0); + + result = session.run("RETURN com.neo4jh3.latlongash3( 107.8199, -122.4783, 13) AS value"); + assertEquals(-3L, result.single().get("value").asLong(),0); - result = session.run("return com.neo4jh3.gridDistance(1234,599686015589810175) as value"); - assertEquals(-1L,result.single().get("value").asLong(),0); + result = session.run("RETURN com.neo4jh3.latlongash3( 17.8199, -222.4783, 13) AS value"); + assertEquals(-4L, result.single().get("value").asLong(),0); - result = session.run("RETURN com.neo4jh3.toparentString('892830926cfffff', 6) AS value"); - assertEquals("862830927ffffff", result.single().get("value").asString()); + result = session.run("RETURN com.neo4jh3.latlongash3( 17.8199, -122.4783, 22) AS value"); + assertEquals(-2L, result.single().get("value").asLong(),0); + + result = session.run("return com.neo4jh3.h3RingsForDistance(6,7) as value"); + assertEquals(3, result.single().get("value").asInt()); - result = session.run("RETURN com.neo4jh3.toparentString('892830926cfffff', 26) AS value"); - assertEquals("-2", result.single().get("value").asString()); + result = session.run("return com.neo4jh3.gridDistanceString('85283473fffffff','8528342bfffffff') as value"); + assertEquals(2L,result.single().get("value").asLong(),0); + + result = session.run("return com.neo4jh3.gridDistance(599686030622195711,599686015589810175) as value"); + assertEquals(2L,result.single().get("value").asLong(),0); - result = session.run("RETURN com.neo4jh3.toparent(604197150066212863, 3) AS value"); - assertEquals(590686371182542847L, result.single().get("value").asLong()); + result = session.run("return com.neo4jh3.gridDistance(1234,599686015589810175) as value"); + assertEquals(-1L,result.single().get("value").asLong(),0); - result = session.run("RETURN com.neo4jh3.toparent(604197150066212863, 17) AS value"); - assertEquals(-2L, result.single().get("value").asLong()); + result = session.run("RETURN com.neo4jh3.toparentString('892830926cfffff', 6) AS value"); + assertEquals("862830927ffffff", result.single().get("value").asString()); - result = session.run("RETURN com.neo4jh3.toparent(604197150066212863, 13) AS value"); - assertEquals(-2L, result.single().get("value").asLong()); + result = session.run("RETURN com.neo4jh3.toparentString('892830926cfffff', 26) AS value"); + assertEquals("-2", result.single().get("value").asString()); - result = session.run("RETURN com.neo4jh3.toparent(12345, 13) AS value"); - assertEquals(-1L, result.single().get("value").asLong()); + result = session.run("RETURN com.neo4jh3.toparent(604197150066212863, 3) AS value"); + assertEquals(590686371182542847L, result.single().get("value").asLong()); - result = session.run("RETURN com.neo4jh3.cellToLatLng( 635714569676958015) AS value"); - assertEquals("\"37.819895,-122.478297\"", result.single().get("value").toString()); - - /* - result = session.run("RETURN com.neo4jh3.cellToLatLngString('892830926cfffff') AS value"); - assertEquals("\"37.56424780593244,-122.3253058831214\"", result.single().get("value").toString()); - */ + result = session.run("RETURN com.neo4jh3.toparent(604197150066212863, 17) AS value"); + assertEquals(-2L, result.single().get("value").asLong()); - result = session.run("RETURN com.neo4jh3.cellToLatLngString('123') AS value"); - assertEquals("\"-1\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.cellToLatLng(123) AS value"); - assertEquals("\"-1\"", result.single().get("value").toString()); - - result = session.run("return com.neo4jh3.distanceBetweenHexes(3111,599686015589810175) as value"); - assertEquals(-1.0,result.single().get("value").asDouble(),0); + result = session.run("RETURN com.neo4jh3.toparent(604197150066212863, 13) AS value"); + assertEquals(-2L, result.single().get("value").asLong()); + + result = session.run("RETURN com.neo4jh3.toparent(12345, 13) AS value"); + assertEquals(-1L, result.single().get("value").asLong()); + + result = session.run("RETURN com.neo4jh3.cellToLatLng( 635714569676958015) AS value"); + assertEquals("\"37.819895,-122.478297\"", result.single().get("value").toString()); + + /* + result = session.run("RETURN com.neo4jh3.cellToLatLngString('892830926cfffff') AS value"); + assertEquals("\"37.56424780593244,-122.3253058831214\"", result.single().get("value").toString()); + */ + + result = session.run("RETURN com.neo4jh3.cellToLatLngString('123') AS value"); + assertEquals("\"-1\"", result.single().get("value").toString()); - result = session.run("return com.neo4jh3.distanceBetweenHexesString('8a2989352777fff','8a498935223ffff') as value"); - assertEquals(2360.820388,result.single().get("value").asDouble(),0); + result = session.run("RETURN com.neo4jh3.cellToLatLng(123) AS value"); + assertEquals("\"-1\"", result.single().get("value").toString()); + + result = session.run("return com.neo4jh3.distanceBetweenHexes(3111,599686015589810175) as value"); + assertEquals(-1.0,result.single().get("value").asDouble(),0); + + result = session.run("return com.neo4jh3.distanceBetweenHexesString('8a2989352777fff','8a498935223ffff') as value"); + assertEquals(2360.820388,result.single().get("value").asDouble(),0); + + result = session.run("return com.neo4jh3.distanceBetweenHexesString('123','8a498935223ffff') as value"); + assertEquals(-1.0,result.single().get("value").asDouble(),0); + + //result = session.run("return com.neo4jh3.cellToLatLng('8a2989352717fff') as value"); +//assertEquals("39.678106484915,-120.23540752726865",result.single().get("value").asString()); + result = session.run("RETURN com.neo4jh3.maxChild(599686042433355775, 10) AS value"); + assertEquals(622204040416821247L, result.single().get("value").asLong()); + + result = session.run("RETURN com.neo4jh3.maxChild(599686042433355775, 20) AS value"); + assertEquals(-2L, result.single().get("value").asLong()); + + result = session.run("RETURN com.neo4jh3.maxChild(123, 10) AS value"); + assertEquals(-1L, result.single().get("value").asLong()); + + result = session.run("RETURN com.neo4jh3.minChild(599686042433355775, 10) AS value"); + assertEquals(622204039496499199L, result.single().get("value").asLong()); + + result = session.run("RETURN com.neo4jh3.minChild(599686042433355775, 23) AS value"); + assertEquals(-2L, result.single().get("value").asLong()); + + result = session.run("RETURN com.neo4jh3.minChild(123, 10) AS value"); + assertEquals(-1L, result.single().get("value").asLong()); + + result = session.run("RETURN com.neo4jh3.maxChildString('85283473fffffff', 10) AS value"); + assertEquals("\"8a2834736db7fff\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.maxChildString('123', 10) AS value"); + assertEquals("\"-1\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.maxChildString('85283473fffffff', 20) AS value"); + assertEquals("\"-2\"", result.single().get("value").toString()); - result = session.run("return com.neo4jh3.distanceBetweenHexesString('123','8a498935223ffff') as value"); - assertEquals(-1.0,result.single().get("value").asDouble(),0); + result = session.run("RETURN com.neo4jh3.minChildString('85283473fffffff', 10) AS value"); + assertEquals("\"8a2834700007fff\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.minChildString('123', 10) AS value"); + assertEquals("\"-1\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.minChildString('85283473fffffff', 20) AS value"); + assertEquals("\"-2\"", result.single().get("value").toString()); + - //result = session.run("return com.neo4jh3.cellToLatLng('8a2989352717fff') as value"); - //assertEquals("39.678106484915,-120.23540752726865",result.single().get("value").asString()); - result = session.run("RETURN com.neo4jh3.maxChild(599686042433355775, 10) AS value"); - assertEquals(622204040416821247L, result.single().get("value").asLong()); + result = session.run("RETURN com.neo4jh3.h3ResolutionString('85283473fffffff') AS value"); + assertEquals(5L, result.single().get("value").asLong(),0); - result = session.run("RETURN com.neo4jh3.maxChild(599686042433355775, 20) AS value"); - assertEquals(-2L, result.single().get("value").asLong()); + result = session.run("RETURN com.neo4jh3.h3Resolution(599686042433355775) AS value"); + assertEquals(5L, result.single().get("value").asLong(),0); - result = session.run("RETURN com.neo4jh3.maxChild(123, 10) AS value"); - assertEquals(-1L, result.single().get("value").asLong()); + result = session.run("RETURN com.neo4jh3.angleBetweenPoints(40.123,-78.111,40.555,-78.910) AS value"); + assertEquals(305.607560, result.single().get("value").asDouble(),0); - result = session.run("RETURN com.neo4jh3.minChild(599686042433355775, 10) AS value"); - assertEquals(622204039496499199L, result.single().get("value").asLong()); + /* Procedures */ - result = session.run("RETURN com.neo4jh3.minChild(599686042433355775, 23) AS value"); - assertEquals(-2L, result.single().get("value").asLong()); + result=session.run("call com.neo4jh3.gridDisk(599686042433355775,1) yield value return value limit 1"); + assertEquals(599686042433355775L,result.single().get(0).asLong()); + + result=session.run("call com.neo4jh3.gridDisk(123,1) yield value return value limit 1"); + assertEquals(-1L,result.single().get(0).asLong()); + + result=session.run("call com.neo4jh3.gridDisk(599686042433355775,-3) yield value return value limit 1"); + assertEquals(-2L,result.single().get(0).asLong()); + + result=session.run("call com.neo4jh3.gridDiskString('85283473fffffff',1) yield value return value limit 1"); + assertEquals("\"85283473fffffff\"",result.single().get(0).toString()); + + result=session.run("call com.neo4jh3.gridDiskString('85283473fffffff',-3) yield value return value limit 1"); + assertEquals("\"-2\"",result.single().get(0).toString()); + + result=session.run("call com.neo4jh3.gridDiskString('12345',1) yield value return value limit 1"); + assertEquals("\"-1\"",result.single().get(0).toString()); + + result=session.run("call com.neo4jh3.tochildren(12345,1) yield value return value limit 1"); + assertEquals(-1L,result.single().get(0).asLong()); + + result=session.run("call com.neo4jh3.tochildren(599686042433355775,0) yield value return value limit 1"); + assertEquals(-2L,result.single().get(0).asLong()); + + result=session.run("call com.neo4jh3.tochildren(599686042433355775,6) yield value return value limit 1"); + assertEquals(604189641121202175L,result.single().get(0).asLong()); + + result=session.run("call com.neo4jh3.tochildrenString('12345',1) yield value return value limit 1"); + assertEquals("\"-1\"",result.single().get(0).toString()); + + result=session.run("call com.neo4jh3.tochildrenString('85283473fffffff',0) yield value return value limit 1"); + assertEquals("\"-2\"",result.single().get(0).toString()); + + result=session.run("call com.neo4jh3.tochildrenString('85283473fffffff',6) yield value return value limit 1"); + assertEquals("\"862834707ffffff\"",result.single().get(0).toString()); + + result=session.run("call com.neo4jh3.polygonToCells(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],7,'latlon') yield value return value limit 1"); + assertEquals(608692971759468543L,result.single().get(0).asLong(),0); - result = session.run("RETURN com.neo4jh3.minChild(123, 10) AS value"); - assertEquals(-1L, result.single().get("value").asLong()); + result=session.run("call com.neo4jh3.polygonToCells(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],20,'latlon') yield value return value limit 1"); + assertEquals(-2L,result.single().get(0).asLong(),0); + + result=session.run("call com.neo4jh3.polygonToCellsString(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],7,'latlon') yield value return value limit 1"); + assertEquals("\"872830866ffffff\"",result.single().get(0).toString()); - result = session.run("RETURN com.neo4jh3.maxChildString('85283473fffffff', 10) AS value"); - assertEquals("\"8a2834736db7fff\"", result.single().get("value").toString()); + result=session.run("call com.neo4jh3.polygonToCellsString(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],20,'latlon') yield value return value limit 1"); + assertEquals("\"-2\"",result.single().get(0).toString()); - result = session.run("RETURN com.neo4jh3.maxChildString('123', 10) AS value"); - assertEquals("\"-1\"", result.single().get("value").toString()); + result=session.run("call com.neo4jh3.polygonIntersection(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],['37.9866,-123.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],7,'latlon') yield value return value limit 1"); + assertEquals(608692975685337087L, result.single().get(0).asLong(),0); - result = session.run("RETURN com.neo4jh3.maxChildString('85283473fffffff', 20) AS value"); - assertEquals("\"-2\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.minChildString('85283473fffffff', 10) AS value"); - assertEquals("\"8a2834700007fff\"", result.single().get("value").toString()); + result=session.run("call com.neo4jh3.polygonIntersectionString(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],['37.9866,-123.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],7,'latlon') yield value return value limit 1"); + assertEquals("\"872830950ffffff\"",result.single().get(0).toString()); - result = session.run("RETURN com.neo4jh3.minChildString('123', 10) AS value"); - assertEquals("\"-1\"", result.single().get("value").toString()); + result = session.run("call com.neo4jh3.multilineash3('MULTILINESTRING((-73.99311 40.73669), (-73.99265 40.73733), (-74.00265 40.93733))',12,'lonlat') yield value return value limit 1"); + assertEquals(631243922688246783L, result.single().get(0).asLong(),0); - result = session.run("RETURN com.neo4jh3.minChildString('85283473fffffff', 20) AS value"); - assertEquals("\"-2\"", result.single().get("value").toString()); + result = session.run("call com.neo4jh3.multilineash3('MULTILINESTRING((-73.99311953429248 40.736691045913472), (-73.99265431029018 40.73733046783797), ( -74.00265431029018 40.93733046783797))',17, 'lonlat') yield value return value limit 1"); + assertEquals(-2L,result.single().get(0).asLong(),0); + + result = session.run("call com.neo4jh3.multilineash3String('ZZZ((-73.99311953429248 40.736691045913472), (-73.99265431029018 40.73733046783797), ( -74.00265431029018 40.93733046783797))',12, 'lonlat') yield value return value limit 1"); + assertEquals("\"-1\"",result.single().get(0).toString()); + + result = session.run("call com.neo4jh3.multilineash3String('MULTILINESTRING((-73.99311953429248 40.736691045913472), (-73.99265431029018 40.73733046783797 ), (-74.00265431029018 40.93733046783797))',17, 'lonlat') yield value return value limit 1"); + assertEquals("\"-2\"",result.single().get(0).toString()); - - result = session.run("RETURN com.neo4jh3.h3ResolutionString('85283473fffffff') AS value"); - assertEquals(5L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.h3Resolution(599686042433355775) AS value"); - assertEquals(5L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.angleBetweenPoints(40.123,-78.111,40.555,-78.910) AS value"); - assertEquals(305.607560, result.single().get("value").asDouble(),0); - - /* Procedures */ - - result=session.run("call com.neo4jh3.gridDisk(599686042433355775,1) yield value return value limit 1"); - assertEquals(599686042433355775L,result.single().get(0).asLong()); - - result=session.run("call com.neo4jh3.gridDisk(123,1) yield value return value limit 1"); - assertEquals(-1L,result.single().get(0).asLong()); - - result=session.run("call com.neo4jh3.gridDisk(599686042433355775,-3) yield value return value limit 1"); - assertEquals(-2L,result.single().get(0).asLong()); - - result=session.run("call com.neo4jh3.gridDiskString('85283473fffffff',1) yield value return value limit 1"); - assertEquals("\"85283473fffffff\"",result.single().get(0).toString()); - - result=session.run("call com.neo4jh3.gridDiskString('85283473fffffff',-3) yield value return value limit 1"); - assertEquals("\"-2\"",result.single().get(0).toString()); - - result=session.run("call com.neo4jh3.gridDiskString('12345',1) yield value return value limit 1"); - assertEquals("\"-1\"",result.single().get(0).toString()); - - result=session.run("call com.neo4jh3.tochildren(12345,1) yield value return value limit 1"); - assertEquals(-1L,result.single().get(0).asLong()); - - result=session.run("call com.neo4jh3.tochildren(599686042433355775,0) yield value return value limit 1"); - assertEquals(-2L,result.single().get(0).asLong()); - - result=session.run("call com.neo4jh3.tochildren(599686042433355775,6) yield value return value limit 1"); - assertEquals(604189641121202175L,result.single().get(0).asLong()); - - result=session.run("call com.neo4jh3.tochildrenString('12345',1) yield value return value limit 1"); - assertEquals("\"-1\"",result.single().get(0).toString()); - - result=session.run("call com.neo4jh3.tochildrenString('85283473fffffff',0) yield value return value limit 1"); - assertEquals("\"-2\"",result.single().get(0).toString()); - - result=session.run("call com.neo4jh3.tochildrenString('85283473fffffff',6) yield value return value limit 1"); - assertEquals("\"862834707ffffff\"",result.single().get(0).toString()); - - result=session.run("call com.neo4jh3.polygonToCells(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],7,'latlon') yield value return value limit 1"); - assertEquals(608692971759468543L,result.single().get(0).asLong(),0); + result = session.run("call com.neo4jh3.multilineash3String('MULTILINESTRING((-73.99311 40.73669), (-73.99265 40.73733), (-74.00265 40.93733))',12,'lonlat') yield value return value order by value limit 1"); + assertEquals("\"8c2a100800925ff\"",result.single().get(0).toString()); - result=session.run("call com.neo4jh3.polygonToCells(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],20,'latlon') yield value return value limit 1"); - assertEquals(-2L,result.single().get(0).asLong(),0); - - result=session.run("call com.neo4jh3.polygonToCellsString(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],7,'latlon') yield value return value limit 1"); - assertEquals("\"872830866ffffff\"",result.single().get(0).toString()); + result = session.run("call com.neo4jh3.multilineash3String('MULTILINESTRING(( -73.99311 40.73669), ( -73.99265 40.73733), ( -74.00265 40.93733))',12,'lonlat') yield value return value order by value limit 1"); + assertEquals("\"8c2a100800925ff\"",result.single().get(0).toString()); - result=session.run("call com.neo4jh3.polygonToCellsString(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],20,'latlon') yield value return value limit 1"); - assertEquals("\"-2\"",result.single().get(0).toString()); + result = session.run("call com.neo4jh3.lineash3String('ZZZ((-121.915080 37.271355 ), (-121.862223 37.353926))',7,'lonlat') yield value return value limit 1"); + assertEquals("\"-1\"", result.single().get("value").toString()); - result=session.run("call com.neo4jh3.polygonIntersection(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],['37.9866,-123.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],7,'latlon') yield value return value limit 1"); - assertEquals(608692975685337087L, result.single().get(0).asLong(),0); + result = session.run("call com.neo4jh3.lineash3String('LINESTRING((-121.915080 37.271355 ), (-121.862223 37.353926))',7,'lonlat') yield value return value limit 1"); + assertEquals("\"87283409affffff\"",result.single().get(0).toString()); + + result = session.run("call com.neo4jh3.lineash3('ZZZ((-121.915080 37.271355), (-121.862223 37.353926))',7,'lonlat') yield value return value limit 1"); + assertEquals(-1L, result.single().get(0).asLong(),0); - result=session.run("call com.neo4jh3.polygonIntersectionString(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],['37.9866,-123.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],7,'latlon') yield value return value limit 1"); - assertEquals("\"872830950ffffff\"",result.single().get(0).toString()); + result = session.run("call com.neo4jh3.lineash3('LINESTRING((73.99311953429248 40.736691045913472), (-73.99265431029018 40.73733046783797), (-74.00265431029018 40.93733046783797 ))',12, 'lonlat') yield value return value limit 1"); + assertEquals(631243922688264703L, result.single().get(0).asLong(),0); - result = session.run("call com.neo4jh3.multilineash3('MULTILINESTRING((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018) , (40.93733046783797 -74.00265431029018))',12) yield value return value limit 1"); - assertEquals(631243922688264703L, result.single().get(0).asLong(),0); - - result = session.run("call com.neo4jh3.multilineash3String('MULTILINESTRING((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018) , (40.93733046783797 -74.00265431029018))',12) yield value return value limit 1"); - assertEquals("\"8c2a100d27549ff\"",result.single().get(0).toString()); - - 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"); - assertEquals(-2L,result.single().get(0).asLong(),0); - - result = session.run("call com.neo4jh3.multilineash3String('ZZZ((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018) , (40.93733046783797 -74.00265431029018))',12) yield value return value limit 1"); - assertEquals("\"-1\"",result.single().get(0).toString()); - - result = session.run("call com.neo4jh3.multilineash3String('MULTILINESTRING((40.736691045913472 73.99311953429248), (40.73733046783797 -73.99265431029018) , (40.93733046783797 -74.00265431029018))',17) yield value return value limit 1"); - assertEquals("\"-2\"",result.single().get(0).toString()); + /* Geography tests */ + result = session.run("RETURN com.neo4jh3.pointash3('POINT(37.8199 -122.4783)',13, 'latlon') AS value"); + assertEquals(635714569676958015L, result.single().get("value").asLong(),0); - result = session.run("call com.neo4jh3.lineash3String('ZZZ((37.271355 -121.915080), (37.353926 -121.862223))',7) yield value return value limit 1"); - assertEquals("\"-1\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.pointash3('POINT(-122.4783 37.8199)',13, 'lonlat') AS value"); + assertEquals(635714569676958015L, result.single().get("value").asLong(),0); - result = session.run("call com.neo4jh3.lineash3String('LINESTRING((37.271355 -121.915080), (37.353926 -121.862223))',7) yield value return value limit 1"); - assertEquals("\"87283409affffff\"",result.single().get(0).toString()); - - result = session.run("call com.neo4jh3.lineash3('ZZZ((37.271355 -121.915080), (37.353926 -121.862223))',7) yield value return value limit 1"); - assertEquals(-1L, result.single().get(0).asLong(),0); - - 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"); - assertEquals(631243922688264703L, result.single().get(0).asLong(),0); - - /* Geography tests */ - result = session.run("RETURN com.neo4jh3.pointash3('POINT(37.8199 -122.4783)',13, 'latlon') AS value"); - assertEquals(635714569676958015L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.pointash3('POINT(-122.4783 37.8199)',13, 'lonlat') AS value"); - assertEquals(635714569676958015L, result.single().get("value").asLong(),0); - - result = session.run("RETURN com.neo4jh3.pointash3('POINT(-122.4783 37.8199)',16, 'lonlat') AS value"); - assertEquals(-2L,result.single().get(0).asLong(),0); - - result = session.run("RETURN com.neo4jh3.pointash3String('POINT(37.8199 -122.4783)',13, 'latlon') AS value"); - assertEquals("\"8d283087022a93f\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.pointash3String('POINT(-122.4783 37.8199)',13, 'lonlat') AS value"); - assertEquals("\"8d283087022a93f\"", result.single().get("value").toString()); - - result = session.run("RETURN com.neo4jh3.pointash3String('POINT(-122.4783 37.8199)',16, 'lonlat') AS value"); - assertEquals("\"-2\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.pointash3('POINT(-122.4783 37.8199)',16, 'lonlat') AS value"); + assertEquals(-2L,result.single().get(0).asLong(),0); - result = session.run("RETURN com.neo4jh3.ispentagon(590112357393367039) AS value"); - assertEquals(true, result.single().get("value").asBoolean()); - - result = session.run("RETURN com.neo4jh3.ispentagon(12345) AS value"); - assertEquals(false, result.single().get("value").asBoolean()); - - result = session.run("RETURN com.neo4jh3.ispentagonString('85283473fffffff') AS value"); - assertEquals(false, result.single().get("value").asBoolean()); - - result = session.run("call com.neo4jh3.gridpathlatlon(37.8199, -122.4783, 47.8199, -122.5, 13) yield value return value limit 1"); - assertEquals(635714569676958015L, result.single().get("value").asLong(),0); - - result = session.run("call com.neo4jh3.gridpathlatlon(97.8199, -122.4783, 47.8199, -122.5, 13) yield value return value limit 1"); - assertEquals(-3L, result.single().get("value").asLong(),0); - - result = session.run("call com.neo4jh3.gridpathlatlon(37.8199, -122.4783, 47.8199, -122.5, 23) yield value return value limit 1"); - assertEquals(-2L, result.single().get("value").asLong(),0); - - result = session.run("call com.neo4jh3.gridpathlatlon(37.8199, -122.4783, 47.8199, -222.5, 13) yield value return value limit 1"); - assertEquals(-4L, result.single().get("value").asLong(),0); - - result = session.run("call com.neo4jh3.gridpathlatlonString(97.8199, -122.4783, 47.8199, -122.5, 13) yield value return value limit 1"); - assertEquals("\"-3\"", result.single().get("value").toString()); - - result = session.run("call com.neo4jh3.gridpathlatlonString(37.8199, -122.4783, 47.8199, -122.5, 23) yield value return value limit 1"); - assertEquals("\"-2\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.pointash3String('POINT(37.8199 -122.4783)',13, 'latlon') AS value"); + assertEquals("\"8d283087022a93f\"", result.single().get("value").toString()); - result = session.run("call com.neo4jh3.gridpathlatlonString(37.8199, -122.4783, 47.8199, -222.5, 13) yield value return value limit 1"); - assertEquals("\"-4\"", result.single().get("value").toString()); - - result = session.run("call com.neo4jh3.gridpathlatlonString(37.8199, -122.4783, 47.8199, -122.5, 13) yield value return value limit 1"); - assertEquals("\"8d283087022a93f\"", result.single().get("value").toString()); + result = session.run("RETURN com.neo4jh3.pointash3String('POINT(-122.4783 37.8199)',13, 'lonlat') AS value"); + assertEquals("\"8d283087022a93f\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.pointash3String('POINT(-122.4783 37.8199)',16, 'lonlat') AS value"); + assertEquals("\"-2\"", result.single().get("value").toString()); + + result = session.run("RETURN com.neo4jh3.ispentagon(590112357393367039) AS value"); + assertEquals(true, result.single().get("value").asBoolean()); + + result = session.run("RETURN com.neo4jh3.ispentagon(12345) AS value"); + assertEquals(false, result.single().get("value").asBoolean()); + + result = session.run("RETURN com.neo4jh3.ispentagonString('85283473fffffff') AS value"); + assertEquals(false, result.single().get("value").asBoolean()); + + result = session.run("call com.neo4jh3.gridpathlatlon(37.8199, -122.4783, 47.8199, -122.5, 13) yield value return value limit 1"); + assertEquals(635714569676958015L, result.single().get("value").asLong(),0); + + result = session.run("call com.neo4jh3.gridpathlatlon(97.8199, -122.4783, 47.8199, -122.5, 13) yield value return value limit 1"); + assertEquals(-3L, result.single().get("value").asLong(),0); + + result = session.run("call com.neo4jh3.gridpathlatlon(37.8199, -122.4783, 47.8199, -122.5, 23) yield value return value limit 1"); + assertEquals(-2L, result.single().get("value").asLong(),0); + + result = session.run("call com.neo4jh3.gridpathlatlon(37.8199, -122.4783, 47.8199, -222.5, 13) yield value return value limit 1"); + assertEquals(-4L, result.single().get("value").asLong(),0); + + result = session.run("call com.neo4jh3.gridpathlatlonString(97.8199, -122.4783, 47.8199, -122.5, 13) yield value return value limit 1"); + assertEquals("\"-3\"", result.single().get("value").toString()); + + result = session.run("call com.neo4jh3.gridpathlatlonString(37.8199, -122.4783, 47.8199, -122.5, 23) yield value return value limit 1"); + assertEquals("\"-2\"", result.single().get("value").toString()); + + result = session.run("call com.neo4jh3.gridpathlatlonString(37.8199, -122.4783, 47.8199, -222.5, 13) yield value return value limit 1"); + assertEquals("\"-4\"", result.single().get("value").toString()); + + result = session.run("call com.neo4jh3.gridpathlatlonString(37.8199, -122.4783, 47.8199, -122.5, 13) yield value return value limit 1"); + assertEquals("\"8d283087022a93f\"", result.single().get("value").toString()); + + result=session.run("call com.neo4jh3.linepolyIntersection(['37.271355,-121.915080','37.353926,-121.862223','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798','37.271355,-121.915080'],[],'LINESTRING(( 37.271355 -121.915080), (37.353926 -121.862223))',7,'latlon') yield value return value limit 1"); + assertEquals(608693241537101823L, result.single().get(0).asLong(),0); + + result=session.run("call com.neo4jh3.linepolyIntersection(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],'LINESTRING((37.271355 -121.915080), (37.353926 -121.862223))',27,'latlon') yield value return value limit 1"); + assertEquals(-2L, result.single().get(0).asLong(),0); + + result = session.run("call com.neo4jh3.polygonash3('POLYGON((-84.3641541604937 33.71316821215546,-84.36414611386687 33.71303657522174,-84.36409515189553 33.71303657522174,-84.36410319852232 33.71317267442025,-84.3641541604937 33.71316821215546))',13) yield value return value limit 1"); + assertEquals(636217124138601599L,result.single().get(0).asLong()); + + result = session.run("call com.neo4jh3.polygonash3('POLYGON((-84.3641541604937 33.71316821215546, -84.36414611386687 33.71303657522174 ,-84.36409515189553 33.71303657522174 ,-84.36410319852232 33.71317267442025,-84.3641541604937 33.71316821215546))',13) yield value return value limit 1"); + assertEquals(636217124138601599L,result.single().get(0).asLong()); + + result = session.run("call com.neo4jh3.polygonash3('POLYGON((-77.436031 38.471420, -77.395123 38.536569, -77.294124 38.511703, -77.310611 38.395709, -77.436031 38.471420))',13) yield value return value limit 1"); + assertEquals(635758222702368959L,result.single().get(0).asLong()); - result=session.run("call com.neo4jh3.linepolyIntersection(['37.271355,-121.915080','37.353926,-121.862223','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798','37.271355,-121.915080'],[],'LINESTRING((37.271355 -121.915080), (37.353926 -121.862223))',7,'latlon') yield value return value limit 1"); - assertEquals(608693241537101823L, result.single().get(0).asLong(),0); + result = session.run("call com.neo4jh3.polygonash3('POLYGON((-77.436031 38.471420, -77.395123 38.536569, -77.294124 38.511703, -77.310611 38.395709, -77.436031 38.471420))',19) yield value return value limit 1"); + assertEquals(-2L,result.single().get(0).asLong()); - result=session.run("call com.neo4jh3.linepolyIntersection(['37.7866,-122.3805','37.7198,-122.3544','37.7076,-122.5123','37.7835,-122.5247','37.8151,-122.4798'],[],'LINESTRING((37.271355 -121.915080), (37.353926 -121.862223))',27,'latlon') yield value return value limit 1"); - assertEquals(-2L, result.single().get(0).asLong(),0); + result = session.run("call com.neo4jh3.polygonash3String('POLYGON((-77.436031 38.471420, -77.395123 38.536569, -77.294124 38.511703, -77.310611 38.395709, -77.436031 38.471420))',13) yield value return value limit 1"); + assertEquals("\"8d2aabc333558bf\"",result.single().get(0).toString()); } driver.close();