I'm having a weird issue and it seems the geofield_compute_values() is doing something weird with my WKT.

I am importing a shapefile into my geofield. I have custom code to do this (hoping to release it soon as a geofield widget). The Shapefile has 4 features, all polygons.

I am trying to combine this into a multipolygon. When I sent the multipolygon feature into geofield_compute_values(), it removed some of the 4th polygon (by far the largest). While poking around, I tried reversing the order of the polygons, so that the largest one was entered first. Strangely, this seemed to preserve the data.

Clearly the order to the features shouldn't matter. Perhaps I am mangling the data somehow.

I have attached the two MULTIPOLYGON wkt features so that they can be tested. Running them through geofield_compute_values() shoud return the same data but it's not working for me.

CommentFileSizeAuthor
#1 wkt_array_serialized.txt80.85 KBdtarc
good.wkt_.txt80.81 KBdtarc
bad.wkt_.txt80.81 KBdtarc

Comments

dtarc’s picture

StatusFileSize
new80.85 KB

Here's the code I'm using to generate the WKT, from an array of polygons that have had the POLYGON( and ) stripped off:

      $wkt = array('wkt' => sprintf('MULTIPOLYGON(%s)', implode(',', $feature_array)));
      $return_features[] = geofield_compute_values($wkt);

Using it this way causes data loss. However, using it this way:

      $wkt = array('wkt' => sprintf('MULTIPOLYGON(%s)', implode(',', array_reverse($feature_array))));
      $return_features[] = geofield_compute_values($wkt);

Pulls in data in just fine.

This seems very curious. I have attached the serialized array.

phayes’s picture

Hi Dave,

I'm digging into this and it looks to be a problem with geoPHP's WKT parsing functions. Haven't found the absolute root cause yet. I do note however, that if GEOS is installed, the problem does not manifest (because GEOS takes over WKT parsing).

I won't have time to dig any deeper for two weeks, so I would encourage you to either use GEOS or to look into geoPHP's WKT Adapter.

phayes’s picture

To ease debugging, here's a much simpler WKT snippet that has the same problem:

MULTIPOLYGON(((10 12, 15 13, 11, 10, 10 12)),((-111 58,-110 57,-109 56,-111 58),(-113 57,-114 57,-112 57,-113 57),(-113 57,-113 57,-113 57,-113 57)))
phayes’s picture

Even simpler: The inner-boundary on the second polygon is lost:

MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20)))
phayes’s picture

Status: Active » Fixed

Okay, this is now fixed in the latest master branch of geoPHP

phayes’s picture

I've also rolled out a 0.6 version of geoPHP which incorporates this fix. On the geofield side I've bumped the recommend geoPHP version to 0.6

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.