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.

Using OGR in Python, I'd like to create some geometries within a DXF file, but not in the "0" layer, but in new ones.

I tried with:

import ogr, os, osr, sys
ds = ogr.GetDriverByName('DXF').CreateDataSource('output.dxf' )
myLayer = ds.CreateLayer('entities')
newFeature = ogr.Feature(feature_def = myLayer.GetLayerDefn())
newFeature.SetGeometryDirectly(ogr.CreateGeometryFromWkt( 'LINESTRING(0 0, 100 100)'))
myLayer.CreateFeature( newFeature )
newFeature.Destroy()
ds.Destroy()
ds = None

But I don't have any idea about how to continue and create new layers.

I tried also with

layers = ds.ExecuteSQL("INSERT INTO entities (Layer) VALUES ('Layer1')")

but it does not work.

  • Any suggestion?
  • Is it worth using another DXF+Python library?

Thank you very much.

share|improve this question
    
You may want to accept some of your previous questions to up your accept rate. The community is more likely to help users who accept answers. –  artwork21 Jul 2 '12 at 16:22

1 Answer 1

'layer' is an attribute field. Add:

newFeature.SetField( myLayer.GetLayerDefn().GetFieldIndex("layer"), 'newlayer')

And the feature will appear on layer newlayer.

share|improve this answer

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.