Posts Tagged ‘code’

The Challenge Of Open

One of the great things about the combination of maps, geo, location and London is that roughly once a month there’s some kind of meetup happening in the city on these themes. One of the longer running players in this space is the Geospatial Specialist Group of the British Computer Society which is being relaunched and reinvigorated as the Location Information SG. Earlier this week I gave a talk, but what to talk about?

It didn’t take too long to come up with a suitable theme. In my current day job, consulting with open data specialists Lokku, I come across the benefits and the challenges in using open data on almost a daily basis. One of the earliest lessons is that nothing is simple and nothing is straightforwards when you bring licensing into a field and open data is no exception.

Read On…

Customising WordPress Without Modifying Core, Theme Or Plugin Files

A standard WordPress install is incredibly powerful and flexible. For a lot of people, WordPress out of the box plus one of the stock WordPress themes is enough. But the possibilities for customization are endless; you can add plugins and other themes. Sometimes these do just what you want. Sometimes you need to … tweak WordPress.

A very high proportion of the customization advice you’ll find on the web starts with these lines … add the following to the end of your theme’s functions.php or even worse, advises that you modify the source code of your theme or your plugins. This is bad for many reasons:

  • Editing your theme’s functions.php makes theme specific customizations; change your theme and your customizations will no longer get loaded.
  • When your theme and plugins get updated you’ll find all your careful hand crafted customizations get overwritten and lost.
  • A lot of theme and plugin authors won’t offer support for changes you might have made to the source code.
  • Your customizations might work; but you might also inadvertently make some other changes which will stop things working.

WordPress doesn’t yet support a way for site specific customizations to be made and loaded without touching theme, plugin or core files; that’s why I wrote WP Customizer and that’s what this plugin is for. When WordPress does support such a way, this plugin will thankfully be obsolete.

screenshot-1

There’s another, not entirely altruistic, reason behind this plugin. One of the most common support requests I get for WP Biographia is to help with clashes between someone’s theme’s CSS and the plugin’s CSS. Once that’s been resolved, the next question is almost always how do I load this custom CSS? The answer is now straightforward. Put your CSS file in a directory in the root of your WordPress installation, install WP Customizer, tell it to load custom CSS files and where to find them and you’re done. No editing of functions.php. No learning now to hook into the wp_enqueue_scripts action, no learning how to call wp_register_style and wp_enqueue_style. It should all just work.

But WP Customizer works with more than just custom CSS files. You can also load custom PHP functions and custom Javascript and jQuery files as well. What’s more, you can configure these to load just for your site’s publicly visible front end, just for your site’s admin pages or even both.

WP Customizer uses the file system as a data-store metaphor and allows you to main a library of common customisations that are independent of the theme and plugins you’re currently using. Out of the box, the plugin looks for custom files to load in the root of your WordPress installation in a set of named directories which should be relatively self explanatory, functions, admin_functions, common_functions and so on for CSS and for scripts.

But you can just as easily create your own directory structure, put together in a way that makes sense to you, perhaps something along the lines of … site/front-end/css, site/front-end/functions, site/admin/scripts and so on

… you’re limited only by the limitations of your file system and the way of organising things that make sense to you.

screenshot-5

One final word of caution though. In order to use this plugin, you have to know how to write the code that lives in the customisation files themselves. That means knowing how to write PHP functions to exercise the WordPress API. How to write JavaScript and jQuery that works with WordPress. How to write CSS. This plugin can’t help you with that. But there’s ample tutorials and information out there on the interwebs to help you.

Just remember, when you read something that says just add the following code to your theme’s functions.php, ignore this little piece of advice and add it a local customisation file and load that through WP Customizer instead. Your WordPress site will thank you for it someday.

To download or install WP Customizer, either search for WP Customizer from the WordPress Dashboard or go to plugin’s page on the official WordPress plugin repository. If you want to fork the source code of the plugin, you can find it on the plugin’s GitHub page at https://github.com/vicchi/wp-customizer.

