Choropleth Map of Brazil

1,444 views
Skip to first unread message

Bertjan Broeksema

unread,
Jan 26, 2012, 5:16:24 AM1/26/12
to d3-js
Hi All,

A friend of mine is doing research on agriculture risk in Brazil so I
thought I'd help her out a bit by building some visualizations for
her. I'd like to do something similar as this example
http://mbostock.github.com/d3/ex/choropleth.html. However, it is not
clear to me how to get such a map (country, state, county level) for
Brazil. Is there some service where I can get these maps in GeoJSON
format or do I have to construct them manually?

In the latter case, I found some SVG images on wikipedia with state
boundaries like this one here: http://en.wikipedia.org/wiki/File:Brazilian_States.svg
but it doesn't contain county boundaries. Now, there are SVG files for
each state with county boundaries but I'd really like to have
something as in the example.

Any input on creating such a map (or even better a source for such
map) is highly appreciated. Also, in the case that it is necessary to
construct such data myself, any help/pointers on how to tackle that
would be appreciated as well. For example, does the GeoJSON format
require real world coordinates? and if so how would one convert path
coordinates from SVG to real world coordinates. And how would you
create a single map out of separate state files like this:
http://en.wikipedia.org/wiki/File:SaoPaulo_Municip_Aparecida.svg.

Well, lots of questions, looks like a bigger problem to me than I
though on forehand, but perhaps there is a (rather) simple solution.

Thanks in advance,

Bertjan

Lars Kotthoff

unread,
Jan 26, 2012, 5:31:38 AM1/26/12
to d3...@googlegroups.com, b.bro...@gmail.com
> Is there some service where I can get these maps in GeoJSON
> format or do I have to construct them manually?

You can get the data (for example) from http://www.diva-gis.org/gdata
(specifically I found http://gadm.org/data/shp/BRA_adm.zip) as
shapefiles and convert that to GeoJSON. Shapefiles are a standard
geodata format and there's a lot of tools that are able to work with
them/convert them.

I'd recommend that you add the data you want to display in the choropleth map
to the shapefile before converting it to GeoJSON. If you're unsure how to do
that, feel free to contact me off list, I'd be happy to help.

Lars

Bertjan Broeksema

unread,
Jan 26, 2012, 7:23:24 AM1/26/12
to d3-js
> You can get the data (for example) fromhttp://www.diva-gis.org/gdata
> (specifically I foundhttp://gadm.org/data/shp/BRA_adm.zip) as
> shapefiles and convert that to GeoJSON. Shapefiles are a standard
> geodata format and there's a lot of tools that are able to work with
> them/convert them.

Awesome, that's just what I was looking for. I probably used the wrong
search terms as I didn't get here.

> I'd recommend that you add the data you want to display in the choropleth map
> to the shapefile before converting it to GeoJSON.

For which particular reason? In the example the data is separated from
the geographic data as well.

> If you're unsure how to do
> that, feel free to contact me off list, I'd be happy to help.

Thanks!

Bertjan

Lars Kotthoff

unread,
Jan 26, 2012, 7:49:53 AM1/26/12
to d3...@googlegroups.com, b.bro...@gmail.com
> > I'd recommend that you add the data you want to display in the
> > choropleth map to the shapefile before converting it to GeoJSON.
>
> For which particular reason? In the example the data is separated from
> the geographic data as well.

I've found that this works better in practice. As I've said, there're many tools
to work with shapefiles and it's easier to debug if something goes wrong -- most
GIS applications will let you make something like a choropleth map easily so
that you can check that everything looks like it should without spending a lot
of time getting the D3 part to work.

It's certainly feasible to add data to the GeoJSON as well though.

Lars

Bertjan Broeksema

unread,
Jan 26, 2012, 8:44:28 AM1/26/12
to d3-js
Just got the basics up and running. Once you have the data its really
a piece of cake. This blog post has been helpful to me as well:
http://vallandingham.me/shapefile_to_geojson.html

Thanks for the input.

Bertjan

Nelson Minar

unread,
Jan 26, 2012, 11:29:19 AM1/26/12
to d3...@googlegroups.com
Another great source of geographic data is Natural Earth: http://www.naturalearthdata.com/

You might find a GIS program like QuantumGIS is helpful for doing the geographic parts. 

Mike Bostock

unread,
Jan 26, 2012, 11:35:51 AM1/26/12
to d3...@googlegroups.com, d3...@googlegroups.com, b.bro...@gmail.com
Your other advice is excellent, and thank you for fielding support questions, but I don't agree with this particular point--simply because it is so convenient to have separate GeoJSON files and data files (in a format of your choosing, be it CSV or whatever).

That way, it's trivial to change the dataset you are showing without generating (or downloading) another massive GeoJSON file. The only properties I would include in the GeoJSON would be a unique identifier and possibly human-readable names.

Separate data also means that you can load datasets on-demand, again without reloading the GeoJSON. And it's easier to derive a new example with different data.

Mike

Lars Kotthoff

unread,
Jan 26, 2012, 12:12:29 PM1/26/12
to d3...@googlegroups.com, mbos...@gmail.com, b.bro...@gmail.com
> Your other advice is excellent, and thank you for fielding support questions,
> but I don't agree with this particular point--simply because it is so
> convenient to have separate GeoJSON files and data files (in a format of your
> choosing, be it CSV or whatever).

I see your point. I usually put everything in one file for efficiency reasons
however (same reason my JS and CSS is usually inline). I find that loading lots
of small files is usually slower than one large file. Updating data in the JSON
(or whatever) files is not an issue for me.

For on-demand loading of data I totally agree with you.

Lars

tomhobson

unread,
Jan 28, 2012, 1:46:58 PM1/28/12
to d3-js
Hi Bertjan,
Really useful list of free map data (including administrative
boundaries at sub-country level available at:
http://blog.rtwilson.com/categorised-list-of-free-gis-datasets/
This is a work in progress being compiled by Robin Wilson at
Southampton Univ. Some really good references. Anyone working with
mapped data will find it interesting. Be warned though - most GIS data
sets will only be available as .shp files.

Tom

On Jan 26, 10:16 am, Bertjan Broeksema <b.broeks...@gmail.com> wrote:
> Hi All,
>
> A friend of mine is doing research on agriculture risk in Brazil so I
> thought I'd help her out a bit by building some visualizations for
> her. I'd like to do something similar as this examplehttp://mbostock.github.com/d3/ex/choropleth.html. However, it is not

Carolina Bigonha

unread,
Oct 21, 2013, 3:38:44 PM10/21/13
to d3...@googlegroups.com
Hi All,

Recently, I published a repository that may help you guys and others who want to work with Brazilian maps: http://bit.ly/17qzC3q
It is called br-atlas and it's inspired on Mike Bostock's repositories us-atlas and world-atlas. 

Essentially, it's an utility for downloading brazilian maps directly from IBGE (Instituto Brasileiro de Geografia e Estatística) and generating GeoJSON/TopoJSON files.

There's plenty of room for improvement, like implementing other types of map (this first version considers only the administrative boundaries of states and counties). Feel free to contribute!

I hope it's useful.
Reply all
Reply to author
Forward
0 new messages