Opened 14 years ago

Closed 13 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
Cc:

Description

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()
srs.ImportFromEPSG(4326)

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))')
feature.SetGeometryDirectly(geom)

layer.CreateFeature(feature)

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()
srs.ImportFromEPSG(4326)

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

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

layer.CreateFeature(feature)

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 14 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 by cdestigter, 14 years ago

The error I get is:

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

by cdestigter, 14 years ago

Attachment: gdal-multipoint-fix.diff added

comment:2 by cdestigter, 14 years ago

The above patch fixes this (applies to trunk r19990 )

comment:3 by warmerdam, 14 years ago

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 by cdestigter, 13 years ago

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.