Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I am trying to extract the value of 'Geom' for a geofield entry. This is stored as a BLOB in the database. I can create a 'View' that extracts the location, which results in:
'geom' => 'POLYGON ((-6.2846829687501 53.553679269551, -6.2256314550782 53.548784005325, -6.2613370214844 53.520217009763, -6.2846829687501 53.553679269551))'
However, I need to access the data manually, as it is part of a customised API I am building.
I've tried variations of the following, but getting a 'results cannot be parsed' error, which I guess means the contents aren't actally being unserialised. All help appreciated!
function get_geom($eid) {
$results = db_query ( 'SELECT l.field_portal_location_geom
FROM {field_data_field_portal_location} l WHERE
l.entity_id = :eid', array (
':eid' => $eid
) );
$items = $results->fetchAssoc ();
return unserialize ( $items ['field_portal_location_geom'] );
}
Comments
Comment #1
Chris87 CreditAttribution: Chris87 commentedWhat I need is the WKT version of the geom, to return in the API as a JSON/XML value.
If I run the following code, a POINT is returned, but I know this is inaccurate and that the value should be a polygon
I'm not sure if the solution is related to the mysql code, geofield or geophp. I'm not that familiar with the geo modules. If anyone can help with getting the WKT value of the geom, it would be much appreciated.