Skip to content

Commit

Permalink
Seattle parks - minor refactoring, added features to datasets, added …
Browse files Browse the repository at this point in the history
…park proportions choropleth
  • Loading branch information
daslu committed Jan 24, 2024
1 parent 4ff375a commit 6b3d952
Showing 1 changed file with 47 additions and 14 deletions.
61 changes: 47 additions & 14 deletions projects/geography/seattle-parks/notebooks/index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
[scicloj.kindly.v4.kind :as kind]
[scicloj.kindly.v4.api :as kindly]
[hiccup.core :as hiccup]
[charred.api :as charred])
[charred.api :as charred]
[clojure2d.color :as color])
(:import (org.locationtech.jts.index.strtree STRtree)
(org.locationtech.jts.geom Geometry Point Polygon Coordinate)
(org.locationtech.jts.geom.prep PreparedGeometry
Expand Down Expand Up @@ -178,14 +179,17 @@ We will enrich every feature (e.g., neighborhood) with data relevant for its vis
details]
{:reagent/deps [:leaflet]})))

(defn Seattle-choropleth-map [enriched-features]
(choropleth-map
{:tile-layer openstreetmap-tile-layer
:center Seattle-center
:enriched-features enriched-features}))

(md "For our basic neighborhoods map:")

(delay
(choropleth-map
{:tile-layer openstreetmap-tile-layer
:center Seattle-center
:enriched-features neighborhoods-enriched-features}))
(Seattle-choropleth-map
neighborhoods-enriched-features))


(md "Now, let us see the parks:")
Expand All @@ -203,14 +207,10 @@ We will enrich every feature (e.g., neighborhood) with data relevant for its vis
:color "darkgreen"
:fillColor "darkgreen"}})))))))

(delay
(choropleth-map
{:tile-layer openstreetmap-tile-layer
:center Seattle-center
:enriched-features parks-enriched-features}))



(delay
(Seattle-choropleth-map
parks-enriched-features))

(md "## Coordinate conversions")

Expand Down Expand Up @@ -268,7 +268,8 @@ which is locally correct in terms of distances in a region around Seattle.

(def neighborhoods
(-> neighborhoods-features
(geojson->dataset "Seattle neighborhoods")))
(geojson->dataset "Seattle neighborhoods")
(tc/add-column :feature neighborhoods-enriched-features)))

(delay
(-> neighborhoods
Expand Down Expand Up @@ -411,7 +412,39 @@ For every neighborhood, we will compute the proportion of its area covered by pa
(tc/head 10)
plot-neighborhoods-with-park-proportions))

;; # A choroplety colored by park proportions
;; ## Representing park proportions as colors

(def gradient
(color/gradient [:grey :green]))

(delay
(-> 0.4
gradient
color/format-hex))

(delay
(-> neighborhoods-with-park-proportions
(tc/map-columns :feature
[:feature :park-proportion]
(fn [feature park-proportion]
(let [color (-> park-proportion
gradient
color/format-hex)]
(-> feature
(update-in
[:properties :style]
(fn [style]
(-> style
(assoc :color color
:fillColor color
:opacity 0.5
:fillOpacity 0.5))))))))
:feature
vec
Seattle-choropleth-map))


;; ## A choropleth colored by park proportions



Expand Down

0 comments on commit 6b3d952

Please sign in to comment.