Written and posted from home (51.427051, -0.333344)

How A Map Can Go Viral (In 8 Simple Steps)

Back in February of this year, at the height of the madness that was the Vaguely Rude Places Map, Ed Freyfogle from London’s #geomob meetup got in touch and asked me to come and tell the story behind the map. This is that story.

And so last night, in the Chadwick Lecture Theatre in the basement of London’s UCL, after listening to some amazing presentations on building a map of mobile cell tower coverage, of building a seismically powered alternative to GPS and a whole host of other great talks, I took my place on the podium and started where any good story needs to start … at the beginning.

Slide01

Read On…

Map Push Pins vs. Dots? Google Map Engine vs. Dotspotting?

Yesterday, Google launched their Maps Engine Lite beta; a way of quickly and easily visualising small scale geographic data sets on (unsurprisingly) a Google map. The service allows you to upload a CSV file containing geographic information and style the resulting map with the data added to it. I thought I’d give it a try.

I turned to my tried and trusted data set for things like this; a data set I derived from a Flickr set of geotagged photos I’d taken of the London Elephant Parade in 2010. It’s a known data source and I know what the results of this data set will give me; it lets me do a reasonably meaningful visual comparison of how a particular product or service interprets and displays the data.

Google Maps Engine

Reading up on Map Engine Lite, I noted that I could only upload a maximum of 100 data points into a layer on the map, which wasn’t a problem as my data set is localised to London and contains only 10 pieces of information, one for each photo I’d taken. Once I’d uploaded the data I could style the colours of the push pins and the background style of the map. It looks pretty good, even if you are limited to 100 points per layer and it’s for strictly personal and non commercial use only.

But I was sure I’d seen this sort of thing before and I had, in the form of Stamen’s Dotspotting. I already had an account with Dotspotting and, even though I’d forgotten about it, I’d previously made a map from my London Elephants data set.

DotSpotting

The parallels are many. Both Map Engine and Dotspotting allow you to upload data in CSV format. Both services try to work out coordinates from the data, if there’s no lat/long coordinates already. Both services allow you to style the resultant map.

There are differences. Dotspotting allows you to download your data; it doesn’t appear that Google does. Map Engine allows you to style the map markers; it doesn’t seem that Dotspotting allows this. Dotspotting supports Excel spreadsheets, CSV files, Flickr and Google My Maps feeds; Map Engine only supports CSV files.

There’s also one other key difference; Map Engine was launched yesterday, whilst Dotspotting was launched 2 years ago.

But there’s an old saying that imitation is the sincerest form of flattery.

Written and posted from home (51.427051, -0.333344)

Countries That Cry; Countries That Don’t (100% Mercator Free)

March the 5th 2013 marked the 501st birthday of Gerardus Mercator, whose map projection appears on virtually every web map you’ll find on the interwebs today. It appears he’s none too happy about the lack of royalties on this and so I felt compelled to use a projection for my next map which wasn’t Mercator’s.

mercator-tweet

I’ve been using a lot of Natural Earth‘s vector data to make maps recently and so Tom Patterson‘s rather beautiful Natural Earth projection seemed fitting and avoided the wrath of Gerardus into the bargain.

crying-countries

Continuing my dabblings in Mike Bostock’s D3, reworking the Countries That Do And Don’t Cry For Me map that did the rounds on the internet some years back took up a couple of spare hours last night; making maps is addictive it seems.

The full map is here, hosted on maps.geotastic.org … and for those who don’t get the cultural reference, this song from a certain 1970’s musical might help.

Written and posted from home (51.427051, -0.333344)

The Great British Map; Or Great Britain vs. The United Kingdom vs. The British Isles

