I presented this talk at the 2017 FOSS4G conference in Boston. The target audience was a group of GIS developers and users who were not WordPress experts.
You can view the slide deck or view the video presentation below, or download a PDF of the slides here. The text below the video mostly follows what I said in the presentation, reformatted to make sense as a blog post.
Today I’d like to tell you about an Open Source project that millions of people use every day, which until now hasn’t had good spatial support.
Today I’m going to cover three things:
- I’m going to introduce WordPress to you, and discuss why it hasn’t had good spatial support.
- I’m going to introduce WP-GeoMeta-Lib and tell you why I think it is the best way to add spatial support to WordPress
- I’m going to make an argument that WordPress is a land of opportunity for Open Source GIS projects
An introduction to WordPress
WordPress is a Content Management System (or CMS) for making websites. It’s written in PHP and uses the MySQL database for storage.
You can drag-and-drop photos, use a visual editor instead of writing HTML and everything else that you’d expect out of a modern day content management system. Out of the box it’s configured to let you create web pages and a blog, but you can extend it with over 50,000 free plugins. There is also a thriving marketplace of paid, but still Open Source, plugins.
There plugins can turn WordPress into a membership directory, a web store, or whatever else you want it to be.
So what’s the big deal about a content management system and why am I discussing it when talking about GIS?
Well, WordPress is popular. Very popular. It’s the most popular content management system in the world, in fact, with over 2.8 million websites using it to manage their content.
With so many users, there must be a thriving collection of GIS plugins and support, right?
Sadly, No. WordPress and GIS seem to hardly be aware of each other. So, by way of introduction: GIS, this is WordPress. WordPress this is GIS!
Pros and Cons of WordPress
Now, WordPress does have problems and we’ll get to that, but it’s good enough for 2.8 million websites and some of those sites have spatial data needs.
The first thing you should know about WordPress is that it’s known for its ease of use.
Many non-technical people install it and use it. If you go to a WordPress meet up you’re as likely to meet a travel bloggers as are a developers.
And WordPress is everywhere.
Many of the cheapest web hosts support WordPress which makes it a great for startups and individuals who are just trying to get an online presence.
Established businesses use it because of its extensive collection of plugins which quickly add functionality, and because developers are plentiful. Also, since it’s everywhere, businesses can find someone else in their market that is using WordPress and feel confident that WordPress can do what they need it to.
Finally, you should know that WordPress does a good job at a good price. It gets the job done, and both users and developers know what to expect.
Now on to WordPress’ problems. The first problem isn’t with WordPress per se, but is worth being aware of.
Hardly anyone is doing GIS in WordPress. There are about 700 plugins that will display a map of some sort, but GIS is so much more than just displaying a map.
So, if you’re going to start doing GIS in WordPress it might be a bit lonely for now.
Even if you, as a developer, are happy doing GIS where others aren’t you still need to overcome the next challenge in WordPress: the WordPress data structure.
In WordPress there are objects which have a handful of built-in properties. Each object may have zero or more metadata properties tied to it.
This one to many relationship is handled with what is essentially a key-value store. Each row in the metadata table includes the ID of an object, the meta property key and the meta value.
This metadata table is the logical place to store spatial data pertaining to WordPress objects, however, since values can be of any data type, the meta_value column in the database is of type longtext.
Longtext as the name implies, is text. Dates, numbers, booleans, etc. are all converted to text. To store spatial data here, you’d need to convert it to a text friendly format (or MySQL would convert it for you). This means you can’t benefit from spatial functions or indices, and searching becomes complicated. Essentially, your stored spatial data can’t be easily used for anything.
The last WordPress concern I’m going to cover here involves a quick topology lesson.
Do these two shapes intersect? It depends on if you’re using the actual geometry to check your intersection, or if you use the shape’s bounding boxes! (The bounding box is the smallest rectangle that can contain a shape).
MySQL 5.6 was released in 2011 with support for real spatial comparisons. Before that only bounding box comparisons were possible.
Unfortunately those cheap webhosts I mentioned often use the Long-Term-Release versions of software which means they’re just now phasing out MySQL 5.5.
If you were to randomly pick one of those 2.8 million WordPress sites today, less than half of them have a database that could do proper spatial comparisons.
Happily, this issue is going away quickly. Last November only 29% of sites had good databases, today over 48% have databases with the real spatial comparisons.
So, WordPress has it’s issues for sure, but it’s a solid content management system and its users deserve more spatial support than they’re getting now.
WordPress is open source and it’s used by a huge percentage of the internet. Bringing spatial capabilities to WordPress could bring many new users under the Open Source Spatial umbrella. It’s an opportunity to share GIS with a huge new audience that doesn’t even know that they need GIS.
In other words, I think GIS and WordPress need to get together.
WP-GeoMeta-Lib What, Why and How
Now that you know everything you need to know about WordPress, on to WP-GeoMeta-Lib. What is it? Why should you use it? How does it work?
I was working on a WordPress and GIS integration for a client and we were storing the location information in the metadata system. We were storing the latitude and longitude in separate fields, as text strings. As I was looking at this, I wished that we could query it efficiently.
So, we took a step back and looked at what a generic, basic, GIS workflow might look like.
We determined that in a generic GIS workflow, someone needs to collect or import data and store it somewhere. Later they will want to query it, possibly analyze it, and then display it.
We couldn’t find a good existing way to perform this workflow with WordPress. Storing and Querying spatial data were the key weakness. The other steps were missing too but without a way to store and query spatial data the rest was meaningless.
After some initial proof of concept code, we set out to build a library that we could use and share. The results were, of course, WP-GeoMeta-Lib.
What Does WP-GeoMeta-Lib Do
WP-GeoMeta-Lib, on its own, is not a WordPress plugin. It’s a library that you can include in your own plugins or which you can ask other plugin developers to include in their plugins.
It makes saving and querying spatial data easy and very WordPress-y.
It starts with making a place to store the data. WordPress has four built-in object types and four corresponding metadata tables. WP-GeoMeta-Lib creates a corresponding spatial metadata for each non-spatial metadata table.
In these tables, instead of storing the meta_value as “longtext”, it’s stored in a “geometrycollection” column with a spatial index. It then uses the WordPress API to intercept requests to store spatial metadata and puts a copy of it in the spatial metadata tables.
Later when queries are run through WordPress’ search functions, the spatial parts of those queries are re-routed to query the spatial metadata tables. It also has some convenience functions for working with GeoJSON and for calling MySQL spatial functions from PHP.
My hope is that if you’re a GIS developer who is new to WordPress, WP-GeoMeta-Lib will hide some of the complexities of WordPress. If you’re a WordPress developer who is new to GIS, I hope that it will hide some of the complexities of GIS.
WordPress is a land of opportunity!
There are over 2.8 million websites out there powered by WordPress.
WordPress probably isn’t going to become a full-fledged GIS. I’m not asking you to imagine how a county could manage its entire spatial infrastructure using WordPress or anything like that, but individuals and businesses that have light-weight spatial data needs could be served by WordPress if someone would just write the code.
WordPress users need various ways to collect spatial data. They need to have multiple interfaces to query data in different ways. They should be able to build maps and charts based on spatial relationships between WordPress objects and display them.
Here at LuminFire we have started building a few of the options that users will need. I’m going to wrap up this post by showing mentioning three free plugins that we’ve released which use WP-GeoMeta-Lib. They all have to do with collecting data.
The first is WP-GeoMeta. It’s a spatial dashboard that gives the WordPress admin an overview of what spatial data they have, the health of their database and which spatial functions are available. It also includes GeoJSON importer for quickly loading data into WordPress.
Brilliant Geocoder for Gravity Forms is an add-on for the popular drag-and-drop form builder plugin, Gravity Forms.
You can choose a geocoding engine, including OSM Nominatim, geocod.io or the Google Maps API and choose which form fields will be used for geocoding.
You can then use Gravity Forms to collect spatial information from site visitors, or to create WordPress users or objects with spatial metadata.
Lastly, GeoMeta for ACF is an add-on for the popular Advanced Custom Fields, or ACF plugin.
It allows a website admin to add map input fields where site editors can draw the location or shape of an object.
1. WordPress is a great CMS, but needs spatial support
2. WP-GeoMeta-Lib is the best way to add that support
3. You should go write a spatial WordPress plugin today!
For more information on WP-GeoMeta-Lib and how to use it, please visit the WP-GeoMeta-Lib GitHub page. The library is open source and can be freely used in your WordPress plugins and themes.