|
|
We provide our Leaflet maps with shapes in the form of GeoJSON. I'm sure their are probably a number of pre-made US state and county GeoJSON files available on GitHub and such, but it's nice to know a general procedure.
|
|
|
|
|
|
For our example here, we'll create a GeoJSON file of the fifty states and Washington, D.C., and we'll try to keep it under 200KB.
|
|
|
For our example here, we'll create a GeoJSON file of the fifty states and Washington, D.C., and we'll try to keep it under 200 KB.
|
|
|
|
|
|
### Step 1. Get geography files from the Census Bureau
|
|
|
The Census Bureau is usually the most convenient source for governmental boundaries in the US. Like many other federal agencies (*cough*, USGS, *cough*), the Census has lots of different web interfaces with slightly different features to access the same data, and the old, simple one is usually the best even though it's now hard to find from the agency's homepage.
|
... | ... | @@ -13,4 +13,9 @@ For our example here, we'll download US States. (It also includes "state equival |
|
|
|
|
|
FYI, [TIGER/Line](https://en.wikipedia.org/wiki/Topologically_Integrated_Geographic_Encoding_and_Referencing) is what the Census Bureau calls their data model. [Shapefile](https://en.wikipedia.org/wiki/Shapefile) is a file format.
|
|
|
|
|
|
### Step 2. Topology-aware simplification |
|
|
\ No newline at end of file |
|
|
### Step 2. Topology-aware simplification with MapShaper
|
|
|
You might have noticed the file you downloaded — which is a ZIP archive containing several files (And yes, all of them are part of the "Shapefile"; no, you can't delete everything except the .shp.) — is about 10 MB in size. If you were get ahead of our process and convert it to GeoJSON now, you'd end up with about 6.5 MB gzipped. Ooof.
|
|
|
|
|
|
Obviously, our little web map doesn't need to be quite this precise enough to see every little bend in every river that forms a state border. Fortunately, just about every GIS tool out there has tools to shrink file sizes by dramatically simplifying shapes. A good and widely available algorithm is Visvalingam’s Algorithm, for which you can find a very nice, visual explanation [here](https://bost.ocks.org/mike/simplify/).
|
|
|
|
|
|
*Un*fortunately, most of those tools are not topology-aware: they're going to process, for example, the Georgia-Alabama border once for the Georgia shape and once for the Alabama shape, possibly making slightly different decisions for each, leading to small gaps or overlaps. This is where [MapShaper](https://mapshaper.org) comes in. |
|
|
\ No newline at end of file |