Hot answers tagged

7

The reason it works inside your module is that you are passing each feature class (fc) into your function. If you look carefully you can see that the line: fcname = fc is redundant. Here you are essentially reassigning the feature class to the variable fcname and then not using it i.e. checkfields = FieldExists(fc, fieldname) # you are still passing fc ...


7

In your main script you have switched a couple of parameters around. In the first line of your for loop you have fc = fcname and it should read fcname = fc import arcpy from arcpy import env arcpy.env.workspace = "C:/EsriPress/Python/Data/Final/Scratch.gdb" import final_functions fclist = arcpy.ListFeatureClasses('Fire*') for fc in fclist: fcname = fc ...


5

You need to use the str.replace() to replace the characters in your field values. Also needed to put a for fc in fcs: to loop through your shapefiles, and remove the square brackets from around fieldList in your cursor (this is what is giving you the error 'field_names' must be string or non empty sequence of strings) And note the u in front of u"Ü" so ...


4

You can try to use a python script and use one of the two following modules. But think of it carefully as running a program out of a script can do many unpleasent things. import subprocess subprocess.call(['C:\\folder\\gams.exe']) import os os.system('"C:\\folder\\gams.exe"') Update as it is about a file of the type .gms: Check out the answers on this ...


4

You'll want to use a cursor to figure out the rows that have values that have already occurred four times. Then you can create an SQL and a feature layer or table view with the SQL applied. Finally you can delete rows from the feature layer or table view. Sample code: #Table/shapefile table = r"C:\Users\e1b8\Desktop\E1B8\Workspace\Workspace.gdb\abc123" ...


4

Looks like you're trying to add data to the insert cursor one column at a time. Cursors think about the world one row at time. I recommend the following code. A few other notes... Python code runs in order, so make sure you declare your outpath variable before you set your env.workspace to outpath. Also, this code is going to create a shapefile with the ...


3

You have some repeating processes that could probably be rearranged. It may help with speed. Clearing all the layers' selections could be done at the beginning of the loop instead of within each if/else statement Edit (this may slow down the process since the clear selection happens every iteration): if count == 1: with arcpy.da.SearchCursor(table, ...


2

