From d3dea146f8e57f39cd037cc882c4d8a49edce11e Mon Sep 17 00:00:00 2001 From: Will Cohen Date: Wed, 5 Jan 2022 13:05:16 -0500 Subject: [PATCH 1/4] Update dependencies --- deps.edn | 22 +++++++++++----------- project.clj | 22 +++++++++++----------- test/geo/t_h3.clj | 22 ++++++++++------------ test/geo/t_jts.clj | 10 +++++----- 4 files changed, 37 insertions(+), 39 deletions(-) diff --git a/deps.edn b/deps.edn index a9b76c4..5f7fd37 100644 --- a/deps.edn +++ b/deps.edn @@ -2,21 +2,21 @@ {:1.7 {:extra-deps #:org.clojure{clojure #:mvn{:version "1.7.0"}}}, :1.8 {:extra-deps #:org.clojure{clojure #:mvn{:version "1.8.0"}}}, :1.9 {:extra-deps #:org.clojure{clojure #:mvn{:version "1.9.0"}}}, - :dev {:extra-deps {cheshire #:mvn{:version "5.9.0"}, + :dev {:extra-deps {cheshire #:mvn{:version "5.10.1"}, codox-theme-rdash #:mvn{:version "0.1.2"}, com.fasterxml.jackson.core/jackson-core #:mvn{:version "2.10.2"}, com.fasterxml.jackson.dataformat/jackson-dataformat-cbor #:mvn{:version "2.10.2"}, com.fasterxml.jackson.dataformat/jackson-dataformat-smile #:mvn{:version "2.10.2"}, - criterium #:mvn{:version "0.4.5"}, - midje #:mvn{:version "1.9.9"}, - org.clojure/clojure #:mvn{:version "1.10.1"}}}}, + criterium #:mvn{:version "0.4.6"}, + midje #:mvn{:version "1.10.5"}, + org.clojure/clojure #:mvn{:version "1.10.3"}}}}, :deps {ch.hsr/geohash #:mvn{:version "1.4.0"}, - com.uber/h3 #:mvn{:version "3.6.3"}, - org.clojure/math.numeric-tower #:mvn{:version "0.0.4"}, - org.locationtech.jts.io/jts-io-common #:mvn{:version "1.16.1"}, - org.locationtech.jts/jts-core #:mvn{:version "1.16.1"}, - org.locationtech.proj4j/proj4j #:mvn{:version "1.1.0"}, - org.locationtech.spatial4j/spatial4j #:mvn{:version "0.7"}, - org.wololo/jts2geojson #:mvn{:version "0.14.3"}}, + com.uber/h3 #:mvn{:version "3.7.1"}, + org.clojure/math.numeric-tower #:mvn{:version "0.0.5"}, + org.locationtech.jts.io/jts-io-common #:mvn{:version "1.18.2"}, + org.locationtech.jts/jts-core #:mvn{:version "1.18.2"}, + org.locationtech.proj4j/proj4j #:mvn{:version "1.1.4"}, + org.locationtech.spatial4j/spatial4j #:mvn{:version "0.8"}, + org.wololo/jts2geojson #:mvn{:version "0.16.1"}}, :mvn/repos {"releases" {:url "https://clojars.org/repo"}, "snapshots" {:url "https://clojars.org/repo"}}} diff --git a/project.clj b/project.clj index 8ce7f1b..61bc158 100644 --- a/project.clj +++ b/project.clj @@ -7,24 +7,24 @@ :comments "same as Clojure"} :description "Geospatial operations over points, lines, polys, geohashes, etc." :dependencies - [[org.clojure/math.numeric-tower "0.0.4"] + [[org.clojure/math.numeric-tower "0.0.5"] [ch.hsr/geohash "1.4.0"] - [com.uber/h3 "3.6.3"] - [org.locationtech.proj4j/proj4j "1.1.0"] - [org.locationtech.spatial4j/spatial4j "0.7"] - [org.locationtech.jts/jts-core "1.16.1"] - [org.locationtech.jts.io/jts-io-common "1.16.1"] - [org.wololo/jts2geojson "0.14.3"]] + [com.uber/h3 "3.7.1"] + [org.locationtech.proj4j/proj4j "1.1.4"] + [org.locationtech.spatial4j/spatial4j "0.8"] + [org.locationtech.jts/jts-core "1.18.2"] + [org.locationtech.jts.io/jts-io-common "1.18.2"] + [org.wololo/jts2geojson "0.16.1"]] :codox {:themes [:rdash]} :profiles {:dev {:global-vars {*warn-on-reflection* true} :plugins [[lein-midje "3.2.2"] [lein-codox "0.10.7"] [lein-project-version "0.1.0"]] - :dependencies [[org.clojure/clojure "1.10.1"] + :dependencies [[org.clojure/clojure "1.10.3"] [codox-theme-rdash "0.1.2"] - [criterium "0.4.5"] - [cheshire "5.10.0"] - [midje "1.9.9"]]} + [criterium "0.4.6"] + [cheshire "5.10.1"] + [midje "1.10.5"]]} :1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]} :1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]} :1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}} diff --git a/test/geo/t_h3.clj b/test/geo/t_h3.clj index 738c66e..fa0beae 100644 --- a/test/geo/t_h3.clj +++ b/test/geo/t_h3.clj @@ -159,28 +159,26 @@ "871f24accffffff" "871f24aebffffff" "871f24ae8ffffff" "871f24aecffffff" "871f24ae1ffffff" "871f24ae0ffffff"]]) (fact "polyfill" - (sut/polyfill (geohash/geohash "u4pruy") 9) => [617541026878062591 - 617541026799157247 + (sut/polyfill (geohash/geohash "u4pruy") 9) => [617541026877538303 617541026800992255 - 617541026877538303 + 617541026878062591 + 617541026799157247 617541026879111167] - (sut/polyfill-address (geohash/geohash "u4pruy") 9) => ["891f24ac54bffff" - "891f24ac097ffff" + (sut/polyfill-address (geohash/geohash "u4pruy") 9) => ["891f24ac543ffff" "891f24ac0b3ffff" - "891f24ac543ffff" + "891f24ac54bffff" + "891f24ac097ffff" "891f24ac55bffff"] (-> (jts/multi-polygon [(spatial/to-jts (geohash/geohash "u4pruy")) (spatial/to-jts (geohash/geohash "u4pruu"))]) (sut/polyfill 9)) - => [617541026878062591 617541026799157247 617541026800992255 617541026877538303 - 617541026879111167 617541026790244351 617541026789982207 617541026789720063 - 617541026789457919] + => [617541026877538303 617541026800992255 617541026878062591 617541026799157247 + 617541026879111167 617541026790244351 617541026789457919 617541026789982207 617541026789720063] (-> (jts/multi-polygon [(spatial/to-jts (geohash/geohash "u4pruy")) (spatial/to-jts (geohash/geohash "u4pruu"))]) (sut/polyfill-address 9)) - => ["891f24ac54bffff" "891f24ac097ffff" "891f24ac0b3ffff" "891f24ac543ffff" - "891f24ac55bffff" "891f24ac00fffff" "891f24ac00bffff" "891f24ac007ffff" - "891f24ac003ffff"] + => ["891f24ac543ffff" "891f24ac0b3ffff" "891f24ac54bffff" "891f24ac097ffff" + "891f24ac55bffff" "891f24ac00fffff" "891f24ac003ffff" "891f24ac00bffff" "891f24ac007ffff"] (count (sut/polyfill geohash-with-hole 12)) => 1648) (fact "polyfill works recursively on large shapes" (count (sut/polyfill (jts/polygon-wkt [[-70 42 -70 44 -68 44 -68 42 -70 42]]) 7)) => 6769 diff --git a/test/geo/t_jts.clj b/test/geo/t_jts.clj index eef3435..bafcc9e 100644 --- a/test/geo/t_jts.clj +++ b/test/geo/t_jts.clj @@ -133,12 +133,12 @@ (facts "proj4j" (fact "point: 3 param transform" (same-geom? (transform-geom (point 3.8142776 51.285914 4326) 23031) - (point 556878.9016076007 5682145.166264554 23031)) + (point 556878.9016075989 5682145.166262922 23031)) => truthy (same-geom? (set-srid (transform-geom (point 3.8142776 51.285914 4326) "+proj=utm +zone=31 +ellps=intl +towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs") 23031) - (point 556878.9016076007 5682145.166264554 23031)) + (point 556878.9016075989 5682145.166262922 23031)) => truthy (spatial/latitude (point 556878.9016076007 5682145.166264554 23031)) => (roughly 51.285914 0.000001) @@ -167,12 +167,12 @@ (fact "geometry: projection can happen using an external transform object, though SRID may be set to 0 if it cannot be determined." (same-geom? (transform-geom (point 3.8142776 51.285914 4326) (crs/create-transform 4326 23031)) - (point 556878.9016076007 5682145.166264554 23031)) + (point 556878.9016075989 5682145.166262922 23031)) => truthy) (fact "An EPSG can be specified as a number, an 'EPSG:XXXX' string, as an equivalent proj4 string, or a proj4j CRS object." (let [p1 (point 3.8142776 51.285914 4326) - p2 (point 556878.9016076007 5682145.166264554 23031)] + p2 (point 556878.9016075989 5682145.166262922 23031)] (same-geom? (transform-geom p1 23031) p2) => truthy (same-geom? (transform-geom p1 "EPSG:23031") p2) @@ -185,7 +185,7 @@ => 23031)) (fact "If using a different CRS name or proj4 string, SRID is not automatically set" (let [p1 (point 3.8142776 51.285914 4326) - p2 (point 556878.9016076007 5682145.166264554 23031)] + p2 (point 556878.9016075989 5682145.166262922 23031)] (same-geom? (-> (transform-geom p1 "+proj=utm +zone=31 +ellps=intl +towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs") (set-srid 23031)) p2) From bda5f5af7e26c46fb107865735a77446e423ed80 Mon Sep 17 00:00:00 2001 From: Will Cohen Date: Thu, 6 Jan 2022 10:43:07 -0500 Subject: [PATCH 2/4] Add nix flake and clj-build framework for CI --- README.md | 14 ++++++++++++++ deps.edn | 6 +++++- flake.lock | 43 +++++++++++++++++++++++++++++++++++++++++++ flake.nix | 27 +++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/README.md b/README.md index 96ef906..2a12659 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,20 @@ update the `deps.edn` from the project root is: `clj -A:depify | clj -A:zprint > deps.edn.tmp ; mv deps.edn.tmp deps.edn` +# Development environment using nix + +For a reproducible development environment, `geo` provides a `flake.nix`. + +On a machine with nix installed: + +``` bash +$ nix develop +... + +$ clj -T:build ci +$ clj -T:build install +``` + # License This project and many of its dependencies are licensed under the Eclipse Public diff --git a/deps.edn b/deps.edn index 5f7fd37..f76eaae 100644 --- a/deps.edn +++ b/deps.edn @@ -9,7 +9,11 @@ com.fasterxml.jackson.dataformat/jackson-dataformat-smile #:mvn{:version "2.10.2"}, criterium #:mvn{:version "0.4.6"}, midje #:mvn{:version "1.10.5"}, - org.clojure/clojure #:mvn{:version "1.10.3"}}}}, + org.clojure/clojure #:mvn{:version "1.10.3"}} + :main-opts ["-m"]} + :build {:deps {io.github.seancorfield/build-clj + {:git/tag "v0.6.7" :git/sha "22c2d09"}} + :ns-default build}} :deps {ch.hsr/geohash #:mvn{:version "1.4.0"}, com.uber/h3 #:mvn{:version "3.7.1"}, org.clojure/math.numeric-tower #:mvn{:version "0.0.5"}, diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1611d26 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1641479610, + "narHash": "sha256-XqdVcA3/2vhknfnhMmLUpbI0VqSucgso5RJ6Hm8GoXU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e4f818576620732ec564d21e88e96b579d9a0782", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "master", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6b04bfa --- /dev/null +++ b/flake.nix @@ -0,0 +1,27 @@ +{ + description = "Flake to manage clojure workspace"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/master"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + in { + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + clojure + jdk + leiningen + ]; + shellHook = '' + export JAVA_HOME=${pkgs.jdk} + PATH="${pkgs.jdk}/bin:$PATH" + ''; + }; + }); +} From 86ab5a7d17d5ada8a95e6825129ab8cd1e8cdb06 Mon Sep 17 00:00:00 2001 From: Will Cohen Date: Thu, 6 Jan 2022 10:48:07 -0500 Subject: [PATCH 3/4] Add build.clj --- build.clj | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 build.clj diff --git a/build.clj b/build.clj new file mode 100644 index 0000000..f9bf581 --- /dev/null +++ b/build.clj @@ -0,0 +1,31 @@ +(ns build + "Geo build script. + + clojure -T:build ci + + clojure -T:build install + + clojure -T:build deploy" + + (:require [clojure.tools.build.api :as b] + [org.corfield.build :as bb])) + +(def lib 'Factual/geo) +(def version "3.0.1") + +(defn ci "Run the CI pipeline of tests (and build the JAR)." [opts] + (-> opts + (assoc :lib lib :version version) + ;(bb/run-tests) ;; Pending move to clojure.test and cljs + (bb/clean) + (bb/jar))) + +(defn install "Install the JAR locally." [opts] + (-> opts + (assoc :lib lib :version version) + (bb/install))) + +(defn deploy "Deploy the JAR to Clojars." [opts] + (-> opts + (assoc :lib lib :version version) + (bb/install))) From 57227b6b10b4a98a87d87f40b1f75f4ffc63127b Mon Sep 17 00:00:00 2001 From: Will Cohen Date: Tue, 2 Apr 2024 15:51:45 -0400 Subject: [PATCH 4/4] Update dependencies --- deps.edn | 27 +++++------ project.clj | 13 +++--- src/geo/h3.clj | 108 ++++++++++++++++++++++---------------------- src/geo/spatial.clj | 10 ++-- test/geo/t_h3.clj | 8 ++-- 5 files changed, 84 insertions(+), 82 deletions(-) diff --git a/deps.edn b/deps.edn index f76eaae..4299c72 100644 --- a/deps.edn +++ b/deps.edn @@ -2,25 +2,26 @@ {:1.7 {:extra-deps #:org.clojure{clojure #:mvn{:version "1.7.0"}}}, :1.8 {:extra-deps #:org.clojure{clojure #:mvn{:version "1.8.0"}}}, :1.9 {:extra-deps #:org.clojure{clojure #:mvn{:version "1.9.0"}}}, - :dev {:extra-deps {cheshire #:mvn{:version "5.10.1"}, - codox-theme-rdash #:mvn{:version "0.1.2"}, + :dev {:extra-deps {cheshire/cheshire #:mvn{:version "5.10.1"}, + codox-theme-rdash/codox-theme-rdash #:mvn{:version "0.1.2"}, com.fasterxml.jackson.core/jackson-core #:mvn{:version "2.10.2"}, com.fasterxml.jackson.dataformat/jackson-dataformat-cbor #:mvn{:version "2.10.2"}, com.fasterxml.jackson.dataformat/jackson-dataformat-smile #:mvn{:version "2.10.2"}, - criterium #:mvn{:version "0.4.6"}, - midje #:mvn{:version "1.10.5"}, + criterium/criterium #:mvn{:version "0.4.6"}, + midje/midje #:mvn{:version "1.10.5"}, org.clojure/clojure #:mvn{:version "1.10.3"}} - :main-opts ["-m"]} + :main-opts ["-m"]}, :build {:deps {io.github.seancorfield/build-clj {:git/tag "v0.6.7" :git/sha "22c2d09"}} - :ns-default build}} + :ns-default build}}}, :deps {ch.hsr/geohash #:mvn{:version "1.4.0"}, - com.uber/h3 #:mvn{:version "3.7.1"}, - org.clojure/math.numeric-tower #:mvn{:version "0.0.5"}, - org.locationtech.jts.io/jts-io-common #:mvn{:version "1.18.2"}, - org.locationtech.jts/jts-core #:mvn{:version "1.18.2"}, - org.locationtech.proj4j/proj4j #:mvn{:version "1.1.4"}, + com.uber/h3 #:mvn{:version "4.1.1"}, + org.clojure/math.numeric-tower #:mvn{:version "0.1.0"}, + org.locationtech.jts.io/jts-io-common #:mvn{:version "1.19.0"}, + org.locationtech.jts/jts-core #:mvn{:version "1.19.0"}, + org.locationtech.proj4j/proj4j #:mvn{:version "1.3.0"}, + org.locationtech.proj4j/proj4j-epsg #:mvn{:version "1.3.0"}, org.locationtech.spatial4j/spatial4j #:mvn{:version "0.8"}, - org.wololo/jts2geojson #:mvn{:version "0.16.1"}}, + org.wololo/jts2geojson #:mvn{:version "0.18.1"}}, :mvn/repos {"releases" {:url "https://clojars.org/repo"}, - "snapshots" {:url "https://clojars.org/repo"}}} + "snapshots" {:url "https://clojars.org/repo"}} diff --git a/project.clj b/project.clj index 61bc158..06d6e7e 100644 --- a/project.clj +++ b/project.clj @@ -7,14 +7,15 @@ :comments "same as Clojure"} :description "Geospatial operations over points, lines, polys, geohashes, etc." :dependencies - [[org.clojure/math.numeric-tower "0.0.5"] + [[org.clojure/math.numeric-tower "0.1.0"] [ch.hsr/geohash "1.4.0"] - [com.uber/h3 "3.7.1"] - [org.locationtech.proj4j/proj4j "1.1.4"] + [com.uber/h3 "4.1.1"] + [org.locationtech.proj4j/proj4j "1.3.0"] + [org.locationtech.proj4j/proj4j-epsg "1.3.0"] [org.locationtech.spatial4j/spatial4j "0.8"] - [org.locationtech.jts/jts-core "1.18.2"] - [org.locationtech.jts.io/jts-io-common "1.18.2"] - [org.wololo/jts2geojson "0.16.1"]] + [org.locationtech.jts/jts-core "1.19.0"] + [org.locationtech.jts.io/jts-io-common "1.19.0"] + [org.wololo/jts2geojson "0.18.1"]] :codox {:themes [:rdash]} :profiles {:dev {:global-vars {*warn-on-reflection* true} :plugins [[lein-midje "3.2.2"] diff --git a/src/geo/h3.clj b/src/geo/h3.clj index 5f725e9..72fae0a 100644 --- a/src/geo/h3.clj +++ b/src/geo/h3.clj @@ -8,7 +8,7 @@ [clojure.math.numeric-tower :as numeric-tower]) (:import (ch.hsr.geohash GeoHash) (com.uber.h3core AreaUnit H3Core LengthUnit) - (com.uber.h3core.util GeoCoord) + (com.uber.h3core.util LatLng) (geo.spatial Point Shapelike) (org.locationtech.jts.geom Geometry LinearRing MultiPolygon Polygon) (org.locationtech.spatial4j.shape.impl RectangleImpl))) @@ -37,58 +37,58 @@ (.stringToH3 h3-inst h)) (defn- h3->pt-long - "Long helper to return a GeoCoord of the center point of a cell." + "Long helper to return a LatLng of the center point of a cell." [^Long h] - (.h3ToGeo h3-inst h)) + (.cellToLatLng h3-inst h)) (defn- h3->pt-string - "String helper to return a GeoCoord of the center point of a cell." + "String helper to return a LatLng of the center point of a cell." [^String h] - (.h3ToGeo h3-inst h)) + (.cellToLatLng h3-inst h)) (defn- get-resolution-string "String helper to return the resolution of a cell." [^String h] - (.h3GetResolution h3-inst h)) + (.getResolution h3-inst h)) (defn get-resolution-long "Long helper to return the resolution of a cell." [^Long h] - (.h3GetResolution h3-inst h)) + (.getResolution h3-inst h)) (defn get-faces-string "String helper to return the icosahedron faces intersected by a cell, represented by integers 0-19." [^String h] - (into [] (.h3GetFaces h3-inst h))) + (into [] (.getIcosahedronFaces h3-inst h))) (defn get-faces-long "Long helper to return the icosahedron faces intersected by a cell, represented by integers 0-19." [^Long h] - (into [] (.h3GetFaces h3-inst h))) + (into [] (.getIcosahedronFaces h3-inst h))) (defn- k-ring-string "String helper to return a list of neighboring indices in all directions for 'k' rings." [^String h ^Integer k] - (.kRing h3-inst h k)) + (.gridDisk h3-inst h k)) (defn- k-ring-long "Long helper to return a list of neighboring indices in all directions for 'k' rings." [^Long h ^Integer k] - (.kRing h3-inst h k)) + (.gridDisk h3-inst h k)) (defn- k-ring-distances-string "String helper to return a list of neighboring indices in all directions for 'k' rings, ordered by distance from the origin index." [^String h ^Integer k] - (.kRingDistances h3-inst h k)) + (.gridDiskDistances h3-inst h k)) (defn- k-ring-distances-long "String helper to return a list of neighboring indices in all directions for 'k' rings, ordered by distance from the origin index." [^Long h ^Integer k] - (.kRingDistances h3-inst h k)) + (.gridDiskDistances h3-inst h k)) (defn- to-jts-common "Convert a geo boundary to JTS Polygon." @@ -103,127 +103,127 @@ (defn- to-jts-string "String helper for: given an H3 identifier, return a Polygon of that cell." [^String h] - (to-jts-common (.h3ToGeoBoundary h3-inst h))) + (to-jts-common (.cellToBoundary h3-inst h))) (defn- to-jts-long "Long helper for: given an H3 identifier, return a Polygon of that cell." [^Long h] - (to-jts-common (.h3ToGeoBoundary h3-inst h))) + (to-jts-common (.cellToBoundary h3-inst h))) (defn- edge-string "String helper for: given both 'from' and 'to' cells, get a unidirectional edge index." [^String from ^String to] - (.getH3UnidirectionalEdge h3-inst from to)) + (.cellsToDirectedEdge h3-inst from to)) (defn- edge-long "Long helper for: given both 'from' and 'to' cells, get a unidirectional edge index." [^Long from ^Long to] - (.getH3UnidirectionalEdge h3-inst from to)) + (.cellsToDirectedEdge h3-inst from to)) (defn- edge-origin-string "String helper for: given a unidirectional edge, get its origin." [^String edge] - (.getOriginH3IndexFromUnidirectionalEdge h3-inst edge)) + (.getDirectedEdgeOrigin h3-inst edge)) (defn- edge-origin-long "Long helper for: given a unidirectional edge, get its origin." [^Long edge] - (.getOriginH3IndexFromUnidirectionalEdge h3-inst edge)) + (.getDirectedEdgeOrigin h3-inst edge)) (defn- edge-destination-string "String helper for: given a unidirectional edge, get its destination." [^String edge] - (.getDestinationH3IndexFromUnidirectionalEdge h3-inst edge)) + (.getDirectedEdgeDestination h3-inst edge)) (defn- edge-destination-long "Long helper for: given a unidirectional edge, get its destination." [^Long edge] - (.getDestinationH3IndexFromUnidirectionalEdge h3-inst edge)) + (.getDirectedEdgeDestination h3-inst edge)) (defn- edges-string "String helper to get all edges originating from an index." [^String cell] - (into [] (.getH3UnidirectionalEdgesFromHexagon h3-inst cell))) + (into [] (.originToDirectedEdges h3-inst cell))) (defn- edges-long "Long helper to get all edges originating from an index." [^Long cell] - (into [] (.getH3UnidirectionalEdgesFromHexagon h3-inst cell))) + (into [] (.originToDirectedEdges h3-inst cell))) (defn- edge-boundary-string "String helper to get coordinates representing the edge." [^String edge] - (into [] (.getH3UnidirectionalEdgeBoundary h3-inst edge))) + (into [] (.directedEdgeToBoundary h3-inst edge))) (defn- edge-boundary-long "Long helper to get coordinates representing the edge." [^Long edge] - (into [] (.getH3UnidirectionalEdgeBoundary h3-inst edge))) + (into [] (.directedEdgeToBoundary h3-inst edge))) (defn- pentagon?-string "String helper to check if an index is a pentagon" [^String cell] - (.h3IsPentagon h3-inst cell)) + (.isPentagon h3-inst cell)) (defn- pentagon?-long "Long helper to check if an index is a pentagon" [^Long cell] - (.h3IsPentagon h3-inst cell)) + (.isPentagon h3-inst cell)) (defn- is-valid?-string "String helper to check if an index is valid" [^String cell] - (.h3IsValid h3-inst cell)) + (.isValidCell h3-inst cell)) (defn- is-valid?-long "Long helper to check if an index is valid" [^Long cell] - (.h3IsValid h3-inst cell)) + (.isValidCell h3-inst cell)) (defn- neighbors?-string "String helper to check if cells are neighbors" [^String c1 ^String c2] - (.h3IndexesAreNeighbors h3-inst c1 c2)) + (.areNeighborCells h3-inst c1 c2)) (defn- neighbors?-long - "String helper to check if cells are neighbors" + "Long helper to check if cells are neighbors" [^Long c1 ^Long c2] - (.h3IndexesAreNeighbors h3-inst c1 c2)) + (.areNeighborCells h3-inst c1 c2)) (defn- h3-distance-string "String helper to return the distance in number of h3 cells" [^String c1 ^String c2] - (.h3Distance h3-inst c1 c2)) + (.gridDistance h3-inst c1 c2)) (defn- h3-distance-long "Long helper to return the distance in number of h3 cells" [^Long c1 ^Long c2] - (.h3Distance h3-inst c1 c2)) + (.gridDistance h3-inst c1 c2)) (defn- h3-line-string "String helper to return the line of indexes between cells" [^String c1 ^String c2] - (.h3Line h3-inst c1 c2)) + (.gridPathCells h3-inst c1 c2)) (defn- h3-line-long "Long helper to return the line of indexes between cells" [^Long c1 ^Long c2] - (.h3Line h3-inst c1 c2)) + (.gridPathCells h3-inst c1 c2)) (defn- h3-to-center-child-string "String helper to return the center child at the given resolution" [^String cell ^Integer child-res] - (.h3ToCenterChild h3-inst cell child-res)) + (.cellToCenterChild h3-inst cell child-res)) (defn- h3-to-center-child-long "String helper to return the center child at the given resolution" [^Long cell ^Integer child-res] - (.h3ToCenterChild h3-inst cell child-res)) + (.cellToCenterChild h3-inst cell child-res)) (defprotocol H3Index (to-string [this] "Return index as a string.") (to-long [this] "Return index as a long.") - (h3->pt [this] "Return a GeoCoord of the center point of a cell.") + (h3->pt [this] "Return a LatLng of the center point of a cell.") (get-resolution [this] "Return the resolution of a cell.") (get-faces [this] "Return the icosahedron faces intersected by a cell, represented by integers 0-19.") (k-ring [this k] "Return a list of neighboring indices in all directions for 'k' rings.") @@ -338,7 +338,7 @@ ([^Point pt ^Integer res] (pt->h3 (spatial/latitude pt) (spatial/longitude pt) res)) ([^Double lat ^Double lng ^Integer res] - (try (.geoToH3 h3-inst lat lng res) + (try (.latLngToCell h3-inst lat lng res) (catch Exception e (throw (Exception. (string/join ["Failed to complete pt->h3 for lat " lat ", long " lng, ", res " res ". H3 exception message: " e]))))))) @@ -347,13 +347,13 @@ ([^Point pt ^Integer res] (pt->h3-address (spatial/latitude pt) (spatial/longitude pt) res)) ([^Double lat ^Double lng ^Integer res] - (try (.geoToH3Address h3-inst lat lng res) + (try (.latLngToCellAddress h3-inst lat lng res) (catch Exception e (throw (Exception. (string/join ["Failed to complete pt->h3-address for lat " lat ", long " lng, ", res " res ". H3 exception message: " e]))))))) (defn geo-coords - "Return all coordinates for a given Shapelike as GeoCoords" + "Return all coordinates for a given Shapelike as LatLngs" [^Shapelike s] (map spatial/h3-point (jts/coordinates (spatial/to-jts s)))) @@ -402,17 +402,17 @@ "Given a set of H3 cells, return a compacted set of cells, at possibly coarser resolutions." [cells] (cond (number? (first cells)) - (.compact h3-inst cells) + (.compactCells h3-inst cells) (string? (first cells)) - (.compactAddress h3-inst cells))) + (.compactCellAddresses h3-inst cells))) (defn uncompact "Given a set of H3 cells, return an uncompacted set of cells to a certain resolution." [cells res] (cond (number? (first cells)) - (.uncompact h3-inst cells res) + (.uncompactCells h3-inst cells res) (string? (first cells)) - (.uncompactAddress h3-inst cells res))) + (.uncompactCellAddresses h3-inst cells res))) (defn- safe-uncompact "Given a set of H3 cells, if the maximum size of the uncompacted set is below a @@ -439,7 +439,7 @@ (let [h (polyfill-p-common s)] (if (.isEmpty (geo.spatial/to-jts s)) [] - (compact (.polyfillAddress h3-inst (geo-coords (:e h)) (map geo-coords (:i h)) res))))) + (compact (.polygonToCellAddresses h3-inst (geo-coords (:e h)) (map geo-coords (:i h)) res))))) (defn- polyfill-p "Helper to polyfill a single polygon, returning indexes in long form." @@ -447,7 +447,7 @@ (let [h (polyfill-p-common s)] (if (.isEmpty (geo.spatial/to-jts s)) [] - (compact (.polyfill h3-inst (geo-coords (:e h)) (map geo-coords (:i h)) res))))) + (compact (.polygonToCells h3-inst (geo-coords (:e h)) (map geo-coords (:i h)) res))))) (defn- hex-radius-in-meters "See h3's bbox.c." @@ -545,7 +545,7 @@ flatten)))) (defn- geocoord-array-wkt - "Create a wkt-style data structure from a collection of GeoCoords." + "Create a wkt-style data structure from a collection of LatLngs." [coords] (->> coords (map (fn [coord] [(spatial/longitude coord) (spatial/latitude coord)])) @@ -555,7 +555,7 @@ (defn- geocoord-multi-helper "Helper function to pass to postwalk for multi-polygon generators." [v] - (if (instance? GeoCoord (first v)) + (if (instance? LatLng (first v)) (geocoord-array-wkt v) v)) @@ -563,7 +563,7 @@ "Multi-polygon generator for numbers" [cells] (as-> cells v - (.h3SetToMultiPolygon h3-inst v true) + (.cellsToMultiPolygon h3-inst v true) (mapv #(into [] %) v) (walk/postwalk geocoord-multi-helper v) (jts/multi-polygon-wkt v))) @@ -572,7 +572,7 @@ "Multi-polygon generator for strings" [cells] (as-> cells v - (.h3AddressSetToMultiPolygon h3-inst v true) + (.cellAddressesToMultiPolygon h3-inst v true) (mapv #(into [] %) v) (walk/postwalk geocoord-multi-helper v) (jts/multi-polygon-wkt v))) @@ -588,10 +588,10 @@ (defn get-res-0-indexes "Return a collection of all base cells" [] - (.getRes0Indexes h3-inst)) + (.getRes0Cells h3-inst)) (defn get-pentagon-indexes "Return a collection of all topologically pentagonal cells at the given resolution" [res] - (.getPentagonIndexes h3-inst res)) + (.getPentagons h3-inst res)) diff --git a/src/geo/spatial.clj b/src/geo/spatial.clj index f091842..89cdbeb 100644 --- a/src/geo/spatial.clj +++ b/src/geo/spatial.clj @@ -20,7 +20,7 @@ [geo.jts :as jts]) (:import (ch.hsr.geohash WGS84Point) (ch.hsr.geohash.util VincentyGeodesy) - (com.uber.h3core.util GeoCoord) + (com.uber.h3core.util LatLng) (org.locationtech.spatial4j.shape SpatialRelation Shape Rectangle) @@ -142,7 +142,7 @@ ([this c1 c2 geometry-factory] (crs/transform-geom this c1 c2 geometry-factory))) - GeoCoord + LatLng (to-shape [this] (spatial4j-point this)) (to-jts ([this] (jts-point this)) @@ -188,7 +188,7 @@ (to-geohash-point [this] (geohash-point this)) (to-h3-point [this] (h3-point this)) - com.uber.h3core.util.GeoCoord + com.uber.h3core.util.LatLng (latitude [this] (.lat this)) (longitude [this] (.lng this)) (to-spatial4j-point [this] (spatial4j-point this)) @@ -279,11 +279,11 @@ (WGS84Point. lat long))) (defn h3-point - "Returns a GeoCoord used by the H3 library." + "Returns a LatLng used by the H3 library." ([point] (h3-point (latitude point) (longitude point))) ([lat long] - (GeoCoord. lat long))) + (LatLng. lat long))) (def point spatial4j-point) diff --git a/test/geo/t_h3.clj b/test/geo/t_h3.clj index fa0beae..07076f0 100644 --- a/test/geo/t_h3.clj +++ b/test/geo/t_h3.clj @@ -7,7 +7,7 @@ [geo.spatial :as spatial] [midje.sweet :refer [fact facts falsey roughly truthy]]) (:import (org.locationtech.jts.geom Geometry Polygon) - (com.uber.h3core.util GeoCoord))) + (com.uber.h3core.util LatLng))) (def geohash-with-hole (jts/set-srid (.difference (spatial/to-jts (geohash/geohash "u4pruy")) (spatial/to-jts (geohash/geohash "u4pruyk"))) @@ -36,17 +36,17 @@ (fact "jts boundary" (type (sut/to-jts h3-example-str)) => Polygon) (fact "geo coord" - (type (first (sut/geo-coords (geohash/geohash "u4pruy")))) => GeoCoord) + (type (first (sut/geo-coords (geohash/geohash "u4pruy")))) => LatLng) (fact "edges" (sut/edge "871f24ac4ffffff" "871f24ac0ffffff") => "1371f24ac4ffffff" (sut/edge-origin "1371f24ac4ffffff") => "871f24ac4ffffff" (sut/edge-destination "1371f24ac4ffffff") => "871f24ac0ffffff" (sut/edges "871f24ac4ffffff") => ["1171f24ac4ffffff" "1271f24ac4ffffff" "1371f24ac4ffffff" "1471f24ac4ffffff" "1571f24ac4ffffff" "1671f24ac4ffffff"] - (type (first (sut/edge-boundary "1371f24ac4ffffff"))) => GeoCoord) + (type (first (sut/edge-boundary "1371f24ac4ffffff"))) => LatLng) (fact "h3->pt" (str (spatial/to-jts (sut/h3->pt h3-example-str))) - => "POINT (10.423520614389421 57.65506363212537)") + => "POINT (10.423520614389426 57.655063632125355)") (fact "pentagon" (sut/pentagon? "8f28308280f18f2") => falsey (sut/pentagon? "821c07fffffffff") => truthy)