AnsweredAssumed Answered

Copy and Paste specific row in the same point fc for several fclasses

Question asked by kostas_ptr88 on Mar 30, 2015
Latest reply on Apr 1, 2015 by kostas_ptr88

I have 10 point feature classes to process each of them having different name, in which i must copy and paste a specific row, updating also a specific column with new values, doing that with a loop for 10 pnts . Maybe it's easy to many of you, but as new to programming i can't understand very well how to use ArcPy for my procedure. I have written this script for the things i want to do with my point fc.

 

1. copy the last row which is different for each fc

2. paste it in the first row without overwritting the existing feature there

3. delete the last row i used for copy

4. update the FID column starting from 0

 

my tables are in the form of:

FID    SHAPE   LINEOID    VALIE

0         POINT       0            10

1         POINT       0            20

2         POINT       0            30

3         POINT       0            40

4         POINT       0            50

5         POINT       0            60

6         POINT       0            70

7..

8..

500     POINT       0             0   

 

If someone can answer, PLEASE it will help if responding a bit analytically about the mistakes in my script

 

# PURPOSE:CALCULATE THE NUMBER OF FEATURES IN A FEATURE CLASS,  Name: fcCount.py

# Import system modules

import arcpy

from arcpy import env

lyrfile = "c:/W/S/pntp.lyr"

result = arcpy.GetCount_management(lyrfile)

count = int(result.getOutput(0))

print count

       

#SELECT ANALYSIS-EXPORT SELECTED ROW/FEATURE AS PNTP2

from arcpy import env

arcpy.Select_analysis("pntp.shp", "C:/W/S/pntp2.shp", 'FID = count')

 

 

#DELETE ROW WITH UPDATE CURSOR

with arcpy.da.UpdateCursor("c:/W/S/pntp.shp",["FID"]) as cursor:

    c = max([FID])

    print C

    for row in cursor:

        if row[0] ==(count):

            cursor.deleteRow()

 

 

#INSERT CURSOR

import arcpy

# Create an insert cursor for a table specifying the fields that will have values provided

fields = ['FID', 'Shape', 'LineOID', 'Valie']

cursor = arcpy.da.InsertCursor('c:/W/S/pntp.shp', fields)

# Create 1 new row at top of the attribute table TO INSERT the feature PNTP2

for x in(0):

    cursor.insertRow((0, 0, 0, 0))

    # Delete cursor object

    del cursor

 

 

#UPDATE CURSOR

with arcpy.da.UpdateCursor("c:/W/S/pntp.shp",["FID"]) as cursor:

    FID += 1

Outcomes