Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Field Calculator text field to new shapefile

$
0
0

I have point features being selected by a polygon feature and copied to their own shapefile. I also have certain values of the polygon feature being applied to the newly created point file. The point file already has the required fields that need to be populated. The integer/floating fields are copying correctly, but the lone string field (SfcType)/row[4] value isn’t being applied. I realize this has to do with the fact that it is a string, but I cant seem to find the right syntax. Can anyone point out my (obvious) mistake?

from arcpy import * import os
arcpy.env.overwriteOutput = True

#Make feature layer of feature classes to allow selection
MakeFeatureLayer_management (inPolyfc, "Polylyr")
MakeFeatureLayer_management (inPointfc, "Pointlyr")

#Get name of OID field for sql expression
polyOIDfld = Describe ("Polylyr").OIDFieldName

#iterate through polygons with cursor
cursor = da.SearchCursor ("Polylyr", ["OID@", PolyIDfld, "Slope", "endelev", "SfcType", "NearID"])
for row in cursor:
#sql to select individual polygon
sql = '"{0}" = {1}'.format (polyOIDfld, str(row[0]))
    #select individual polygon
SelectLayerByAttribute_management ("Polylyr", "", sql)

#select intersecting points
SelectLayerByLocation_management ("Pointlyr", "", "Polylyr")

#Check to make sure points are selected, ie at least one point actually intersects polygon
if Describe ("pointlyr").FIDSet:
    FeatureClassToFeatureClass_conversion ("Pointlyr", outPath, str(row[1]))
    print "Created Shapefile Named: " + str(row[1])
    Fc = outPath + "/"+ str(row[1]) + ".shp"
    arcpy.CalculateField_management (Fc, "Slope", str(row[2]))
    print "Added SLope to " + Fc
    Fc = outPath+ "/" + str(row[1]) + ".shp"
    arcpy.CalculateField_management (Fc, "endelev", str(row[3]))
    print "Added Rwy End Elev to " + Fc
    Fc = outPath+ "/" + str(row[1]) + ".shp"
    arcpy.CalculateField_management (Fc, "SfcType", str(row[4]))
    print "Added Sfc Type to " + Fc
    Fc = outPath+ "/" + str(row[1]) + ".shp"
    arcpy.CalculateField_management (Fc, "NearID", str(row[5]))
    print "Added NearID to " + Fc
    #Create empty feature class if no points intersect
else:
    print "No points were under the " + str(row[1]) + " surface"

Viewing all articles
Browse latest Browse all 767

Latest Images

Trending Articles



Latest Images