Opened 10 years ago

Closed 10 years ago

#3677 closed defect (wontfix)

OGR shape driver doesn't handle writing points to a multipoint shp.

Reported by: cdestigter Owned by: warmerdam
Priority: normal Milestone:
Component: OGR_SF Version: 1.6.1
Severity: normal Keywords: shape


If I write a polygon to a multipolygon shape, it works fine:

from osgeo import ogr, osr

d = ogr.GetDriverByName("ESRI Shapefile")
ds = d.CreateDataSource("/home/cdestigter/test_polygons")

srs = osr.SpatialReference()

layer = ds.CreateLayer("test_polygons", srs, ogr.wkbMultiPolygon)

feature = ogr.Feature(layer.GetLayerDefn())
geom = ogr.CreateGeometryFromWkt('POLYGON((0 0,0 1,1 1,1 0,0 0))')


But if I do the same thing with a point instead of a polygon, it throws an error:

from osgeo import ogr, osr

d = ogr.GetDriverByName("ESRI Shapefile")
ds = d.CreateDataSource("/home/cdestigter/test_points")

srs = osr.SpatialReference()

layer = ds.CreateLayer("test_points", srs, ogr.wkbMultiPoint)

feature = ogr.Feature(layer.GetLayerDefn())
geom = ogr.CreateGeometryFromWkt('POINT(0 1)')


I'm using gdal 1.6.1 but from a brief scan of the code, it looks like this behavior is in trunk too.

Is there some reasoning behind this behaviour? Seems like a bug to me.

I'm hoping to fix this and have a patch up shortly.

Attachments (1)

gdal-multipoint-fix.diff (6.7 KB) - added by cdestigter 10 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 10 years ago by cdestigter

The error I get is:

ERROR 1: Attempt to write non-multipoint (POINT) geometry to multipoint shapefile.
Out[30]: 3

Changed 10 years ago by cdestigter

Attachment: gdal-multipoint-fix.diff added

comment:2 Changed 10 years ago by cdestigter

The above patch fixes this (applies to trunk r19990 )

comment:3 Changed 10 years ago by warmerdam

Component: defaultOGR_SF
Keywords: shape added

It is possible to write polygon or multipolygons to a polygon shapefile because the types are not distinguished in the shapefile format.

However, point and multipoint are distinct types of shapefile, and they are distinct types of simple features geometry. There is no expectation in OGR that they should be interchangeable.

The proposed patch might be relatively harmless (hard to say without substantial review), but at best it is adding some extra convenience behavior to just one driver. I am not keen to apply it.

comment:4 Changed 10 years ago by cdestigter

Resolution: wontfix
Status: newclosed

Closing old ticket since Frank's comment above makes a lot of sense.

Note: See TracTickets for help on using tickets.