Select to view content in your preferred language

Use InsertCursor to copy geometry from one dataset to another

7030
1
01-13-2015 04:45 PM
AnthonyCheesman1
Occasional Contributor II

Hi

I'm trying to write a script that needs to copy geometry from one FC to another, and also write some attributes. The way I see it is that an insert cursor on the dataset I'm writing to needs to be nested within a search cursor on the dataset I'm writing from.

It's an iterative script that needs to sequentially work through features via an attribute value.

I could use arcpy.Append_management for this, but if I can get the search/insert cursor nesting working, I think it will be a much neater solution for the job at hand.

The crux of the code is:

scur = arcpy.SearchCursor(fc)

>>> for row in scur:

...     icur = arcpy.InsertCursor(plm)

...     irow = icur.newRow()

...     irow.SHAPE = row.getValue("SHAPE")

...     irow.MMTGEN = row.getValue("MMTGEN")

...     irow.HANDLED = "Y"

...     icur.insertRow(irow)

...     del irow, icur

...which seems very logical to me, but it keeps falling over with generic error 99999.

This is the first time I've used Insert Cursors, so I'm unsure if what I am proposing is possible, and if I've gone about this the right way.

Can anyone provide some insight for me?

0 Kudos
1 Reply
XanderBakker
Esri Esteemed Contributor

Here you have an example of using the da cursor (insert and search nested) to read and write geometry. The da cursor area available for 10.1 (SP1?) and higher: https://community.esri.com/thread/119916#449508

You can first create the insert cursor, next the search cursor and then start to loop the features using the search cursor. Don't put the insert cursor inside the loop through the search cursor.

0 Kudos