Tag Info

New answers tagged

2

Yes, you can run multiprocessing child processes from a toolbox script. Below is some code to demonstrate in a Python Toolbox (*.pyt). There are a number of "gotchas". Some (but not all) will be applicable to Python script tools in a binary toolbox (*.tbx), but I only use Python Toolboxes these days so have not tested. Some "gotchas"/tips: Make sure ...


2

Your example code does not do what your post title asks. You are not attempting to update multiple columns (which are called fields) with a cursor. You are attempting to process through the cursor records (which are called features or rows) more than once with a single cursor. That is not allowed and is never really necessary, since there are better ...


1

It is hard to be certain what you are trying to do, and it should be fine to do all of this is a single pass of the update cursor. However, I think you may be wanting to change data on the second pass based on changes made in the first pass so I have structured the code below to do that. Perhaps give it a run and see how it goes. with ...


0

The problem was the ecw file. In ArcMap 10.3 python gets stuck with the ecw file. I converted the ecw to tif. file


0

You could try setting the output workspace with arcpy.env.workspace to be a folder not a file GDB. Make sure you specify a folder without spaces in the path as ArcGIS will use its default GRID format for temporary rasters which can't have spaces in the path.


3

Based on the comment by @KHibma I put together the code snippet below to demonstrate how to "use arcpy.GetMessageCount and arcpy.GetMessage and get [messages] 1 by 1 by index" import arcpy try: arcpy.CreateFolder_management(r"C:\temp1","test") except: pass for idx in range(0,arcpy.GetMessageCount()): print "Message {}: ...


4

that's nearly it, but the referencing of the field should be done on the field list, not the field name fieldList = arcpy.ListFields(r"C:\your.shp") for field in fieldList[19:]: print field.name


0

for transforming form Swiss-LV95 to WGS84 I currently use arcpy.PointGeometry(arcpy.Point(swissX,swissY),arcpy.SpatialReference(2056)).projectAs(arcpy.SpatialReference(4326)) with ArcGIS 10.1


2

First of all you have some errors in your code: inputlayer = fcs have to be changed inputlayer = fc At my mind the syntax is wrong here: os.path.join(*(fcs) + '.lyr') Here is a working example of your code, it takes mxd file and add every feature class from GDB to mxd file and saves it: import arcpy, os arcpy.env.workspace = r"C:\New File ...


0

also, the original error, I believe is indicating that setNull is not a method for arcpy.da.UpdateCursor, but it is a method for arcpy.UpdateCursor (no "da").


1

The code you posted should not give an indentation error. I recommend that you open a new Python script and copy/paste the code you posted and run that. I will be very surprised if you receive an indentation error by doing that. I suspect that you may have moved the start of the last line left or right in the process of writing your question. W.r.t. ...


2

Using field calculator (or, arcpy.management.CalculateField() if you want): In the code block: def fix_matrix(field_value): if field_value.endswith("A") or field_value.endswith("B"): return field_value[:-1]+"AB" else: return field_value In the expression: fix_matrix(!MATRIX!) + !PLANT! + !PCT! + !SITE!


0

After trial and error I had the geospatial PDF export working using: arcpy.mapping.ExportToPDF(mxd, Output_File, image_quality="BEST" georef_info=True) The image quality parameter is important to cut down processing time, and the georef_info does embed the spatial reference, but does not make it a GeoPDF, rather a geospatial PDF that works fine in Avenza ...


0

I fixed the problem by building the range myself as suggested. It just came to me! Here is the solution. you can add lower range to set the labels as suggested by T. Wayne or just use the range for a some notes i needed to create on the map. lower_range1 = "{:.1f}".format(lyr.symbology.classBreakValues[0]) + " - " + ...


0

Along with T.Wayne's answer, your SQL looks funky as well. You may want to try: "\"CLASS_NAME\" IN ('item1','item2','item3')" This SQL will select all features with either item1, item2, or item3 as its CLASS_NAME field value. or: '"CLASS_NAME" = \'item1,item2,item3\'' This SQL will select all features with item1,item2,item3 as its CLASS_NAME field ...


2

>>> outPoly = "C:\output\newpoly.shp" >>> print "'{0}'".format(outPoly) 'C:\output ewpoly.shp' >>> >>> outPoly = r"C:\output\newpoly.shp" >>> print "'{0}'".format(outPoly) 'C:\output\newpoly.shp' >>> This probably explains it best: https://docs.python.org/2.0/ref/strings.html


0

