File size: 1,911 Bytes
1c76a96
 
 
 
 
656f25c
 
d1dca6b
1c76a96
d1dca6b
1c76a96
656f25c
 
 
 
1c76a96
d1dca6b
 
1c76a96
656f25c
 
 
 
 
 
d1dca6b
 
 
656f25c
 
 
 
 
 
d1dca6b
656f25c
1c76a96
d1dca6b
 
1c76a96
 
 
656f25c
 
 
 
 
 
 
 
 
d1dca6b
656f25c
 
 
d1dca6b
 
656f25c
 
d1dca6b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'''
# LandVote Prototype

'''

import ibis
from ibis import _
import streamlit as st

conn = ibis.duckdb.connect(extensions=["spatial"])

state_boundaries = "https://data.source.coop/cboettig/us-boundaries/us-state-territory.parquet"
county_boundaries = "https://data.source.coop/cboettig/us-boundaries/us-county.parquet"
states = conn.read_parquet(state_boundaries).rename(state_id = "STUSPS", state = "NAME")
county = conn.read_parquet(county_boundaries).rename(county = "NAMELSAD", state = "STATE_NAME")

votes = conn.read_csv("landvote.csv")
votes.count().execute()

vote = (votes
       .filter(_["Jurisdiction Type"] == "County")
       .rename(county = "Jurisdiction Name", state_id = "State")
       .mutate(key = _.county + ibis.literal('-') + _.state_id)
       .rename(amount = 'Conservation Funds at Stake', yes = '% Yes')
       .mutate(amount_n=_.amount.replace('$', '').replace(',', '').cast('float'))
       .mutate(log_amount=_.amount_n.log())
       .mutate(year=_['Date'].year().cast('int32'))
       .select('key', 'Status', 'yes', 'year', 'amount', 'log_amount', )
       )
df = (county
      .join(states.select("state", "state_id"), "state")
      .mutate(key = _.county + ibis.literal('-') + _.state_id)
      .select('key', 'geometry')
      .right_join(vote, "key")
      .drop('key_right')
     )

year = st.slider("Select a year", min_value=1988, max_value=2024, value=2022, step=1)
gdf = df.filter(_.year==year).execute()



outcome = [
      'match',
      ['get', 'Status'], 
      "Pass", '#2E865F',
      "Fail", '#FF3300', 
      '#ccc'
    ]
paint = {"fill-extrusion-color": outcome, 
         "fill-extrusion-opacity": 0.7,
         "fill-extrusion-height": ["*", ["get", "log_amount"], 5000],
        }

#m.add_geojson("vote.geojson")
import leafmap.maplibregl as leafmap
m = leafmap.Map(style="positron")
m.add_gdf(gdf, "fill-extrusion", paint = paint)
m.to_streamlit()