Scratching the surface http://craigmmills.com Most recent posts at Scratching the surface posterous.com Tue, 17 Jan 2012 13:16:00 -0800 Tessellace http://craigmmills.com/93769713 http://craigmmills.com/93769713

Say hello to tessellace!

Tessalace

In the last few projects we have worked on at UNEP-WCMC, we've been using tessellated hexagons in our thematic maps.  The attractive younger sibling of the square grid, we've used them to describe the density of endangered species (using the rather excellent cartodb):

 

and to describe where the conservation priority areas are in mexico:

One thing I've found using this approach is the time it takes to make the hexagons.   I wanted something that would generate hexagons instantly and preferably in geojson.  So... I hacked together tesselace.

It's made using a little javascript to create the hexagons as geojson which are rendered on a leaflet js map.  I have put the methods to create the hexagons on github.  I had already made a ruby version so added a little sinatra app to generate the geojson from a url.  

If you want to make a map pretty quickly, you can paste the url into cartodb or use the new ST_GeomFromGeoJSON function in PostGIS

Hope you find it useful!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1316411/twitter_pic.jpg http://posterous.com/users/4wEYitD2nl05 Craig Mills Craig Craig Mills
Sun, 20 Feb 2011 13:57:00 -0800 Sunday afternoon with tilemill, sinatra and polymaps http://craigmmills.com/marine-protected-areas-with-tilemill-sinatra http://craigmmills.com/marine-protected-areas-with-tilemill-sinatra

I had a rare Sunday on my own today... if you don't include the dog.  She was hoping for a 6 hour dog-walkathon, I was hoping to play with Tilemill on a rainy afternoon.  We did both in the end.  

So while Millie picked the (phantom) rabbit fluff from her teeth in front of the fire, I set about creating tiles of marine protected areas.  Turned out to be very simple. The install was easy and the map styling css stuff was a pleasure.  Exporting to MBTile format took a bit of time but I hear thats being looked at.  Not exporting zoom 0 and 1 made it much faster (it was a 100MB global dataset)- around 30 mins I think.  

Here's a polymap of the marine protected areas served from a little sinatra app I wrote on top of the MBTile sqlite database.  And here is the code

Mpa-tiles

[I reduced the extent to keep the db under the free *skinflint* 5MB limit set by heroku]

Not bad for a rainy Sunday afternoon.  Millie wasn't bothered about the tiles by the way.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1316411/twitter_pic.jpg http://posterous.com/users/4wEYitD2nl05 Craig Mills Craig Craig Mills
Wed, 19 Jan 2011 02:17:00 -0800 GEOIPSUM http://craigmmills.com/geoipsum http://craigmmills.com/geoipsum

Have you ever needed to generate some fake polygons to test a geo application?  No... oh.  I have, so I created GEOIPSUM!!!  Mr Maps will never again look longingly at Mrs Text as she flaunts her lorems and ipsums!.  

What does GEOIPSUM actually do?  You make a request to the GEOIPSUM API specifying a few parameters and it returns some randomly generated polygons inside your bounding box as geojson.  Simple.

Example:

http://geoipsum.org/polygons.json?perimeter=300&bearing_range=70&polygon_number=30&bb=46.86,-32.45,56.61,28.45

The parameters here are -

perimeter:  the perimeter of each polygon

bearing_range: this is the amount of deviation from the mean bearing, the larger (max 360), the more jaggy the polygon.  I wouldn't recommend this being too high at the moment as it is likely to cause self intersecting polygons [something I am working on...]

polygon_number:  the number of polygons

bb: the bounding box within which the polygons will randomly sit.

Screen_shot_2011-01-19_at_10

I have also created geoipsum.org so you don't even have to do any typing.  I used polymaps for the map, rails for the app, don't go near the dateline, it's a bit crap.

If you want to take a look at the code to generate the polygons, it is all open and sitting on github.  The long and short is the polygons are generated using a very simple constrained random walk method where both the step length and bearing are constrained with the aim of getting the walk back to the first point in the polygon.  The walk can go off course a little which is why you might see some 'noses' on the polygons.

 

Stuff to keep in mind.

I don't test for self intersections at the moment, I wanted to keep the code as light as possible but will look into making sure all polygons are valid.

It's only geojson at the moment.  I am going to add WKT, maybe shapefiles, maybe not.

If you want a map of American Samoa, you will have to wait, there's a bug near the dateline!