I think you're expecting too much from 'reclassify'; rather you should be doing a manual classification, or apply this sample code below (untested) to refresh based on specific 'breaks' which of course you define: # from GraduatedColorsSymbology example 2 in web help import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") df = ...


1

Get the list of columns for a table in Oracle using ALL_TAB_COLUMNS from this query using ArcSDESQLExecute... select column_name from all_tab_columns where table_name = 'TABLE_NAME'. The returned list may need to be processed to eliminate unwanted columns.


1

So ESRI has arcpy versions of some common operations from the os module, especially when it comes to listing directories. I have not used arcpy.ListWorkspaces() before, but it seems like it should work for you, and you could add arcpy.ListWorkspaces("*","FileGDB") because you are specifically looking for File Geodatabases. Generally it's good practice to ...


0

There are a wide means of referencing layers within a table of contents. Just check out the various layer properties available. For example, if you wish to find a layer by name, perform your ListLayers and then make use of an if lyr.name == "mylayer": statement in your for loop.


1

Inside a geodatabase you can only store GeoDatabase types, from Esri Help: A key geodatabase concept is the dataset. It is the primary mechanism used to organize and use geographic information in ArcGIS. The geodatabase contains three primary dataset types: Feature classes Raster datasets Tables So, in a GeoDatabase you can only store Tables, ...


3

I think that you will have to keep the polygons as separate features. Polygon multiparts are an evil construct that has no logical topology for analysis and even display in your case. What is wrong with a separate featureclass? If you want to aggregate the properties, then a Dissolve will do this. You could relate the multiple features to the single ...


1

CopyRows can't output to Excel, it can only output to dBASE, ArcSDE geodatabase, file geodatabase, personal geodatabase or INFO tables. You need to use the TableToExcel_conversion tool. Then you need to use os.path.dirname to get the gdb parent directory. Something like (untested...): import os, arcpy folder = arcpy.GetParameterAsText(0) for dirpath, ...


5

Here's the ListLayers documentation ListLayers(map_document_or_layer, {wildcard}, {data_frame}) You can use a wildcard if you know the name of the layer. mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] road_layer = arcpy.mapping.ListLayers(mxd, "Road", df)[0] river_layer = arcpy.mapping.ListLayers(mxd, "River", ...


1

