### Build Docker Image Source: https://github.com/kritsanan1/election-geodata/blob/master/docker/README.md Builds the 'eg' Docker image from the Dockerfile in the 'docker' directory. This image is used to run the project's build and publish scripts. ```bash docker build -t eg docker ``` -------------------------------- ### Run Build-Publish Script with Docker Source: https://github.com/kritsanan1/election-geodata/blob/master/docker/README.md Executes the 'build-publish.sh' script within the 'eg' Docker container. It mounts the current directory into the container, sets environment variables from 'docker/env.ini', and sets the working directory to the mounted volume. ```bash docker run -it --rm --env-file docker/env.ini -v `pwd`:/vol -w /vol eg ``` -------------------------------- ### Query and Aggregate Multi-Year Precinct Data Source: https://context7.com/kritsanan1/election-geodata/llms.txt Illustrates how to handle and analyze state data that includes multiple years, allowing for tracking of precinct boundary changes. Examples include querying specific year/state data using OGR and performing aggregation to count precincts per state per year, outputting the results to a CSV file using 'ogr2ogr' with the SQLITE dialect. ```bash # Example: New York has precincts from 2010, 2012, 2014, 2015, 2016, 2017, 2018 # Query all New York 2016 precinctsogrinfo -sql "SELECT county, precinct, name FROM nation \ WHERE state='36' AND year='2016'" \ -geom=NO nation.gpkg # Count precincts by year for analysis of redistrictingogr2ogr -sql "SELECT year, state, COUNT(*) as precinct_count \ FROM nation GROUP BY year, state ORDER BY state, year" \ -dialect SQLITE -f CSV out/precinct_counts.csv nation.gpkg # Expected output structure: year,state,precinct_count 2010,01,2614 2016,02,441 2018,04,1489 ... ``` -------------------------------- ### Transform State Data to WGS84 (EPSG:4326) Source: https://context7.com/kritsanan1/election-geodata/llms.txt Demonstrates coordinate system transformations using 'ogr2ogr'. The examples show converting Alabama data from NAD83 (EPSG:4269) to WGS84 (EPSG:4326) and handling a complex state plane projection for Florida data, outputting to GeoPackage format. It involves SQL queries to select and alias columns, and specifies source and target SRS. ```bash # Example: Transform Alabama from NAD83 to WGS84 ogr2ogr -sql "SELECT '2010' AS year, STATEFP10 AS state, \ COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy \ FROM tl_2012_01_vtd10" \ -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -f GPKG \ out/01-alabama/state.gpkg \ /vsizip/data/01-alabama/statewide/2010/tl_2012_01_vtd10.zip/tl_2012_01_vtd10.shp # Example: Handle complex state plane projection (Florida) ogr2ogr -sql "SELECT '2016' AS year, '12' AS state, \ CASE county WHEN 'DAD' THEN '086' WHEN 'BAK' THEN '003' ... END AS county, \ '12' || countypct AS precinct, 'polygon' AS accuracy \ FROM fl_2016" \ -s_srs '+proj=tmerc +lat_0=24.33333333333333 +lon_0=-81 +k=0.9999411764705882 +x_0=199999.9999999999 +y_0=0 +ellps=GRS80 +units=us-ft +no_defs' \ -t_srs EPSG:4326 -nln state -append -f GPKG \ out/12-florida/state.gpkg \ /vsizip/data/12-florida/statewide/2016/fl_2016_FEST.zip/fl_2016.shp ``` -------------------------------- ### Run Docker Build Pipeline Source: https://context7.com/kritsanan1/election-geodata/llms.txt Executes the complete build pipeline using Docker. This process includes Git validation, GitHub status updates, data rendering, S3 uploads, and conditional file conversions (Shapefile, ZIP, GPKG compression) for the master branch. It requires specific environment variables to be set in a 'docker/env.ini' file. ```bash docker run --env-file docker/env.ini -v $(pwd):/vol -w /vol eg ``` -------------------------------- ### Build Docker Image with Docker Source: https://context7.com/kritsanan1/election-geodata/llms.txt Builds a Docker image for the project using the provided Dockerfile. This image is used within the CI/CD pipeline to build the complete dataset and publish artifacts. ```bash # Build Docker image docker build -t eg docker ``` -------------------------------- ### Download Published National Datasets Source: https://context7.com/kritsanan1/election-geodata/llms.txt Provides commands to download the latest national election geodata from S3. It includes downloading the recommended GeoPackage format, a Shapefile for legacy systems, a preview render, and Python code using GeoPandas to load and inspect the data. An OGR command for querying specific subsets is also included. ```bash # Download national GeoPackage (recommended format) wget https://s3.amazonaws.com/nvkelso-election-geodata/branches/master/nation.gpkg # Download national Shapefile (for legacy GIS tools) wget https://s3.amazonaws.com/nvkelso-election-geodata/branches/master/nation-shp.zip unzip nation-shp.zip # View preview render wget https://s3.amazonaws.com/nvkelso-election-geodata/branches/master/render.png # Load into QGIS qgis nation.gpkg # Load into Python with GeoPandas import geopandas as gpd gdf = gpd.read_file('nation.gpkg', layer='nation') print(f"Total precincts: {len(gdf)}") print(gdf[gdf['state'] == '06'].head()) # Show California precincts # Query specific state/year with OGRogrinfo -sql "SELECT * FROM nation WHERE state='36' AND year='2016'" nation.gpkg ``` -------------------------------- ### Render Map Visualizations with Mapnik Source: https://context7.com/kritsanan1/election-geodata/llms.txt Generates visual previews of precinct coverage using the Mapnik library. It handles rendering for the continental US, Alaska, and Hawaii separately, with specific projections and bounding boxes for each region, and includes a placeholder for compositing the final image. ```python #!/usr/bin/env python import mapnik, sys, os # Render continental US, Alaska, and Hawaii separately # Usage: ./render/draw.py out/conus.png out/alaska.png out/hawaii.png out/render.png # Continental US render (US National Atlas projection) map1 = mapnik.Map(1780, 1250) mapnik.load_map(map1, 'render/style.xml') bbox = mapnik.Box2d(-2700000, -2800000, 2570000, 770000) map1.zoom_to_box(bbox) mapnik.render_to_file(map1, 'out/conus.png') # Alaska render (NAD83 Alaska Albers) map2 = mapnik.Map(580, 480) mapnik.load_map(map2, 'render/style.xml') map2.srs = '+proj=aea +lat_1=55 +lat_2=65 +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs' bbox = mapnik.Box2d(-1250000, 380000, 1550000, 2400000) map2.zoom_to_box(bbox) mapnik.render_to_file(map2, 'out/alaska.png') # Hawaii render (Old Hawaiian TM) map3 = mapnik.Map(360, 290) mapnik.load_map(map3, 'render/style.xml') map3.srs = '+proj=tmerc +lat_0=20.33333333333333 +lon_0=-156.6666666666667 +k=0.999966667 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs' bbox = mapnik.Box2d(40000, -170000, 700000, 220000) map3.zoom_to_box(bbox) mapnik.render_to_file(map3, 'out/hawaii.png') # Composite final image using ImageMagick # convert -size 1780x1250 xc:skyblue \ # out/conus.png -geometry +0+0 -composite \ # out/alaska.png -geometry +0+770 -composite \ # out/hawaii.png -geometry +580+960 -composite \ # out/render.png ``` -------------------------------- ### Build National Dataset with Make Source: https://context7.com/kritsanan1/election-geodata/llms.txt Orchestrates the data processing pipeline using GNU Make to transform raw state-level shapefiles into a unified national GeoPackage dataset. It normalizes coordinate systems, assigns FIPS codes, and merges data into a single national layer. ```makefile # Build the complete national dataset make out/nation.gpkg # This executes a multi-stage pipeline: # 1. Processes all state GPKGs from raw source data # 2. Normalizes to EPSG:4326 coordinate system # 3. Merges into single national layer with schema: # - year: Election year (e.g., '2016') # - state: 2-digit FIPS code (e.g., '06' for California) # - county: 3-digit FIPS code (e.g., '001') # - precinct: State-specific precinct identifier # - accuracy: Data quality indicator ('polygon') # - geometry: MultiPolygon geometry in WGS84 # Clean build artifacts make clean # Example output structure: # out/nation.gpkg - Single file containing all precincts nationwide # Layer: nation # Features: ~175,000+ precinct polygons # Attributes: year, state, county, precinct, accuracy, geometry ``` -------------------------------- ### Process State-Level Data with Make and OGR Source: https://context7.com/kritsanan1/election-geodata/llms.txt Processes individual state datasets from source shapefiles, performing state-specific field mappings and transformations. It uses GDAL/OGR tools for operations like spatial joins, intersection, and outputting to a standardized schema. ```bash # Build California precincts (complex multi-source example) make out/06-california/state.gpkg # This processes: # 1. Precinct boundaries from statewide merged shapefile # 2. Census county subdivision data for spatial joins # 3. Intersects precincts with counties # 4. Assigns each precinct to county containing majority of its area # 5. Outputs to standardized schema: # year=2016, state=06, county=XXX, precinct=pct16 # Example SQL transformation for California: ogr2ogr -sql "SELECT '2016' AS year, '06' AS state, i.county AS county, \ p.pct16 AS precinct, 'polygon' AS accuracy, p.GEOM AS geometry \ FROM precinct p, county_intersection i \ WHERE i.precinct=p.pct16 AND i.area=max_area" \ -dialect SQLITE -t_srs EPSG:4326 -nln state -append -f GPKG \ out/06-california/state.gpkg staging.gpkg ``` -------------------------------- ### Generate NYC Election District to County Mapping Script Source: https://github.com/kritsanan1/election-geodata/blob/master/data/36-new-york/README.md The `generate-county-field.sh` script is used to create a mapping between New York City's election districts and their respective counties. This is essential for analyzing election results at a county level for NYC data. ```bash generate-county-field.sh ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.