Tag Info

New answers tagged

1

If you're trying to just add up the values on the fly, using a cursor may be a good option. If you're going to need more statistics than just a sum or if you're going to want to save or re-use the value, you may want to look at using the Summary Statistics Tool: http://resources.arcgis.com/en/help/main/10.1/index.html#//00080000001z000000 There should be ...


1

You're nearly there, you just need to accumulate. Start by initializing a variable (total) to 0 and then for each row add the value to the total like this: Total = 0 field = "Tot_Aff" cursor = arcpy.SearchCursor(fc) for row in cursor: Total += row.getValue(field) print("Total is : %d" % Total) Null values will mess with this, to keep it simple I ...


0

you need to provide an output feature class (e.g. "C:/outputfolder/newfc.shp" or "C:/outputfolder/geodatabase.gdb/newfc", if geodatabase.gdb already exists) and not an output folder (C:/outputfolder) for the merge tool. Also check that your shapefile have a defined CRS, but the error probably comes from the above output.


2

Make your table look like you want it to in your layout; change field aliases, hide fields you don't want etc. When you're done, use the "Add table to layout" button:


0

I think this may be a Question best posed to Esri's software developers via your local Esri support because it sounds like you are saying that you think they made a mistake when finalizing their 10.2.1 release. If they did, then I suspect they will be keen to address it, but if they stand by their code, then they may be able to help you with the Python ...


0

This should work for both shapefile and separate dbf file import os import arcpy import csv def dbf2csv(dbfpath, csvpath): ''' To convert .dbf file or any shapefile/featureclass to csv file Inputs: dbfpath: full path to .dbf file [input] or featureclass csvpath: full path to .csv file [output] ''' #import csv rows = ...


4

An .esriaddin file is just a ZIP-compressed archive containing the files that make up your add-in. You can open it with something like 7-Zip to prove this to yourself. The Essential Python Add-in concepts article hints at this. The layout of your-addin, including definitions of toolbars, menus and buttons, is all stored within the config.xml, whose syntax ...


0

The symptoms that you describe seem to be the same as those discussed in the Esri Knowledge Base Article 38563 entitled Error: AttributeError: 'module' has no attribute when calling Spatial ETL tool which recommends that you: Copy and paste the following code into the Python script after importing the arcpy module and before using the Spatial ETL tool ...


0

Thanks for all the help but I think I fixed the problem. The computer had two versions of python 27 installed and seems that that is the reason behind python crashing when using the CalcFiled method. I removed the version Arcgis does not use and it is not crashing anymore so its working normal now. Thanks for the help


6

Try something like this: import arcpy from arcpy import env env.workspace = "E:\Example.gdb" # here you are creating a list of all features from your workspace lst = arcpy.ListFeatureClasses("", "Polyline") # and here you are looping for featureClass in list: arcpy.CreateRandomPoints_Management(


2

I would simply set my workspace (arcpy.env.workspace = "NAME OF GDB HERE") and then list the Line feature classes into a python list (fcs = arcpy.ListFeatureClasses("","Polyline")). Then you can loop through them. So same as other answer provided but with 1 minor difference - incorporating the Polyline option: import arcpy arcpy.env.workspace = ...


2

