Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

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

'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.