Tag Info

Hot answers tagged

6

My method for this was to use the Field Mappings and Table to Table conversion functions. Using field mappings you can set new fields based on the names of fields in your input table. The following link has examples for feature classes: http://resources.arcgis.com/en/help/main/10.1/index.html#//018z0000007p000000 My code below will change all fields in an ...


4

In Python a backslash is an escape character. In order to put a backslash in the string you need to need to put another backslash next to it to stop it from forcing a new line. myString = "this is\\ a string with a backslash" I can see your paths are set correctly but maybe the strings you are parsing only have a single backslash. You can solve this ...


4

I would take a different approach and use Delete Identical (Data Management). The following script creates a copy of your table or FC and then removes the duplicate rows in that copy. import arcpy table = r'C:\test\temp.gdb\table' copy = r'C:\test\temp.gdb\table2' # Create a copy of your table arcpy.CopyFeatures_management(table, copy) # Delete ...


3

I would usually suggest the da.SearchCursor as well, but its order by clause only works withe data in a database. So, if it is in a database: a_table = "YourTable" order_fld = "Time" return_flds = ["Time", "SomeOtherField"] where_str = """Time > DATEADD(minute, -2, GETDATE())""" sql_clause = (None,'ORDER BY {} DESC'.format(order_fld)) last_row = '' ...


3

Vamping on PolyGeo's comment, I believe that the Summary Statistics tool would work easily. If I understand correctly you just need a list of unique values for the "Units" field. You can set up the tool like this (see the screenshot) except instead of using the "Name" field, you would use "Units". [Be sure to add Wellbore_Name w/ stat type "FIRST" as one of ...


3

Instead of if self.params[0].altered: try if self.params[0].value: I just tested and that seemed to work as you are hoping for. The .altered and .hasBeenValidated properties are super useful, but are still a little mysterious to me sometimes, even after reading the documentation... UPDATE: Thanks for the feedback, I misinterpreted what you were ...


3

Here is a block of code to get you started. This should change dependent on whether you are performing an append or merge. You will also have to create separate lists and loops/appends for your line data and point data. # import modules to use import arcpy, os # input folder containing your new shapefiles inputFolder = arcpy.GetParameterAsText(0) # ...


2

You are touching on a number of issues that are all related: First, Python uses quotes to create strings. A string can be surrounded by either " or ', and whichever type is not used there can be used inside of the string without a problem. An escape character, as you note, can be used to allow for the outside quotation marks to be used inside the string. ...


2

This is a great example of how relatively simple arcpy.mapping scripts can offer more functionality than Data Driven Pages. First, if you haven't already, run a Spatial Join with your trees as your target layer and your districts as your point layer using the INTERSECT match option. It's better practice to perform a spatial join and apply a definition query ...


2

The arcpy.gp.Plus_sa() is probably an older method of doing the same thing. I would go with the ESRI help version because it is Actually Documented and probably won't be dropped from support as quickly.


2

You need to filter away those map documents which contain "land use" in their names. It is better to test and if the evaluation gave us "false", proceed with the processing. env.workspace = r"C:\Project" Layer1 = arcpy.mapping.Layer("abc.lyr") for mxd in arcpy.ListFiles("*.mxd"): if 'land use' not in mxd: print mxd mapdoc = ...


2

You haven't shown how you received the parameter value, but I would guess you're likely using parameters[n].valueAsText. Use parameters[n].values instead to receive the value back as a list.


2

As mentioned by several other users here. Using Search and Insert cursors may not be necessary, but if for some reason you would still like to see how it is done, the following script should do everything you need. You will need to setup parameters for the script tool. I'll assume for now that you already know how to do this. Parameters: (0) Input ...


2

Another idea, though all these answers should work. This will avoid having to iterate the whole cursor. Not sure if the sql_clause will decrease performance though: oid_field = "OBJECTID" sql = ("ORDER BY {0} D".format(oid_field),"") with arcpy.da.SearchCursor(table,"*",sql_clause=sql) as cursor: for row in cursor: last_row = row break ...


