GeoCommons GeoJSON in OpenLayers

So, with GeoCommons you can export all the features from a dataset in GeoJSON format. This is very useful. Then can it be displayed in Openlayers? Why yes it can!

I use the following strategy, wrapping the response with a little bit extra so that the GeoJSON format can read it properly.

var url = "http://geocommons.com/overlays/128725/features.json?limit=100";

var p = new OpenLayers.Format.GeoJSON();

OpenLayers.loadURL(url, {}, null, function (response) {
 var gformat = new OpenLayers.Format.GeoJSON();
 gg = '{"type":"FeatureCollection", "features":' +
      response.responseText + '}';
 var feats = gformat.read(gg);

 vector_layer.addFeatures(feats);
});

Have a look a the live demo of this example of loading points from a Geocommons dataset straight into an OpenLayers map
(Note that I am using an OpenLayers.ProxyHost proxy to make it work in FF)

It is of course very basic in terms of styling, but it’s a start!

Incidentally the points are from “CARMA, India Power Plant Emissions, India, 2000/ 2007/Future” (carbon monitoring)

JSON prettifier for gedit

Just a quick note for those of you that use gedit and want to format json so that it goes from something like this:

{"published":"2011-06-23T11:04:37-04:00","title":"TNC's Ecoregional Portfolio (public)","data_type":"WMS","calculation_params":null,"contributor":"jrfishe1","state":"complete","geometry_types":null,"permissions":[{"permissions":{"download":true,"view":true},"group_id":"everyone"}],"link":"http://geocommons.com/overlays/128841.json","feature_count":0,"icon_link":null,"name":"TNC's Ecoregional Portfolio (public)","extent":[-180.0,-85.0511,180.0,85.0511],"process_notes":"EPSG:4326,EPSG:3857","is_raster":true,"description":"The Nature Conservancy's Ecoregional Portfolio (public version) represents our priority areas for conservation.","short_classification":"Y","author":"The Nature Conservancy","source":"http://maps.tnc.org/","url":"http://maps.tnc.org/ecadpubprodanon/services/portfolio_anon_WM/MapServer/WMSServer?request=GetCapabilities&service=WMS","data_attributes":null,"tags":"conservation,priorities,the nature conservancy,tnc","id":128841,"pagination":{"total":0,"sort":null,"start":0,"limit":1000000},"url_type":"wms","classification":null}

ergh! To something like this

{
  "short_classification": "Y",
  "name": "TNC's Ecoregional Portfolio (public)",
  "icon_link": null,
  "author": "The Nature Conservancy",
  "title": "TNC's Ecoregional Portfolio (public)",
  "url_type": "wms",
  "data_attributes": null,
  "extent": [
    -180.0,
    -85.0511,
    180.0,
    85.0511
  ],
  "published": "2011-06-23T11:04:37-04:00",
  "url": "http://maps.tnc.org/ecadpubprodanon/services/portfolio_anon_WM/MapServer/WMSServer?request=GetCapabilities&service=WMS",
....
  "source": "http://maps.tnc.org/",
  "process_notes": "EPSG:4326,EPSG:3857",
  "state": "complete"
}

How to

Have Ruby. Install json gem.

Enable the external tool plugin in Gedit

Open up Manage External Tools

Create a new item

in the box type

#!/bin/sh
ruby /usr/bin/prettify_json.rb

Voila!

To activate it, load up a json file, then select the new command under tools > external tools

 

 

 

 

WhereCampEU 2011 recap & berlin psychogeography

Last week in Berlin I was lucky enough to go to WhereCampEU – thanks to Gary and Chris for organising this wonderful unconference. The conference was held in a trendy hipster ish part of the city, but which had also, I heard, the highest number of young families and births. It was also in the former Eastern part of the city. It gave the area a nice appeal, overall.

photo by Chris Fleming

I did a couple of sessions, one on a preview of GeoCommons2.0  talked about in a previous post and the other a psychogeography session. For the psychogeography session I sent four teams out to explore the environs around the campus.

One team followed people around. They said “I’m amazed by how slowly some people moved” and “Well, often we followed someone and then they would wander into a book shop”  – revealing the nature of the people and the type of area, bohem style cafes and shops, lazily people.

Another group were sent to ask people to point to were the centre of Berlin was. I asked some people where they thought was the centre, and most of them scratched their chins, and pointed to the Mitte area of the city, usually on the map, or waved southwards. Part of a consequence of being a split city, really. The western bit, someone said, “looks and feels more like a CBD” – that is, big shops, tall towers etc. I did venture to the former western CBD centre, and came across a mile long car show. This area was where the money was.

The other group was sent to walk around the area according to the Game of Life algorithm, Left left Right where you walk and take the first left, then the second left, then the next right, and so on. It’s impossible to predict where you will end up. I joined this group. We had a good explore over a small area, really, but encountering a lot of different environments. Shared (private) gardens / courtyards in the middle of apartment blocks, churches, cafes, and shops.

The fourth team were given a secret mission, and so I cannot reveal to you what they did. However, they are all in good health, and saw the city in a new light.

Photo by Chris Fleming

Back to the unconference, and some of the highlights were:

* Playing the Skobbler game, treasure hunting for addresses in the neighbourhood.

* Seeing offmaps evolve over the year. I’ve not got an iPhone, but that app looked very nice.

* Spatial databases, and in particular CouchDb – and their spatial bits

* CASA did a few talks – I’m getting more and more fond of their work – if anything they really seem to love the stuff they are doing – they share the same vision as me as giving GI tools and benefits to as many people as possible.

* Peter Batty wore an ipad t-shirt – and gave a great presentation about essentially putting utilities information onto a Gmaps like interface and mobile map.

* Gary Gale gave a compelling reason for standardizing place. And it makes sense.

* Meeting the NomadLabs guys for the first time, and being able to say “Thank You” for their work on Ruby on Rails GIS Hacks that I found very useful 4 years ago!

* Corridor talk, beer and food

Some stuff I’ve been working on with new GeoCommons 2.0

Last weekend, if you were at WhereCampEU in Berlin (blog post to follow) , you may have caught my sneak peak into the new GeoCommons 2.0, which has been revealed just the other day. Here are some of the highlights of the new GeoCommons

  • The flash map has been overhauled and re-written, mainly by Andrei – and it can handle hundreds of thousands numbers of points quite happily
  • Analytics library is completed, but not currently accessible to normal users of GeoCommons – hopefully it will be soon, if people want it.
  • Behind the scenes, the system uses a number of distributed workers and tasks to offload processing intensive or long processing tasks
  • Datasets and Maps get given nice overview images, and the attributes of datasets have histograms generated for them
  • Data can be edited in the system, and filtered, and saved either to replace itself or as a new dataset
  • Animation of temporal data is much nicer now
  • Polymaps for HTML5 non-flash map support
  • Filters can be applied to the map, so that attributes can be filtered out.
  • Thematic maps can be made with categories now
  • Acetate is used as standard
  • Custom markers can be added to a map, and even animated ones work too!
The GeoIQ developer blog has a developer orientated review of wha’ts new and there is a good overview of GeoCommons on the main GeoIQ blog too.
Keep your eyes peeled on the GeoIQ Developer Blog over the next few days as the team adds some more posts about some of the technology behind it.