Я не могу обнаружить ошибку, пытаюсь вставить ... столбцы не совпадают - PullRequest
0 голосов
/ 08 июня 2018

Таким образом, код выполняется до вставки новой строки, после чего я получаю >>>
', пытаясь вставить [результат 3 элементов] в эти столбцы [5 элементов].Я пытался выяснить, где мой код приводит к потере результатов, но не могу.Любые предложения будут великолепны.Дополнительная информация, мой класс пространственных объектов, который я вставляю, имеет пять полей, и они совпадают с полями исходного поля.Это достигает моей длины! = И моя ошибка печатает.Пожалуйста, помогите, если вам кто-то захочет.

# coding: utf8

import arcpy
import os, sys
from arcpy import env
arcpy.env.workspace = r"E:\Roseville\ScriptDevel.gdb"

arcpy.env.overwriteOutput = bool('TRUE')
# set as python bool, not string "TRUE"     

fc_buffers = "Parcels" # my indv. parcel buffers

fc_Landuse = "Geology" # my land use layer 


outputLayer = "IntersectResult" # output layer   


outputFields = [f.name for f in arcpy.ListFields(outputLayer) if f.type not in ['OBJECTID', "Geometry"]] + ['SHAPE@']

    landUseFields = [f.name for f in arcpy.ListFields(fc_Landuse) if f.type not in ['PTYPE']]


parcelBufferFields = [f.name for f in arcpy.ListFields(fc_buffers) if f.type not in ['APN']]


intersectionFeatureLayer = arcpy.MakeFeatureLayer_management(fc_Landuse, 'intersectionFeatureLayer').getOutput(0)

selectedBuffer = arcpy.MakeFeatureLayer_management(fc_buffers, 'selectedBuffer').getOutput(0)


def orderFields(luFields, pbFields):

    ordered = []

    for field in outputFields:

        # append the matching field

        if field in landUseFields:

            ordered.append(luFields[landUseFields.index(field)])

        if field in parcelBufferFields:

            ordered.append(pbFields[parcelBufferFields.index(field)])

    return ordered
    print pbfields


with arcpy.da.SearchCursor(fc_buffers, ["OBJECTID", 'SHAPE@'] + parcelBufferFields) as sc, arcpy.da.InsertCursor(outputLayer, outputFields) as ic:

    for row in sc:

        oid = row[0]
        shape = row[1]
        print (oid)     
        print  "Got this far"

        selectedBuffer.setSelectionSet('NEW', [oid])

        arcpy.SelectLayerByLocation_management(intersectionFeatureLayer,"intersect", selectedBuffer)


        with arcpy.da.SearchCursor(intersectionFeatureLayer, ['SHAPE@'] + landUseFields) as intersectionCursor:

            for record in intersectionCursor:

                recordShape = record[0]
                print "list made"


                outputShape = shape.intersect(recordShape, 4)

                newRow = orderFields(row[2:], record[1:]) + [outputShape] 

                if len(newRow) != len(outputFields):

                    print 'there is a problem.  the number of columns in the record you are attempting to insert into', outputLayer, 'does not match the number of destination columns'

                    print '\tattempting to insert:', newRow

                    print '\tinto these columns:', outputFields

                    continue

                # insert into the outputFeatureClass

                ic.insertRow(newRow)

1 Ответ

0 голосов
/ 03 июля 2018

Ваш оператор with, в котором вы определяете курсоры, создает курсор ввода с 5 полями, но ваша строка, которую вы пытаетесь заполнить, состоит только из 3 полей.Вы должны убедиться, что курсор вставки имеет ту же длину, что и строка.Я подозреваю, что проблема на самом деле в методе orderfields.Или то, что вы передаете ему.

...