what you need to use is MakeXYEventLayer_management to create a point layer CopyFeature_managment to convert your layer to a feature class (some analysis are not possible if you don't have an object identifier) SpatialJoin_analysis to get the value of the closest line feature class to your point What you should know is that the GUI uses LAYERS to ...


0

In the ArcGIS 10.2 Online Help there is a Debugging Python add-ins page which says: Anytime a tool or button fails to load and displays Missing on the toolbar instead of the expected icon or name, it is commonly due to a Python syntax error. Recheck your Python script for syntax errors or incorrect inputs to Python functions.


5

Alex Tereshenkov's comment does bring up a good point; you probably should look into using a validation script for this specific case. But to answer your question, you should be passing the path (or name) of the feature class, along with an optional wild card and field type to arcpy.ListFields; see the ESRI docs for ListField. That method actually returns ...


0

As @Erica said, there is an indentation error in your code block. I'm surprised it isn't throwing a Syntax Error when you try to run calculate field. In any case, codeblock = """import math def GetAzimuthPolyline(shape): radian = math.atan((shape.lastpoint.x - shape.firstpoint.x)/(shape.lastpoint.y - shape.firstpoint.y)) degrees = radian * 180 / ...


1

buff_name = "name_to_test_first" # or =raw_input("Please enter a new data set name") while arcpy.Exists(buff_name + "*"): # I use a wild card because the new FC include the buffer size, so this is the name you don't want to exist buff_name=raw_input("Please enter a new data set name") #don"t forget to indent #else: this else has nothing to do ...


2

This is more a Python logic problem than a GIS problem, I'd recommend asking questions like these on Stack Overflow. Try this: import arcpy arcpy.env.overwriteOutput = 1 arcpy.env.workspace = "C:\\salzburg.gdb" sbgRivers = "sbg_rivers" buff_name = raw_input("Please insert a file name:") while arcpy.Exists(buff_name): for buffer_size in ...


1

Through blind luck, I seemed to have solved it by removing the SHAPE. out of the expression. No idea if this is the best way to do this, but it works, so I'm going with it!


0

Maybe you should start with a "repair geometry" and check your coordinate system to make sure that your shapefile is not the source of your problem. If calculateField still doesn't work, but the rest of your Python script runs properly, probably the best solution would be to use an arcpy.da.updateCursor() and compute the area for each row. Possible ...


1

The documentation only makes mention of being able to use shape.area on Python expressions. You will need to use a Python expression to do this. I would very strongly recommend reinstalling ArcGIS. Python not working is indicative of a corrupt installation of ArcGIS, and working around it will not alleviate the problem in other areas.


5

If 10.1+, you can use arcpy.da.Walk and not touch the global arcpy environments: from os.path import join import arcpy def find_all_fcs(workspace): """ return list of all fcs """ fcs = [] for dirpath, dirnames, filenames in arcpy.da.Walk( workspace, topdown=True, followlinks=False, ...


2

If it were me I would pass into your function the Featureclass and create and destroy the search cursor within the function. I would not pass a cursor as a parameter into it. If you use the new da module you can use the with statement to ensure that it is released releasing memory rather than have some object floating around in memory locking the data ...


3

I have only tested this very briefly (and with a limited variety of data), but this script demonstrates one way this might be accomplished: import arcpy import csv import os import codecs import cStringIO def batch_convert_dbf_to_csv(input_dir, output_dir, rename_func=None): """Converts shapefiles and standalone DBF tables within the input directory ...


3

If you look for a full arcpy solution (without dbf) you can use import glob glob.glob('S:\\output_tables\\*.dbf') for listing you tables, then arcpy.ListFields() for the field names and outname = os.path.basename(inputtable)[3:-4] + ".csv" to create your output names and finally arcpy.da.SearchCursor() to get a Python iterable that you can ...


3

you cannot use equal with more than one value use either in or OR to do this "\"STATION_ID\" IN ('CAP', 'DDM')" "\"STATION_ID\" = 'CAP' OR \"STATION_ID\" = 'DDM'" note that I recommand using """ to clarify your strings """ "STATION_ID" IN ('CAP', 'DDM') """


2

Just been looking at this thread and followed the link to the other thread which showed Numpy being used. I've personally never used this approach before so I started reading the help file about it and I think this can all be done in 5 lines! The dataset I tested this on was a polyline layer representing the rivers of the Amazon. So my code is as: InFc = ...


3

I think you're getting the error because the fieldnames list still contains the field LABEL, but you said you're not adding it to the output_fc. for field in fields: fieldnames.append(field.name) Right here you're getting all the field names. If you do a print statement above this line: cursor = arcpy.da.InsertCursor(output_fc, fieldnames) I ...


0

Few tips from ESRI support: http://support.esri.com/es/knowledgebase/techarticles/detail/35151 Try "Change the data frame coordinate system to match the data being exported." first.


2

You need to use tool validation for this. For custom Python script tool (that has two input parameters - string with filter value list and string with filter value list for feature layers in the currently open map document). import arcpy class ToolValidator(object): """Class for validating a tool's parameter values and controlling the behavior of the ...


1

when it come to creating a new dataset (like with createTIN), you need to store it somewhere on the disk. Layer and maps are used to display the data. So if you wan your TIN to be visible on the map, you can use a layer as input (it points to some data), create an output in a scratchworkspace, then add your new dataset as a layer using arcpy.mapping


3

Below is a ToolValidator class (in its entirety so it will make sense) where I needed not only for input datasets to have a spatial reference defined, BUT the datum could only be either WGS84 or NAD83. If validation failed, they got little messages informing them of the issues. class ToolValidator: """Class for validating a tool's parameter values and ...


1

Code looks OK to me so I guess its down to formatting of the string especially with "\" or "/" or "\\" . This line: lyr1 = arcpy.mapping.Layer("C:\ArcGis\Aerial_Imagery.lyr") should really be: lyr1 = arcpy.mapping.Layer(r"C:\ArcGis\Aerial_Imagery.lyr") or it could be: lyr1 = arcpy.mapping.Layer("C:\\ArcGis\\Aerial_Imagery.lyr") So the full path ...


2

I actually had this exact same issue. I had a script that would search through sub folders in a root directory, check if they had shapefiles, convert the shapefiles to feature layers then to kmls. It would run through about 20-40 conversions and then just stop, no error codes, just the script would end. It would end at different places each time. My ...


4

I would approach this issue in this way. One can create a feature layer consisting of just one point feature and check whether it intersects the polygon feature layer (using arcpy.da.SearchCursor). However, this would be a bit inefficient since you are dealing with so many features. However, we could create a feature layer and check whether it intersects ...


1

At the Esri Discussion Forums I found a 2011 response from @JasonScheirer which says: Arcpy is built on arcgisscripting, which is in turn a CPython extension. You will not be able to use arcpy in IronPython.


3

When you bring in a csv, Arc does its best to determine the appropriate field types and as you have found it doesn't always get it right. One solution is to use a schema.ini file (see bottom of page) to explicitly set the field types for your columns. There are several related (duplicate?) questions here on the GIS SE if you search for 'schema.ini'. More ...


-3

I have arcgis 10 and I think you can not import CSV files into the geodatabase, much less save as .DBF. First, try to add to ArcMap, then export to geodatabase.


3

A successful workaround was to create a new file geodatabase, and write the mosaic image to this - the gap is now gone, with no other changes to the code. This may be a bug, or perhaps there's a problem with using PNG files as the output?


0

Similar, but different to above: import arcpy fc = "YOUR FC" fields = [f.name for f in arcpy.ListFields(fc) if f.Type == "String"] cur = arcpy.UpdateCursor(fc) for row in cur: for field in fields: try: row.setValue(field) = row.getValue(field).upper() except: pass row.updateCursor(row)


1

Here's a quick example: fc = "whatever" fields = ("Name", "Addy", "Stuff") with arcpy.da.UpdateCursor(fc, fields) as cursor: for row in cursor: row[0] = row[0].upper() row[1] = row[1].upper() row[2] = row[2].upper() cursor.updateRow(row) And here's the ArcGIS manual for the da.UpdateCursor


6

The following example shows how to integrate the built-in python method .upper() with the arcpy update cursor. This example first tests if a field is of type String then checks each row within that string for lowercase values. If there are lower case values, the row is updated with all upper case. import arcpy fc = r'C:\temp\test.gdb\yourFC' desc = ...


1

Here is how you can use .upper() in python: data = "lower case data" upper_case_data = data.upper() print upper_case_data it can also be used directly with a string print "lower case data".upper()


1

You could go two ways. 1) You could use Table To Domain (Data Management) GP tool after you have found out the domain name to export the domain values and descriptions into a geodatabase table and then run Join on the feature class and table and then calculate the field. To find out the domain name for a field in a feature class you need the code: ...


1

arcpy.RefreshActiveView and arcpy.RefreshTOC are only used with the "current" map of ArcMap. Creating a MapDocument object by specifying a full path to an MXD does not cause it to be loaded into ArcMap, it just makes its properties and methods available to ArcPy.


4

Since you asked for a 1-liner: firstRow = next(([row.getValue(field) for field in (f.name for f in arcpy.ListFields(ds))] for row in arcpy.SearchCursor(ds)), None) This uses a generator expression and the next() built-in function to short-circuit the evaluation of the generator such that only the first row is fetched. The None argument avoids a ...


6

Give this a try: import arcpy ds = "NAME OF DATASET" fields = [f.name for f in arcpy.ListFields(ds)] cur = arcpy.SearchCursor(ds) outlist = [] for row in cur: for field in fields: outlist.append(row.getValue(field)) break


0

If your script knowledge is limited have you considered doing this in model builder? The model below will identify the minimum cell value and extract all cells with this value to a new grid.


1

You can use Get Raster Properties (Data Management) to extract minimum elevation values. import arcpy inputRaster = r'C:\temp\dem.img' raster = arcpy.GetRasterProperties_management (inputRaster, "MINIMUM") To extract the information so that you can use it in a command such as Con or Reclassify use the following: elevMin = raster.getOutput(0) To put ...


0

I decided to scrap arcpy for the create folder portion of the script and use os.makedirs instead. That worked much easier for me. My new code is: import arcpy, os, datetime from arcpy import env # Set Workspace env.workspace = "C:/GIS_Work" inputFile = arcpy.GetParameterAsText(0) outputFile = arcpy.GetParameterAsText(1) # Create folder with today's date ...


-1

You may need to add the out_folder_path to out_name. os.path.join(out_folder_path, out_name)



Top 50 recent answers are included