POST
|
I'm trying to write in test field from some layer based on iterate feature selction. I get succes using model builder but I'm fail when I try with my own code. The process with MB. The code and error. Here is the code. import arcpy from arcpy import env env.workspace = r'D:\Eric\Ejercicio\shp\ejercicioTest.gdb\shp' crbuff = r'D:\Eric\Ejercicio\shp\ejercicioTest.gdb\shp\CRojaPBuff' insumo = r'D:\Eric\Ejercicio\shp\ejercicioTest.gdb\shp\Insumo' # Add field to insumo. arcpy.AddField_management(insumo, "test", "TEXT", "", "", "50", "", "NULLABLE", "NON_REQUIRED", "") # Make a layer from crbuff to get the select by location works. arcpy.MakeFeatureLayer_management (crbuff, 'crbuff_layer') arcpy.MakeFeatureLayer_management (insumo, 'insumo_layer') # loop with cursor cursor = arcpy.SearchCursor(crbuff) field = "Lab" # Specify the field in the loop. for row in cursor: print (row.getValue(field)) arcpy.SelectLayerByLocation_management('insumo_layer', "HAVE_THEIR_CENTER_IN", 'crbuff_layer', "", "NEW_SELECTION", "NOT_INVERT") # Process: Calculate Field. cursorIn = arcpy.UpdateCursor('insumo_layer') for row in cursorIn: row.setValue("test", row.getValue(field)) cursorIn.updateRow(row) # Process: Summary Statistics. intable = r'D:\Eric\Ejercicio\shp\Insumo.shp' outtable = r'D:\Eric\Ejercicio\shp' arcpy.Statistics_analysis(intable, outtable + "stats.dbf", "POB1 SUM;POB8 SUM;POB11 SUM;POB14 SUM;POB15 SUM;POB16 SUM;POB24 SUM;POB31 SUM;POB57 SUM;MIG7 SUM;INDI1 SUM;DISC1 SUM;DISC4 SUM;DISC5 SUM;DISC6 SUM;ECO1 SUM;ECO4 SUM;ECO25 SUM;ECO28 SUM;SALUD1 SUM;SALUD2 SUM;SALUD3 SUM;SALUD4 SUM;SALUD5 SUM;SALUD6 SUM", "test") Thanks.
... View more
03-10-2016
08:35 AM
|
0
|
1
|
2608
|
POST
|
I'm trying to write in test field from some layer based on iterate feature selction. I get succes using model builder but I'm fail when I try with my own code. The process with MB. The code and error. Any suggestions?
... View more
03-10-2016
08:12 AM
|
0
|
0
|
825
|
POST
|
Thanks Luke. That corrects the syntax problem. Now I get a new problem. Traceback (most recent call last): File "D:\Eric\Ejercicio\script\again.py", line 23, in <module> row.setValue("test", row.getValue(field)) File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\arcobjects\arcobjects.py", line 1096, in getValue return convertArcObjectToPythonObject(self._arc_object.GetValue(*gp_fixargs(args))) RuntimeError: ERROR 999999: Error executing function. I'm trying to write in "test" field from insumo layer the value field from the select by location features loop of crbuff layer.
... View more
03-10-2016
07:41 AM
|
0
|
0
|
825
|
POST
|
I 'm trying to run my script but I get this error message. Here is the code. import arcpy from arcpy import env env.workspace = r'D:\Eric\Ejercicio\shp\ejercicioTest.gdb\shp' crbuff = r'D:\Eric\Ejercicio\shp\ejercicioTest.gdb\shp\CRojaPBuff' insumo = r'D:\Eric\Ejercicio\shp\ejercicioTest.gdb\shp\Insumo' # Add field to insumo. arcpy.AddField_management(insumo, "test", "TEXT", "", "", "50", "", "NULLABLE", "NON_REQUIRED", "") # Make a layer from crbuff to get the select by location works. arcpy.MakeFeatureLayer_management (crbuff, 'crbuff_layer') arcpy.MakeFeatureLayer_management (insumo, 'insumo_layer') # loop with cursor cursor = arcpy.SearchCursor(crbuff) field = "Lab" # Specify the field in the loop. for row in cursor: print (row.getValue(field)) arcpy.SelectLayerByLocation_management('insumo_layer', "HAVE_THEIR_CENTER_IN", 'crbuff_layer', "", "NEW_SELECTION", "NOT_INVERT") # Process: Calculate Field. cursorIn = arcpy.UpdateCursor('insumo_layer') for row in cursorIn: row.setValue("test", (row.getValue(field)) cursorIn.updateRow(row) # Process: Summary Statistics. intable = r'D:\Eric\Ejercicio\shp\Insumo.shp' outtable = r'D:\Eric\Ejercicio\shp' arcpy.Statistics_analysis(intable, outtable + "stats.dbf", "POB1 SUM;POB8 SUM;POB11 SUM;POB14 SUM;POB15 SUM;POB16 SUM;POB24 SUM;POB31 SUM;POB57 SUM;MIG7 SUM;INDI1 SUM;DISC1 SUM;DISC4 SUM;DISC5 SUM;DISC6 SUM;ECO1 SUM;ECO4 SUM;ECO25 SUM;ECO28 SUM;SALUD1 SUM;SALUD2 SUM;SALUD3 SUM;SALUD4 SUM;SALUD5 SUM;SALUD6 SUM", "test") I need help ...
... View more
03-09-2016
06:19 PM
|
0
|
6
|
2726
|
POST
|
Thank you for responding. I modified the code and run ok.
... View more
03-03-2016
10:00 AM
|
0
|
0
|
4582
|
POST
|
Hi, I'm trying to join attributes from 12 tables to a single layer. This is the script. import arcpy from arcpy import env # Set overwrite option arcpy.env.overwriteOutput = True arcpy.env.qualifiedFieldNames = False # Set the current workspace. env.workspace = r'D:\INSUMOS\INEGI\21 Puebla.mdb' # Set local variables. inFeatures = r'D:\INSUMOS\INEGI\21 Puebla.mdb\JOIN\mNoJoin' layerName = 'mNoJoin_layer' joinField = 'CVEGEO' outFeature = r'D:\INSUMOS\INEGI\21 Puebla.mdb\JOIN\m_Join' # Create a feature layer from the vegtype featureclass. arcpy.MakeFeatureLayer_management (inFeatures, layerName) # Get a list of stand alone tables in the geodatabase and print out. tableList = arcpy.ListTables("*manzanas*") for table in tableList: # Join the feature layer to a tables. arcpy.AddJoin_management(layerName, joinField, tableList, joinField) # Copy the layer to a new permanent feature class arcpy.CopyFeatures_management(layerName, outFeature) print "Number of tables joined to inFeature: ", len(tableList) print "Done." I get this from Shell: Traceback (most recent call last): File "D:\Eric\python script\AddMultipleJoinToFeature.py", line 24, in <module> arcpy.AddJoin_management(layerName, joinField, tableList, joinField) File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 6110, in AddJoin raise e RuntimeError: Object: Error in executing tool I suppose this a newbie stuff, but I appreciate if you guys help me.
... View more
03-03-2016
07:30 AM
|
0
|
2
|
11018
|
POST
|
The script work ! thanks for your help. I notice that the script run fine in python window, however when I run it in pyscripter don´t work, I mean when I check the copy (D1Copy..mxd) the old picture remains. Any way thanks. Eric
... View more
06-23-2015
12:04 PM
|
0
|
1
|
532
|
POST
|
hi, I change the path, but nothing happen >>> #!/usr/bin/env python ... # -*- coding: utf-8 -*- ... import arcpy ... import os ... ... def main(): ... # path to folder where all mxd files reside ... path = r"D:\Test" ... ... # recursive loop through folder and sub folders ... for root, dirs, files in os.walk(path): ... for filename in files: ... if filename.endswith('.mxd'): ... # use only mxd files ... mxd_in = os.path.join(root, filename) ... ... def updateLayout(mxd_in): ... path, name_ext = os.path.split(mxd_in) ... name, ext = os.path.splitext(name_ext) ... mxd_out = os.path.join(path, "{0}Copy.{1}".format(name, ext)) ... ... mxd = arcpy.mapping.MapDocument(mxd_in) ... locfinal = arcpy.mapping.ListLayoutElements(mxd,"PICTURE_ELEMENT","Localización2") ... for object in locfinal: ... object.sourceImage = r"D:\Test\Picture\test_picture.jpg" ... object.name = "loc mun estatal" ... object.elementHeight = 9.4827 ... object.elementWidth = 11.99 ... object.elementPositionX = 77.0 ... object.elementPositionY = 94.0 ... mxd.saveACopy(mxd_out) ... del mxd ... ... if __name__ == '__main__': ... main() ...
... View more
06-23-2015
07:19 AM
|
0
|
3
|
532
|
POST
|
HI, I am trying to loop this script in 35 mxd's, in different folders, but I don't know how. Can someone help me? Eric import arcpy mxd = arcpy.mapping.MapDocument(r"D:\Test\D1.mxd") locfinal = arcpy.mapping.ListLayoutElements(mxd,"PICTURE_ELEMENT","Localización2") for object in locfinal: object.sourceImage = r"D:\Test\Picture\test_picture.jpg" object.name = "loc mun estatal" object.elementHeight = 9.4827 object.elementWidth = 11.99 object.elementPositionX = 77.0 object.elementPositionY = 94.0 mxd.saveACopy(r"D:\Test\D1copy.mxd")
... View more
06-22-2015
04:07 PM
|
0
|
5
|
3368
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:25 AM
|