1

I used below codes to create shapefile layer:

OGRDataSource       *poDS,  *poSHPDS;
OGRLayer   *poSHPLayer;
...
poSHPLayer = poSHPDS->CreateLayer (shpFileName, NULL, wkbPolygon , NULL);

And I used below code to create feature:

OGRFeature *poSHPFeature; 
poSHPFeature = OGRFeature::CreateFeature (poSHPLayer->GetLayerDefn());  
poSHPFeature->SetGeometry (poGeometry);

But when I tried to add create a LineString feature into shapefile layer. I got the error:

"Attempt to write non-polygon geometry to polygon type shapefile". Please see my image.

Image

How can I add linestring into layer (shapefile) ?

1

I'm afraid you have to accept the error message :-(

Shapefiles are intended to be point, line or polygon geometries, but not a mixture of them.

From http://www.gdal.org/ogr/drv_shapefile.html:

ESRI shapefiles can only store one kind of geometry per layer (shapefile).

There are other data formats (GML, GeoJSON, KML) which allow that, but you will be getting problems when you want to transform those formats to shapefiles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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