forked from nvkelso/election-geodata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
1366 lines (1193 loc) · 97.3 KB
/
Makefile
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
all: out/render.png
clean:
rm -rf out
# To build and publish rendered map, collected data, and Github status,
# create docker/env.ini from template in docker/env.ini-sample.
status:
docker build -t nvkelso/elections-geodata docker
docker run --env-file docker/env.ini --rm -v `pwd`:/vol -w /vol nvkelso/elections-geodata
.PHONY: all clean status
out/render.png: render/precincts-2163.shp render/style.xml
render/draw.py out/conus.png out/alaska.png out/hawaii.png $@
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 \
$@
render/precincts-2163.shp: out/nation.gpkg
rm -f $@
ogr2ogr -t_srs EPSG:2163 -overwrite -skipfailures $@ $<
out/nation.gpkg: \
data/template.shp \
out/01-alabama/state.gpkg \
out/02-alaska/state.gpkg \
out/05-arkansas/state.gpkg \
out/04-arizona/state.gpkg \
out/06-california/state.gpkg \
out/08-colorado/state.gpkg \
out/09-connecticut/state.gpkg \
out/10-delaware/state.gpkg \
out/11-district-of-columbia/state.gpkg \
out/12-florida/state.gpkg \
out/13-georgia/state.gpkg \
out/15-hawaii/state.gpkg \
out/16-idaho/state.gpkg \
out/17-illinois/state.gpkg \
out/18-indiana/state.gpkg \
out/19-iowa/state.gpkg \
out/20-kansas/state.gpkg \
out/21-kentucky/state.gpkg \
out/22-louisiana/state.gpkg \
out/23-maine/state.gpkg \
out/24-maryland/state.gpkg \
out/25-massachusetts/state.gpkg \
out/26-michigan/state.gpkg \
out/27-minnesota/state.gpkg \
out/28-mississippi/state.gpkg \
out/29-missouri/state.gpkg \
out/30-montana/state.gpkg \
out/31-nebraska/state.gpkg \
out/32-nevada/state.gpkg \
out/33-new-hampshire/state.gpkg \
out/34-new-jersey/state.gpkg \
out/35-new-mexico/state.gpkg \
out/36-new-york/state.gpkg \
out/37-north-carolina/state.gpkg \
out/38-north-dakota/state.gpkg \
out/39-ohio/state.gpkg \
out/40-oklahoma/state.gpkg \
out/41-oregon/state.gpkg \
out/42-pennsylvania/state.gpkg \
out/45-south-carolina/state.gpkg \
out/46-south-dakota/state.gpkg \
out/47-tennessee/state.gpkg \
out/48-texas/state.gpkg \
out/49-utah/state.gpkg \
out/50-vermont/state.gpkg \
out/51-virginia/state.gpkg \
out/53-washington/state.gpkg \
out/54-west-virginia/state.gpkg \
out/55-wisconsin/state.gpkg \
out/56-wyoming/state.gpkg \
out/72-puerto-rico/state.gpkg
rm -f $@
ogr2ogr -f GPKG -nln nation -nlt MultiPolygon -overwrite $@ data/template.shp
ogr2ogr -f GPKG -nln nation -append $@ out/01-alabama/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/02-alaska/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/04-arizona/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/05-arkansas/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/06-california/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/08-colorado/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/09-connecticut/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/10-delaware/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/11-district-of-columbia/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/12-florida/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/13-georgia/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/15-hawaii/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/16-idaho/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/17-illinois/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/18-indiana/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/19-iowa/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/20-kansas/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/21-kentucky/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/22-louisiana/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/23-maine/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/24-maryland/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/25-massachusetts/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/26-michigan/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/27-minnesota/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/28-mississippi/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/29-missouri/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/30-montana/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/31-nebraska/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/32-nevada/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/33-new-hampshire/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/34-new-jersey/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/35-new-mexico/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/36-new-york/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/37-north-carolina/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/38-north-dakota/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/39-ohio/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/40-oklahoma/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/41-oregon/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/42-pennsylvania/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/45-south-carolina/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/46-south-dakota/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/47-tennessee/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/48-texas/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/49-utah/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/50-vermont/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/51-virginia/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/53-washington/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/54-west-virginia/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/55-wisconsin/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/56-wyoming/state.gpkg
ogr2ogr -f GPKG -nln nation -append $@ out/72-puerto-rico/state.gpkg
out/01-alabama/state.gpkg: data/01-alabama/statewide/2010/tl_2012_01_vtd10.zip data/template.shp
mkdir -p out/01-alabama
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
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 $@ \
'/vsizip/data/01-alabama/statewide/2010/tl_2012_01_vtd10.zip/tl_2012_01_vtd10.shp'
# from 2013 but reused for next few elections
out/02-alaska/state.gpkg: data/02-alaska/statewide/2016/ak_2016_FEST.zip data/template.shp
mkdir -p out/02-alaska
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2016' AS year, '02' AS state, CONCAT('0', SUBSTR(DISTRICT, 0, 2)) AS county, CONCAT('020', DISTRICT) AS precinct, name as name, 'polygon' AS accuracy FROM ak_2016" \
-s_srs EPSG:4326 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/02-alaska/statewide/2016/ak_2016_FEST.zip/ak_2016.shp'
out/04-arizona/state.gpkg: data/04-arizona/statewide/2018/Arizona_2018_Shell.zip data/template.shp
mkdir -p out/04-arizona
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2018' AS year, '04' AS state, CASE COUNTYNAME WHEN 'Apache' THEN '001' WHEN 'Cochise' THEN '003' WHEN 'Coconino' THEN '005' WHEN 'Gila' THEN '007' WHEN 'Graham' THEN '009' WHEN 'Greenlee' THEN '011' WHEN 'La Paz' THEN '012' WHEN 'Maricopa' THEN '013' WHEN 'Mohave' THEN '015' WHEN 'Navajo' THEN '017' WHEN 'Pima' THEN '019' WHEN 'Pinal' THEN '021' WHEN 'Santa Cruz' THEN '023' WHEN 'Yavapai' THEN '025' WHEN 'Yuma' THEN '027' ELSE COUNTYNAME END AS county, '04' || GISPRECINC AS precinct, 'polygon' AS accuracy, 'polygon' AS accuracy, GEOMETRY AS geometry FROM Arizona_2018_Shell" \
-dialect SQLITE \
-s_srs EPSG:2223 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/04-arizona/statewide/2018/Arizona_2018_Shell.zip/Arizona_2018_Shell.shp'
out/05-arkansas/state.gpkg: data/05-arkansas/statewide/2016/ELECTION_PRECINCTS.zip data/template.shp
mkdir -p out/05-arkansas
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2016' AS year, '05' AS state, county_fip AS county, precinct AS precinct, 'polygon' AS accuracy FROM boundaries_ELECTION_PRECINCTS" \
-s_srs EPSG:26915 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/05-arkansas/statewide/2016/ELECTION_PRECINCTS.zip/boundaries_ELECTION_PRECINCTS.shp'
out/06-california/state.gpkg: data/06-california/statewide/2016/merged.zip \
data/06-california/counties/tl_2016_06_cousub.zip \
data/template.shp
mkdir -p out/06-california
# GPKG are weird
rm -f $@
# Because we have to join multiple data sets together, we use a staging
# GPKG to hold them.
# Copy precinct data
ogr2ogr -t_srs EPSG:4326 -append -f GPKG out/06-california/staging.gpkg \
/vsizip/data/06-california/statewide/2016/merged.zip/merged.shp
# Copy township data. This data comes from the census.
# https://catalog.data.gov/dataset/tiger-line-shapefile-2016-state-iowa-current-county-subdivision-state-based
ogr2ogr -t_srs EPSG:4326 -append -f GPKG out/06-california/staging.gpkg \
/vsizip/data/06-california/counties/tl_2016_06_cousub.zip/tl_2016_06_cousub.shp
# Aggregate court district data into counties.
ogr2ogr -sql "SELECT c.COUNTYFP AS county, 'polygon' AS accuracy, ST_Union(c.GEOM) AS geom, ST_Envelope(ST_Union(c.GEOM)) AS envelope FROM tl_2016_06_cousub c GROUP BY c.COUNTYFP" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln county -append -f GPKG out/06-california/staging.gpkg out/06-california/staging.gpkg
# Pull out precincts and envelopes
ogr2ogr -sql "SELECT pct16, area, 'polygon' AS accuracy, GEOM AS geom, ST_Envelope(GEOM) AS envelope FROM merged" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln precinct -append -f GPKG out/06-california/staging.gpkg out/06-california/staging.gpkg
# Compute all county/precinct intersections as a precursor to assigning
# precincts to the counties that contain the most of their area. We use
# the funny expression as ID because the individual fields are not
# unique.
ogr2ogr -sql "SELECT p.pct16 || '_' || CAST(p.area AS TEXT) AS precinct, c.county AS county, 'polygon' AS accuracy, ST_Intersection(p.GEOM, c.GEOM) AS geom, ST_Area(ST_Intersection(p.GEOM, c.GEOM)) AS area, ST_Area(p.GEOM) AS parea, ST_Area(c.GEOM) AS carea FROM precinct p, county c WHERE ST_Disjoint(c.envelope, p.envelope)=0 AND ST_Intersection(p.GEOM, c.GEOM) IS NOT NULL" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln intersection -append -f GPKG out/06-california/staging.gpkg out/06-california/staging.gpkg
# Join each precinct to the county that contains the most of its area.
# We'd prefer to use a window function, which would make this much
# simpler, but the build version of ogr2ogr does not have a recent
# enough version to support them.
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
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 (SELECT precinct, MAX(area) AS maxarea FROM intersection i GROUP BY precinct) m, intersection i, precinct p WHERE i.precinct=m.precinct AND i.precinct=p.pct16 || '_' || CAST(p.area AS TEXT) AND i.area=m.maxarea" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ out/06-california/staging.gpkg
rm -f out/06-california/staging.gpkg
out/08-colorado/state.gpkg: data/08-colorado/statewide/2010/tl_2012_08_vtd10.zip data/template.shp
mkdir -p out/08-colorado
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2010' AS year, '08' AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_08_vtd10" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/08-colorado/statewide/2010/tl_2012_08_vtd10.zip/tl_2012_08_vtd10.shp'
out/09-connecticut/state.gpkg: data/09-connecticut/statewide/2010/tl_2012_09_vtd10.zip data/template.shp
mkdir -p out/09-connecticut
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2010' AS year, '09' AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_09_vtd10" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/09-connecticut/statewide/2010/tl_2012_09_vtd10.zip/tl_2012_09_vtd10.shp'
out/10-delaware/state.gpkg: data/10-delaware/statewide/2016/de_2016_FEST.zip \
data/10-delaware/counties/tl_2016_10_cousub.zip \
data/template.shp
mkdir -p out/10-delaware
# GPKG are weird
rm -f $@
# Because we have to join multiple data sets together, we use a staging
# GPKG to hold them.
# Copy precinct data
ogr2ogr -s_srs EPSG:4326 -t_srs EPSG:4326 -append -f GPKG out/10-delaware/staging.gpkg \
/vsizip/data/10-delaware/statewide/2016/de_2016_FEST.zip/de_2016.shp
# Copy township data. This data comes from the census.
# https://catalog.data.gov/dataset/tiger-line-shapefile-2016-state-delaware-current-county-subdivision-state-based
ogr2ogr -t_srs EPSG:4326 -append -f GPKG out/10-delaware/staging.gpkg \
/vsizip/data/10-delaware/counties/tl_2016_10_cousub.zip/tl_2016_10_cousub.shp
# Aggregate historical court districts data into counties.
ogr2ogr -sql "SELECT c.COUNTYFP AS county, 'polygon' AS accuracy, ST_Union(c.GEOM) AS geom FROM tl_2016_10_cousub c GROUP BY c.COUNTYFP" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln county -append -f GPKG out/10-delaware/staging.gpkg out/10-delaware/staging.gpkg
# Compute all county/precinct intersections as a precursor to assigning
# precincts to the counties that contain the most of their area.
ogr2ogr -sql "SELECT p.EDRD_2012 AS precinct, c.county AS county, 'polygon' AS accuracy, ST_Intersection(p.GEOM, c.GEOM) AS geom, ST_Area(ST_Intersection(p.GEOM, c.GEOM)) AS area, ST_Area(p.GEOM) AS parea, ST_Area(c.GEOM) AS carea FROM de_2016 p, county c WHERE ST_Disjoint(ST_Envelope(c.GEOM), ST_Envelope(p.GEOM))=0 AND ST_Intersection(p.GEOM, c.GEOM) IS NOT NULL" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln intersection -append -f GPKG out/10-delaware/staging.gpkg out/10-delaware/staging.gpkg
# Join each precinct to the county that contains the most of its area.
# We'd prefer to use a window function, which would make this much
# simpler, but the build version of ogr2ogr does not have a recent
# enough version to support them.
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2016' AS year, '10' AS state, i.county AS county, p.EDRD_2012 AS precinct, 'polygon' AS accuracy, p.GEOM AS geometry FROM (SELECT precinct, MAX(area) AS maxarea FROM intersection i GROUP BY precinct) m, intersection i, de_2016 p WHERE i.precinct=m.precinct AND i.precinct=p.EDRD_2012 AND i.area=m.maxarea" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ out/10-delaware/staging.gpkg
rm -rf 'out/10-delaware/staging.gpkg'
out/11-district-of-columbia/state.gpkg: data/11-district-of-columbia/statewide/2012/Voting_Precinct__2012.zip data/template.shp
mkdir -p out/11-district-of-columbia
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2012' AS year, '11' AS state, '001' AS county, CONCAT( '11', '01', NAME) AS precinct, 'polygon' AS accuracy FROM Voting_Precinct__2012" \
-s_srs EPSG:4326 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/11-district-of-columbia/statewide/2012/Voting_Precinct__2012.zip/Voting_Precinct__2012.shp'
out/12-florida/state.gpkg: data/12-florida/statewide/2016/fl_2016_FEST.zip data/template.shp
mkdir -p out/12-florida
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2016' AS year, '12' AS state, CASE county WHEN 'ALA' THEN '001' WHEN 'BAK' THEN '003' WHEN 'BAY' THEN '005' WHEN 'BRA' THEN '007' WHEN 'BRE' THEN '009' WHEN 'BRO' THEN '011' WHEN 'CAL' THEN '013' WHEN 'CHA' THEN '015' WHEN 'CIT' THEN '017' WHEN 'CLA' THEN '019' WHEN 'CLL' THEN '021' WHEN 'CLM' THEN '023' WHEN 'DAD' THEN '086' WHEN 'DES' THEN '027' WHEN 'DIX' THEN '029' WHEN 'DUV' THEN '031' WHEN 'ESC' THEN '033' WHEN 'FLA' THEN '035' WHEN 'FRA' THEN '037' WHEN 'GAD' THEN '039' WHEN 'GIL' THEN '041' WHEN 'GLA' THEN '043' WHEN 'GUL' THEN '045' WHEN 'HAM' THEN '047' WHEN 'HAR' THEN '049' WHEN 'HEN' THEN '051' WHEN 'HER' THEN '053' WHEN 'HIG' THEN '055' WHEN 'HIL' THEN '057' WHEN 'HOL' THEN '059' WHEN 'IND' THEN '061' WHEN 'JAC' THEN '063' WHEN 'JEF' THEN '065' WHEN 'LAF' THEN '067' WHEN 'LAK' THEN '069' WHEN 'LEE' THEN '071' WHEN 'LEO' THEN '073' WHEN 'LEV' THEN '075' WHEN 'LIB' THEN '077' WHEN 'MAD' THEN '079' WHEN 'MAN' THEN '081' WHEN 'MON' THEN '087' WHEN 'MRN' THEN '083' WHEN 'MRT' THEN '085' WHEN 'NAS' THEN '089' WHEN 'OKA' THEN '091' WHEN 'OKE' THEN '093' WHEN 'ORA' THEN '095' WHEN 'OSC' THEN '097' WHEN 'PAL' THEN '099' WHEN 'PAS' THEN '101' WHEN 'PIN' THEN '103' WHEN 'POL' THEN '105' WHEN 'PUT' THEN '107' WHEN 'SAN' THEN '113' WHEN 'SAR' THEN '115' WHEN 'SEM' THEN '117' WHEN 'STJ' THEN '109' WHEN 'STL' THEN '111' WHEN 'SUM' THEN '119' WHEN 'SUW' THEN '121' WHEN 'TAY' THEN '123' WHEN 'UNI' THEN '125' WHEN 'VOL' THEN '127' WHEN 'WAK' THEN '129' WHEN 'WAL' THEN '131' WHEN 'WAS' THEN '133' ELSE county END AS county, '12' || countypct AS precinct, 'polygon' AS accuracy, GEOMETRY AS geometry FROM fl_2016" \
-dialect SQLITE \
-s_srs '+proj=tmerc +lat_0=24.33333333333333 +lon_0=-81 +k=0.9999411764705882 +x_0=199999.9999999999 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/12-florida/statewide/2016/fl_2016_FEST.zip/fl_2016.shp'
out/13-georgia/state.gpkg: data/13-georgia/statewide/2016/VTD2016-Shape.shp data/template.shp
mkdir -p out/13-georgia
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
rm -f out/13-georgia/temporary.geojson
ogr2ogr -sql "SELECT '2016' AS year, '13' AS state, FIPS1 AS county, CONCAT(FIPS1, DISTRICT) AS precinct, precinct_n AS name FROM "'"VTD2016-Shape"' \
-s_srs EPSG:4019 -t_srs EPSG:4326 -overwrite \
-f GeoJSON out/13-georgia/temporary.geojson $<
ogr2ogr -nln state -append $@ out/13-georgia/temporary.geojson
rm out/13-georgia/temporary.geojson
out/15-hawaii/state.gpkg: data/15-hawaii/statewide/2014/Election_Precincts_Polygon.zip data/template.shp
mkdir -p out/15-hawaii
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
# Hawaii has 5 counties:
#
# * Hawaii County (001)
# * Honolulu County (003)
# * Kalawao County (005)
# * Kauai County (007)
# * Maui County (009)
#
# The file labels "counties" as the big islands:
# * HAWAII
# * MAUI
# * OAHU
# * KAUAI
#
# This maps well to counties exception for Kalawao County, which is one
# precinct in the area labeled MAUI.
#
# Precincts are labeled NN-NN, so we'll transform to 4-digit precinct
# codes by removing the '-' character.
ogr2ogr -sql "SELECT '2014' AS year, '15' AS state, CASE county WHEN 'HAWAII' THEN '001' WHEN 'MAUI' THEN (CASE dp WHEN '13-09' THEN '005' ELSE '009' END) WHEN 'OAHU' THEN '003' WHEN 'KAUAI' THEN '007' ELSE county END AS county, dp AS precinct, 'polygon' AS accuracy, geometry AS geometry FROM Election_Precincts" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln state -append -f GPKG 'out/15-hawaii/staging.gpkg' \
'/vsizip/data/15-hawaii/statewide/2014/Election_Precincts_Polygon.zip/Election_Precincts.shp'
ogr2ogr -sql "SELECT year AS year, state AS state, county AS county, state || county || REPLACE(precinct, '-', '') AS precinct, 'polygon' AS accuracy, geom AS geom FROM state" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ 'out/15-hawaii/staging.gpkg'
rm -rf 'out/15-hawaii/staging.gpkg'
out/16-idaho/state.gpkg: data/16-idaho/statewide/2010/tl_2012_16_vtd10.zip data/template.shp
mkdir -p out/16-idaho
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2010' AS year, '16' AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_16_vtd10" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/16-idaho/statewide/2010/tl_2012_16_vtd10.zip/tl_2012_16_vtd10.shp'
out/17-illinois/state.gpkg: data/17-illinois/statewide/2010/tl_2012_17_vtd10.zip data/template.shp
mkdir -p out/17-illinois
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2010' AS year, '17' AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_17_vtd10" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/17-illinois/statewide/2010/tl_2012_17_vtd10.zip/tl_2012_17_vtd10.shp'
out/18-indiana/state.gpkg: data/18-indiana/statewide/2010/tl_2012_18_vtd10.zip \
data/18-indiana/003-allen/2012/precincts.geojson.gz \
data/18-indiana/039-elkhart/2012/precincts.geojson.gz \
data/18-indiana/057-hamilton/2012/precincts.geojson.gz \
data/18-indiana/097-marion/2012/precincts.geojson.gz \
data/18-indiana/141-St-Joseph/2012/Voter_Precincts.zip \
data/18-indiana/157-tippecanoe/2016/precincts.geojson.gz \
data/18-indiana/163-vanderburgh/2012/precincts.geojson.gz \
data/template.shp
mkdir -p out/18-indiana
# GPKG are weird
rm -rf $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
# Skip a few since they'll come from another file.
ogr2ogr -sql "SELECT '2010' AS year, '18' AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_18_vtd10 WHERE COUNTYFP10 NOT IN ('003', '039', '057', '097', '141', '157', '163')" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -nln state $@ \
'/vsizip/data/18-indiana/statewide/2010/tl_2012_18_vtd10.zip/tl_2012_18_vtd10.shp'
# Add Allen County (FIPS 003) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2012' AS year, '18' AS state, '003' AS county, Precinct AS precinct, 'polygon' AS accuracy FROM "'"precincts.geojson"' \
-t_srs EPSG:4326 -f GPKG -nln state -nln state -append \
$@ /vsigzip/data/18-indiana/003-allen/2012/precincts.geojson.gz
# Add Elkhart County (FIPS 039) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2012' AS year, '18' AS state, '039' AS county, P12 AS precinct, 'polygon' AS accuracy FROM "'"precincts.geojson"' \
-t_srs EPSG:4326 -f GPKG -nln state -nln state -append \
$@ /vsigzip/data/18-indiana/039-elkhart/2012/precincts.geojson.gz
# Add Hamilton County (FIPS 057) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2012' AS year, '18' AS state, '057' AS county, PRECINCT AS precinct, 'polygon' AS accuracy FROM "'"precincts.geojson"' \
-t_srs EPSG:4326 -f GPKG -nln state -nln state -append \
$@ /vsigzip/data/18-indiana/057-hamilton/2012/precincts.geojson.gz
# Add Marion County (FIPS 097) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2012' AS year, '18' AS state, '097' AS county, PRECINCT AS precinct, 'polygon' AS accuracy FROM "'"precincts.geojson"' \
-t_srs EPSG:4326 -f GPKG -nln state -nln state -append \
$@ /vsigzip/data/18-indiana/097-marion/2012/precincts.geojson.gz
# Add St. Joesph County (FIPS 141) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2012' AS year, '18' AS state, '141' AS county, PRECINCT AS precinct, 'polygon' AS accuracy FROM Voter_Precincts" \
-t_srs EPSG:4326 -f GPKG -nln state -nln state -append \
$@ '/vsizip/data/18-indiana/141-St-Joseph/2012/Voter_Precincts.zip/Voter_Precincts.shp'
# Add Tippecanoe County (FIPS 157) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '18' AS state, '157' AS county, P12_STFID AS precinct, 'polygon' AS accuracy FROM "'"precincts.geojson"' \
-t_srs EPSG:4326 -f GPKG -nln state -nln state -append \
$@ /vsigzip/data/18-indiana/157-tippecanoe/2016/precincts.geojson.gz
# Add Vanderburgh County (FIPS 163) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2012' AS year, '18' AS state, '163' AS county, NAME AS precinct, 'polygon' AS accuracy FROM "'"precincts.geojson"' \
-t_srs EPSG:4326 -f GPKG -nln state -nln state -append \
$@ /vsigzip/data/18-indiana/163-vanderburgh/2012/precincts.geojson.gz
out/19-iowa/state.gpkg: data/19-iowa/statewide/2016/pcts_04172014_0908am.zip \
data/19-iowa/counties/tl_2016_19_cousub.zip \
data/template.shp
mkdir -p out/19-iowa
# GPKG are weird
rm -f $@
# Because we have to join multiple data sets together, we use a staging
# GPKG to hold them.
# Copy precinct data
ogr2ogr -t_srs EPSG:4326 -append -f GPKG out/19-iowa/staging.gpkg \
/vsizip/data/19-iowa/statewide/2016/pcts_04172014_0908am.zip/pcts_04172014_0908am/Precincts041714.shp
# Copy township data. This data comes from the census.
# https://catalog.data.gov/dataset/tiger-line-shapefile-2016-state-iowa-current-county-subdivision-state-based
ogr2ogr -t_srs EPSG:4326 -append -f GPKG out/19-iowa/staging.gpkg \
/vsizip/data/19-iowa/counties/tl_2016_19_cousub.zip/tl_2016_19_cousub.shp
# Aggregate township data into counties.
ogr2ogr -sql "SELECT c.COUNTYFP AS county, 'polygon' AS accuracy, ST_Union(c.GEOM) AS geom FROM tl_2016_19_cousub c GROUP BY c.COUNTYFP" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln county -append -f GPKG out/19-iowa/staging.gpkg out/19-iowa/staging.gpkg
# Compute all county/precinct intersections as a precursor to assigning
# precincts to the counties that contain the most of their area. We use
# the funny expression as ID because the individual fields are not
# unique.
ogr2ogr -sql "SELECT p.DISTRICT || '_' || p.NAME AS precinct, c.county AS county, 'polygon' AS accuracy, ST_Intersection(p.GEOM, c.GEOM) AS geom, ST_Area(ST_Intersection(p.GEOM, c.GEOM)) AS area, ST_Area(p.GEOM) AS parea, ST_Area(c.GEOM) AS carea FROM Precincts041714 p, county c WHERE ST_Disjoint(ST_Envelope(c.GEOM), ST_Envelope(p.GEOM))=0 AND ST_Intersection(p.GEOM, c.GEOM) IS NOT NULL" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln intersection -append -f GPKG out/19-iowa/staging.gpkg out/19-iowa/staging.gpkg
# Join each precinct to the county that contains the most of its area.
# We'd prefer to use a window function, which would make this much
# simpler, but the build version of ogr2ogr does not have a recent
# enough version to support them.
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2016' AS year, '19' AS state, i.county AS county, p.NAME AS precinct, 'polygon' AS accuracy, p.GEOM AS geometry FROM (SELECT precinct, MAX(area) AS maxarea FROM intersection i GROUP BY precinct) m, intersection i, Precincts041714 p WHERE i.precinct=m.precinct AND i.precinct=p.DISTRICT || '_' || p.NAME AND i.area=m.maxarea" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ out/19-iowa/staging.gpkg
rm -rf 'out/19-iowa/staging.gpkg'
out/20-kansas/state.gpkg: data/20-kansas/statewide/2012/kansas_state_voting_precincts_2012.geojson.gz
mkdir -p out/20-kansas
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2012' AS year, '20' AS state, SUBSTR(VTD_2012, 3, 3) AS county, VTD_2012 AS precinct, 'polygon' AS accuracy FROM "'"kansas_state_voting_precincts_2012.geojson"'" WHERE SUBSTR(VTD_2012, 3, 3) NOT IN ('045', '091', '173', '209', '227')" \
-s_srs EPSG:4326 -t_srs EPSG:4326 -nln state -nlt MultiPolygon -f GPKG \
$@ /vsigzip/data/20-kansas/statewide/2012/kansas_state_voting_precincts_2012.geojson.gz
# Add Douglas County (FIPS 045) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '20' AS state, '045' AS county, CONCAT(CAST(precinctid AS character(255)), ' ', CAST(subprecinctid AS character(255))) AS precinct, 'polygon' AS accuracy FROM "'"precincts.geojson"' \
-s_srs EPSG:4326 -t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsigzip/data/20-kansas/2016/20045-douglas/precincts.geojson.gz
# Add Johnson County (FIPS 091) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '20' AS state, '091' AS county, NAME AS precinct, 'polygon' AS accuracy FROM "'"precincts.geojson"' \
-s_srs EPSG:4326 -t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsigzip/data/20-kansas/2016/20091-johnson/precincts.geojson.gz
# Add Sedgwick County (FIPS 173) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '20' AS state, '173' as county, PRECINCT AS precinct, 'polygon' AS accuracy FROM "'"precincts.geojson"' \
-s_srs EPSG:4326 -t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsigzip/data/20-kansas/2016/20173-sedgwick/precincts.geojson.gz
# Add Shawnee County (FIPS 227) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '20' AS state, '227' as county, SUBSTR(PRECINCTID, 3, 6) AS precinct, 'polygon' AS accuracy FROM "'"precincts.geojson"' \
-s_srs EPSG:4326 -t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsigzip/data/20-kansas/2016/20227-shawnee/precincts.geojson.gz
# Add Wyandotte County (FIPS 209) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '20' AS state, '209' as county, VTD_S AS precinct, 'polygon' AS accuracy FROM "'"precincts.geojson"' \
-s_srs EPSG:4326 -t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsigzip/data/20-kansas/2016/20209-wyandotte/precincts.geojson.gz
out/21-kentucky/state.gpkg: data/21-kentucky/statewide/2016/kyprecinctsmergedfinal.zip data/template.shp
mkdir -p out/21-kentucky
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2014' AS year, '21' AS state, COUNTY AS county, VTD AS precinct, 'polygon' AS accuracy FROM "'"KY Precincts Merged Final"' \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/21-kentucky/statewide/2016/kyprecinctsmergedfinal.zip/KY Precincts Merged Final.shp'
out/22-louisiana/state.gpkg: data/22-louisiana/statewide/2016/2016_LA_Precincts.zip data/template.shp
mkdir -p out/22-louisiana
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2016' AS year, STATEFP10 AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM "'"2016_LA_Precincts"' \
-s_srs EPSG:4019 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/22-louisiana/statewide/2016/2016_LA_Precincts.zip/2016_LA_Precincts.shp'
out/23-maine/state.gpkg: data/23-maine/statewide/2010/tl_2012_23_vtd10.zip data/template.shp
mkdir -p out/23-maine
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2010' AS year, STATEFP10 AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_23_vtd10" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/23-maine/statewide/2010/tl_2012_23_vtd10.zip/tl_2012_23_vtd10.shp'
# "2010" Census data from 2012 release is used in newer elections, see Readme
out/24-maryland/state.gpkg: data/24-maryland/statewide/2016/md_2016_FEST.zip data/template.shp
mkdir -p out/24-maryland
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2016' AS year, '24' AS state, CASE JURIS WHEN 'ALLE' THEN '001' WHEN 'ANNE' THEN '003' WHEN 'BACI' THEN '510' WHEN 'BACO' THEN '005' WHEN 'CALV' THEN '009' WHEN 'CARO' THEN '011' WHEN 'CARR' THEN '013' WHEN 'CECI' THEN '015' WHEN 'CHAR' THEN '017' WHEN 'DORC' THEN '019' WHEN 'FRED' THEN '021' WHEN 'GARR' THEN '023' WHEN 'HARF' THEN '025' WHEN 'HOWA' THEN '027' WHEN 'KENT' THEN '029' WHEN 'MONT' THEN '031' WHEN 'PRIN' THEN '033' WHEN 'QUEE' THEN '035' WHEN 'SOME' THEN '039' WHEN 'STMA' THEN '037' WHEN 'TALB' THEN '041' WHEN 'WASH' THEN '043' WHEN 'WICO' THEN '045' WHEN 'WORC' THEN '047' ELSE JURIS END AS county, '24' || preid AS precinct, name AS name, 'polygon' AS accuracy, GEOMETRY AS geometry FROM md_2016_w_ushouse" \
-dialect SQLITE \
-s_srs '+proj=lcc +lat_1=38.3 +lat_2=39.45 +lat_0=37.66666666666666 +lon_0=-77 +x_0=400000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs' \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/24-maryland/statewide/2016/md_2016_FEST.zip/md_2016_w_ushouse.shp'
out/25-massachusetts/state.gpkg: data/25-massachusetts/statewide/2010/tl_2012_25_vtd10.zip data/template.shp
mkdir -p out/25-massachusetts
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2010' AS year, STATEFP10 AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_25_vtd10" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/25-massachusetts/statewide/2010/tl_2012_25_vtd10.zip/tl_2012_25_vtd10.shp'
out/26-michigan/state.gpkg: data/26-michigan/statewide/2016/2016_Voting_Precincts.zip data/template.shp
mkdir -p out/26-michigan
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2016' AS year, '26' AS state, CONCAT('26', CountyFips) AS county, CONCAT('26', VTD2016) AS precinct FROM "'"2016_Voting_Precincts"' \
-f GPKG $@ \
'/vsizip/data/26-michigan/statewide/2016/2016_Voting_Precincts.zip/2016_Voting_Precincts.shp'
out/27-minnesota/state.gpkg: data/27-minnesota/statewide/2016/elec2016.zip data/template.shp
mkdir -p out/27-minnesota
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2016' AS year, '27' AS state, SUBSTR(VTD, 0, 5) AS county, VTD AS precinct, pctname AS name FROM elec2016" \
-s_srs EPSG:26915 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/27-minnesota/statewide/2016/elec2016.zip/elec2016.shp'
out/28-mississippi/state.gpkg: data/28-mississippi/statewide/2012/precincts_2012.zip data/template.shp
mkdir -p out/28-mississippi
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2012' AS year, STATEFP10 AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM precincts_12" \
-s_srs EPSG:3814 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/28-mississippi/statewide/2012/precincts_2012.zip/precincts_12.shp'
out/29-missouri/state.gpkg: data/29-missouri/statewide/2010/MO_2010_Census_Voting_Districts_shp.zip data/template.shp
mkdir -p out/29-missouri
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2010' AS year, '29' AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM MO_2010_Census_Voting_Districts_shp" \
-s_srs EPSG:26915 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/29-missouri/statewide/2010/MO_2010_Census_Voting_Districts_shp.zip/MO_2010_Census_Voting_Districts_shp.shp'
out/30-montana/state.gpkg: data/30-montana/statewide/2010/tl_2012_30_vtd10.zip data/template.shp
mkdir -p out/30-montana
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
# GPKG are weird
rm -f $@
# Skip a few since they'll come from another file.
ogr2ogr -sql "SELECT '2010' AS year, STATEFP10 AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_30_vtd10 WHERE COUNTYFP10 NOT IN ('013', '029', '031', '047', '049', '063', '111')" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -append -f GPKG -nln state $@ \
'/vsizip/data/30-montana/statewide/2010/tl_2012_30_vtd10.zip/tl_2012_30_vtd10.shp'
# Add Cascade County (FIPS 013) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2018' AS year, '30' AS state, '013' AS county, CONCAT('30013', Precinct) AS precinct, 'polygon' AS accuracy FROM CascadeCntyPrecincts2013" \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ data/30-montana/county/2018/013-Cascade/CascadeCntyPrecincts2013.shp
# Add Flathead County (FIPS 029) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2018' AS year, '30' AS state, '029' AS county, CONCAT('30029', Precinct) AS precinct, 'polygon' AS accuracy FROM Precinct" \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ data/30-montana/county/2018/029-Flathead/Precinct.shp
# Add Gallatin County (FIPS 031) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2018' AS year, '30' AS state, '031' AS county, CONCAT('30031', Precinct) AS precinct, 'polygon' AS accuracy FROM Precincts2013" \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ data/30-montana/county/2018/031-Gallatin/Precincts2013.shp
# Add Lake County (FIPS 047) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2018' AS year, '30' AS state, '047' AS county, CONCAT('30047', Precinct) AS precinct, 'polygon' AS accuracy FROM Lake_Precincts_May_2018" \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ data/30-montana/county/2018/047-Lake/Lake_Precincts_May_2018.shp
# Add Lewis and Clark County (FIPS 049) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2018' AS year, '30' AS state, '049' AS county, CONCAT('30049', Precinct) AS precinct, 'polygon' AS accuracy FROM LCPrecincts" \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ data/30-montana/county/2018/049-LewisAndClark/LCPrecincts.shp
# Add Missoula County (FIPS 063) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2018' AS year, '30' AS state, '063' AS county, CONCAT('30063', Precinct) AS precinct, 'polygon' AS accuracy FROM Precincts" \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ data/30-montana/county/2018/063-Missoula/Precincts.shp
# Add Yellowstone County (FIPS 111) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2018' AS year, '30' AS state, '111' AS county, CONCAT('30111', Precinct) AS precinct, 'polygon' AS accuracy FROM YC_precincts" \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ data/30-montana/county/2018/111-Yellowstone/YC_precincts.shp
out/31-nebraska/state.gpkg: data/31-nebraska/statewide/2010/tl_2012_31_vtd10.zip data/template.shp
mkdir -p out/31-nebraska
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2010' AS year, STATEFP10 AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_31_vtd10" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/31-nebraska/statewide/2010/tl_2012_31_vtd10.zip/tl_2012_31_vtd10.shp'
out/32-nevada/state.gpkg: data/32-nevada/statewide/2010/tl_2012_32_vtd10.zip \
data/template.shp \
data/32-nevada/county/2016/clark_crel_precinct_p.zip \
data/32-nevada/county/2016/nevadacarsoncity.zip \
data/32-nevada/county/2016/nevadadouglas.zip \
data/32-nevada/county/2016/nevadaelko.zip \
data/32-nevada/county/2016/nevadaeureka.zip \
data/32-nevada/county/2016/nevadawashoe.zip
mkdir -p out/32-nevada
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
# Skip a few since they'll come from another file.
ogr2ogr -sql "SELECT '2010' AS year, '32' AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_32_vtd10 WHERE COUNTYFP10 NOT IN ('003', '510', '005', '007', '011', '013', '031')" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/32-nevada/statewide/2010/tl_2012_32_vtd10.zip/tl_2012_32_vtd10.shp'
# Add Clark County (FIPS 003) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '32' AS state, '003' AS county, CONCAT('32003', CAST(PREC AS character(10))) AS precinct, 'polygon' AS accuracy FROM precinct_p" \
-s_srs '+proj=tmerc +lat_0=34.75 +lon_0=-115.5833333333333 +k=0.9999 +x_0=199999.9999999999 +y_0=7999999.999999997 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsizip/data/32-nevada/county/2016/clark_crel_precinct_p.zip/precinct_p.shp
# Add Carson City (FIPS 510) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '32' AS state, '510' AS county, CONCAT('32510', CAST(Precinct AS character(5))) AS precinct, 'polygon' AS accuracy FROM nevadacarsoncity" \
-s_srs '+proj=tmerc +lat_0=34.75 +lon_0=-118.5833333333333 +k=0.9999 +x_0=799999.9999999998 +y_0=3999999.999999999 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsizip/data/32-nevada/county/2016/nevadacarsoncity.zip/nevadacarsoncity.shp
# Add Douglas (FIPS 005) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '32' AS state, '005' AS county, CONCAT('32005', TAG) AS precinct, 'polygon' AS accuracy FROM nevadadouglas" \
-s_srs '+proj=tmerc +lat_0=34.75 +lon_0=-118.5833333333333 +k=0.9999 +x_0=799999.9999999998 +y_0=3999999.999999999 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsizip/data/32-nevada/county/2016/nevadadouglas.zip/nevadadouglas.shp
# Add Elko (FIPS 007) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '32' AS state, '007' AS county, CONCAT('32007', SUBSTR(NAME,10)) AS precinct, 'polygon' AS accuracy FROM nevadaelko" \
-s_srs EPSG:26911 -t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsizip/data/32-nevada/county/2016/nevadaelko.zip/nevadaelko.shp
# Add Eureka (FIPS 011) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '32' AS state, '011' AS county, CONCAT('32011', Label) AS precinct, 'polygon' AS accuracy FROM nevadaeureka" \
-s_srs EPSG:32008 -t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsizip/data/32-nevada/county/2016/nevadaeureka.zip/nevadaeureka.shp
# Add Humboldt (FIPS 013) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '32' AS state, '013' AS county, CONCAT('32013', LAYER) AS precinct, 'polygon' AS accuracy FROM nevadahumboldt" \
-s_srs '+proj=tmerc +lat_0=34.75 +lon_0=-118.583333333333 +k=0.9999 +x_0=152400.30480061 +y_0=0 +datum=NAD27 +units=us-ft +no_defs' \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsizip/data/32-nevada/county/2016/nevadahumboldt.zip/nevadahumboldt.shp
# Add Washoe (FIPS 031) to the statewide Geopackage file.
ogr2ogr -sql "SELECT '2016' AS year, '32' AS state, '031' AS county, CONCAT('32031', CAST(PRECINCT AS character(10))) AS precinct, 'polygon' AS accuracy FROM nevadawashoe" \
-s_srs '+proj=tmerc +lat_0=34.75 +lon_0=-118.5833333333333 +k=0.9999 +x_0=800000.0000101601 +y_0=3999999.999989841 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' \
-t_srs EPSG:4326 -f GPKG -nln state -append \
$@ /vsizip/data/32-nevada/county/2016/nevadawashoe.zip/nevadawashoe.shp
out/33-new-hampshire/state.gpkg: data/33-new-hampshire/statewide/2016/NHPolitDists.zip data/template.shp
mkdir -p out/33-new-hampshire
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2016' AS year, '33' AS state, CASE COUNTY WHEN 'Belknap' THEN '001' WHEN 'Carroll' THEN '003' WHEN 'Cheshire' THEN '005' WHEN 'Coos' THEN '007' WHEN 'Grafton' THEN '009' WHEN 'Hillsborough' THEN '011' WHEN 'Merrimack' THEN '013' WHEN 'Rockingham' THEN '015' WHEN 'Strafford' THEN '017' WHEN 'Sullivan' THEN '019' ELSE COUNTY END AS county, nameward AS precinct, 'polygon' AS accuracy, GEOMETRY AS geometry FROM NHPolitDists" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/33-new-hampshire/statewide/2016/NHPolitDists.zip/NHPolitDists.shp'
out/34-new-jersey/state.gpkg: data/34-new-jersey/statewide/2010/tl_2012_34_vtd10.zip data/template.shp
mkdir -p out/34-new-jersey
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2010' AS year, STATEFP10 AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_34_vtd10" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/34-new-jersey/statewide/2010/tl_2012_34_vtd10.zip/tl_2012_34_vtd10.shp'
out/35-new-mexico/state.gpkg: data/35-new-mexico/statewide/2012/nm-2012-precincts.zip \
data/35-new-mexico/counties/tl_2016_35_cousub.zip \
data/template.shp
mkdir -p out/35-new-mexico
# GPKG are weird
rm -f $@
# Copy precinct data
ogr2ogr -s_srs EPSG:32613 -t_srs EPSG:4326 -append -f GPKG out/35-new-mexico/staging.gpkg \
'/vsizip/data/35-new-mexico/statewide/2012/nm-2012-precincts.zip/precincts_2012.shp'
# Copy township data. This data comes from the census.
# https://catalog.data.gov/dataset/tiger-line-shapefile-2016-state-new-mexico-current-county-subdivision-state-based
ogr2ogr -t_srs EPSG:4326 -append -f GPKG out/35-new-mexico/staging.gpkg \
'/vsizip/data/35-new-mexico/counties/tl_2016_35_cousub.zip/tl_2016_35_cousub.shp'
# Aggregate historical court districts data into counties.
ogr2ogr -sql "SELECT c.COUNTYFP AS county, 'polygon' AS accuracy, ST_Union(c.GEOM) AS geom FROM tl_2016_35_cousub c GROUP BY c.COUNTYFP" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln county -append -f GPKG out/35-new-mexico/staging.gpkg out/35-new-mexico/staging.gpkg
# Compute all county/precinct intersections as a precursor to assigning
# precincts to the counties that contain the most of their area.
ogr2ogr -sql "SELECT p.NAME10 AS precinct, c.county AS county, 'polygon' AS accuracy, ST_Intersection(p.GEOM, c.GEOM) AS geom, ST_Area(ST_Intersection(p.GEOM, c.GEOM)) AS area, ST_Area(p.GEOM) AS parea, ST_Area(c.GEOM) AS carea FROM precincts_2012 p, county c WHERE ST_Disjoint(ST_Envelope(c.GEOM), ST_Envelope(p.GEOM))=0 AND ST_Intersection(p.GEOM, c.GEOM) IS NOT NULL" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln intersection -append -f GPKG out/35-new-mexico/staging.gpkg out/35-new-mexico/staging.gpkg
# Join each precinct to the county that contains the most of its area.
# We'd prefer to use a window function, which would make this much
# simpler, but the build version of ogr2ogr does not have a recent
# enough version to support them.
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
ogr2ogr -sql "SELECT '2016' AS year, '10' AS state, i.county AS county, p.NAME10 AS precinct, 'polygon' AS accuracy, p.GEOM AS geometry FROM (SELECT precinct, MAX(area) AS maxarea FROM intersection i GROUP BY precinct) m, intersection i, precincts_2012 p WHERE i.precinct=m.precinct AND i.precinct=p.NAME10 AND i.area=m.maxarea" \
-dialect SQLITE \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ out/35-new-mexico/staging.gpkg
rm -rf 'out/35-new-mexico/staging.gpkg'
out/36-new-york/state.gpkg: data/36-new-york/statewide/2010/tl_2012_36_vtd10.zip \
data/36-new-york/001-albany/2012/2012_EDs-Albany.shp \
data/36-new-york/003-allegany/2012/ElectionDistricts2012.shp \
data/36-new-york/003-allegany/2014/ElectionDistricts2014.shp \
data/36-new-york/007-broome/2016/broome_ed.shp \
data/36-new-york/009-cattaraugus/2012/CattaraugusVotingDistricts.shp \
data/36-new-york/011-cayuga/2012/Election_Districts.shp \
data/36-new-york/011-cayuga/2014/Cayuga_County_NY_Elect_Dists.shp \
data/36-new-york/019-clinton/2014/ClintonEDs.shp \
data/36-new-york/023-cortland/2012/election_districts.shp \
data/36-new-york/027-dutchess/2008/DutchessCountyElectionDistricts.shp \
data/36-new-york/027-dutchess/2012/2012_EDs-Dutchess.shp \
data/36-new-york/027-dutchess/2014/DutchessED3-6.shp \
data/36-new-york/029-erie/2001/ny-erie-county-election_dist.zip \
data/36-new-york/029-erie/2012/2012_EDs-Erie.shp \
data/36-new-york/029-erie/2014/2015\ ED\ Final.shp \
data/36-new-york/031-essex/2014/ED15.shp \
data/36-new-york/043-herkimer/2012/2012_EDs-Herkimer.shp \
data/36-new-york/055-monroe/2012/2012_EDs-Monroe.shp \
data/36-new-york/059-nassau/2012/2012_EDs-Nassau.shp \
data/36-new-york/059-nassau/2014/Nassau\ County\ Election\ Districts.shp \
data/36-new-york/059-nassau/2018/Electin\ Districts.shp \
data/36-new-york/061-new-york/2014/nyed.shp \
data/36-new-york/061-new-york/2016/nyed_16d/nyed.shp \
data/36-new-york/061-new-york/2017/nyed_17a/nyed.shp \
data/36-new-york/063-niagara/2012/2012_EDs-Niagara.shp \
data/36-new-york/065-oneida/2012/2012_EDs-Oneida.shp \
data/36-new-york/067-onondaga/2012/2012_EDs-Onondaga.shp \
data/36-new-york/067-onondaga/2014/election_districts.shp \
data/36-new-york/069-ontario/2014/BOE_Election_Districts.shp \
data/36-new-york/069-ontario/2016/BOE_Election_Districts_201605180903412713.zip \
data/36-new-york/071-orange/2012/2012_EDs-Orange.shp \
data/36-new-york/071-orange/2014/OC_ElectionDistricts2014.shp \
data/36-new-york/073-orleans/2008/ALBIVOTE.SHP \
data/36-new-york/073-orleans/2008/CLARVOTE.SHP \
data/36-new-york/073-orleans/2008/MURRVOTE.SHP \
data/36-new-york/073-orleans/2008/BARRVOTE.SHP \
data/36-new-york/073-orleans/2008/GAINVOTE.SHP \
data/36-new-york/073-orleans/2008/SHELVOTE.SHP \
data/36-new-york/073-orleans/2008/CARLVOTE.SHP \
data/36-new-york/073-orleans/2008/KENDVOTE.SHP \
data/36-new-york/073-orleans/2008/YATEVOTE.SHP \
data/36-new-york/075-oswego/2014/funal_run_4.shp \
data/36-new-york/077-otsego/2012/Otsego_Voting_2012_Final.shp \
data/36-new-york/079-putnam/2012/2012_EDs-Putnam.shp \
data/36-new-york/083-rensselaer/2012/cnty_election_districts.shp \
data/36-new-york/083-rensselaer/2014/cnty_ed.shp \
data/36-new-york/083-rensselaer/2016/ren-cnty_ed.zip \
data/36-new-york/087-rockland/2012/2012_EDs-Rockland.shp \
data/36-new-york/087-rockland/2016/Cty_ED_Jan_15_2016.shp \
data/36-new-york/089-st-lawrence/2012/2012_EDs-St_Lawrence.shp \
data/36-new-york/093-schenectady/2012/2012_EDs-Duanesburg.shp \
data/36-new-york/093-schenectady/2012/2012_EDs-Glenville.shp \
data/36-new-york/093-schenectady/2012/2012_EDs-Niskayuna.shp \
data/36-new-york/093-schenectady/2012/2012_EDs-Princetown.shp \
data/36-new-york/093-schenectady/2012/2012_EDs-Rotterdam.shp \
data/36-new-york/093-schenectady/2012/2012_EDs-Schenectady_.shp \
data/36-new-york/095-schoharie/2012/ElectionDists.shp \
data/36-new-york/101-steuben/2012/2012_EDs-Steuben.shp \
data/36-new-york/101-steuben/2014/ElectionDistricts.shp \
data/36-new-york/103-suffolk/2012/2012\ ED\ Files.shp \
data/36-new-york/107-tioga/2012/2012_EDs-Tioga.shp \
data/36-new-york/109-tompkins/2014/ElDistricts2014.shp \
data/36-new-york/111-ulster/2012/2012_EDs-Ulster.shp \
data/36-new-york/113-warren/2012/2012_EDs-Warren.shp \
data/36-new-york/115-washington/2012/2012_EDs-Washington.shp \
data/36-new-york/115-washington/2014/election_districts.shp \
data/36-new-york/119-westchester/2012/2012_EDs-Westchester.shp \
data/36-new-york/119-westchester/2014/Westchester\ 2014\ Election\ Districts.shp \
data/36-new-york/123-yates/2012/2012_EDs-Yates.shp \
data/template.shp
mkdir -p out/36-new-york
# GPKG are weird
rm -f $@
ogr2ogr -s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -overwrite -f GPKG $@ data/template.shp
# Baseline Census 2010 for state (excluding cutouts)
ogr2ogr -sql "SELECT '2010' AS year, STATEFP10 AS state, COUNTYFP10 AS county, GEOID10 AS precinct, 'polygon' AS accuracy FROM tl_2012_36_vtd10 WHERE COUNTYFP10 NOT IN ('001','003','005','007','009','011','019','023','027','029','031','043','047','055','059','061','063','065','067','069','071','073','075','077','079','081','083','085','087','089','093','095','101','103','107','109','111','113','115','119','123')" \
-s_srs EPSG:4269 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/36-new-york/statewide/2010/tl_2012_36_vtd10.zip/tl_2012_36_vtd10.shp'
# Add 001-albany
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '001' AS county, CONCAT('36001', CAST(DistName AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"2012_EDs-Albany\"" \
-s_srs EPSG:2260 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/001-albany/2012/2012_EDs-Albany.shp'
# Add 003-allegany
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '003' AS county, CONCAT('36003', CAST(NAMELSAD10 AS character(20))) AS precinct, 'polygon' AS accuracy FROM ElectionDistricts2012" \
-s_srs '+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/003-allegany/2012/ElectionDistricts2012.shp'
ogr2ogr -sql "SELECT '2014' AS year, '36' AS state, '003' AS county, CONCAT('36003', CAST(NAMELSAD10 AS character(20))) AS precinct, 'polygon' AS accuracy FROM ElectionDistricts2014" \
-s_srs '+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/003-allegany/2014/ElectionDistricts2014.shp'
# Add 007-broome
ogr2ogr -sql "SELECT '2016' AS year, '36' AS state, '007' AS county, CONCAT('36007', CAST(NAME AS character(20))) AS precinct, 'polygon' AS accuracy FROM broome_ed" \
-s_srs '+proj=tmerc +lat_0=40 +lon_0=-76.58333333333333 +k=0.9999375 +x_0=250000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/007-broome/2016/broome_ed.shp'
# Add 009-cattaraugus
ogr2ogr -sql "SELECT '2013' AS year, '36' AS state, '009' AS county, CONCAT('36009', CAST(DISTRICT AS character(20))) AS precinct, 'polygon' AS accuracy FROM CattaraugusVotingDistricts" \
-s_srs '+proj=tmerc +lat_0=40 +lon_0=-78.58333333333333 +k=0.9999375 +x_0=350000.0000000001 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/009-cattaraugus/2012/CattaraugusVotingDistricts.shp'
# Add 011-cayuga
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '011' AS county, CONCAT('36011', CAST(MUNI AS character(20)), CAST(DISTRICT AS character(20))) AS precinct, 'polygon' AS accuracy FROM Election_Districts" \
-s_srs '+proj=tmerc +lat_0=40 +lon_0=-76.58333333333333 +k=0.9999375 +x_0=152400.3048006096 +y_0=0 +datum=NAD27 +units=us-ft +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/011-cayuga/2012/Election_Districts.shp'
# This one errors with: "Failed to reproject feature 38 (geometry probably out of source or destination SRS)."
ogr2ogr -sql "SELECT '2015' AS year, '36' AS state, '011' AS county, CONCAT('36011', CAST(MUNI AS character(20)), CAST(District AS character(20))) AS precinct, 'polygon' AS accuracy FROM Cayuga_County_NY_Elect_Dists" \
-skipfailures -s_srs '+proj=tmerc +lat_0=40 +lon_0=-76.58333333333333 +k=0.9999375 +x_0=152400.3048006096 +y_0=0 +datum=NAD27 +units=us-ft +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/011-cayuga/2014/Cayuga_County_NY_Elect_Dists.shp'
# 015-chemung aren't polygons :(
# 019-clinton
ogr2ogr -sql "SELECT '2015' AS year, '36' AS state, '019' AS county, CONCAT('36019', CAST(Election_D AS character(20))) AS precinct, 'polygon' AS accuracy FROM ClintonEDs" \
-s_srs EPSG:2260 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/019-clinton/2014/ClintonEDs.shp'
# 023-cortland
ogr2ogr -sql "SELECT '2013' AS year, '36' AS state, '023' AS county, CONCAT('36023', CAST(ED AS character(20))) AS precinct, 'polygon' AS accuracy FROM election_districts" \
-s_srs '+proj=tmerc +lat_0=40 +lon_0=-76.58333333333333 +k=0.9999375 +x_0=250000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/023-cortland/2012/election_districts.shp'
# 027-dutchess. not 100% sure that DISTRICT is the right column
ogr2ogr -sql "SELECT '2008' AS year, '36' AS state, '027' AS county, CONCAT('36027', CAST(DISTRICT AS character(20))) AS precinct, 'polygon' AS accuracy FROM DutchessCountyElectionDistricts" \
-s_srs '+proj=longlat +datum=WGS84 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/027-dutchess/2008/DutchessCountyElectionDistricts.shp'
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '027' AS county, CONCAT('36027', CAST(DISTRICT AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"2012_EDs-Dutchess\"" \
-s_srs '+proj=longlat +ellps=GRS80 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/027-dutchess/2012/2012_EDs-Dutchess.shp'
ogr2ogr -sql "SELECT '2015' AS year, '36' AS state, '027' AS county, CONCAT('36027', CAST(DISTRICT AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"DutchessED3-6\"" \
-s_srs '+proj=longlat +ellps=GRS80 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/027-dutchess/2014/DutchessED3-6.shp'
# 029-erie
ogr2ogr -sql "SELECT '2000' AS year, '36' AS state, '029' AS county, CONCAT('36029', CAST(OLMA_ AS character(20))) AS precinct, 'polygon' AS accuracy FROM election_2000" \
-s_srs '+proj=tmerc +lat_0=40 +lon_0=-78.58333333333333 +k=0.9999375 +x_0=350000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=ft +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/36-new-york/029-erie/2001/ny-erie-county-election_dist.zip/election_2000.shp'
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '029' AS county, CONCAT('36029', CAST(ED AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"2012_EDs-Erie\"" \
-s_srs '+proj=utm +zone=18 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/029-erie/2012/2012_EDs-Erie.shp'
# the election district id's gained a left number padding this year, might require tweaking
ogr2ogr -sql "SELECT '2015' AS year, '36' AS state, '029' AS county, CONCAT('36029', CAST(ED AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"2015 ED Final\"" \
-s_srs EPSG:2260 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/029-erie/2014/2015 ED Final.shp'
# 031-essex
ogr2ogr -sql "SELECT '2015' AS year, '36' AS state, '031' AS county, CONCAT('36031', CAST(DIST_NUM AS character(20))) AS precinct, 'polygon' AS accuracy FROM ED15" \
-s_srs '+proj=tmerc +lat_0=40 +lon_0=-74.33333333333333 +k=0.9999666666666667 +x_0=152400.3048006096 +y_0=0 +datum=NAD27 +units=us-ft +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/031-essex/2014/ED15.shp'
# 043-herkimer
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '043' AS county, CONCAT('36043', CAST(Name AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"2012_EDs-Herkimer\"" \
-s_srs '+proj=longlat +ellps=GRS80 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/043-herkimer/2012/2012_EDs-Herkimer.shp'
# 055-monroe
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '055' AS county, CONCAT('36055', CAST(ED AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"2012_EDs-Monroe\"" \
-s_srs '+proj=tmerc +lat_0=40 +lon_0=-78.58333333333333 +k=0.9999375 +x_0=350000.0000000001 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/055-monroe/2012/2012_EDs-Monroe.shp'
# 059-nassau
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '059' AS county, CONCAT('36059', CAST(419035 AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"2012_EDs-Nassau\"" \
-s_srs '+proj=utm +zone=18 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/059-nassau/2012/2012_EDs-Nassau.shp'
ogr2ogr -sql "SELECT '2015' AS year, '36' AS state, '059' AS county, CONCAT('36059', CAST(ID AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"Nassau County Election Districts\"" \
-s_srs '+proj=longlat +ellps=GRS80 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/059-nassau/2014/Nassau County Election Districts.shp'
ogr2ogr -sql "SELECT '2018' AS year, '36' AS state, '059' AS county, CONCAT('36059', CAST(DISTRICT AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"Electin Districts\"" \
-s_srs '+proj=longlat +ellps=GRS80 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/059-nassau/2018/Electin Districts.shp'
# 061-new-york
# Add New York City
ogr2ogr -sql "SELECT '2014' AS year, '36' AS state, county, CONCAT('36', county, CAST(ElectDist AS character(5))) AS precinct, 'polygon' AS accuracy FROM nyed" \
-s_srs '+proj=lcc +lat_1=40.66666666666666 +lat_2=41.03333333333333 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/061-new-york/2014/nyed.shp'
ogr2ogr -sql "SELECT '2016' AS year, '36' AS state, county, CONCAT('36', county, CAST(ElectDist AS character(5))) AS precinct, 'polygon' AS accuracy FROM nyed" \
-s_srs '+proj=lcc +lat_1=40.66666666666666 +lat_2=41.03333333333333 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/061-new-york/2016/nyed_16d/nyed.shp'
ogr2ogr -sql "SELECT '2017' AS year, '36' AS state, county, CONCAT('36', county, CAST(ElectDist AS character(5))) AS precinct, 'polygon' AS accuracy FROM nyed" \
-s_srs '+proj=lcc +lat_1=40.66666666666666 +lat_2=41.03333333333333 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/061-new-york/2017/nyed_17a/nyed.shp'
# 063-niagara
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '063' AS county, CONCAT('36063', CAST(City_Town AS character(20)), CAST(District AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"2012_EDs-Niagara\"" \
-s_srs '+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/063-niagara/2012/2012_EDs-Niagara.shp'
# 065-oneida
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '065' AS county, CONCAT('36063', CAST(ID AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"2012_EDs-Oneida\"" \
-s_srs '+proj=longlat +ellps=GRS80 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/065-oneida/2012/2012_EDs-Oneida.shp'
# 067-onondaga
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '067' AS county, CONCAT('36067', CAST(ELECT_DIST AS character(20))) AS precinct, 'polygon' AS accuracy FROM \"2012_EDs-Onondaga\"" \
-s_srs '+proj=tmerc +lat_0=40 +lon_0=-76.58333333333333 +k=0.9999375 +x_0=250000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/067-onondaga/2012/2012_EDs-Onondaga.shp'
ogr2ogr -sql "SELECT '2014' AS year, '36' AS state, '067' AS county, CONCAT('36067', CAST(ELECT_DIST AS character(20))) AS precinct, 'polygon' AS accuracy FROM election_districts" \
-s_srs '+proj=tmerc +lat_0=40 +lon_0=-76.58333333333333 +k=0.9999375 +x_0=250000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/067-onondaga/2014/election_districts.shp'
# Add 069-ontario
ogr2ogr -sql "SELECT '2015' AS year, '36' AS state, '069' AS county, CONCAT('36069', CAST(JOINCODE AS character(10))) AS precinct, 'polygon' AS accuracy FROM BOE_Election_Districts" \
-s_srs '+proj=tmerc +lat_0=40 +lon_0=-76.58333333333333 +k=0.9999375 +x_0=250000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/069-ontario/2014/BOE_Election_Districts.shp'
ogr2ogr -sql "SELECT '2017' AS year, '36' AS state, '069' AS county, CONCAT('36069', CAST(JOINCODE AS character(10))) AS precinct, 'polygon' AS accuracy FROM BOE_Election_Districts" \
-s_srs '+proj=tmerc +lat_0=40 +lon_0=-76.58333333333333 +k=0.9999375 +x_0=250000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs' \
-t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'/vsizip/data/36-new-york/069-ontario/2016/BOE_Election_Districts_201605180903412713.zip/BOE_Election_Districts.shp'
# 071-orange
ogr2ogr -sql "SELECT '2012' AS year, '36' AS state, '071' AS county, CONCAT('36071', CAST(ELE_DIS AS character(10))) AS precinct, 'polygon' AS accuracy FROM \"2012_EDs-Orange\"" \
-s_srs EPSG:2260 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/071-orange/2012/2012_EDs-Orange.shp'
ogr2ogr -sql "SELECT '2014' AS year, '36' AS state, '071' AS county, CONCAT('36071', CAST(ELE_DIS AS character(10))) AS precinct, 'polygon' AS accuracy FROM \"OC_ElectionDistricts2014\"" \
-s_srs EPSG:2260 -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/071-orange/2014/OC_ElectionDistricts2014.shp'
# 073-orleans
ogr2ogr -sql "SELECT '2008' AS year, '36' AS state, '073' AS county, CONCAT('36073', CAST(ID_ AS character(10))) AS precinct, 'polygon' AS accuracy FROM ALBIVOTE" \
-s_srs '+proj=longlat +ellps=clrk66 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/073-orleans/2008/ALBIVOTE.SHP'
ogr2ogr -sql "SELECT '2008' AS year, '36' AS state, '073' AS county, CONCAT('36073', CAST(ID_ AS character(10))) AS precinct, 'polygon' AS accuracy FROM CLARVOTE" \
-s_srs '+proj=longlat +ellps=clrk66 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/073-orleans/2008/CLARVOTE.SHP'
ogr2ogr -sql "SELECT '2008' AS year, '36' AS state, '073' AS county, CONCAT('36073', CAST(ID_ AS character(10))) AS precinct, 'polygon' AS accuracy FROM MURRVOTE" \
-s_srs '+proj=longlat +ellps=clrk66 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/073-orleans/2008/MURRVOTE.SHP'
ogr2ogr -sql "SELECT '2008' AS year, '36' AS state, '073' AS county, CONCAT('36073', CAST(ID_ AS character(10))) AS precinct, 'polygon' AS accuracy FROM BARRVOTE" \
-s_srs '+proj=longlat +ellps=clrk66 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/073-orleans/2008/BARRVOTE.SHP'
ogr2ogr -sql "SELECT '2008' AS year, '36' AS state, '073' AS county, CONCAT('36073', CAST(ID_ AS character(10))) AS precinct, 'polygon' AS accuracy FROM GAINVOTE" \
-s_srs '+proj=longlat +ellps=clrk66 +no_defs' -t_srs EPSG:4326 -nln state -append -f GPKG $@ \
'data/36-new-york/073-orleans/2008/GAINVOTE.SHP'