I read that in PostGIS, one can have different types of geometry, say, POINT and LINESTRING?? in the same column/field of a table.

I have used ESRI products a lot where each table can only contain one type of geometry. I am just curious what is benefit/motivation for allowing mixed geometry types in PostGIS columns?

To me, what PostGIS did is to have an array of Java ObjectS, which is kind of pointless, since an Object (or Geometry in the case of PostGIS) can be anything. We can't really reason much about the base class geometry (e.g. its dimension and inoperability with other entities etc.) because it's too abstract.

For example, polygons have no length, points have no meaningful lengths or areas (because points are often simplified representation of linear/areal objects). Naturally, one can't do statistics/aggregates such as finding out the average measure of a geometry field because a measure may not be defined for some rows, due to the lack of constraint on the specific type of the geometry.

Am I missing some beneficial aspects of the heterogeneous columns?

Also, are there any practical examples of hetergeneous columns for non-geometric types in Postgres? For example, a column that can be both float-ing point numbers and bytea, or is the mixed columns a PostGIS invention?

| improve this question | | | | |
  • it's more of a List<Geometry> rather than List<Point> and is useful for the same reasons – Ian Turton Jan 11 '16 at 12:16
  • 2
    One could as well ask what is the point not to allow mixed geometry types in ESRI products? I know it is easier to render things if they are all points, lines, or polygons. On the other hand, if features with same attribute schema can be either points, lines, or polygons it can make the system unnecessary complicated. Have a feature with a point geometry, buffer it and you must store it into another place. – user30184 Jan 11 '16 at 12:55
  • 1
    Having a possibility to have mixed geometries in the same column does not mean that you must do it. Desktop GIS programs do not usually support them well. OpenJUMP may be the best example of those who can. Anyway, mixed geometries are supported in Oracle Spatial, Spatialite, GeoPackage, GML, MapInfo tab etc. – user30184 Jan 11 '16 at 13:46
  • 1
    An Object can be anything, but a geometry can only be a geometry. And there are properties that every geometry has in common, such as length, area, centroid, number of dimensions, etc. Geometry is abstract, but not that abstract. (However, why you'd want to put, say, a point in a line column, instead of a degenerate line, I'm not immediately sure...) – Rob Skelly Jan 11 '16 at 16:59
  • 1
    That's the formal mathematical definition of a point. PostGIS uses a different definition. I'm not keen to argue about the philosophical implications of either view at this hour ;) – Rob Skelly Jan 11 '16 at 17:15

I will need to recheck my copy of "PostGIS in Action" by Regina Obe and Leo Hsu (Great book).

Basically it lists the pro's as:

  • It allows you to run a single query of several feature of interest without giving up the luxury of modeling them with the most appropriate geometry type
  • It's simple. you could cram all your geometries into one table if their non spatial attributes are more or less the same.
  • Table creation is quick because you can do it by setting the field as a geometry with a single create table statement and not have to worry about additional need to apply the AddGeometryColumn function, great if you are importing lots of tabulated data

If you can get hold of the book I highly recommend it. It is getting a bit old now and some functions may have changed.

| improve this answer | | | | |
  • 1
    Thanks. Skimming that book is what generated this question. The first point is interesting. It allows you to run a single query of several feature of interest without giving up the luxury of modeling them with the most appropriate geometry type. Would be great if there is a solid example. – tinlyx Jan 11 '16 at 14:22
  • There is the example about Paris on pages 61-64 but then again it didn't help me a lot either – Banger Jan 11 '16 at 21:16
  • 1
    PS you should re-edit, I think it's a great question, also coming from an ESRI background I was a bit shocked at the idea. – Banger Jan 11 '16 at 21:19
  • 1
    Arbitrary example: observations of a species. Sometimes, the location is known with high precision and certainty: a point. Other times, perhaps, the location is only known to an area best modelled as a polygon ("the deer was spotted in the lower half of Valley X but we can't be more precise than that"). Then if you want to summarise all the different types of plants that are within x metres of known deer sightings, you can do so without requiring two different processes for points and polygons. You can still constrain a column to be one geometry type if you need this: it's purely optional. – alphabetasoup Jan 18 '16 at 3:58
  • @RichardLaw Do you have an actual example/application that can be cited, e.g. to a book or study? I am just curious about the details. – tinlyx Jan 18 '16 at 21:13

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