2013-12-22 2 views
0

ArcPy에서 "A"에서 "B"로 복사와 같은 간단한 필드 계산을 수행하는 방법을 알려주십시오. 나는 그들이 여분의 표현을 사용하고 그들이 복잡했던 많은 예제를 웹에서 발견했다.ArcPy에서 간단한 필드 계산

B = !A! 

업데이트 : 내가 필요로하는 ArcMap의 구이 같은 것입니다 내가 지금까지하지만

NameError: name 'A' is not defined

point_shp = "G:\\Temp\\All_Provinces.shp" 
arcpy.AddField_management(point_shp, "B", "TEXT", "", "", "25", "", "NON_NULLABLE", "NON_REQUIRED", "") 
arcpy.CalculateField_management(point_shp, "B", "A", "PYTHON_9.3") 
+0

더 복잡한 예제 중 하나를 게시 할 수 있습니까? –

답변

0

으로 이것을 실행에 오류가 발생하고있는 코드 여기에 좋아 내가 그것을 가지고 와우이 포럼은 굉장

arcpy.CalculateField_management(point_shp, "B","!A!", "PYTHON_9.3") 

"!A!"처럼 A를 포장해야합니다! 너무 많은 도움이됩니다!

1

선택적으로, 당신은 당신이 할 수있는 VB를 사용하여 계산하는 계산 필드 도구를 원한다면 :

대신 Visual Basic에서 요구하는 응용 프로그램이 단지 경우입니다
arcpy.CalculateField_management(point_shp, "B","[A]") 

.

0

당신이 단순성의 필요성을 충족시키는 지 여부는 모르겠지만 나는 업데이트 커서를 사용하여이를 공격 할 것입니다.

point_shp = "G:\\Temp\\All_Provinces.shp" 
updateCursor = arcpy.UpdateCursor(point_shp) 
for row in updateCursor: 
    a = row.getValue("name of the "a" field name") 
    b = a # --> any manipulations to b can also go here.. example b = a + c etc... 
      # --> alternatively if you need to do string manipulations you can always make use of specifiers. such that a = "!%s!" %(a) note:use %d if "a" is a number. This would produce a string "!a!" if you needed it in that format. 
    row.setValue("name of "b" field", b) 
    updateCursor.update(row) 

위의 값을 사용하면 필드 "A"의 값을 가져올 수 있으며 필요에 따라 값을 입력하고 b로 저장할 수 있습니다. 그런 다음 필드 "B"를 b로 채 웁니다.

참고 : 필드 B가 아직 생성되지 않은 경우 ...