Hot answers tagged

7

The input to insertRow() must be a list or tuple. Instead of building this as a string value as listed above, dashboard_site_summary_list.append('((' + str(row[0]) + ',),') append a tuple: dashboard_site_summary_list.append((row[0],)) # don't forget the comma; see below for type comparison or list (whichever you prefer): dashboard_site_summary_list....


4

I suspect that you may be following a code sample for the metadata module of ArcPy which is only available to work with the ArcGIS Pro (and not ArcMap) application of ArcGIS Desktop, and only since ArcGIS Pro 2.5 was released: The Metadata class allows you to access an item's metadata, and export metadata to a standard metadata format. If you have ...


4

You have some problems in the update for. 1) I don't understand why you want to iterate the dictionary, you already have the key in row[0]. 2) This comparison v == min(v) it is always false v is an array and min(v) is an interger. 3) Related with 2, you are only updating on true case. So this is a fix to your code, # Start_End_UpdateAttribute.py # purpose: ...


4

Taking a look at your code I see four different errors: 1) You wrote: Date = datetime.date.today().strftime("%d%m%Y") However, you never import datetime. Add import datetime at the start of your script. 2) You wrote: ArchiefName = Project_number + "_" + Date Archiefsave = os.path.join(Archieffolder, Archiefname) However, Archiefname is not defined. ...


3

When you create the left and right Point() objects using the offset coordinates, also include the original ptX.Z leftP=arcpy.Point(ptX.X+sX, ptX.Y+sY, ptX.Z) lArray.add(leftP) rightP=arcpy.Point(ptX.X-sX, ptX.Y-sY, ptX.Z) rArray.add(rightP) Then when you create the Polyline(), include a spatial_reference and set has_z to True, otherwise they'll end up 2d. ...


3

Try using the arcpy.sa.ExtractValuesToPoints() function which: Extracts the cell values of a raster based on a set of point features and records the values in the attribute table of an output feature class.


3

GDAL 2.1.1 is already installed with the default Python installation in ArcGIS Pro. Any script you create and run within the ArcGIS Pro Python window (or the ESRI installed version of Jupyter) will allow imports of both arcpy and GDAL. See the first image below and this link for more information. If you want to run Python scripts from a third-party ...


3

The error is correctly stating that the MXD doesn't exist. You create the mxd on line 8. On line 48 you saveacopy and then on line 50 you del mxd. You then go through another merge process and on line 95 you try to mxd.saveACopy, but you deleted it on line 50. So you either need to NOT delete it, or create a new copy of it the same as line 8.


3

Create a Dictionary using da.SearchCursor, then update: import arcpy fc = r"path/dat_1" tbl = r"path/dat_2" common_id_field = "ogr_id" valuefield = "field_1" d = {ogrid:value for ogrid,value in arcpy.da.SearchCursor(tbl, [common_id_field, valuefield])} with arcpy.da.UpdateCursor(fc, [common_id_field, valuefield]) as cursor: for row in cursor: ...


2

I assume that you have elevation model (DEM), you filled it (Filled), computed flow accumulation (FACC) and derived stream raster (Streams) containing value of 1, where accumulation exceeds certain threshold. Let's identify lake(s): arcpy.gp.RasterCalculator_sa('Con("Filled" > "DEM",1)', "C:/SCRATCH/DEPRSNS") arcpy.gp.RegionGroup_sa("DEPRSNS", "C:/...


2