It would be helpful if you gave more details about the contents of your CSV file (is there more than one line?) and about what error you are seeing. The main issue I see with your code is that you are making the variable fcs a list, and the arcpy tool you call is looking for a single input object. Passing a list might cause an error (I am not sure as you do ...


2

You can try something like this (see also @radouxju's comment): import arcpy pt = r"C:\AIS\Density_Grid_test.gdb\PivotTable" flist = arcpy.ListFields(pt, "*ShipTypeGroup*") for f in flist: arcpy.AddField_management(pt, f.name.replace("ShipTypeGroup","Ave_STG"),"DOUBLE") newflist = arcpy.ListFields(pt, "*Ave_STG*") for nf in newflist: ...


2

Why not just do the following instead of doing it under a nested loop: import arcpy pt = r"C:\AIS\Density_Grid_test.gdb\PivotTable" arcpy.AddField_management(pt, "Ave_STG", "DOUBLE") arcpy.CalculateField_management(pt, "Ave_STG", "!ShipTypeGroup! / 12", "PYTHON_9.3") or you could try doing it with an UpdateCursor import arcpy pt = ...


2

You've swapped usage of quotes in your Python snippet. Instead of passing in a quoted field name, you've supplied a string literal, ie "KOD5" <> 'KOD5_1'. You need to change the quoting so that the second field name is quoted with double quotes instead: # select areals without no change if change == "Exclude": where_clause = '"' + field_initial + ...


2

There is a Help page entitled Understanding script tool parameters that explains how to do this. You configure the Parameters on the tool dialog and then get them within your script using either arcpy.GetParameter() or arcpy.GetParameterAsText().


2

I would use Rename_management to make sure you get all the parts to the shape file: import os, sys, arcpy InWork = sys.argv[1] # this script designed to be used as a tool, replace with a path if you wish arcpy.env.workspace = InWork for thisFC in arcpy.ListFeatureClasses(): newName = thisFC.replace(" ","_") arcpy.Rename_management(thisFC,newName) ...


2

The line os.path.join is throwing the error. This can be fixed by changing that line to fullPath = os.path.join(workSpace, lyr.name) although personally I'd remove it and use the following: mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, '')[0] workSpace = r"J:\foo\bar\test.gdb" for lyr in ...


2

I think that this is possible as long as the gp service that you have dumps it as a json and then you can make the call to that output from your JS. See this thread for more info. RESTful Geoprocessing Service Request returns empty Result object without errors


2

That's because a geodatabase is an Esri object and not a filesystem object. You can't get a creation date of a feature class (even in ArcObjects) but you can get the date of the database that it resides in. The first thing you need to look at is lyr.isBroken, unreferenced layers are broken and trying to get the path from them will cause issues, then check ...


2

I see a couple things going on here. In your first code example you tried to set fc to a list of two feature classes. The listFields function expects a single feature class, not a list. If you wanted to do that, you'd have to iterate through your feature class list. The next big thing I see is that those funny characters that you're trying to get rid of are ...


2

This line desc = arcpy.Describe(fcs) should be desc = arcpy.Describe(fc) - you have fcs which is a list of all files from your CSV, and instead it should be fc for each file one at a time (since you're looping through fcs one at a time in the for fc in fcs: loop). import csv import arcpy from os import path csvpath = r"D:\QAQC\Chk_Rep_File_list.csv" with ...


1

First, use a da cursor to make your code 10 times faster. Replace the list with a dictionary where the keys are the streetnames and the value is the sum of all lengths. Then you can write it all back in a single pass of an update cursor. At the same time you can get the OID list and do a single SelectLayerbyAttribute to Copy all the features at once to ...


1

Your layer needs to refer to the layer in your MXD, not the path to the feature class. layer = "Layer In MXD" desc = arcpy.Describe(layer) selected = desc.FIDSet print (selected) desc.Fidset will return the ObjectIDs of the selected features mxd = arcpy.mapping.MapDocument("CURRENT") dataFrame = arcpy.mapping.ListDataFrames(mxd)[0] layers = ...


1

One way to do this would be to add an attribute to your polygon layer, say "VALUE", and assign it numeric value of 1000 or more. Then convert the polygon layer to a raster. In arcpy using the spatial analyst module these rasters can be multiplied easily. elevRast = arcpy.Raster("path/elevrast") polyRast = arcpy.Raster("path/polygonraster") resultRast = ...


1

Based on your description are you looking for Get Count? Returns the total number of rows for a table. If the input is a layer or table view containing a selected set of records, only the selected records will be counted.


1

You should be able to just paste the code below into your ArcMap Python console window for it to work, unless you are using a geodatabase in which case you'll need to change the "uniqueIdFieldName" to match your input table's unique id field (like OBJECTID). Like @dslamb said, you will need a field name for a "unique id" in your table. If one "group" has ...


1

You'll need a unique id for each row to distinguish between GEBID's and their area. You could use FID, but this is subject to change when a featureclass is edited (assuming this is a featureclass and not a table of some sort). Assuming you have this unique row ID. You could do something like this. import arcpy gebids = {} #using searchcursor from the da ...


1

If lyr.longName is what you want to use to name your Feature Dataset, then you can just create an empty list fdList = [] and append it with the lyr.longName to pass as FD name later. import arcpy, os mxd = arcpy.mapping.MapDocument("CURRENT") fdList = [] for lyr in arcpy.mapping.ListLayers(mxd): if lyr.isGroupLayer == True: if ...


1

Look at creating a set of valid animal/year values . feed that into the loop. Using arcpy, run frequency analysis on the data, using the two fields as the frequency fields. The resulting rows will be the valid combinations. With a cursor on the table, read the animal/year into your query. Frequency the data Open search cursor on frequency table For row in ...


1

A couple things might be happening here. You have a transparency on the layer (unlikely). You have a stretch type defined in the symbology for the raster. This might be standard deviation: Set it to None and see if that makes any difference.


1

Based off your code, it sounds like you're trying to disable a button rather than an entire toolbar. Instead of WTF_toolbar.enabled = False do fish_button.enabled = False to disable the button. Same goes for WTF_toolbar.enabled = True. More info here


1

The following would do it with your directories: import arcpy InWork = ["D:\\GIS_Temp\Folder A", "D:\\GIS_Temp\\Folder"] for ws in InWork: arcpy.env.workspace = ws datasets = arcpy.ListFeatureClasses() for fc in datasets: newName = fc.replace(' ','_') arcpy.Rename_management(fc, newName[:-4]) Note the [:-4], which I do to ...


1

The output parameter, when I've used it, seems to really only work to add the output as a layer to the map document the tool has been called in. I noticed something that may be giving you errors in your code: if parameters[0].altered: parameters[1].value = arcpy.ValidateFieldName(parameters[1].value, parameters[0].value) parameter[1] is equivalent ...



Only top voted, non community-wiki answers of a minimum length are eligible