New answers tagged

0

I came back to this after a break and was able to get it to work, so posting in case it's useful for anyone else. This was the final code: import arcpy import pythonaddins import os class ComboBoxFolder(object): """Implementation for LayerAddIn_addin.combobox (ComboBox)""" def __init__(self): arcpy.env.workspace ...


1

Some python will help you combine the rows into a single value, you just then need to write that out to a new table. import arcpy tbl = r"C:\Scratch\fGDB_Scratch.gdb\tbl" mylist = list() with arcpy.da.SearchCursor(tbl,["stuff"]) as cursor: for row in cursor: val = row[0] if val.isnumeric(): part1 = val ...


0

I do not have PyCharm installed to test. However, your syntax of: arcpy.FeatureClassToFeatureClass_conversion(r'C:\Workspace\test.gdb\wells', r'C:\Workspace\test.gdb', 'test1', where_clause='This is not sql') seems to match what is required by the tool in its Online Help: FeatureClassToFeatureClass(in_features, out_path, out_name, {where_clause}, {...


2

import arcpy import os fc = r'Database Connections\Connection to sde.sde\table' workspace = os.path.dirname(fc) edit = arcpy.da.Editor(workspace) edit.startEditing(False, True) edit.startOperation() with arcpy.da.InsertCursor(fc, ('field1', 'field2')) as cursor: cursor.insertRow(("string1", "string2")) edit.stopOperation() edit....


3

The "sphere" keyword used with SPHEROID represents an approximate authalic radius (sphere) based on the Clarke 1866 ellipsoid. The value is 6370997.0 meters.


1

The relationship between TOA reflectance to BoA reflectance is not linear but can be well approximated by second-order polynomials. You can check py6s, try some cases, and fit the second order polynomials then it is possible to find the simplified equation to fit into into Arcpy.


6

You can use strptime but it is probably easier to use pandas.to_datetime to convert the strings to datetimes. It is smarter/more flexible and can handle different string formats. Add a date field, create a function in Field Calculator or use da.UpdateCursor: import arcpy import pandas as pd table = r'C:\folder\Default.gdb\datedata' #Change to match your ...


1

A simple approach would be to use NAIP imagery to calculate NDVI with the red and NIR (near infrared) bands and set a threshold over which you consider the electrical feeders to fall in a vegetated area. The formula for NDVI is NDVI = (NIR — VIS)/(NIR + VIS) where VIS is the red NAIP band. You can calculate this in ArcGIS using raster math. However, this ...


2

Use da.SearchCursor its faster. Try using Counter like this: from collections import Counter fc = r'C:\GIS\ArcMap_default_folder\Default.gdb\jl_sample' count = {' ', 'Null', 'NULL', '<Null>'} textfields = [f.name for f in arcpy.ListFields(fc, field_type='String')] cnt = Counter() with arcpy.da.SearchCursor(fc, textfields) as cursor: for row in ...


0

If we kept the logic and code you posted, the one small change that could improve performance is to make you 'subwatershed' from CopyFeatures_management an in_memory feature class rather than write it to disk. esri link


3

It looks like 1200 and 450 are the dimension of the image in pixels, so the image is 1200 pixels wide by 450 pixels tall. The extent (first line of the cell) is in Web Mercator coordinates, so the pixx and pixy calculations are calculating the dimensions of a single pixel in terms of meters. For example the difference between xmax and xmin is 192,621 meters, ...


5

Here is one approach that gathers a list of field names with a list comprehension and selects the 9th field name in the list for deletion. import arcpy shp = r'C:\path\to\your\shapefile.shp' # Get a list of all the field names fields = [x.name for x in arcpy.ListFields(shp)] # Delete the 9th field in the list arcpy.DeleteField_management(shp, fields[8])


2

You can use a generator expression for this. For example: import arcpy fc = r'C:\path\to\geodatabase.gdb\featureclass' unique_list1 = set(row[0] for row in arcpy.da.SearchCursor(fc, 'myid')) unique_list2 = set(row[0] for row in arcpy.da.SearchCursor(fc, 'myname'))


4

Alternatively, you could just calculate it yourself in the raster calculator. The modified version of the SAVI (MSAVI) does not require an L factor and is a bit more stable across a range of settings. It is derived using the red and nir bands thus: (2 * NIR + 1 - sqrt( (2 * NIR + 1)^2 - 8 * (NIR - RED) )) / 2 References Qi J., Chehbouni A., Huete A.R., Kerr ...


2

To fix your field calculator statement change it to: arcpy.CalculateField_management(out_shapefile,"PhotoName","'" + p[2] + "'","PYTHON_9.3")


3

Create a view of the excel table using Make table view Read the values row by row with da.SearchCursor With string format construct the input parameters strings Something like: import arcpy arcpy.MakeTableView_management(in_table=r'C:\GIS\data\testdata\excelfile123.xls\Sheet1$', out_view='tempview') with arcpy.da.SearchCursor('tempview', ['RegY', 'HunCal', '...


5

import arcpy rasterfolder = r'C:\GIS\data\testdata\outrasters' arcpy.env.workspace = rasterfolder temps = arcpy.ListRasters(wild_card='temp*') precs = arcpy.ListRasters(wild_card='prec*') for temp, prec in zip(temps, precs): print(temp, prec) #Do something Prints: temp1.tif prec1.tif temp2.tif prec2.tif


3

I don"t know exactly what you want to do, but if the names are structured the same way you coul list one input and change its name. It is safer than making two lists if one of the prec%.tif file is missing. import arcpy from arcpy.sa import * arcpy.CheckOutExtension('Spatial') arcpy.env.workspace = r'D:\Data' rasters = arcpy.ListRasters('temp*',"...


0

Check out this thread, Load shapefile in ArcMap using python script You might want to try using a df. Check if the script works within ArcMap.


0

Using ArcGIS Pro 2.6.1 I found that passing a layer object through the ApplySymbologyFromLayer() function, as the first arg, does not work. For whatever reason, you should pass a string through it. So basically change your line from: in_layer = arcpy.ApplySymbologyFromLayer_management(in_layer,in_symbology_layer,update_symbology="MAINTAIN")[0] to: ...


0

If you were more comfortable calculating the inflection in excel, you would only need to log the centerline ID and the measure, then use "Make Route Event Layer" to locate those points along the centerline.


1

An alternative approach is to first create a curvature raster (curvature tool is available in 3D or in Spatial analyst) then get the points where this raster exceeds a given threshold. If you have many streams this could be quite efficient.


-1

I you don't mind using a non-ESRI solution - then Mapshaper (Command Line) will do exactly what want. The -lines option will convert your polygons to topological boundaries from which you would be able to extract the internal (shared) boundaries.


4

Ensure your polylineZ centerlines start at the top of your drainage and point downstream. Split your centerlines into some division lengths that are reasonable for your analysis (like the pixel resolution of your water level raster). Add the Z values from your water level raster using Add Z information. Use the add geometry to attribute table to populate ...


2

Make two feature layers, one for each polygon, Intersect with Line output:


1

the easiest that you can use is polygon to line, but you need an advanced licence arcpy.PolygonToLine_management (in_features, out_feature_class, "IDENTIFY_NEIGHBORS") All lines with a positive left and right FID value are shared (lines that are not shared will have a LEFT_FID or a RIGHt_FID = -1).


1

I believe the issue is to do with your input, it's a CSV file, which is simply a text file not a spatial dataset such as geodatabase featureclass or shapefile. Firstly as as @Nick hints your code is missing the workspace environment setting so it does not know where in_Table is. Either make it a full path string or set the workspace. Secondly you construct a ...


0

yes, that looks like a bug. Had the exact same issue https://support.esri.com/de/bugs/nimbus/QlVHLTAwMDEyMDkwNg==


0

I found a solution to my problem: One has to create a MapImageSharingDraft instead of a FeatureSharingDraft. In a second step, one has to edit the created SDDraft-file (XML) to allow feature access. As a result, two services are being created (one Map Image Service and one Feature Service). Please check the second code sample from the following page (Modify ...


1

Tile Packages are produced from ArcPro by using the Create Map Tile Package processing tool (documentation.) This tool is available from arcpy; the documentation includes python syntax examples. Once the tile package is produced, you can publish it using python.


4

in order to use the value of a variable in a text string, I recommend to use .format(). in practice, write your string with missing parameter in between {} then list all parameters in the format function (separated by ,) arcpy.AddField_management(shapes,'Classific','TEXT') arcpy.CalculateField_management(shapes,'Classific',"!Classific!.replace(!...


7

You have made a basic mistake, you have embed the variable you called field directly within a text expression, i.e. within the "", so it sees it as some text not as a variable. Do something like this: expression = "!Classific!.replace(!Classific!,'" + field + "')" shapes2=arcpy.CalculateField_management(shapes1,'Classific',...


2

Updated: I would suggest trying to use the Spatial Join tool, as it may be better suited to what you are trying to do and then using a similar script to what you have above to store the output in a dictionary, instead of a list. By storing it in a dictionary instead of a list you will be able to store more information, and reference the FIDs as "keys&...


0

I wasn't able to find a solution on the RemapValue help page for calling the RemapValue tables that I 'copied and pasted' into the Python environment (look like this SiteA_remap = arcpy.sa.RemapValue([[1,100], [2,200]]). I had tried to build the RemapValue table name within the Python script (e.g., my_Remap = os.path.basename(inPath) + "_remap"), ...


2

TIN's don't have the concept of cell size, rasters do. If you want to improve the resolution then you need to increase the point density of your input data that you are building your TIN from. So in your case you need to increase the density of lines in your contour dataset or add spot heights.


0

I wanted to share that the service runs successfully after performing a repair install of the ArcGIS Server. This fixed some ArcPy dependencies that were broken by running PIP to install a python package on the server. The ERROR 000816: The tool is not valid. message from ArcGIS Server really meant that the ESRI ArcPy environment was messed up.


0

The code should be like this import arcpy, os #Define the workspace that contains all of the folders with the Sentinel Imagery arcpy.env.workspace = "L:\\Arcpy\\Data\\Satellite_image" #Specify where you would like the output to go output = "L:\\Arcpy\\Data\\Layer_stack" # List of all workspace perviously defind the workspace. folders = ...


3

I think the problem is as commented that result list is not a list of strings but tuples (or sets?). Which you are comparing to string. For example: if ('Name1',) == 'Name1' #False Should be if 'Name1' == 'Name1' #True I think you could shorten the code to: import arcpy tbl1 = r'C:\GIS\data\database.gdb\palmoil' f1 = 'NamePalmOil' tbl2 = r'C:\GIS\data\...


4

If you are using the ArcMap application rather than the ArcGIS Pro application of the ArcGIS Desktop product then I believe you will need to use the ArcPy that installs with ArcMap and that requires you to use Python 2.x.


1

Short Answer: ESRI's Spatial Analysis Map Algebra contains a fixed set of operators which can manipulate rasters. Your desired EXPINT() function is not among them. Longer Answer: Since you want to calculate this value for every cell in a new raster based on constants and the value of a corresponding cell in an existing raster, a new feature called the Raster ...


Top 50 recent answers are included