Finally after struggling with code and debugging more than 100 times and talk to ESRI support I am able to resolve this issue, which is a bug listed in Esri BUG-000126550. This bug is not in XY event layer it is in Make query layer. So instead of using arcpy.MakeQueryLayer_management(......) I have to use arcpy.CreateDatabaseView_management (...


2

You can use pandas library. If your table is sorted by Id and OID_copy you dont need to use a dictionary: import arcpy import pandas as pd fc = r'C:\GIS\data.gdb\points' fields = ['Id','Start_End'] df = pd.DataFrame.from_records(data=arcpy.da.SearchCursor(fc,fields), columns=fields) #Create pandas dataframe using da.SearchCursor l = df.groupby(fields[0])....


2

You are not showing all your code. But you could check if split list is to short, and if so then extend with empty string. Example: a = '1st St & A blvd' s = a.split(' & ') print s diff = 3-len(s) if diff != 0: s.extend([' ']*diff) print s Outputs: ['1st St', 'A blvd'] ['1st St', 'A blvd', ' '] Or use try/except: a = [1,2] try: print a[...


2

Make sure you get correct syntax for Calculate Field. It is best to include parameter names (for example in_table='blablabla') instead of just relying on order/index of parameters: arcpy.CalculateField_management (in_table="sometable", field="somefield", expression="someexpression",...) For example you are providing outputFilePath + '/' + name[:-4] as ...


2

Try: def calc(PA, defor, GPS): #The input fields here, not the output field. The field order need to be the same as when you call the function. if PA == 0 and defor == 0: return GPS else: return ((PA + defor) * GPS) Call with coop_score= calc(!PA_score!,!def_score!,!GPS_score!) #You need the actual fieldnames here enclosed in !!


2

You need to embed the code in the tool. Here is a link to some ESRI information on how to embed your script to protect the code. https://desktop.arcgis.com/en/arcmap/10.3/analyze/sharing-workflows/embedding-scripts-and-password-protecting-tools.htm


2

It's important to understand that Esri didn't create the datetime object used to transmit this information -- This is a fundamental Python datatype. The Python documentation covers the timedelta that results from datetime subtraction. The difference in seconds (timedelta.total_seconds()) is a float value because the datetime type supports milliseconds (...


2

@Vince's comment is pretty close, but the GEOID field is actually a string, so you need to explicitly include single quotes around each value in the list in the sql query expression = '"GEOID" in ({:s})'.format(','.join(["'" + str(geoid) +"'" for geoid in interest_list]))


2

For a start ID is irrelevant in your fields, you only need the two fields being worked on 'Name', 'Id_2'. You've also set up a search then an update, you don't need to do this, a single update is enough; what you're after in much less code: fc = r'D:/test/colors.shp' fields = ['Name', 'Id_2'] NCntDic = {} # a new empty dictionary with arcpy.da....


2

As commented by @SonofaBeach: You don't need to import arcpy in ArcMap. It is already imported. You only need to import it for stand-alone scripts run outside of ArcMap. However, something is clearly wrong, as it should not generate an error if you re-import it. I have resolved similar errors in the past by: Using Windows Add/Remove Programs to ...


1

This can be done using networkx module providing 3d distance between end points of the same group lines is smaller than distance to other group points. This is workflow: arcpy.FeatureVerticesToPoints_management("sparts_3d", "C:/SCRATCH/ends_3d.shp","BOTH_ENDS") arcpy.Near3D_3d("ends_3d", "ends_3d") arcpy.AddField_management("ends_3d", "TO_LINE", "LONG") ...


1

Pandas does it with ease. Script: import arcpy import pandas as pd tbl=arcpy.da.TableToNumPyArray("mesh_2d",["ZONE_ID","D_CLASS"]) df=pd.DataFrame(tbl) del tbl df["V"]=[1]*len(df) arcpy.AddMessage(df.head()) pTable=df.pivot_table(values='V', index=['ZONE_ID'], columns='D_CLASS', aggfunc='count') arcpy.AddMessage('\n') arcpy.AddMessage(pTable) arcpy....


1

the second loop (on the range) in your script will run to its end at every row, this is why you end up with the maximum value of your range in each row value. If you just need an incremental value, then you simply need to initialize a counter. If this counter has to be limited by a maximum value, then you can use a modulo operator (%). with arcpy.da....


1

Try: import arcpy, itertools fc_to_update = r'C:\data.gdb\features' field_to_update = 'somefieldname' alist = [1,2,3,4,5,6] repeatingGenerator = itertools.cycle(alist) #https://stackoverflow.com/a/45037522/6936582 with arcpy.da.UpdateCursor(fc_to_update, field_to_update) as cursor: for row in cursor: row[0] = next(repeatingGenerator) ...


1

Your Oiling Zone layer looks like it cannot find its data source because your picture has a red exclamation mark next to it. If a data source cannot be found for a layer then it will not be possible for ArcPy to find any fields within it.


1

From the tool help for Feature Class to Feature Class, the geometry type of the output featureclass to be created is listed with the following options: POINT —Point MULTIPATCH —Multipatch MULTIPOINT —Multipoint POLYGON —Polygon POLYLINE —Polyline Despite the help not specifically mentioning annotation featureclasses, I'd suspect ...


1

I'd make use of the in_memory workspace to store your table. ArcGIS provides an in-memory workspace where output feature classes and tables can be written. Writing geoprocessing output to the in-memory workspace is an alternative to writing output to a location on disk or a network location. Writing data to the in-memory workspace is often ...


1

Instead of copying and deleting, I like to create a feature layer and hide fields, then export. I've created a function for this task. Subtypes don't affect this method. def CreateFieldInfoLayer (fc, lyrName, tempName, flds): """ fc = input feature class lyrName = name of output layer tempName = name of temporary layer. It will be created ...


1

First even though you have multiple "totals" I believe they should be equivalent, just in different units. These "totals" are based on how the network dataset is configured to calculate this "cost". For example the network dataset could be configure to get the "cost" simply from the length of the polylines, or it might come from some attribute on each ...


1

The culprit would be lyr = arcpy.mapping.Layer("Layername") which returns a Result object not a Layer. You can try lyr = arcpy.mapping.Layer("Layername")[0] or MakeFeatureLayer as suggested.


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