Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#5905 closed defect (fixed)

CartoDB geometry type declarations too correct

Reported by: pramsey Owned by: Even Rouault
Priority: normal Milestone: 2.0.0
Component: OGR_SF Version: unspecified
Severity: normal Keywords:
Cc:

Description

It looks like the CartoDB driver is declaring geometry columns with actual geometry types

create table foo (
  the_geom geometry(polygon,4326)
)

CartoDB prefers more generic declarations,

create table foo (
  the_geom geometry(geometry,4326)
)

I discovered this by running the same import routine twice, the second in -append mode, and got this error:

ERROR 1: Error returned by server : Geometry type (Polygon) does not match column type (MultiPolygon)

which brings up a second mystery, of how the column type got defined to multipolygon when the input type was polygon?

Change History (7)

comment:1 Changed 7 years ago by Even Rouault

The PostGIS driver also creates column with strong typing, ala "the_geom geometry(polygon,4326)". By removing that strong typing, this would allow multiple geometry types to be mixed, potential points, lines, polygons in the same column.

Regarding your second issue, this might come if you import a shapefile. The shapefile driver currently returns polygon or multipolygon, but declare the layer geometry type as polygon. This is a long known feature/issue. But your use case seems to be the reverse way, so I'm a bit confused. Maybe the layer was created with -nlt MULTIPOLYGON, and then the append was done after without specifying it ?

comment:2 Changed 7 years ago by pramsey

No, the commands to create it were basically the same:

ogr2ogr --config CARTODB_API_KEY e44...66  -f 'CartoDB' 'CartoDB:pramsey' g50.shp

and then

ogr2ogr --config CARTODB_API_KEY e44...66 -append -f 'CartoDB' 'CartoDB:pramsey' g50.shp

comment:3 Changed 7 years ago by Even Rouault

Ah ok, I did actually try the above and was doubly wrong: 1) To avoid this annoying issue with shapefiles, I actually *did* implement automatic Polygon->MultiPolygon? promotion in the CartoDB driver, when creating a new table, when the declared geometry type of the source layer is Polygon 2) But in the second step, the driver currently fails to retrieve the actually geometry type, so CreateFeature?() doesn't no longer do the Polygon->MultiPolygon? promotion. The fix would be to improve the driver to retrieve the layer geometry type in read/update mode.

A workaround for your second step would actually be to add -nlt multipolygon.

comment:4 Changed 7 years ago by javisantana

The PostGIS driver also creates column with strong typing, ala "the_geom geometry(polygon,4326)". By removing that strong typing, this would allow multiple geometry types to be mixed, potential points, lines, polygons in the same column.

That's something we allow, editor wizard does not support that, but the everything is working with mixed types

comment:5 Changed 7 years ago by Even Rouault

You can disable strong geometry typing on conversion by adding -nlt GEOMETRY to the ogr2ogr command line.

The advantage of keeping the geometry type of the source (when it is strongly typed) in the CartoDB table declaration is that it makes conversion from CartoDB back to an "old" GIS format or consumption by GIS applications easier.

comment:6 Changed 7 years ago by Even Rouault

Milestone: 1.11.32.0
Resolution: fixed
Status: newclosed

trunk r28990 "CartoDB: properly identify geometry type on authenticated opening. Enable by default batch insertion of features in update mode (#5905)"

comment:7 Changed 6 years ago by Even Rouault

Milestone: 2.02.0.0

Milestone renamed

Note: See TracTickets for help on using tickets.