简体   繁体   中英

postgis eliminate inner boundaries from polygons

I constructed a postgis table in PostgreSQL that cointains a set of polygons that are the result of joining many smaller polygons. The result of the join is a polygon with an outer boundary and some of them have inner boundaries (polygons inside). I like to remove the inner boundaries.

The construction of the new table was with:

insert into dl_table 
    select 1 as id_level, 18 as id_sublevel, 
        ST_snaptogrid(ST_Union(geom),0.0001) as geom 
    from small_polygons_table 
    where id_sp in 
          (select id_sp from cdl where id_level=1 and id_sublevel=18);

and the result for geom is:

<Polygon>
  <outerBoundaryIs>
    <LinearRing>
      <coordinates>
         ...points...
      </coordinates>
    </LinearRing>
  </outerBoundaryIs>
  <innerBoundaryIs>
    <LinearRing>
       <coordinates>
         ...points...
       </coordinates>
    </LinearRing>
  </innerBoundaryIs>
  <innerBoundaryIs>
    <LinearRing>
      <coordinates>
         ...points...
      </coordinates>
    </LinearRing>
  </innerBoundaryIs>
</Polygon>

Now I like to remove those inner boundaries.

ST_Union() will dissolve internal boundaries so are you sure that all coordinates are exactly the same?

Your query is more commonly written with a JOIN like this:

insert into dl_table 
  select id_level, id_sublevel, ST_snaptogrid(ST_Union(geom),0.0001) as geom 
  from small_polygons_table
  join cdl using (id_sp)
  where id_level = 1 and id_sublevel = 18;

Just for future reference for others finding this question: the problem here is that the source data doesn't include any topology. There is no "magic" way of cleaning up overlapping polygons that shouldn't overlap, or gaps between polygons that should share a common boundary. One option here is to do the St_snaptogrid before the ST_Union , which will clean it up a bit at least, at the cost of loosing accuracy. But in the end it really depends on the source data and a lot of trial and error will be involved, and possibly manual work too. See https://gis.stackexchange.com/questions/31895/joining-lots-of-small-polygons-to-form-larger-polygon-using-postgis for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM