Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
add comment

1 Answer

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.

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.

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

Your Answer

 
discard

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.