Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to achieve an equivalent to the Dissolve tool from ArcGIS for Desktop using ST_Union from PostGIS but it seems I am not getting expected result.

I have one table which has certain attributes with the Polygon Geometry. (like FID, Locstat, Loccnt, Shape)

Here is my query :

SELECT c.fid, ST_Union(c.boundaryshape) FROM c Group by c.fid,c.boundaryshape;

Thanks in advance.

share|improve this question
    
Can you explain what results you're expecting and what you're getting? Running: SELECT AsText(ST_Union...) FROM ... might help to find the error. –  Micha Sep 18 '13 at 16:30
    
In table I have 6842 records, as per the ArcGIS results I should get 1683 records where as using the query I am getting 6842 records. I also tried ST_Aggr_Union which is give me 742 Records with the multiple null Geometry. –  Dhams Sep 18 '13 at 16:41
add comment

1 Answer 1

Your problem is likely because of what you have included in the group by field.

ST_UNION is an aggregate function, meaning that it is dissolving based on what you specify as the GROUP parameter.

Here is what you entered:

SELECT c.fid, ST_Union(c.boundaryshape) FROM c Group by c.fid,c.boundaryshape;

According to this, you are grouping by your fid, which is probably a unique identifier, and also by boundaryshape, which is the geometry. The problem with this is that it is highly unlikely that the features sharing a unique ID, are going to have identical geometries. Therefore, the ST_Union is probably going to end up with something like the following:

Input:   
fid     boundaryshape  
1         11  
1         12  
1         11  
1         13  
2         12  
2         13  
2         12  
3          5  
3          2  
3          4  

Output:  
fid     boundaryshape  
1        (11 + 11)  
1        12  
1        13  
2        (12 + 12)  
2        13  
3        2  
3        4  
3        5

In this case, you should only be dissolving based on your unique identifier, unless you actually have a number of duplicate geometries with the same fid, that you are trying to get rid of. Even in that situation though, you should only need to group based on the fid, and the union will take care of the geometry duplication.

I would try the following:

SELECT c.fid, ST_Union(c.boundaryshape) FROM c GROUP BY c.fid;

That should give you the desired result of dissolving all features based on the common attribute fid.

Here is the help document at the PostGIS site: ST_Union

See the first example listed at the bottom and notice that it does not include the geometry in the group by section.

share|improve this answer
    
In some cases, it is better to snap geometries to grid before doing union: SELECT ST_Union(ST_SnapToGrid(geom,0.0001)) FROM geo_area group by level_identifier; –  Maxim Eliseev Oct 24 '13 at 13:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.