Last night I made another map. It tries to answer some of more perplexing and confusing facets of the geography surrounding the world’s 9th largest island. I mean of course Great Britain. No, wait. I mean the United Kingdom. No, wait. I mean Britain. Or do I mean England? See, it’s confusing.

  • So if the ISO 3166-2 code is GBR, how come the country is called the United Kingdom?
  • But if England is a country and the United Kingdom is a country, how come England is part of the United Kingdom?
  • What about Scotland, Wales and Northern Ireland?

This isn’t the first time I’ve covered this topic. The first time was for a post on the now defunct Yahoo! Geo Technologies blog entitled UK Addressing, The Non Golden Rules Of Geo Or Help! My Country Doesn’t Exist. The ygeoblog.com domain is now long gone and redirects to the Yahoo! corporate blog but I was able to reproduce this post here and it’s also captured in the Internet Archive’s WayBackMachine. The second time was when I made a variation of The Great British Venn Diagram. But this is the first time (though probably not the last) that I’ve used a map, which is odd as this is something that’s tailor-made for a map.

I’d been looking for a good source of geographic vector data that I could use to easily overlay polygons on a map and came across a rich source of free vector and raster map data from Natural Earth. But instead of overlaying that data on top of a standard slippy map using a JavaScript maps API to tap into a tile server’s bitmap tiles, I soon wondered whether I could actually make a map from the vector data. It turned out I could and decided to revisit the structure of the group of islands I live on one more time and try to visualise the difference between Great Britain, the United Kingdom and the British Isles. The end result, punningly entitled the Great British Map, looks something like this …

Great British Map

When the page first loads you’ll see the coastlines of Britain, Ireland and towards the bottom, the Channel Islands. There’s then five ways of looking at this particular map.

There’s the group of geographic islands that’s termed the British Isles; these show up in purplish-grey and if you’re observant, the Channel Islands vanish as they’re not part of this island group.

Great British Map - Great Britain

Then there’s the individual geographic islands of Great Britain, Ireland, the Isle Of Man and The Channel Islands; these show up in green.

Great British Map - United Kingdom

There’s two sovereign states, The United Kingdom of Great Britain And Northern Island and the Republic Of Ireland; these show up in red.

Great British Map - England

Next comes the administrative countries which make up the United Kingdom; England, Scotland, Wales and Northern Ireland. These show up in yellow.

Great British Map - Crown Dependencies

Finally, there’s the Crown Dependencies, the self governing possessions of the British Crown; the Isle of Man and the Channel Islands are these and they show up as purple.

What’s missing from the map? The British Overseas Territories, which is a polite way of saying what’s left of the British Empire that didn’t gain independence and which the United Kingdom still asserts sovereignty over. These are Anguilla, Bermuda, British Antarctic Territory, British Indian Ocean Territory, British Virgin Islands, Cayman Islands, Falkland Islands, Gibraltar, Montserrat, Pitcairn Islands, St. Helena, Ascension Island, Tristan da Cunha, the Sovereign Base Areas of Akrotiri and Dhekalia and the Turks and Caicos Islands.

If you’re interested in how I actually made the map, read on.

The source data from the map are two public domain datasets from Natural Earth; the 1:10m map Admin 0 Subunits dataset and the 1:10m Populated Places dataset. This data includes shapefiles which can be converted into GeoJSON format by the GDAL ogr2ogr command line tool. I extracted the vectors for the UK, Ireland, Isle of Man and Channel Islands from the Admin 0 Subunits dataset, keying on their ISO 3166-1 Alpha-3 country codes.

$ ogr2ogr -f GeoJSON -where "adm0_a3 IN ('GBR','IRL','IMN','GGY','JEY','GBA')" subunits.json ne_10m_admin_0_map_subunits/ne_10m_admin_0_map_subunits.shp

I then extracted the place data from the Populated Places dataset, again extracting data for the UK, Ireland, Isle of Man and Channel Islands, this time keying on their ISO 3166-1 Alpha-2 country codes. Not entirely sure why one dataset uses Alpha-2 and the other uses Alpha-3 but go figure; the data is free, accurate and open so who am I to complain?

