Counties using Mike Bostock's most excellent us-atlas.
Small difference: "make counties.json" will preserve properties.STATE & properties.COUNTY
gz | |
shp |
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<title>counties1</title> | |
<style> | |
body { | |
font: 20px sans-serif; | |
} | |
path { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
#info { | |
position: absolute; | |
top: 20px; | |
left: 600px; | |
} | |
</style> | |
<body> | |
<div id="info"></div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.19/topojson.min.js"></script> | |
<script> | |
var width = 960, height = 500; | |
var path = d3.geo.path(); | |
var info = d3.select("body").append("div") | |
.attr("id", "info"); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
d3.json("counties.json", function(error, data) { | |
if (error) throw error; | |
features = topojson.feature(data, data.objects.counties).features; | |
svg.selectAll("path") | |
.data(features) | |
.enter() | |
.append("path") | |
.attr("d", path) | |
.on("mouseover", function(d) { var p = d.properties; info.html(p.COUNTY + ", " + p.STATE + "<br>FIPS: " + d.id) }); | |
}); | |
</script> |
# Create counties.json preserving county name & state 2-character ID | |
all: counties.json | |
# Use Mike Bostock's most excellent us-atlas (rest of the makefile is equivalent) | |
counties.json.orig: | |
cd ../us-atlas; make topo/us-counties-10m-ungrouped.json | |
cp ../us-atlas/topo/us-counties-10m-ungrouped.json counties.json.orig | |
gz/countyp010_nt00795.tar.gz: | |
curl 'http://dds.cr.usgs.gov/pub/data/nationalatlas/$(notdir $@)' -o $@ | |
shp/us/counties-unfiltered.shp: gz/countyp010_nt00795.tar.gz | |
rm -rf $(basename $@) | |
mkdir -p $(basename $@) | |
tar -xzm -C $(basename $@) -f $< | |
for file in $(basename $@)/*; do chmod 644 $$file; mv $$file $(basename $@).$${file##*.}; done | |
rmdir $(basename $@) | |
# remove water counties (e.g., Great Lakes) | |
shp/us/counties.shp: shp/us/counties-unfiltered.shp | |
rm -f $@ | |
ogr2ogr -f 'ESRI Shapefile' -where "FIPS NOT LIKE '%000'" $@ $< | |
counties.json: shp/us/counties.shp | |
mkdir -p $(dir $@) | |
topojson \ | |
-o $@ \ | |
--no-pre-quantization \ | |
--post-quantization=1e6 \ | |
--simplify=7e-7 \ | |
-p STATE,COUNTY \ | |
--id-property=+FIPS \ | |
-- $< |