Below your 'CopyRows' command, where you're outputting tables inside the gdb, you need to output essentially to a level 'up', as indicated in your diagram...do this with a simple os.path.dirname(dirpath). (Make sure you've imported the os module.) FYI, to be consistent you should use os.path.join similarly (instead of '+ os.sep +'): os.path.join(dirpath, ...


5

I use the following settings to "Start a program" in the task scheduler. I find it best to use the full path to the Python executable to be safe. Program/script: Full path to Python.exe, C:\Python27\ArcGIS10.2\python.exe Arguments: Name of script, script.py Start in: Location of script.py, something like C:\path\to\script Also, if you pass in arguments ...


2

I have always set up simple batch files like this: start C:\Python27\ArcGIS10.3\python.exe \\some_server\some_script.py You'll just want to make sure the full path to the executable and script match exactly. If the path has any spaces in in it, you'll need to wrap it in double quotes. (" ")


5

The problem is that your string inputFeature_json has special characters that are not in the ascii encoding. If you have characters that are not in the english alphabet they can cause encoding errors. Try to convert the string as unicode. for example: # Script arguments inputFeatures_json = arcpy.GetParameterAsText(0) #wtite to file jsonFileName = ...


0

Found the problem... The feature class had somehow become corrupted and converted itself into a table (even though it still confusingly displayed it's XY data on the map). Will fix the layer and it should work !


0

As indicated in the comments, you have a few issues. The first one I see is your enumerating through fcs. What do you expect to enter at the prompt? Your code will enumerate through each letter, which I expect is not what you want. For example, if you enter "fred, bob", the list will be: [f,r,e,d, , b,o,b]. Try: arcpy.env.workspace = r'c:\data' ...


2

You should save the output raster to a raster format, not to a geodatabase, e.g.: outReclass1.save(r"C:\output\reclass.tif") EDIT: And there is a missing bracket in the Reclassify line (RemapRange is enclosed but not Reclassify). I've updated my code as well. You can also simplify the remap parameter a little bit by using the missing_values parameter for ...


0

you might try referencing the layer myLayerRef = arcpy.mapping.Layer("path to your layer" or layer var) arcpy.SaveToLayerFile_management(myLayerRef, "D:\Data\Workspace\Test.lyr")


2

Iterating is a little tricky for the first time user who has done VB or C, there is no for i = 1 to n iteration in python (yet). To iterate from one number to another you have to make a range (list) of integers then step through it with for value in list: Use this as an example to adjust your code, I've written the whole thing to give you some context: ...


0

It looks like you're doing a little extra work, and it is telling that it works better when you force lowercase. Maybe some of the layer files end in ".Lyr" or something strange like that. Ultimately, you are doing two list processes, the first loop with filename and then the second listing with ListLayers. At any rate, I'd recommend simplifying to the ...


1

You will want to use clipping_geometry = True as in the following example. import arcpy shp = r'C:\temp\myshp.shp' raster = r'C:\temp\someRaster.tif' arcpy.Clip_management (raster, in_template_dataset = shp, out_raster = r'C:\temp\outRaster.tif', clipping_geometry = True)


3

I think that your first approach has the right idea, but needs to be reordered somewhat. You do not need to check the field name/type on each cursor loop, but only once before executing the cursor. You don't need to get all the fields with your UpdateCursor, just the two you are interested in (the field providing the data, and the field you're calculating ...


1

I encountered the same problem and I solved it by simply setting the "has_z" property to TRUE while creating the polygon geometry: arcpy.Polygon(my_array, my_spat_ref, TRUE). In the code below I update the z value of the vertices of my polygon fc taking the z values of a point fc. import arcpy arcpy.env.workspace = "my_path" point_fc="my_points_fc.shp" ...


1

Here is the working code updating one of two dictionaries based on common keys: Mesh_dict={} Point_dict={} Mesh = open (r'short3.txt','r+') for row in Mesh: # extract lines describing one type of geometry if row.startswith('ND'): Inline= row.split() IDM = Inline[1] ZM = Inline[4] # actualise the dictionary of original data ...


2

Why don't you have it written to a list? my_list = list() A = 'A' B = 'B' C = 'C' my_list.append(A) my_list.append(B) my_list.append(C) The result of str(my_list) will be ['A', 'B', 'C']. To turn it into the end result that you want, just run tuple on it: str(tuple(my_list))


0

Double check that the directories that python needs are in the PYTHONPATH environmental variable. The paths that I have are: C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy;C:\Program Files (x86)\ArcGIS\Desktop10.2\bin\


3

Instead of import sys.arcpy, try import arcpy


1

Here is an example of a SA script that I run from the command line: import os,sys,arcpy if (len(sys.argv) != 3): arcpy.AddError("Incorrect number of parameters") # this script has 3 parameters sys.exit(0) if arcpy.CheckExtension("Spatial") == "Available": arcpy.AddMessage("Checking out Spatial") arcpy.CheckOutExtension("Spatial") else: ...


6

You want to access each item in the set individually, and print it: for value in uniqueValues: arcpy.AddMessage(value)


0

While you may not be able to prevent the alias from changing, you should be able to change it back easily enough with a few more lines of code. Say fc is your variable for the new feature class. Change the AREA field alias this way: for field in arcpy.ListFields (fc): if field.name == "AREA": field.alias = "AREA"


1

In your question it appears that you want to assign the values of each cell of V based on the value of rainfall at that cell. arcpy doesn't allow you (as a numpy array would) to compare a raster to a constant. Also note that in each iteration of your loop V is being completely overwritten, and then the results aren't being saved anywhere, so once you get to ...


3

An ArcGIS Desktop add-in will probably meet your requirements. With an add-in you ship a single compressed file as opposed to a folder structure that includes your source code.


5

You will want to use Feature Class To Feature Class (Conversion) to copy the feature class or shapefile. Make sure to specify which fields are included in the output feature class using FieldMappings (arcpy). Alternatively, use Feature Class To Feature Class (Conversion) or Copy Features (Data Management) to make a copy of your features, then use Delete ...


5

A standard, modern approach to address this issue, create a web service that contains your proprietary knowledge. Your tool then calls the web service. Any local code can be cracked open. All you can do is make the process more difficult. Python is not the tool to use to keep your proprietary knowledge secret.


2

Despite the help file saying that the field parameter is of type Field it actually takes a string which is the field name, ESRI need to update their help file... Hopefully someone is reading this? So this: arcpy.AlterField_management(fc, field, new_fieldName_List[0], new_fieldName_List[0]) becomes this: arcpy.AlterField_management(fc, field.name, ...


3

The group layer you try to access with AddLayerToGroup is supposed to be in the TOC of your mxd, not on your disk... Refering to it as the .lyr file on your disk shouldn't work, it's weird that you could do it with 10.0. The AddLayerToGroup help page says (same in 10.0 and 10.2): AddLayerToGroup does not allow you to add layers to group layers within ...



Top 50 recent answers are included