From 57227b6b10b4a98a87d87f40b1f75f4ffc63127b Mon Sep 17 00:00:00 2001 From: Will Cohen Date: Tue, 2 Apr 2024 15:51:45 -0400 Subject: [PATCH] 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)