Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I used below codes to create ShapeFile layer

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

And I used below codes to create feature:

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

But when I tried to add create a LineString feature into shape file layer. I got the error: "Attempt to write non-polygon geometry to polygon type shape file". Please see my image. Image

How can I add linestring into layer (shape file) ?

share|improve this question
up vote 1 down vote accepted

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.


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.

share|improve this answer
Thank you, I will create a new shapefile for lines – taibc Jun 10 '13 at 1:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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