[GIS] Can PostGIS constrain a column to multipolygons and polygons

postgis

I'm currently using PostGIS 1.5.3, but I will be upgrading to 2.0 soon. So please note any differences between the two versions that are relevant to the following questions.

  • Is it possible to create a column of the PostGIS geometry type that allows insertion of polygons and multipolygons but restricts insertion of other geometry types without manually modifying the constraint PostGIS generates when calling AddGeometryColumn?
  • Are there reasons not to do this? In particular, does PostGIS store any metadata that manually modifying the constraint might negatively impact? (I'm very new to PostGIS, so forgive me if the idea of PostGIS storing metadata is absurd.)
  • How significant is any overhead incurred by using multipolygons for everything?

I'm already aware of using ST_Multi to convert polygons into multipolygons before insertion, so if it's not possible or not a good idea, I'll do that.

Best Answer

For each of your questions...

  1. Not without manually modifying the constraint.

  2. There is some metadata stored in the PostGIS geometry. Technically, there is no reason not to do this. If you want a column to hold polygon or multipolygon, that is up to you. The general reason for sticking with one geometry type per column is simplicity as the table grows and/or if the table is massive.

  3. A multipolygon comprised of only one polygon will be larger than just the polygon, but not significantly. The speed of spatially querying (with the appropriate index) the multipolygon with one polygon vs just one polygon would be the same though.

For my data, if the column is to contain polygons, I have the column be a multipolygon as it allows for the eventuality that a multipolygon will be inserted in the column. Just run ST_Multi as you're inserting.