2

You can do this with a Search Cursor wrapped in a list comprehension: import arcpy # Your input shp of fc fc = r'C:\path\to\your.shp' # List all of the row values as a list of tuples rows = [row for row in arcpy.da.SearchCursor(fc, "*")] # Get the last row print rows[-1]


2

If you're using 10.2, I would first recommend using the data analysis version of the search cursor. Then you can use python's list comprehension to get the last value. Try something like the code below. It creates a list of all values in the 'time' field, and then accesses the last record through indexing (the [-1] at the end of the list comprehension ...


2

Shapefiles don't support nulls. Read the section 'Null value representation' here: http://desktop.arcgis.com/en/desktop/latest/manage-data/shapefiles/geoprocessing-considerations-for-shapefile-output.htm If you really need to have nulls, consider migrating this data into a geodatabase.


2

Use else: row[1] = None None is what Python uses for Null. I'm not very familiar with regex, so I'm going to suggest a different version of your cursor operations, see if this works: for row in cursor: if row[0] == " ": row[1] = None else: row[1] = round(float(row[0]), 1) cursor.updateRow(row) The issue may ...


1

You are not providing the code required to add a layer to the map at all. You need a feature layer from the shapefile and then save it on disk as the .lyr file. inputLocationsSavedFcFeatLyr = arcpy.MakeFeatureLayer_management(input_locations_fc,"Stops") arcpy.SaveToLayerFile_management(in_layer=inputLocationsSavedFcFeatLyr, ...


1

How about just making a list of the OBJECTID's you want and making it into a query? ## start with list of all objectids all_oids = [row[0] for row in arcpy.da.SearchCursor(Input,"OBJECTID")] ## make list of every 3600th objectid oids = [] for index, oid in enumerate(range(len(all_oids))): if index % 3600 == 0: oids.append(oid) ## make sql ...


1

I would simplify things a bit and convert your string to float using float(). I used the new cursor style, which you may prefer. Please test this "untested" script on a sample dataset before going live. import arcpy, os from arcpy import env arcpy.env.overwriteOutput = True env.workspace = "C:\Users\OuelletteMS\Desktop\Ice_Data_testarea" listFCs = ...


1

You are using Decimal against the field name, not the value. Try row.setValue(newNCT, Decimal(row.getValue(strNCT)))


1

This is unntested and incomplete, but should give you the gist of it. Plenty of ways to make this "more Pythonic", but hopefully you can understand this code. You will have to correctly set your workspace. import arcpy arcpy.env.workspace('workspace') # ListFeatureClasses just works off this environment variable fcList = ...


1

I'll provide a couple links with more information. To familiarize yourself with what you are doing with field mappings, I recommend doing a spatial join or a merge operation within ArcMap. Perhaps visit the Geoprocessing Results window too. This will really help if you can first simulate manually the join that you want to do programmatically. They can be ...


1

Like I said in my comment, I don't think this is possible exactly how you describe it. This should work. import os # Change the following 3 variables - - - - - - - - - - - -- - dir_fc = r'C:\dir\to\the\shapefiles' # set the index name and attribute from that layer to be used for the filename index_fc_name = "index" index_fc_attribute = ...


1

I see two fixes: For the first error: ERROR 000161: The length of the grid name must not exceed 13 characters Convert your output to tiff format, which does not have the character length limitations that the Esri grid raster format does. mamcnty_out = os.path.join(output_workSpace, "cnty_" + species_str + ".tif") For the second error: ERROR ...


1

The first thing that springs to mind is an incorrectly defined nodata value. What I notice in the two images is that the dark blue area should be nodata and that it only occurs between valid/data/light blue pixels. Based on the help file, it actually relates to two of the tool parameters - nodata_value and background_value. From the help file: Use this ...



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