$ ogr2ogr -f GeoJSON -where "iso_a2 IN ('GB','IM','JE','GG') AND SCALERANK < 8" places.json ne_10m_populated_places/ne_10m_populated_places.shp

Finally, I merged subunits.json and places.json into a single TopoJSON file, with the added bonus that TopoJSON is much much smaller than GeoJSON. The source GeoJSON weighed in at 549 KB whereas the combined TopoJSON is a mere 78 KB.

$ topojson --id-property su_a3 -p NAME=name -p name -o great-british-map.json subunits.json places.json

The main reason for use of TopoJSON is not that it’s much more lightweight than GeoJSON, but that Mike Bostock’s excellent D3 JavaScript library can easily slurp in TopoJSON and inject SVG straight into an HTML document. Which is precisely what the map’s underlying code does. There’s a lot more that D3 could do with this map, but it’s early days and for a first step into a new maps library, I’m pretty happy with how it’s turned out.

Speaking of code, it should come as no surprise that the map’s code base is available on GitHub. The Great British Map is based on great D3 tutorial that Mike has written on vector mapping using Natural Earth, so the similarity between Mike’s map and my map is entirely intentional.

Written and posted from home (51.427051, -0.333344)

You Were Here; Mapping The Places I’ve Been To According To Foursquare

Over the weekend I made another map. While I don’t think for one moment this one will be as wildly popular as my last map was, this one is just as satisfying and a whole lot more personal.

At 8.01 PM on the 11th. of October 2009 I checked into Sushi Tomi in Mountain View, California. This was my very first Foursquare check-in. Since then I’ve checked-in on this particular location based service a further 12,394 times. Each check-in has been at a place I’ve visited. As this is a location based service, each check-in comes with a longitude and latitude.

This sounded to me like an ideal candidate for a map. But how to go about making one?

Checkins - Global

I could have written some code to use the Foursquare API, but I’ve been running an instance of Aaron Cope‘s privatesquare for a couple of years now, which meant every check-in I’ve ever made, give or take the last 6 hours or so, is sitting comfortably in a MySQL database.

So I wrote some code to go through the database, extract each checkin and make a list of each place I’d checked into, the place’s coordinates, the place’s name and how many times I’d checked into that place. Armed with this information, I could then spit this out in GeoJSON format, which made making a map no more complicated than some mapping API JavaScript, in this case the Leaflet API. OK. There was some slight complication. I need to do some cleverness to make each checkin a CircleMarker, where the radius of the circle was proportional to the number of check-ins. Thankfully Mike Bostock’s D3 library does this with ease.

It’s not the most classy of visualisations. But I do like that the map shows me the global picture of where I’ve been over the last 4 or so years. As you zoom into the map, it’s fascinating to see the patterns of my movements in areas I seem to go to on a regular basis, such as the San Francisco Bay Area …

Checkins - Bay Area

… or Berlin …

Checkins - Berlin

… or even Dar Es Salaam …

Checkins - Dar Es Salaam

… as well as my journeys around my home country.

Checkins - UK

But there’s still a lot of things that the map doesn’t do.

The z-index, or stacking order, of the markers is based on each place’s coordinates; ideally this will be adjusted so that the larger markers, those with the most check-ins, stack underneath the smaller ones so they’re not obscured. I also want to add the ability to see some form of timeline and add some richer data about each place to the marker’s popups.

But for now, it does the job I set out to do and to make life easier, should you wish to do the same, you’ll find the source code up on GitHub.

What next? Well, now that I can download my Twitter history, I think all of my geotagged tweets are suitable candidates for some mapping …

Written and posted from home (51.427051, -0.333344)

The Internet Seems To Like The Combination Of Maps And Innuendo

Oh people of the interwebs; you are indeed a wondrous thing. If you build something and put it up on the internet, you’ve no expectation that anyone will see it, let alone look at it. But it appears that the combination of innuendo and some vaguely sounding rude place names (actually with some very rude place names) seems to be something that the citizens of the internet actually like.

