Leaflet.
November 15, 2011 at 11:19 am | Posted in gis | Leave a commentHaving fun with Leaflet – the mapping api from Cloudmade.com Loading in polygons from OSM, via GeoCommons and shown on Leaflet as GeoJSON.
Pubs in England: How to do it with Polymaps and GeoCommons Filters
August 2, 2011 at 12:25 pm | Posted in gis | 2 CommentsIn this post I will show one way to display and interact with data from GeoCommons, using the powerful “filters”, and all on the mapping library, PolyMaps. It will show a basic example showing points on a map based on a filter and a more advanced example with changeable filters and some basic interaction on the points.
Few weeks ago, I wrote about how to display data from GeoCommons quickly on an OpenLayers map. The resulting little map was not that interactive, but it showed how easy it was to get started using GeoCommons as a data source. PolyMaps is a bit different than other libraries – it’s very lightweight, fast and powerful, but in terms of bells and whistles, you have to roll your own, like with Jquery core and all the plugins. It follows JQuery in another way, in that it uses method chaining. Anyhow, here is a map of Green Map named pubs in England. The base dataset, of all (24 thousand or so) pubs in England, was from OpenStreetMap, and the data is cc-by-sa. http://geocommons.com/overlays/136549/ England pubs OSM july 2011 I added the data from an extract from geofabrik.de.
GeoCommons Filters
The GeoCommons API gives more information, but the filter we are using looks like this:
http://geocommons.com/overlays/136549/features.json?filter[name][][like]=green%20man
filter[string_col][][operator] = text
We can use things like equals, min and max for numeric and date type attributes, and equals and like for string. We can also add more than one filter to the query.
Green Map pubs in England
Filtered GeoCommons features on polymaps.
Most of the gubbings is in the pubs.js file. Lets see what’s going on here.
The first section sets up the map, and adds the Acetate basemap to it, and adds a control to it. Notice the method chain: ”map.add(po.image().url(po.url ” pretty nice, eh?
var po = org.polymaps;
var map_div = document.getElementById("map");
var map = po.map()
.container(map_div.appendChild(po.svg("svg")))
.zoom(5)
.center({"lat":54, "lon":-3})
.add(po.interact());
map.add(po.image().url(po.url("http://acetate.geoiq.com/tiles/terrain/{Z}/{X}/{Y}.png")))
The second section gets json from GeoCommons, based on a filter. A filter is like a search parameter. Then we can see that a layer is created and the features from the json are added to it. We have to get the json outside of polymaps as the json is not quite valid GeoJSON yet – (it doesn’t wrap the features array in a featureCollection) – but no matter, polymaps can handle it.
var url = "http://geocommons.com/overlays/136549/features.json?limit=100000"+
"&filter[name][][like]=green%20man";
url = "/cgi-bin/proxy.cgi?url=" + escape(url);
j = jQuery.getJSON(url, function(data){
map.add(po.geoJson().features(data))
});
Pretty basic, really, and not clickable, and the points are black. The points are SVG – and are default formatted.
Adding More Functionality
Search for any pub name, click on point gives the name.
This example lives at http://geothings.net/geoiq/any_pubs.htm and the key part of the javascript lives in http://geothings.net/geoiq/any_pubs.js
We will be building upon the last example a bit.
We have refactored the adding layer bit, because this time we are making several requests. We give it a reasonably random and throwaway id, which we assign to a global variable of the currentLayerId, so we can delete it in the future.
function addLayer(filterText){
if (currentLayerId){
element = document.getElementById(currentLayerId);
if (element) {
var parent = element.parentNode;
parent.removeChild(element);
}
}
var guid = Math.floor(Math.random()*3000);
currentLayerId = guid;
var url = "http://geocommons.com/overlays/136549/features.json?limit=10000"+
"&filter[name][][like]="+escape(filterText);
url = "/cgi-bin/proxy.cgi?url=" + escape(url);
j = jQuery.getJSON(url,
function(data){
map.add(po.geoJson().id(guid).features(data).on("load", setFeatures))
});
}
When the features are added, there is a callback method (setFeatures) which stuffs the name of the pub into the point’s SVG, gives it a CSS class so we can style it with pubs_styles.css, and add a mousedown event
function setFeatures(e){
for (var i = 0; i < e.features.length; i++) {
var feature = e.features[i];
feature.element.setAttribute("feat_name", feature.data.name); //give the element an id
feature.element.setAttribute("class", "pub_point"); //set css class for colours
feature.element.setAttribute("r", "5"); //radius of svg circle.
feature.element.addEventListener("mousedown", function(e){
clickFeature(this, e);
}, false);
}
}
pub_styles.css - the fill is purple, the stroke, white and the opacity 0.6 – we style the features using CSS!
.pub_point {
fill:rgb(148,0,211);
stroke: #fff;
fill-opacity: 0.6;
}
The click / mousedown event function gets the SVG feature and the event, and displays a div whose contents is made up from the feat_name attribute from the featrure. function setFeatures(e){
function clickFeature(f, evt){
var blurb = "<div class='info_blurb'>" + f.getAttribute("feat_name") + "</div>";
var infowin = document.getElementById('infowin')
infowin.style.width = "200px";
infowin.style.maxHeight = "200px";
infowin.style.overflow = "auto";
infowin.style.left = evt.clientX + "px";
infowin.style.top = evt.clientY + "px";
infowin.style.position = 'absolute';
infowin.style.display = 'block';
infowin.innerHTML = blurb;
}
So, wastefully using just bit of JQuery to handle to form, when text is entered in the box and the button pressed, the current layer is removed, and a new one is requested, give it a go!
It’s basic, in that if you change layer, the text label may still be there, and the labels don’t move when the map is panned, but hopefully you can see that you would have to roll your won stuff on top of polymaps to do this.
GeoCommons GeoJSON in OpenLayers
June 26, 2011 at 7:23 pm | Posted in geo, geodata, Mapping, neogeography | 5 CommentsTags: geocommons, geoiq, 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
June 23, 2011 at 4:12 pm | Posted in gis | Leave a commentJust 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
June 6, 2011 at 7:14 pm | Posted in geo, Mapping, neogeography, psychogeography | Leave a commentLast 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
June 6, 2011 at 6:40 pm | Posted in geo, geodata, gis, Mapping, neogeography | Leave a commentTags: big data, geocommons, geoiq, maps
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!
WherecampUK 2010 Recap
November 25, 2010 at 4:27 pm | Posted in geo, Mapping, neogeography, openstreetmap | Leave a commentLast week I journeyed down on the train to Nottingham to go to WhereCampUK – an unconference for all things “geo” – but it was only a few months since the similarly named WhereCampEU of (which I never actually wrote something about) down in London. Before I share some of the best bits, here’s some of the similarities and differences.
* Less international folks
* Less big geo personalities and keynotes
* More OSM
* No T-Shirts
* More beer – we drank a large pub dry, literally. The next day, the landlord swore at me for pissing off their regulars.
* More cake
* Cheaper and quicker to run, setup and organise.
For more pointers in how to run an unconference, check out Steve Coast‘s latest post, where he writes about what he did for Wherecamp in Denver. How I ran a successful unconference in 6 hours and you can too.
Overall, the event was great.
I ran two sessions. The main one was “What is Psychogeography“. The best part of this was sending all participants out with directions in twos and threes, for 10 mins before lunch. They had directions such as “left left right”, “follow someone”, “ask where the centre is, follow that direction, ask again”, “find hidden portals”, “find fairies”, “hear something, take a photo”.
I also quickly slotted in the NYPL Warper presentation, and included this slide. You get 20 points if you know what this refers to!
I also mentioned the words “neogeography” for the first time in the conference, and that was at 3:30pm, which says quite a bit about the use of the term.
Talks I liked were:
* Vernacular Geography & Informal Placenames
* Geo Games
* Education and mobile maps
* Augmented Reality roundup
* How streets get names
* Peoples Collection Wales
* Haptic Navigation
* OSM Talks including – Potlatch 2
* Gregory Mahler’s – I’m a Psycho Mapper!
* OSGEO
AGI GeoCommunity – NYPL & Mapwarper
October 1, 2010 at 2:37 pm | Posted in geo, geodata, gis, Mapping, neogeography | Leave a commentYesterday I presented at the AGI Annual conference on the NYPL Map Rectifier. I was also able to launch MapWarper.net – to showcase the user submitted version of the code base, which you can get on github, should you like! I’ll put the slides up to slideshare asasp
I also showed the video of the newest Stamen Design work on the redesign of the interface. This interface will be applied to the application, and will be featuring at the British Library Growing Knowledge exhibition in a couple of weeks
The whole conference was okay, well organised, and well attended by fellow AGI Northern Group members. The soapbox – an evening even over beers – short 20:20′s but with the emphasis on ranting and comedy proved very popular, and was very amusing – keep an eye out for the videos when they come out!
The free W3Geo unconference which was on the day before the main conference, and as Ed writes, had the more interesting talks and energy here. w3g had a number of fixed keynotes and speakers, which I think was a good idea – it allowed people to attend knowing that certain people would be speaking. Alas, I didn’t really believe it was promoted that well beforehand.
The main conference had a number of interesting talks. The guys from CASA really do seem to be enjoying themselves. Survey Mapper was highlighted – essentially it’s an onlne survey application, but with, yes geography! It would be great to be able to allow the export of the results from a survey, and use this as a data layer in GeoCommons – to compare against any number of other datasets. They also showcased their work with Twitter – exploratory – one thing with pretty much all twitter map experiements is that people are so overwhelmed with the dataset, that the analysis, the task of generating information from this data tends to be overlooked. Most of the mapping done tends to show that, for the very first time, that people tend to live and do things in urban areas.
ESRI were keynoting, but with a somewhat downbeat “why doesn’t anyone understand and use GIS” cry, with a call to promote the usefullness of GIS to decision makers. Nothing new here, but in these economic times, seemed to imply that GIS budgets were being hit hard.
Nigel Shadbolt’s closing talk convinced me of the importance of linked data. However, the talk was more about the benefits and importance of Open Data as a whole, and he was speaking at such a higher level than most of the other talks were operating at. They were talking about “how to share” data, whilst with open data at a national level operates at a much more fundamental level
The Ordnance Survey have now escaped much of the fights and shouting what with the OS Open Data, and today have announced better, clearer, more generous terms for Derivative data (see here and here for more info on that
With GeoCommons
August 26, 2010 at 4:03 pm | Posted in Uncategorized | 2 Comments
I’m now working with FortiusOne and GeoCommons!
Which will mean me working on lots of exciting geo stuff, and you getting to play with it on GeoCommons.com soon!
Can’t really get into much detail at this time except that GeoCommons shares the same vision of making geospatial data, tools and analysis available for all to use, through the web – the same vision which got me started freelance in the first place, so I’m very enthusiastic.
I’ll still be supporting and developing on mapwarper.net and the NYPL Warper maps.nypl.org – and on that note, expect some eye popping news from Stamen Design related to this soon! In the meantime have a play with http://polymaps.org/.
WhooTS a small wms to tile proxy – WMS in Potlatch
July 15, 2010 at 11:04 pm | Posted in geo, gis, j2me, openstreetmap | 1 CommentWhooTS is a small and simple wms to tiles proxy / redirect system.

Essentially it enables the use of WMS in applications that only accept Tiles (google / Openstreetmap scheme) – WMS is now in Potlatch!
How to use it?
http://whoots.mapwarper.net/tms/z/x/y/{layer}/http://path.to.wms.server
Example:
a mapwarper map:
http://whoots.mapwarper.net/tms/!/!/!/2013/http://warper.geothings. net/maps/wms/2013
viewing it in Potlatch, the OpenStreetMap editor:
Using a mapserver WMS request, with one layer:
http://hypercube.telascience.org/cgi-bin/mapserv?map=/home/ortelius/ haiti/haiti.map&request=getMap&service=wms&version=1.1.1&format=image/jpeg &srs=epsg:4326&exceptions=application/vnd.ogc.se_inimage&layers=HAITI&
Goes to:
Caveats:
Its’s quite simple, does not do any caching, it just redirects a tile url to an equivalent WMS request. It would only work with WMS servers that accept EPSG:900913 projections, and at the moment, it outputs OSM / Google Tile scheme, not a proper TMS tile scheme.
It’s written in Ruby with the Sinatra micro web application framework. The code is available on GitHub too. http://github.com/timwaters/whoots
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.





