New answers tagged

-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

GetCount returns a Result object and not an integer or a string. To get a string you use the getOuput method of the result object and pull its first part. To see any other parts try switching the 0 for 1, 2, etc. If you need to turn that string into an integer then use an int() function. To learn more about the Result object and its getOutput method ...


0

To see these changes take effect I think you will need to include both arcpy.RefreshActiveView() and arcpy.RefreshTOC() in your script.


0

Featureless data type option will allow the end user the ability to choose from either shapefile or gdb featureless.


2

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(["...


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('...


0

If you define "north of" as being simply that a newly selected point has a Y coordinate greater than any of the originally selected features, then this should be doable by: using Select By Location within a distance of 10 meters to get them first then use ArcPy to work out the Y coordinate of the northernmost point then use ArcPy to examine the Y ...


-1

The Intersect tool, when run on polygon input(s), and requesting LINE output, will produce the result that you are after i.e. the lines in common to neighboring polygons. This is is described in the ArcGIS Help about how Intersect works. As noted by @klewis the lines that result are "duplicated" but this is easily addressed by running Dissolve on that ...


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"]: ...


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(...


0

What I meant is limiting spatial join by excluding field mapping, I.e. ) after keep all. Field mapping is optional for spatial join. Next step create list of fields of the output. List2remove =filter(completeList not in fields2keep) Delete field(spjoinOutput,list2remove) I am on the phone and have to use pseudo code


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 ...


0

To continue with your code sample: 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.getValue(field1) == "BUILDING": value = str(row.getValue(field2)) for elm in arcpy.mapping....


0

Hard to tell what is wrong, because a code is a bit untidy. So I modified it slightly: try: arcpy except: import arcpy import traceback, os, sys from arcpy import env env.overwriteOutput = True from arcpy.sa import * inputVector=r'D:\Scratch\Walkover.gdb\rpoints' inRaster = r'D:\Aerials\Backups\arc2mdem' outAgl="outAgl" outViewshed="outViewshed" outagl = ...


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)


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, ['...


-1

Very interesting debates put forward by you all. The only thing which I can think of is using the "plus" tool to add the DEM and Polygon raster with an estimated VALUE for height. This advice is given in the ESRI Resource Center Blog here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z000000v8000000.htm But with this in mind, if you ...


0

I ran in to a memory leak type issue which I resolved with the code snippet below, but then ran into the "layout.exportToPDF(*args) AttributeError: PageLayoutObject: Error in executing ExportToPDF" error, and have not yet resolved it. Here's how I got around the memory leak (reload the map doc every 100 reports): TotalPages = (ReportMXD.dataDrivenPages....


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 ...


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 ...


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) ...


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(...


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 ...


0

The call to the cursor.updateRow(row) method appears to be out-of-loop in the code snippet provided. Given the code snippet, I'm thinking cursor.updateRow(row) would only execute once, after exiting the for loop. Indenting the cursor.updateRow(row) as follows should fix it: cursor = arcpy.UpdateCursor(fc) for row in cursor: row.setValue("...


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

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.


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'...


1

I'm going to go ahead and convert my comment to an answer. I'm assuming you've named your last field incorrectly. I think you may have meant it to be "B0R010" and not "B0R0010". Also, you may need to ensure that all fields are in the file. Also, check your indentation, as per @Jacob F's comment.


0

In your code sample, you're trying to save the mxd object, not a path to the object. i.e., mxd.saveACopy(mxd). This is not the correct way to perform this action. The documentation advises using the entire file path, like the following: import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") for df in arcpy.mapping.ListDataFrames(mxd): ...


1

Use label expression: def FindLabel ( [OID] ): mxd = arcpy.mapping.MapDocument("CURRENT") lr=arcpy.mapping.ListLayers(mxd)[0] with arcpy.da.UpdateCursor(lr, ('Shape@','POINT_X','POINT_Y'),r'"OID"='+str( [OID] )) as cursor: for row in cursor: row[1]=row[0].firstPoint.X row[2]=row[0].firstPoint.Y cursor.updateRow(row) ...


1

Sort table by time, if it is not already a case and assign good unique IDs Convert points to line using field animal as line ID. Split lines at points Remove lines longer than 20 m Assign FROM node and TO node IDs to segment using something like this Transfer time at FROM node and TO node to table of segments Find difference in seconds. Expect trouble at ...


1

Copy features is meant to copy a feature to a feature class in a geodatabase (http://pro.arcgis.com/en/pro-app/tool-reference/data-management/copy-features.htm). Since you're not copying your features into a geodatabase, try using arcpy.Copy_management instead (http://pro.arcgis.com/en/pro-app/tool-reference/data-management/copy.htm) EDIT: I was able to ...


0

@PolyGeo's solution is top-notch, but not perfect for every use case. For example, in my use case, I had a Python 2.7.11 install on my machine and then I installed ArcGIS which came with Python 2.7.8. When I followed the instructions at Importing ArcPy, I found that the path C:\Python27\ArcGIS10.3\Lib\site-packages had a file called Desktop10.3.pth in it ...


1

As I've noted in my comment, you may use the arcpy delete management method to delete the service area layer. Permanently deletes data from disk. All types of geographic data supported by ArcGIS, as well as toolboxes and workspaces (folders, geodatabases), can be deleted. If the specified item is a workspace, all contained items are also deleted.


0

inNetworkDataset = C:\\Temp2\\data.gdb\\Network\\Network_ND outNALayerName = Catchments arcpy.Delete_management(r'C:\\Temp2\\data.gdb\\Network\\Network_ND\\Catchments') This deletes it. I wasn't sure if it needed a .lyr, but it seems not. Perhaps there is a way to list the service areas currently in the GDB, as seen in this question


2

I believe the issue is that you are giving two integers in the CalculateField expression, so an integer is returned. You need to force one to a float or decimal to get a proportional value back. Try: exp = str(float(count)) + "/!Total_Properties!"


0

Use some of python's standard string formatting functions and create a unique list (set) of your base file names. Then you can iterate the set object and run your processing steps for each bio value. This code should get you started ImgList = arcpy.ListRasters() bio_list = [] for ras in ImgList: a = ras.split('_') b = '_'.join(a[:-1]) ...


1

To go along with my comment. The problem you have is having to figure out a way to implement interprocess communication. Whenever you start up a python script, you're creating another process to run (python.exe) to go along with your already running process (ArcMap.exe). The problem here is that there needs to be a way to communicate back and forth. You ...


3

Try changing: arcpy.env.workspace = "D:\Users\ShawnO\Desktop\PythonExercizes\Parcel_Ownership_update_model\Parcels.gdb" inFeatures = "D:\Users\ShawnO\Desktop\PythonExercizes\Parcel_Ownership_update_model\Parcels.gdb\Parcel_Owners" outLocation = "D:\Users\ShawnO\Desktop\PythonExercizes\Parcel_Ownership_update_model\Old_Parcel_Owner\Old_Parcel_Owners.gdb" ...


0

This is how I would do this, i am unsure why you are trying to split the fc out if its printing fine, maybe the split is causing the issue. This isn't tested, but give it a shot. import arcpy import csv dir = r'D:\Test\gdb' arcpy.env.workspace = dir gdbList = arcpy.ListWorkspaces('*','FileGDB') filename = r'D:\Test\FC_List.csv' with open(filename, 'wb') ...


2

If you do this on windows, you can do this through cmd prompt and use setup tools. I have to do it on a restricted computer all the time. I just install the source setup.py files as ziggy has suggested. https://pypi.python.org/pypi/setuptools In command prompt, change your directory to the location where you have extracted the package that you want to ...


1

I would recommend using the CSV module, I find it an extremely useful module to know, especially with any kind of reporting that needs to be done. https://docs.python.org/2/library/csv.html I have made up this code, I don't have arcpy on my computer at home, so you will need to check if it works import csv import arcpy csvLocation = r'/desktop/test.csv' ...


1

It doesn't seem that this is supported directly in the ArcObjects API. As a workaround using the save to v9.3 route could be slow, but how slow and does it actually matter? For example let's guess it added 10sec per export. That could be annoying yes, but I'd argue that being able to use dynamic text in your mxd would save you more than 10sec in the making ...


0

collections.defaultdict works brilliantly here. Consider the following: from collections import defaultdict intDict, listDict = defaultdict(int), defaultdict(list) for i in xrange(15): if i % 4: intDict["A"] += 1 listDict["A"].append(i) else: intDict["B"] += 1 listDict["B"].append(i) >>>print(intDict) ...


0

Here is a Python based spell checker for ArcGIS. There are three toolbox tools that will check the spelling of the layout items (title, legend, text), an attribute column, or the table of contents. The misspelled words are printed to the geoprocessing results window. The tools requires an installation of PyEnchant which is included in the zip file as an ...


3

Your first expression works because you have paired outermost single quotes (notice the sitename is black, because it is a variable and not part of the string). Your second expression does not work because sitename is between a the outermost double quote pair when it should be outside of two double quote pairs (notice that sitename is brown and therefore ...


2

I don't think you need to do your initial line splitting. If you iterate through the points in the SHAPE@JSON attribute of the feature class, you can measure the sum of angles for each line and divide by the number of vertices. import re import math import arcpy from math import acos from numpy.linalg import norm import numpy import json def findangle(p1,...



Top 50 recent answers are included