WherePress

GIS for WordPress and MySQL

  • Home
  • Projects and Plugins
    • WP-GeoMeta
    • WP-GeoMeta-Lib
    • GeoMeta for ACF
    • SavvyMapper
    • WP Spatial Capabilities Check
  • Contact
  • About
  • test
  • Pond Test

WP-GeoMeta-Lib

The core of WP-GeoMeta and GeoMeta for ACF is WP-GeoMeta-Lib. WP-GeoMeta-Lib is a spatial library meant for use in WordPress plugins.

Download Now!

It gracefully handles multiple installations, upgrades and un-installations so that plugin developers like yourself don’t have to.

How Does It Work?

WordPress includes four metadata tables. Their default names are wp_postmeta, wp_commentmeta, wp_termmeta and wp_usermeta. Those tables stores metavalues as strings in a MySQL LONGTEXT field. This is not a suitable place to store or query spatial data.

When a plugin using WP-GeoMeta-Lib is activated, it creates wp_postmeta_geo, wp_commentmeta_geo, wp_termmeta_geo and wp_usermeta_geo with MySQL GEOMETRYCOLLECTION, and a spatial index.

Updating Spatial Metadata

After metadata is added (or updated, or deleted), WP-GeoMeta-Lib checks the value that was sent to the regular metadata table. If it looks like spatial data (GeoJSON by default), then it will convert the metavalue into a MySQL compatible format and update the appropriate spatial metadata table.

Out of the box WP-GeoMeta-Lib supports GeoJSON, WKT and geo_latitude/geo_longitude pairs. There are filters so you could add support for other geometry formats if needed.

Querying Spatial Metadata

Storing spatial data is no good if you can’t query it! WP-GeoMeta-Lib gives you access to MySQL spatial functions right within WP_Query! During meta_query processing WP-GeoMeta-Lib checks if the meta query is using a spatial operator and if it is, it re-routes that part of the query to search the spatial tables instead of the normal non-spatial metadata table.

You can also run your own custom queries against the spatial tables, the same way that you can run custom queries directly against the wp_postmeta table.

See the documentation for more info on running spatial queries.

Other Features

WP-GeoMeta-Lib includes a couple of other features to make your life as a developer easier.

Run Spatial Functions From PHP

You can run any MySQL supported spatial function from PHP, passing in GeoJSON and getting GeoJSON back (if a geometry should be returned). Simply run:

$do_they_intersect = WP_GeoUtil::ST_Intersects({PointGeoJSON},{PolygonGeoJSON});

or

$spatial_union = WP_GeoUtil::ST_Union({PolygonGeoJSON_1},{PolygonGeoJSON_2});

Custom Auxiliary Functions

Working with latitude and longitude in degrees can be cumbersome if you need to buffer points or find the distance between two points. WP-GeoMeta-Lib creates several stored functions to help with these common operations. For example wp_buffer_point_m and wp_buffer_point_mi will buffer a point using meters or miles instead of degrees like ST_Buffer would expect.

If you create custom spatial functions you can add them to WP-GeoMeta-Lib using a filter, so that you can other developers can use them like you would any native MySQL spatial function.

Copyright © 2018 · Cimbura.com · Log in