Hot answers tagged

4

You are trying to add your point X/Y data as field values rather than to SHAPE. Include your X/Y as tuple in new_rows, and add them into SHAPE@XY with your Insert Cursor new_rows = [((centpointX, centpointY), distance, TRangle), ((centpointX, centpointY), distance, LRangle)] cursor = arcpy.da.InsertCursor(pointshap, ['...


3

It looks like you're mixing up data access update cursors and calculate field. Use the data access update cursor (it's faster): with arcpy.da.UpdateCursor (StreetCenterlines, ["Latitude", "Longitude", "SHAPE@X", "SHAPE@Y"]) as cursor: for lat, long, x, y in cursor: row = (x, y, x, y) cursor.updateRow (row)


3

The Append tool: Appends multiple input datasets into an existing target dataset. Input datasets can be point, line, or polygon feature classes, tables, rasters, raster catalogs, annotation feature classes, or dimensions feature classes. For one ArcPy example its Help has: import arcpy arcpy.env.workspace = "C:/data/" arcpy.Append_management(["...


3

arcpy.CalculateField_management(fc, "time", "!DATE!.split(' ')[1]", "PYTHON") This uses Python to split the string at the space (which returns a list containing the date as a string and the time as a string), and populates the field with the second item in the list, which is the time.


2

Using arcpy you should be able to do this pretty easily, the distance is just a plane distance though not sure if that matters. I have also never used a cursor with itertools.combinations, but it works with the test dictionary that I created. An answer here suggests you can https://arcpy.wordpress.com/2012/02/01/find-overlapping-features/ Even if you can'...


2

If your mxd is open, use mxdloc = arcpy.mapping.MapDocument("CURRENT") Changes made to your mxd on your disk (by referencing the mxd's path) won't be visible if the mxd is open in ArcMap so depending on where you are running it you may need to add mxdloc.save()


2

You could also avoid arcpy all together: import os os.chdir(r'C:\Set_to_your_directory') substring = '2014' files = os.listdir(os.curdir) for file in files: if substring in file: file_new = file.replace("2014","2015") os.rename(file, file_new) This will replace "2014" with "2015" for any file in a folder. It is also possible to ...


2

You can search for a substring in a string using if (substring) in (string), and then use string.replace() to replace the value you find. import arcpy, os arcpy.env.workspace = r"d:\Temp\SE\RenShapes" fcs = arcpy.ListFeatureClasses("*.shp") for fc in fcs: if "2014" in fc: x = fc.replace("2014", "2015") arcpy.Rename_management(fc, x) ...


2

Since Winners is a list of integers, and MakeFeatureLayer is expecting a SQL string in a particular format, you need to convert. Here's a simple way: >>> Winners = [1, 4, 59, 330] >>> sql = "OBJECTID_12 IN ({})".format(",".join(map(str, Winners))) >>> print(sql) 'OBJECTID_12 IN (1,4,59,330)' Since your values are integers, you ...


2

Here you have a pretty similar solution. import arcpy env.workspace = r"D:/datafolder" shapefiles_list = arcpy.ListFeatureClasses() for shapefile in shapefiles_list: desc = arcpy.Describe(shapefile) fields = desc.fields fields_to_zero = [] for i in fields: if i.type in ["FLOAT","DOUBLE", "LONG", "SHORT"]: ...


2

There is no need to define the workspace if you are explicitly defining the variable paths. Additionally, you are formatting the paths incorrectly--try using r'C:\path\to\your\data'. I would recommend writing the output raster to .tif or .img format. As your script is currently configured, it is trying to output a grid format raster. This is how I would ...


2

You are close, but the (r)split will create a list. Therefore you need to get the element from the list (-1 for the last one) arcpy.Calculatefield_management(fc,"time",!DATE!.rsplit()[-1])


2

SelectLayerByLocation requires a Layer to select features, you can't select features directly on a feature class, which is what your script is trying to do. The reason it worked in ArcMap is because in ArcMap you were referencing the map layers rather than feature classes. Add a MakeFeatureLayer and set your SelectLayerByLocation to select that. for grid ...


1

You can try this code instead: arcpy.Calculatefield_management(fc,"time",!DATE![9:len(!DATE!)]) Len gets the length of the string the square brackets are saying, "Return the 9th character of the string (in date) to the last character of the string"


1

If you're using ArcGIS 10.1 or above, you can use data access cursors. You can also remove your second outer loop by doing all the same stuff within the first loop. You don't need to reset the arcpy workspace to the same path twice. As I commented above, you pretty much never want to use try/except, until you have your script working properly. I've added ...


1

Apart from the already cited "insertCursor" and "Append" tools, a simple way to copy one or more features into an existing feature class is to make a copy-paste while in edit mode. Start an edit session for your target feature class Select the features that you want to copy CTRL+C CTRL+V save edit


1

Using an insert cursor would do the trick. If you are using greater than 10.0 then use the da cursors but this code is for 10.0. Code isn't tested. inFC = 'test.shp' outFC = 'existing.shp' inCur = arcpy.InsertCursor(outFC) searchField = 'BLAH' searchCur = arcpy.SearchCursor(inFC,fields = searchField) for sRow in searchCur: rowVal = sRow.getValue('...


1

"Feature Layer" is going to be the most flexible, as this will accept any vector-based layer that is available on disk, and it will ALSO accept any layer that is in your table of contents. The "Feature Class" option will only accept inputs on disk (or database).


1

Feature Class data type option will allow the end user the ability to choose from either shapefile or gdb feature class. [ESRI software] In ArcGIS, a collection of geographic features with the same geometry type (such as point, line, or polygon), the same attributes, and the same spatial reference. Feature classes can be stored in geodatabases, ...


1

I'm not sure why you have to set all the values to zero before populating them from somewhere else, but this should do it. import arcpy fc = r'path' desc = arcpy.Describe(fc) fields = desc.fields procFields = [] for field in fields: if field.Type in ('Double', 'Single', 'Integer', 'Float'): procFields.append(field.Name) replVal = [0] * len(...


1

As @FelixIP comments I think it is easier to drop unwanted fields. Here is what your code would look like, using the fieldInfo object: import arcpy def filter_fields(FC, fieldList): # List input fields fields= arcpy.ListFields(FC) # Create a fieldinfo objects fieldinfo = arcpy.FieldInfo() # Iterate over input fields, add them to the ...


1

The above doesn't use field maps correctly; you instantiate a couple of them, but don't define anything in them. Field maps are useful when you want to consolidate/combine/concatenate/perform math on more than one input field for one output field. If you're aim is simply to keep certain wanted fields from the set of all input fields, the following should do ...


1

Finally resolved the problem this morning by adding tempraster.save() to persist the accumulating raster between loop iterations. #create/update summed agl raster if row[0] == 1: tempraster = hidecon #create the raster that will be used to sum tempraster.save() else: tempraster = tempraster + ...


1

You are getting that error because on line 5 you have opened a single quote without closing it. Since you have used double rather than single quotes in the remainder of your code I suggest changing that single quote to a double quote. Also, you need to let Python know that your pathnames should be interpreted as raw strings because the backslashes in a ...


1

To continue with your code sample: import arcpy mxd = arcpy.mapping.MapDocument("Current") fc = r"W:\\GIS_Projects\\Impervious_Surfaces_Tables\\TOTAL" field1 = "SURFACE_TYPE" field2 = "SUM_SQ_FT" value = "" with arcpy.da.SearchCursor(fc, [field1, field2]) as cursor: for row in cursor: if row[0] == "BUILDING": value = str(row[1])...


1

The Python installation of ArcGIS is not "standard" 1) you need first to install pip 2) then in theory you can install SciPy but SciPy is not a pure Python module, it needs compilation of C files and Windows has no compiler by default. You can try the Microsoft Visual C++ Compiler for Python 2.7 or a version of Christoph Gohlke Unofficial Windows ...


1

As my comment noted, your code logic is correct, just your error messaging may of been misleading "Error reading data". "Error reading data" could be renamed to "other fc found: {}".format(shp_file) or just remove the entire else condition.


1

You could follow this basic procedure. First, I would move your point feature class from a shapefile to a feature class in a file geodatabase. Then I would make your time column a datetime column so you can sort your time column in ascending order. This will make the process easier. Also, assign a unique ID to each point so you can match your pairs based on ...


1

You can move the ArcPy directory into the Anaconda folder. Make sure you are using the 32-bit version of Anaconda before you do this. Go into the root folder for the ArcGIS python: C:\Python27\ArcGIS10.4\Lib\site-packages then look for a file named Desktop 10.4.pth If you are using a different version of Arc it will read 10.x instead of 10.4 which is ...


1

Here is an alternate approach that I used to create multiple fishnets within the extents of each feature within a feature class. The search_extents variable defines the path to that feature class defining the extents of each fishnet I wanted to create. There was no rotation of the fishnet. search_extents = "path to extents" rows = arcpy.SearchCursor(...



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