Skip to main content
1 of 2
Nicklas Avén
  • 13.3k
  • 1
  • 40
  • 48

The most common reason to get results like this is that the oeigin polygons are invalid. You can check with:

SELECT ST_IsValidReason(geom) from RegionsRaw where not ST_IsValid(geom);

If you get any rows in return you have bad polygons.

But you can try to fix them. In PostGIS 2.0 ther will be a function called ST_MakeValidwhich will try to fix the polygons.

But if you are not running some beta-release of 2.0 you can try with a buffer with 0 as argument.

Another note is that there is no reason to make an array before unioning. ST_Union also works as an aggregate function, so try something like:

SELECT ST_AsText(ST_Union(ST_Buffer(geom,0.0))) FROM
RegionRaw 
WHERE ParentName = '" . $parentName . "';

if you want the text output of the result.

Also note that if you want one unioned polygon for each "parentName" you can just group by parentName instead and get them all at once. One on each row

HTH
Nicklas

Nicklas Avén
  • 13.3k
  • 1
  • 40
  • 48