Tag Info

Hot answers tagged

7

Try lyr.longName longName (Read Only) This property is valuable when trying to determine whether a layer belongs to a group layer. If a layer does not belong to a group layer, the long name will equal the layer name. If a layer does belong to a group layer, the group layer structure will be included in the long name. For example, the name of a ...


5

Your Try: statement is capitalised, it should be lower case - try:


4

This can be solved with use of a dictionary object. Dictionaries let you associate a key value with another value. In the code below, I use your first cursor to associate the City value with the NearFeature value, if the Distance value is 0. I then use your second cursor to update the Comments field, if the value in the City field occurs in the dictionary. ...


4

Figured it out. Boy that was easy! >>> import arcpy ... ... fc = "C:\Users\PythonTesting.gdb\My_File" ... f1, f2, f3 = "EDITOR", "COUNTY", "OBJECTID" ... clause = arcpy.AddFieldDelimiters(fc, f3) + "= 1" ... for row in sorted (arcpy.da.SearchCursor (fc, [f1, f2], clause)): ... print ("{0}_{1}".format(row[0], row[1])) ... name ...


3

float("Inf") is not a true float. You can't do normal math with it. Feature class fields can only store actual numeric values, within specific ranges. From the help: Data type | Storable range --------------------------------------------------- Short integer | -32,768 to 32,767 Long integer | -2,147,483,648 to 2,147,483,647 Float | ...


3

there is no such thing as the "sum" operator for difference (which is not permutable), so you should test the validity of each item to decide how you run the substraction. def stack(item1,item2): if item1 != None and item2 != None: return item1-item2 elif item1 != None: return item1 elif item2 != None: return -item2 ...


3

[I'm guessing based on available information]: Your problem is with what you're passing in when running it in a an IDE (outside the app) try: arcpy.geocoder_geocoder('gc_01', 'J:/Postal/Postal/99_Geocode/01/composites/composite_1', 'J:/Postal/Postal/99_Geocode/01/composites/composite_2', ...


3

You can check to see if the layer is a group layer or not using the isGroupLayer property: Returns True if a layer is a group layer. Layer (arcpy.mapping) Code e.g. for lyr in arcpy.mapping.ListLayers(mxd, "", dataframe): if not lyr.isGroupLayer: # continue


2

The text property from the TextElement (arcpy.mapping) is expecting a string and the survey variable is a tuple. Try using str() to convert the datatype. for el in ellist: if el.name == "survey": el.text = str(survey)


2

This is one approach to selecting features and then exporting the selection to a shapefile. import arcpy # Define Workspace arcpy.env.workspace = r"C:\Project\layers\New File Geodatabase.gdb" # Create Layer arcpy.MakeFeatureLayer_management('atikot', 'atikot_lyr') # Select arcpy.SelectLayerByLocation_management('atikot_lyr', 'intersect', 'ways') # Copy ...


2

I believe the issue is with your variable newPath. You will need to designate a directory as well as the name of the text file for the script to work. Try something like this to set the variable: newPath = os.path.join (r"C:\test", "testtext.txt") I can't say how the script works without it. I hope this helps!


2

You can do this by looping through the shapefile first with a SearchCursor, creating a dictionary item for each "Key" field, where the value is a list of the "Accuracy" field values. Then loop through again with a UpdateCursor, compare with the maximum accuracy value from the dictionary, and delete the row as appropriate. import arcpy # Create dictionary d ...


2

If you don't have .lyr files or an existing mxd referencing the data, I think what you're trying to do should be impossible with Python. A better approach would be to create (manually) a template mxd with a geotiff and an ascii file in it, then (with Python): copy the template mxd (with saveACopy) and replace the data sources of both layers with e.g. ...


2

Have you looked at the arcpy.mapping LegendElement? Not sure that will do what you want, but is one way of manipulating legend elements.


2

There is only one way to efficiently do this that I know of. Load the replica database fields into a dictionary using a searchcursor with the GlobalID as the dictionary key, then loop through a searchcursor on the origin database and attempt to retrieve the GlobalID dictionary key that matches each record. Set up four counters: count, added, deleted, and ...


1

Years and Months behave differently in several ways that make your expression work for years, but break for months. Any set of year ranges that are positive will work with the original years expression. No set of ranges across multiple years alone can select just dates from a given month. For months you have to set an overall range of all dates regardless ...


1

I can think of a few ways to accomplish this, if you want to automate the process you would use a similar approach to this example in the ArcGIS help LegendElement example 4: The following script updates all layers in the legend to use a custom legend item style item called MyNewStyle. import arcpy mxd = ...


1

Try this: for month in range (01,12): arcpy.MakeFeatureLayer_management("Sightings1995-2014", "test%s" %month,"DATE >= date'01.%s.1995' AND DATE < date'01.%s.2014'" % (month, month+1) When you did it for year you ended your for statement with a colon (:), but when you did it for month that was omitted.


1

I would confirm as @Vince suggests if your input datasets have spatial indices. If your inputs are Shapefiles then these by default do not have spatial indices and need building. Another suggestion that will speed up your code is to replace the cursor you are using with a cursor from the da module as described here.


1

The long execution time is relatively normal. I had a script which I ran from the Python window inside ArcMap and that took more than two hours. I realized that when I converted the script to a script tool, the execution time went down to 12 minutes. A script tool is like a toolbox. You connect your script to the tool. You will need to add a few lines in ...


1

Similar to what the other posters have said. Use arcpy.da.searchcursor and use the where clause. You can then set the where clause to be "where accuarcy > 80" or whatever you want. check out this resource http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001r000000


1

You have this problem because the field names to be used when you have a join are not the original field names. If you don't need the join anymore, you can use the "remove join" tool. If you do need the values from the joined table, you must include the table name in the field name, like this : !table_name.field_name! If you want to make sure of the ...


1

ESRI has a variety of free web-based courses. One that may meet your requirements is called Python for Everyone. The course addresses the following subjects: Choose the Python scripting environment that meets your needs. Choose appropriate data types and apply Python syntax rules when writing a script. Quickly create a script to automate a ...


1

The grid I was using was stored as a feature class within a geodatabase; printing cursor iterations over the table revealed that it was only reading about 1,000 records at a time at which point it would pause for quite a while before reading another 1,000 records. AFter 45 minutes, the table still had not been traversed. By exporting to a shapefile I was ...



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