[gdal-dev] Save to DXF with specific layer name with c#

Colin Wright wrightc at forthvalleygis.co.uk
Fri Jul 30 05:21:20 EDT 2010


I'm using GDAL/OGR 1.7.2 with the C# bindings to write a tool that will export data to various formats.

When it exports to DXF I want it to use a specific layer name rather than using the default dxf layer 0.
The problem is that even though I'm setting the attribute "Layer" for each feature, it is still appearing as layer 0 in the final DXF file.  I've checked and the "Layer" attribute does exist, and setting the attribute value doesn't throw any errors.  The geometry is getting saved to the DXF OK.  

Any ideas?  An extract of my code is below.

//--------------------------------------------------
//Loop through input layers writing to output
lyrInput.ResetReading();
Feature inFeat = lyrInput.GetNextFeature();
iError = -1;
while (inFeat != null)
{
               //Try approach of creating new feature
	Feature outFeat = new Feature(lyrOutput.GetLayerDefn());
                if (outFeat.SetGeometry(inFeat.GetGeometryRef()) == Ogr.OGRERR_NONE)
               {
                       bFeatOK = true;

                      //Generic attribs for DXF
                      if (sOutFormat == "DXF")
                      {
                                  //I've checked and this section is getting called
                                  outFeat.SetField("Layer", "MyLayerName");
                        
                       }
               }
               if (bFeatOK)
               {
	         iError = lyrOutput.CreateFeature(outFeat);
               }

               outFeat.Dispose();
               inFeat = lyrInput.GetNextFeature();
}


Thanks

Colin


--------------------------------


More information about the gdal-dev mailing list