Spaces:
Sleeping
Sleeping
cassiebuhler
commited on
Commit
•
cae0459
1
Parent(s):
2cc9bf8
omitted cities in party pmtiles; too many features for tippecanoe
Browse files- get_party.ipynb +10 -11
get_party.ipynb
CHANGED
@@ -123,7 +123,7 @@
|
|
123 |
" .cast({\"geometry\": \"geometry\",\"municipal\": \"string\"})\n",
|
124 |
" .mutate(jurisdiction = ibis.literal(\"County\"))\n",
|
125 |
" .select(\"state\", \"county\", \"municipal\",\"jurisdiction\",\"geometry\", \"year\", \"party\")\n",
|
126 |
-
" )"
|
127 |
]
|
128 |
},
|
129 |
{
|
@@ -162,7 +162,7 @@
|
|
162 |
"id": "ae5b417d-4266-456d-952c-ac2696234ea0",
|
163 |
"metadata": {},
|
164 |
"source": [
|
165 |
-
"# Make PMTiles. Each jurisdiction type is its own layer"
|
166 |
]
|
167 |
},
|
168 |
{
|
@@ -188,7 +188,7 @@
|
|
188 |
" repo_id=repo_id,\n",
|
189 |
" repo_type=\"dataset\",\n",
|
190 |
" )\n",
|
191 |
-
"def generate_pmtiles(input_file, input_file2,
|
192 |
" # Ensure Tippecanoe is installed\n",
|
193 |
" if subprocess.call([\"which\", \"tippecanoe\"], stdout=subprocess.DEVNULL) != 0:\n",
|
194 |
" raise RuntimeError(\"Tippecanoe is not installed or not in PATH\")\n",
|
@@ -202,16 +202,14 @@
|
|
202 |
" \"--force\",\n",
|
203 |
" \"--projection\", \"EPSG:4326\", \n",
|
204 |
" \"-L\",\"state:\"+input_file,\n",
|
205 |
-
" \"-L\",\"county:\"+input_file2
|
206 |
-
" \"-L\",\"municipal:\"+input_file3\n",
|
207 |
" ]\n",
|
208 |
" # Run Tippecanoe\n",
|
209 |
" try:\n",
|
210 |
" subprocess.run(command, check=True)\n",
|
211 |
" print(f\"Successfully generated PMTiles file: {output_file}\")\n",
|
212 |
" except subprocess.CalledProcessError as e:\n",
|
213 |
-
" print(f\"Error running Tippecanoe: {e}\")\n"
|
214 |
-
"\n"
|
215 |
]
|
216 |
},
|
217 |
{
|
@@ -227,10 +225,11 @@
|
|
227 |
"gdf_county = df_county.execute().set_crs(\"EPSG:4326\")\n",
|
228 |
"gdf_county.to_file(\"party_county.geojson\")\n",
|
229 |
"\n",
|
230 |
-
"
|
231 |
-
"gdf_city.
|
|
|
232 |
"\n",
|
233 |
-
"generate_pmtiles(\"party_state.geojson\", \"party_county.geojson\"
|
234 |
"hf_upload(\"party_polygons.pmtiles\", \"boettiger-lab/landvote\")\n"
|
235 |
]
|
236 |
},
|
@@ -272,7 +271,7 @@
|
|
272 |
"name": "python",
|
273 |
"nbconvert_exporter": "python",
|
274 |
"pygments_lexer": "ipython3",
|
275 |
-
"version": "3.
|
276 |
}
|
277 |
},
|
278 |
"nbformat": 4,
|
|
|
123 |
" .cast({\"geometry\": \"geometry\",\"municipal\": \"string\"})\n",
|
124 |
" .mutate(jurisdiction = ibis.literal(\"County\"))\n",
|
125 |
" .select(\"state\", \"county\", \"municipal\",\"jurisdiction\",\"geometry\", \"year\", \"party\")\n",
|
126 |
+
" )\n"
|
127 |
]
|
128 |
},
|
129 |
{
|
|
|
162 |
"id": "ae5b417d-4266-456d-952c-ac2696234ea0",
|
163 |
"metadata": {},
|
164 |
"source": [
|
165 |
+
"# Make PMTiles with only state/county. Each jurisdiction type is its own layer. "
|
166 |
]
|
167 |
},
|
168 |
{
|
|
|
188 |
" repo_id=repo_id,\n",
|
189 |
" repo_type=\"dataset\",\n",
|
190 |
" )\n",
|
191 |
+
"def generate_pmtiles(input_file, input_file2, output_file, max_zoom=12):\n",
|
192 |
" # Ensure Tippecanoe is installed\n",
|
193 |
" if subprocess.call([\"which\", \"tippecanoe\"], stdout=subprocess.DEVNULL) != 0:\n",
|
194 |
" raise RuntimeError(\"Tippecanoe is not installed or not in PATH\")\n",
|
|
|
202 |
" \"--force\",\n",
|
203 |
" \"--projection\", \"EPSG:4326\", \n",
|
204 |
" \"-L\",\"state:\"+input_file,\n",
|
205 |
+
" \"-L\",\"county:\"+input_file2\n",
|
|
|
206 |
" ]\n",
|
207 |
" # Run Tippecanoe\n",
|
208 |
" try:\n",
|
209 |
" subprocess.run(command, check=True)\n",
|
210 |
" print(f\"Successfully generated PMTiles file: {output_file}\")\n",
|
211 |
" except subprocess.CalledProcessError as e:\n",
|
212 |
+
" print(f\"Error running Tippecanoe: {e}\")\n"
|
|
|
213 |
]
|
214 |
},
|
215 |
{
|
|
|
225 |
"gdf_county = df_county.execute().set_crs(\"EPSG:4326\")\n",
|
226 |
"gdf_county.to_file(\"party_county.geojson\")\n",
|
227 |
"\n",
|
228 |
+
"# city data too large to add to pmtiles :( \n",
|
229 |
+
"# gdf_city = df_city.execute().set_crs(\"EPSG:4326\")\n",
|
230 |
+
"# gdf_city.to_file(\"party_municipal.geojson\")\n",
|
231 |
"\n",
|
232 |
+
"generate_pmtiles(\"party_state.geojson\", \"party_county.geojson\", \"party_polygons.pmtiles\")\n",
|
233 |
"hf_upload(\"party_polygons.pmtiles\", \"boettiger-lab/landvote\")\n"
|
234 |
]
|
235 |
},
|
|
|
271 |
"name": "python",
|
272 |
"nbconvert_exporter": "python",
|
273 |
"pygments_lexer": "ipython3",
|
274 |
+
"version": "3.12.7"
|
275 |
}
|
276 |
},
|
277 |
"nbformat": 4,
|