Guide for County Based Heat Maps?

I'm trying to make a heat map based on counties but not in this state. Is there a guide for how to do awesome stuff like this?

Hi @paintbb84
You add the GeoJSON file you want to Admin > Settings > Maps. This example it's this:
https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/california-counties.geojson
Have a look here: https://www.metabase.com/learn/visualization/maps

Hi @flamber -
I'm looking to do the same as the OP.

I'm attempting to use this file on github:

Metabase is telling me Invalid custom GeoJSON: does not contain features.

If I look at the file, I can see it mentions 'features'. What I'm not clear on is whether the URL is allowing metabase to get directly to the file, or whether the use of 'features' in the file meets the expectations that metabase has.

@ChrisH That map doesn't look valid, check what is being displayed via Github's preview:
https://github.com/lgdelacruz92/us-counties-geojson-and-topojson/blob/main/Idaho/geo-county-min-37.json

Yeah - looks like garbage in the GitHub preview, but I've never seen a working example so I'm not sure whether the preview works properly. Do you happen to know if the GitHub preview is reliable for these files?

If I can find a working example, then I can compare the files and see what might be missing from the ones I want to use.

@ChrisH Have a look at the built-in US states region map:
https://github.com/metabase/metabase/blob/master/resources/frontend_client/app/assets/geojson/us-states.json

That helps!

If I compare the us-states.json you provided and this file for Idaho (geo-county-min-37.json), I can see that the Idaho file contains some extra fields: id & properties (circled below).

Could those extra fields be causing Metabase to think there are no 'features'?

@ChrisH Perhaps it's the ID that is messing things up, not sure. The US states also has properties, ex ,"properties":{"STATE":"ID","NAME":"Idaho"}

Play around in http://geojson.io and see if you can cleanup the GeoJSON.
Also recommend https://mapshaper.org

Otherwise try searching for different GeoJSON maps out there. There's usually many sources.

Sweet! I found what looks like a good file - it will import anyway:
https://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_050_00_5m.json

Am I going to need to add a column to my data that maps to the COUNTY property? or is there some way I can map my 'state' and 'county' columns to the 'STATE' and 'NAME' properties in the map?

@ChrisH You will needs to make sure that your results contains the region identifier, otherwise Metabase doesn't know how to map the data.
Or alternatively, adjust the GeoJSON, so it fits with your data.
If you only need a specific subset (just Idaho), then remove everything else from the GeoJSON.

1 Like

I've got this working, but I would love for the map to zoom in to focus on just the state where there is data:

In the picture, you can see that I have data just in Idaho, but it' super tiny.

I'm sure I could "zoom in" by creating a Region map file for each state, but it would be great if there were a way to filter the Region map by a value in the map. Is that possible?

@ChrisH upvote by clicking :+1: on the first post on each issue:
https://github.com/metabase/metabase/issues/13533
https://github.com/metabase/metabase/issues/4724

All other map related issues:
https://github.com/metabase/metabase/issues?q=is%3Aopen+is%3Aissue+label%3AVisualization%2FMaps

1 Like

I Voted!

For now, here is my process :smiley:
And yes, it could be significantly optimized and automated once I go beyond 2 states. But this worked well as a hack-job proof-of-concept.

Geo data

Source: https://eric.clst.org/tech/usgeojson/

(also has congressional districts)

Medium res Counties:

https://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_050_00_5m.json

Dump all county info:

PowerShell
((Invoke-WebRequest "https://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_050_00_5m.json").content | convertfrom-json).features.properties | export-csv geo_state.csv

Dump states to get state to state ID to state name mappping

((Invoke-WebRequest "https://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_040_00_5m.json").content | convertfrom-json).features.properties | export-csv geo_county.csv

Split the county file into state files

  • Look at \state\geo_state.csv to see what the number is for a particular state

    • Idaho is '16'
  • Copy file with all states (\county\eric.clst.org_gz_2010_us_050_00_5m.json) to an Idaho file (\county\eric.clst.org_gz_2010_us_050_00_5m_idaho.json)

  • Copy contents of the idaho file to the clipboard

  • In PowerShell

    get-clipboard | sls '"STATE": "16"' | %{$_.tostring()+","} | Set-Clipboard

  • Delete all of the Features in the idaho file

  • Paste the clipboard in the Features section of the file

  • Delete the trailing comma ,

  • Copy the entire contents

  • Create a new gist on github named: eric.clst.org_gz_2010_us_050_00_5m_idaho

  • Save it as Public

  • Click the Raw button

  • Get the URL

  • Open Meltano > Settings > Admin settings > Maps

  • Select Add a map

    • Name: US Counties - Idaho

    • URL: Past raw gist url from clipboard

    • Region's identifier: GEO_ID

    • Region's display name: NAME

    • Select Add map

1 Like

Chris, you're a rockstar! I'm going to try and follow in your footsteps on this. If I can make any improvements, I'll post 'em!

Adding an example since I didn't provide one previously: