Skip to content

Instantly share code, notes, and snippets.

@tin6150
Last active February 16, 2024 07:30
Show Gist options
  • Save tin6150/e271e5d3bef6d93ebc6817170ddd2456 to your computer and use it in GitHub Desktop.
Save tin6150/e271e5d3bef6d93ebc6817170ddd2456 to your computer and use it in GitHub Desktop.
Displaying Census TIGER/line population data in mapbox

Displaying Census TIGER/line population data in mapbox

This gist covers how to get mapbox gl js web-based map to display population data from US Census data, specifically, from their TIGER/line product, which has ESRI shapefile and dbf (dBase III) data file

Here is an example of finished product: https://tin6150.github.io/inet-dev-class/mapbox/mapbox-census-pop.html

screenshot of census data displayed in Mapbox WebGL JavaScript

Steps

Code snipplet

map.on('mousemove', function (e) {
    var states = map.queryRenderedFeatures(e.point, {
        layers: ['delaware-tabblock2010-10-pophu-a0nmlv']
    });
    if (states.length > 0) {
        document.getElementById('pd').innerHTML
        = "<strong> pop:"   + states[0].properties.POP10      + "</strong><p>"
        + "blockce: "       + states[0].properties.BLOCKCE    + "<br>"
        + "blockid10: "     + states[0].properties.BLOCKID10  + "<br>"
        + "countyfp10: "    + states[0].properties.COUNTYFP10 + "<br>"
        + "housing10: "     + states[0].properties.HOUSING10  + "<br>"
        + "partflg: "       + states[0].properties.PARTFLG    + "<br>"
        + "statefp10: "     + states[0].properties.STATEFP10  + "<br>"
        + "tractce10: "     + states[0].properties.TRACECE10  + "<br>"
        + "</p>";
    };
};

Other Examples

  • Smelly. This map has modeling data about odor concentration dispersal for various solid waste to energy plants across california. JavaScript is used to dynamically load/unload necessary layer and fly to desired location. https://github.com/tin6150/smelly

Dealing with large census zip files

Mapbox tileset import limit import to 260 MB. CA is 408 MB, so that need to be split... The map for Medium with Census Block Group level population density end up using a .geojson that was 17M. It could have been imported into mapbox as Tileset (it converts during import), but ended up serving the .geojson via http by github.

Author

tin (at) berkeley.edu

Thanks

  • Mapbox... this is a really awesome product!
  • Census... amazing amount of data!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment