I'm attempting to update a script that I used in ArcMap for ArcGIS Pro. Getting an AttributeError: 'list' object has no attribute 'ListLayers' Any ideas? I based this on the code snippet here:  import arcpy  aprx = arcpy.mp.ArcGISProject('CURRENT')  lyr = aprx.listMaps('GeologicHazardMap').listLayers('qfaults')[0] cp = lyr.connectionProperties cp['connection_info']['database'] = 'N:\\ReferenceMaterials\\ArcGIS Python\\Current Catalog\\Test Data' cp['dataset'] = 'FaultsReprojected.shp' lyr.updateConnectionProperties(lyr.connectionProperties, cp)
121623
A common ArcPy coding pattern that I used with ArcGIS Pro 1.4 (and earlier) no longer works at ArcGIS Pro 2.0.  I have an ArcGIS Pro project with one map called Map, and that map has one layer called Test Layer.  Test Layer has as its data source a file geodatabase feature class called testFC.  I have used the Select tool to create a new feature class called testFC2 which is a subset of testFC (so it has an identical schema).  In ArcPy at ArcGIS Pro 1.4 I had no trouble switching the data source of Test Layer from testFC to testFC2 in the same file geodatabase using this code:  import arcpy aprx = arcpy.mp.ArcGISProject(r"C:\temp\test.aprx") mapx = aprx.listMaps("Map")[0] lyr = mapx.listLayers("Test Layer")[0] lyr.dataSource = r"C:\temp\test.gdb\testFC2"   However, the same code at ArcGIS Pro 2.0 gives:     AttributeError: can't set attribute   I checked the  and that now says that the dataSource property is now Read Only whereas previously it was Read and Write.  The same help page says:     Changing a layer's data source is a common requirement. There is a   method and a property on the Layer object that help with this. For a   more detailed discussion, parameter information, scenarios, and code   samples, please refer to the    help topic.   I can find no suitable code sample to use in place of my coding pattern at  which seems to be focussed on switching workspaces of data sources.  How do we switch the data source of a layer to a new feature class using ArcPy with ArcGIS Pro 2.0?  The same issue seems to have been noted at  where Marco Boeringa says:     The "dataSource" property of the Layer class also seems to have become   Read Only. However, you can use the "updateConnectionProperties" on   the same class to solve this   However, I think his situation must have been slightly different because I cannot see how updateConnectionProperties can be used to answer my question above.
27436
I would like to find a Python script that will access an attribute table within a shapefile and either update or replace records inside a field column. More specifically, I would like to use the replace expression to convert a table record like "123-456-789" to "123456789". I have many records to process and would like the best approach to do this task using Python.
37610
I'm trying to iterate through a feature class and select each feature one by one by using the OBJECTID field. When I use a single value, the SelectLayerByAttribute works, but how do I compare the OBJEECTID to a variable that increases in count through the loop. The program is then suppose to create a layer for each feature in the feature class. This is what I have so far:  import arcpy import os arcpy.env.workspace = "C:\Users\Daimon Nurse\Desktop\DFMPROJECT\DFMPROJECT.gdb" arcpy.env.overwriteOutput=True inlayer = "C:\Users\Daimon Nurse\Desktop\DFMPROJECT\DFMPROJECT.gdb\ZonesPolyline"   with arcpy.da.SearchCursor(inlayer, ("OID@", "SHAPE@AREA")) as cursor:     i = 1     for row in cursor:         print("Feature {0} has an area of {1}".format(row[0], row[1]))         outlayer = "ZonePolygon"         arcpy.MakeFeatureLayer_management (inlayer, outlayer)         arcpy.SelectLayerByAttribute_management (outlayer, "NEW_SELECTION", """           "OBJECTID" = 1 """)         output = r'C:\Users\Daimon Nurse\Desktop\Grounds Project\DFMGROUNDS.gdb'         outfile = os.path.join (output, i)         arcpy.CopyFeatures_management(outlayer, outfile)         print i         i = i + 1
17673
Does anyone now how to add a group layer with Python in ArcGIS Desktop 10?  I can use arcpy.mapping.AddLayer but surely this is only for an actual layer as opposed to a group layer.  so far I have this  import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.listdataframes(mxd, "layers")[0] arcpy.mapping.AddLayer
45045
I am a beginner to python coding in GIS. I want to calculate the total number of counts in raster attribute table. In order to do that:   I would like to build a attribute table of raster data use a loop through attribute table using ARCPY.SearchCursor()   Therefore, I wrote a code to build an attribute table. However, I am getting an error while running the code and not able to figure out the error in the code.  Code:  import arcpy # Create the geoprocessing object  import arcgisscripting gp = arcgisscripting.create()  #To overwrite output arcpy.env.overwriteOutput = True  #Set environment settings gp.workspace = "C:/Subhasis/Test/raster-read"  #Build Raster Attribute Table gp.BuildRasterAttributeTable_management("sti-9", "Overwrite")  Error Message: Traceback (most recent call last):   File "C:/Subhasis/Test/raster-read/test.py", line 15, in &lt;module&gt;     gp.BuildRasterAttributeTable_management("sti-9", "Overwrite") ExecuteError: ERROR 000049: Failed to build attribute table Failed to execute (BuildRasterAttributeTable).
21641
How would I setup  to recognize import arcpy?   I'd like to use PyCharm to develop and debug geoprocessing tool.
100109
&gt;&gt;&gt; import arcpy Traceback (most recent call last):   File "&lt;interactive input&gt;", line 1, in &lt;module&gt;   File "C:\Python27\lib\arcpy\__init__.py", line 21, in &lt;module&gt;     from arcpy.geoprocessing import gp   File "C:\Python27\lib\arcpy\geoprocessing\__init__.py", line 14, in &lt;module&gt;     from _base import *   File "C:\Python27\lib\arcpy\geoprocessing\_base.py", line 14, in &lt;module&gt;     import arcgisscripting ImportError: DLL load failed: The specified module could not be found.   This is the error I get when i try to import arcpy. Any suggestions?
57758
Being new with python so far, I got inspired by this answer:   to dive into it a bit.  When creating features in a new target layer from an existing source layer, all "solutions" I found so far to create that new layer, were to either   prepare the new target layer manually in QGIS beforehand, adding all fields (with field types, lengths etc). Hard-code the field settings into the python script when creating that new target layer.    It seems a bit odd to me that there should be no programmatic way to clone the attribute scheme of a layer, and create a new (memory) layer with this scheme, so you wont have to change your script for each new layer, or fumble things together manually.  I'm focused on the creation of memory-layers, cause I want to have the opportunity to decide by myself if the outcome is satisfactory and save it manually when it fits my needs.
93697
Is there a way to source a shapefile to a layer file in QGIS much like how you do this in the properties of an ArcGIS layer? (i.e. Go to layer properties, source tab and then just depress the 'Set Dat Source' button)  I've been all over the layer properties in QGIS and I don't see this anywhere...  EDIT: I've received comments explaining that you cannot do this with shapefiles, but if I were to change the name of a shapefile and then open a pre-existing project file which contains this shapefile as a layer, I will get the 'Handle Bad Layers' dialogue, which allows me to navigate and re-source the layer to any shapefile I want to. I find it odd that you can resource in that scenario, but you cannot do it manually through the layer properties dialogue box.
103137
I am new to both ArcGIS and Python. My requirement is to automate the below MANUAL process:   Creating a layer in ArcGIS for Desktop. To put it in another words, creating an ArcMap document (.mxd). Publishing the created ArcMap document (in Step 1) as a service to ArcGIS Server.   Currently we are doing this manually. I have come across scripts to automate step 2 using Python.  How can I automate step 1 and step 2?
104595
Can anybody help me write a script that excludes certain collections (for rendering)?  In the outliner the tooltip says: Layer.Collection.exclude and bpy.data.scenes["Scene"].exclude, so I've tried things like:  bpy.ops.outliner.LayerCollection('Structure').exclude bpy.data.scenes["Scene"].LayerCollection('Structure').exclude   The online Python link is here:  but I don't know what to do with that information.
19651
I am having trouble running a script tool that I just created in Arc 10.1.  The script runs fine in PythonWin, but when I create a script tool with it, the tool seems to not want to accept folders or geodatabases as its output workspace.  I have the output parameter (argument) set as both an output and a workspace in the script tool, but it still keeps giving me an error that the "Dataset.....already exists"    I'm a new user, so I can't post a picture, but the error is 000725  Here is my script, if that helps out.  import arcpy #allow for overwrites arcpy.env.overwriteOutput = True  #set the workspace inWorkspace = arcpy.GetParameterAsText (0)  #set the erase feature eraseFeature = arcpy.GetParameterAsText (1)  #set the output workspace outWorkspace = arcpy.GetParameterAsText (2)   #get a list of all the features in the workspace arcpy.env.workspace = inWorkspace featureClassList = arcpy.ListFeatureClasses()  try:      #loop through all of the features in the workspace     for featureClass in featureClassList:          #construct the output path         outEraseFeature = outWorkspace + "\\erase_" + featureClass          #perform erase         arcpy.Erase_analysis(featureClass, eraseFeature, outEraseFeature)          arcpy.AddMessage("Wrote clipped file " + outEraseFeature + ". ")         print "Wrote clipped file " + outEraseFeature + ". "  except:      # Report if there was an error     arcpy.AddError("Could not erase feature classes")     print "Could not erase feature classes"     print arcpy.GetMessages()
63011
I have a few shapefiles where some of the attributes contain the non-English characters ÅÄÖ. Since some queries doesn't work with these characters (specifically ), I tried to change them in advance with a simple script and add the new strings to another field.  However, change in characters works fine but not updating the field with arcpy.UpdateCursor.   What is an appropriate way of solving this?  I have also tried to do this via the Field Calculator while posting "code" to the codeblock, with the same error.  Error message: Runtime error  Traceback (most recent call last):   File "", line 1, in    File "c:/gis/python/teststring.py", line 28, in      val = code(str(prow.Typkod)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in position 3: ordinal not in range(128)  Code:  # -*- coding: cp1252 -*- def code(infield):     data = ''     for i in infield: ##        print i         if i == 'Ä':             data = data + 'AE'         elif i == 'ä':             data = data + 'ae'         elif i == 'Å':             data = data + 'AA'         elif i == 'å':             data = data + 'aa'         elif i == 'Ö':             data = data + 'OE'         elif i == 'ö':             data = data + 'oe'         else:             data = data + i     return data   shp = r'O:\XXX\250000\DB\ArcView\shape.shp'  prows = arcpy.UpdateCursor(shp)  for prow in prows:     val = code(unicode(str(prow.Typkod), "utf-8"))     prow.Typkod_U = val     print val     prows.updateRow(prow)   The values of Typkod are of the type: [D, D, S, DDRÄ, TRÄ] etc.  I use ArcMap Basic (10.1) on Windows 7.    New Error message:  Runtime error  Traceback (most recent call last):   File "", line 1, in    File "c:/gis/python/teststring.py", line 29, in      val = code(unicode(str(row.Typkod), "utf-8")) UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in position 3: ordinal not in range(128)  &gt;&gt;&gt; val 'DDRÄ' &gt;&gt;&gt; type(val) type 'str'      It appears as if the output from the function is wrong somehow. When there's ÅÄÖ involved it returns data = u'DDR\xc4' and not (as was my intention) data = 'DDRAE'. Any suggestions on what might cause this?
74127
Using ESRI Tutorial Data for Utility Network Tracing (Montgomery.gdb) which is a File Geodatabase and following Arcpy script  I am not getting any erro on running the script to find the path between two points in Flag (point) layer  # Import arcpy module import arcpy # Local variables: gnVersionFDS_Net = "E:/Montgomery.gdb/Water/Water_Net" Flags = "E:/Montgomery.gdb/Water/Flags" gnVersionFDS_1 = "gnVersionFDS_1_Net" # Process: Trace Geometric Network arcpy.TraceGeometricNetwork_management(gnVersionFDS_Net, gnVersionFDS_1, Flags, "FIND_PATH", "", "", "", "", "", "NO_TRACE_ENDS", "", "", "", "AS_IS", "", "", "", "AS_IS") print "The Proccess Done"   I added the Flag layer manually to the Dataset and it has two points as     again, I am not getting any error but I am not seeing any layer and path to be generated or added to somewhere. Can you please let me know what I am doing wrong or how can I make this rum properly?     Update   I try to copy the output as a shapefile using this ArcPy  arcpy.Copy_management(gnVersionFDS_1, "C:/data/path.shp")   but I am getting  this error now
44950
I'm trying to use arcpy to save an .mxd and am having an issue.  It doesn't matter if I use mxd.save or mxd.saveACopy I get the same error.  I know it doesn't look like I am doing anything w/ it here, but it's just a portion of my code:  import arcpy import arcpy.mapping as map arcpy.env.overwriteOutput = True  env.workspace = r"C:\MGIS\FinalProject2.gdb     mxd = map.MapDocument(r"C:\MGIS\Finalproject2.mxd") df = map.ListDataFrames(mxd)[0]  for df in map.ListDataFrames(mxd): df.scale = 2000000  #Add layers into map document addLayer = map.Layer(OKXcounties) addLayer1 = map.Layer(contourLabelText) addLayer2 = map.Layer(contoursClipLyr) addLayer3 = map.Layer(clipOKXLyr) map.AddLayer(df, addLayer, "AUTO_ARRANGE") map.AddLayer(df, addLayer1, "AUTO_ARRANGE") map.AddLayer(df, addLayer2, "AUTO_ARRANGE") map.AddLayer(df, addLayer3, "AUTO_ARRANGE")  # Add contour Labels for lyr in map.ListLayers(mxd):     if lyr.name == "contourLabelText":         lyr.showLabels = True     if lyr.name == "Contour Features":         lyr.transparency = 100  mxd.saveACopy(mxd)   I get the following error:   Traceback (most recent call last):   File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript     exec codeObject in __main__.__dict__   File "C:\MGIS\geog485\FinalProject2\mxdtest.py", line 7, in &lt;module&gt;     mxd.saveACopy(mxd)   File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_     return fn(*args, **kw)   File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 668, in saveACopy     self._arc_object.saveACopy(file_name) AttributeError: MapDocObject: Unable to save.  Check to make sure you have write access to the specified file and that there is enough space on the storage device to hold your document.   Space is not the issue, I have 60 GB of free space and I've checked the windows properties of the .mxd file.  Read-only box is unchecked and I've "allowed" all permissions for all groups:    Does anyone have any idea how if this is a bug or how I can fix this?  I'm using ArcInfo 10.0 SP4.
117002
I can display a shapefile in openlayers but I need to add some attribute data.    I can open the dbf file in excel but there is no save as option in excel to the updated file as a dbf.    What is the best way (or software to use) to add attribute data to my shapefile?
54890
I'm trying to used the Python syntax in ArcGIS 10's field calculator and am thoroughly confused. So far the most basic calculations are failing me, and I don't understand why. I'm trying to create a function to just set the values of all cells in a column to be a multiple of the argument that I pass in ( I wanted to try something simple to test it out, as anything more complicated I tried also failed).   However, the error messages are telling me that my syntax is incorrect:    but I can't understand what is incorrect.     As an aside, I'm also horrified at how hard it is to write readable python in the field calculator box as there is no syntax highlighting, or clear indentation. It would be quicker, and easier to write an external Python script to do this calculation, but I want to try to figure out how this new function worked within the program.