If you want to help contribute any code, feel free.  Just let me know.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1316411/twitter_pic.jpg http://posterous.com/users/4wEYitD2nl05 Craig Mills Craig Craig Mills
Sat, 09 Jan 2010 00:21:30 -0800 I'll swap you three Belgiums for a Portugal http://craigmmills.com/2010/01/ill-swap-you-three-belgiums-for-a-portugal http://craigmmills.com/2010/01/ill-swap-you-three-belgiums-for-a-portugal I have been thinking about how ones brain interprets spatial stats.  For example, when talking about spatial scale, the popular media often quote, ‘an area the size of Belgium/Wales/Texas’ and with that they try and invoke in your mind the impressive scale of whatever they are describing. The most recent example I discovered  is a report about a newly designated marine protected area in the South Orkneys.  The area stands at 94,000km2- an area the size of Portugal.   Impressive you may think…. This led my train of thought to marine protected areas in general and how much of the sea has been targeted for protection.  While this isn’t the arena to rattle on about UN mandates and conservation conventions, the rough amount of sea that would ideally be protected from us human beans is 10% - an area the size of AFRICA (now we are talking). For me the size of Africa seems a lot, and also, I like to see stuff to believe it. I thought the easiest way to visualize this was to displace all the African nations across the seas.  So that’s what I did.
Media_httpwwwcraigmmi_uijjb
Using a simple random placement algorithm I picked up each country in Africa and slung it in the sea (with a little help from ArcObjects).  I constrained the randomness so not to allow countries to overlap with each other or the coastline and outputted a simple map to see the results.  For me, I think it looks like a large part of the sea needs protecting and if these targets which have to be met in two years are going to be, there is a pile of work twice the size of Belgium to achieve it. Caveats:  I wouldn’t recommend designing the marine protected areas network on this analysis, there is no account of whether protecting a Kenyan shaped area in the Atlantic would be useful or not- better than what we currently have I suppose, but as my biology teacher regularly told me ‘you must do better…’

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1316411/twitter_pic.jpg http://posterous.com/users/4wEYitD2nl05 Craig Mills Craig Craig Mills
Sun, 11 Oct 2009 20:49:00 -0700 What's a hotspot not? http://craigmmills.com/2009/10/whats-a-hotspot-not http://craigmmills.com/2009/10/whats-a-hotspot-not

Question:  Are local people in the most important areas for biodiversity likely to be able to connect to the internet?

Media_httpwwwpocketga_fshdw

Why do I ask?  Well,  we want biodiversity knowledge, protected areas knowledge, species knowledge.  We assume the best knowledge is local knowledge and the cheapest way to capture that knowledge is harnessing the tentacles of the internet.  We want to focus on areas of the world that are most important for biodiversity and are facing serious threat. So in true back of the envelope style, I have taken two sources of information.  One, biodiversity hotspots from Conservation International, the other, a random google search 'internet usage by country' and squeezed them together (with a splash of ESRI Country basemaps) to do a quick comparison.

The techy part is really simple (or so it seemed).  I simply wanted to know which country polygons intersected the biodiversity hotspot polygons.  The challenge, I didn't have a floating license of ArcGIS (hurry up with the license checkout ESRI PLEASE!) so thought I would use Qgis.  Unfortunately the select by location tool crashed each time I used it.  Maybe it was too big a job for my laptop, so I simplified and dissolved where I could- again fail (2 hours wasted...).  So, with my last breath I imported the whole lot into postgis and did it all there with no fuss, 6 second query, bob's your uncle. Anyway, here's the interesting bit.  How well connected are the most import countries for biodiversity? Well, not very well.  Out of the top ten countries for internet usage only 2 contain biodiversity hotspots, in the top 20, there are 6 with hotspots.  The long and short of it is, at this moment, there is serious internet capacity problems in many areas where biodiversity is high.  So does that mean we should drop the internet as a tool to collect better biodiversity information?  Of course not.   Given connection to the internet is as  important for global economic growth as electricity, the growth and expansion of people all over the planet hooking up to the internet whether through the ground or via mobile networks is going exponential.  Africa alone is set to increase its internet usage by 3000% in the next 2 years.  So even if its not in these important regions this very minute- check back in a year (even a few months); it will be.

Caveats:  The main caveats are this is truly back of the envelope stuff- I make no guarantee it's correct or the data are the most suitable.  I have simply squeezed together data that is freely available (well done CI) and see what sticks and hope people find it interesting enough to talk about.  I know hotspots don't include all important species or threats and the internet usage data are a few years out of date.  But hey, this is the first blog so only my mother will read it anyway (hi mum).

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1316411/twitter_pic.jpg http://posterous.com/users/4wEYitD2nl05 Craig Mills Craig Craig Mills