The map hit the internet at maps.geotastic.org/rude/ around lunchtime on the 6th. of February; since then, several things have happened.

Firstly, Eric Rodenbeck, the CEO of Stamen Design, whose map tiles I used on the Rude Map, dropped me an email to say he liked it. I’m a massive fan of the cartography that Stamen produces and this would, alone, be enough to make the making of the map worthwhile.

But then, the URL of the site started proliferating over Twitter … including Jonathan Crowe, author of the late and utterly lamented Map Room blog.

Then the map started to get written about. Firstly by The Independent, then by Laughing Squid, Blame It On The Voices, Reddit and io9.

Rude Places Map - The Independent

And it keeps on getting mentions on Twitter, on Google+ and other social networks. According to the server logs, the map’s been viewed a staggering (to me at least) 53,000 times; this definitely classes as a first for me. So with tongue firmly in cheek and innuendo firmly in mind, it seems that if you build it, they will come can be the case sometimes.

All of which, makes me wonder … what should I build a map of next?

Written and posted from home (51.427051, -0.333344)

Ooh That Sounds Rude; Mapping British Innuendo

No-one can really define what being British is, though many have tried. One thing that lots of people do seem to agree on is that part of being British is a love for and an appreciation of the British sense of humour. This can be roughly and with a sweeping generalisation said to consist of equal parts of finding fun in everyday situations Peep Show), satire and parody (Have I Got News For You), social awkwardness (The Office), surrealism and nonsense (Monty Python) and innuendo (the Carry On films).

Focus on that trait of innuendo for a moment. Could you possibly combine the British fondness for innuendo with geography and put it on a map? It turns out you can. So I did. It may be vaguely NSFW but there’s real geographical data behind this.

Rude Places Map

Maybe it’s part of bring British, but an airport whose code is BUM is just … funny.

As a classic Web 2.0 style maps mashup, this is never going to win any awards for originality or innovativeness. But the source of each of these vaguely rude sounding names was from Yahoo’s WOE data set, before the data was released via the GeoPlanet API and (currently offline) GeoPlanet Data download. A list of real but amusing sounding place names, culled from GeoPlanet by one of the old Yahoo! Geo team, has been sitting in a file on one of my backup drives for too many years now. But given a geographic data set. Stamen’s wonderful Toner map tiles and a JavaScript maps API, in this case Leaflet, the temptation to make a map out of it all was just too strong.

Yes it’s a map, yes it’s geographical innuendo and yes, it’s very much part of the British sense of humour. If you’re British, try not to snigger too much; if you’re not British, just shake your head sadly and mutter “those crazy Brits”.

Written and posted from home (51.427051, -0.333344)

Foursquare Checkins, Maps And WordPress; Now With MOAR Maps

If you’re an avid Foursquare user you can already display your last checkin, visualised on a map, in the sidebar of your WordPress powered site with the WP Quadratum plugin. Foursquare, checkins and maps … what more could you ask for? Maybe the answer is more maps.

Version 1.1 of the WP Quadratum plugin, which went live this morning, now has added maps. The previous versions of the plugin used Nokia’s maps, because I work for Nokia’s Location & Commerce group and I wanted to use the maps that I work on. But if Nokia’s maps aren’t the maps for you then how about Google’s, or maybe CloudMade’s OpenStreetMap maps or perhaps OpenLayers’ OpenStreetMap maps.

Thanks to the Mapstraction JavaScript mapping API, WP Quadratum now allows you to choose which mapping provider you’d like to see your checkins appear on. And if you don’t want a map on the sidebar of your site, you can embed the checkin map in any post or page with the plugin’s shortcode too.

As usual, the plugin is free to download and use, either from the official WordPress plugin repository or from GitHub.

As a fully paid up and self confessed map geek I may be somewhat biased but surely most things can be improved with the simple addition of more maps.

Written and posted from home (51.427051, -0.333344)