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 have a MultiPolygon representation of some shapes in POSTGIS, I am trying to convert them to Polygon data.

I tried, st_geometryn(r.geom, 1) but that didnt work because the way polygons are embedded I think. Just returns a partial.

Tried ST_ConcaveHull(ST_Collect(r.geom), 0.99), no luck returns nothing

Tried:

SELECT f.gid, ST_AsGeoJSON(ST_Union(f.geom)) as singlegeom FROM (SELECT gid, 
       (ST_Dump(geom)).geom As geom FROM public.nyc_boroughs ) As f GROUP BY gid" 

but getting back to Multi Polygon,

I feel like a little bit of direction could help me figure out.

Data is here http://www.sendspace.com/file/2savyw

share|improve this question
add comment

1 Answer

The polygons features are indeed multipart, so st_geometryn(r.geom, 1) will discard data.

If you are just trying to get the footprint for the polygon(s), use ST_ConvexHull(r.geom). Or to apply this only to true multi-part geometries, but keep single-part:

SELECT
  CASE
    WHEN ST_NumGeometries(r.geom) > 1 THEN
      ST_ConvexHull(r.geom)
    ELSE
      ST_GeometryN(r.geom, 1)
  END AS geom
FROM mytable AS r
...

Warning: the former multi-part geometries might look funny.

share|improve this answer
    
Thank you for the response, I just realized ST_ConcaveHull is only available at v2.0+, and ST_ConvexHull is not precise enough for what I need. (see bit.ly/129VmAo). I am gonna upgrade, test will post results. –  Igal Nassima Dec 13 '12 at 7:22
2  
upgraded to 2.0 and used ST_ConcaveHull, works pretty well, here is a result bit.ly/Zm3uOz –  Igal Nassima Dec 13 '12 at 20:31
1  
Yup, that certainly looks good. However, I'd only use a concave hull functions on true multi-part geometries, using the CASE ... statement provided, simply because it can unnecessarily alter a single-part geometry. –  Mike T Dec 13 '12 at 22:48
    
@IgalNassima Please accept the answer if your problem is solved. –  underdark Feb 11 '13 at 7:09
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.