New answers tagged

0

just got it to work, I had a space in the string...replace with underscore and it worked


1

From the comments it's clear that the issue is bad characters in your output name. I recommend using ValidateTableName to ensure your inputs won't throw the exception. newFc = arcpy.ValidateTableName (newFc, outPath) arcpy.CreateFeatureclass_management(outpath, newFC, "POLYGON")


0

So I figured it out. The issue I was having is that I wasn't referencing down all the way to the REST API URL. Once you give it the feature service URL page to your feature service then it works fine. Code provided below: from arcgis.gis import GIS import arcpy gis = GIS("http://arcgis.com", "XXXXXXXXX", "XXXXXXXXXXX") print("Credentials Verified") ####...


1

It's failing because you're passing in a string to the addLayer function and hoping the method will resolve to the layer you created. In short, it wont. You'll need to be more explicit in what you pass addLayer - the actual layer from the result. In the below code I know that grabbing the first index ([0]) gets the layer object. fooResult = arcpy....


0

Here is the code that I finally successfully got working (with help from the examples above) to solve the problem described here: env.workspace = "C:/Holly/Work/Projects/NavigationStudy2019/Data" # Fetch each feature from the cursor and examine the extent properties for row in arcpy.da.SearchCursor(feature_class, ['SHAPE@', 'id']): ...


3

A few things to note: If you are expecting the changes to be visible when you open the MXD file in ArcMap, save the MXD at the end of your script using the newmxd2.save() method. If you want to export the map (e.g. PNG of PDF) and want to see the changes in the exported file, you don't need to save the MXD as you are only using it as a template. If you are ...


0

As usual, it was a simple thing that was missed. I had neglected to set the output coordinate system and apply a transformation. I added these lines at the beginning: env.outputCoordinateSystem = arcpy.SpatialReference("NAD 1983 UTM Zone 13N") env.geographicTransformations = "WGS_1984_(ITRF00)_To_NAD_1983" The rasters then rendered properly.


3

Assuming you have all your features in the same folder or GDB you can try the following: import arcpy arcpy.env.workspace = r'path\to\your\folder' feature_classes = arcpy.ListFeatureClasses() clip_feature = r'path\to\clip_feature' # this would have to be on a different folder for fc in feature_classes: arcpy.Clip_analysis(fc, clip_feature, 'clip_{}'....


0

I wondered if your code was only applying itself to the first instance, as the indentation isn't correct for a for loop. for index in index_list: # set extent env.extent = index env.snapRaster = index env.cellSize = index This might make the code apply to all the indexes in your index_list.


0

A few things here: 1) output will always be D:\BRB Snow Cover\Sample\output0.tif in your script. You are not changing it anywhere. If this is the expected behaviour (which I suspect is not) and you want to overwrite that file, simply write arcpy.env.overwriteOutput = True. 2) If you want to change the output name and increase it by 1 (which I assume is ...


0

The UploadServiceDefinition tool was originally created to publish services to ArcGIS Server. The ArcGIS/Esri stack has evolved that publishing is now done to a portal (portal and ArcGIS Online are essentially the same thing for the sake of this answer). The in_folder parameter on the tool was used to set the folder for the GIS Server originally. I'd bet ...


0

Using your Trail_Data variable: # select all features query = Trail_Data.query(where='1=1') # save selected features to specified geodatabase query.save("path_to_geodatabase", "new_feature_class_name") I am constantly confused by the ArcGIS API for Python, but from what I gather, your Trail_Data variable is a Feature Collection and the query result is a ...


2

The structure of a Standard Toolbox (TBX) is quite different to that of a Python Toolbox (PYT). You should be able to re-use most of your execute functions but parameter handling is very different. I recommend reviewing the help on writing Python Script Tools e.g. Understanding script tool parameters.


1

The solution turned out to be that I was trying to run the script from a py file inside a toolbox that I created, and not as a saved pyt file.


0

Solved it by slicing my string. Don't know why the output name made a problem, but now it works. for z in mylist: inShapefiles=z basename=os.path.basename(inShapefiles)[:7] arcpy.Select_analysis(inShapefiles,arcpy.os.path.join(outputworkspace,basename),where_clause) ValidateTableName did not work for me without this change. The reason for the ...


2

I've had similar problems when writing to shapefiles where some characters in the filename causes issues (in this case the hyphen). My suggestion is to use the function to validate table names in arcpy: arcpy.Select_analysis(inShapefiles,arcpy.ValidateTableName(os.path.join(outputworkspace,z)),where_clause)


0

I do not know how to project many raster files but I figured a method in ArcGIS Pro. First, find the tool "Project Raster" in the Geoprocessing and then right-click this tool. You will find "Batch" when you right-click the tool. Choose this "Batch" and then you will find the Batch Project Raster, you can choose many raster files in the "Input Raster" and ...


0

The above question is part of a script. The purpose of the script is to create a buffer and do selections based on the percentage of different values. Here is the updated version of my script and hope it is useful for other users. import pandas as pd import arcpy arcpy.env.workspace = "D:/WQ.gdb" arcpy.env.overwriteOutput = True #overwrite the exsiting ...


1

It has been a while since I post this question. The script has been updated since then and I post my answer in the following part for other users. list = [] rows = arcpy.SearchCursor(bufferclip) SumArea = bufferclip + "Area" for row in rows: area = row.getValue("Shape_Area") list.append(area) SumArea = sum(list) print SumArea arcpy....


0

As explained in comments, and demonstrated in the other answer (but not fully explained there), the solution was to make sure that each line is created with the same spatial reference as the polygons. (I had actually tried this earlier, and got an error stating that spatial_reference is a read-only attribute. Turns out I had specified it incorrectly, and ...


0

As they mentioned, you will need some kind of atmospheric or radiative tranfer model to convert to surface reflectance. Try looking into py6s. Python libraries are available already such as this one: https://py6s.readthedocs.io/en/latest/installation.html


2

You can specify the GDB as your workspace and then use the arcpy.ListFeatureClasses() function to get all the names of the features in that GDB: import arcpy arcpy.env.worskapce = r'C:\path\to\my.gdb' for fc in arcpy.ListFeatureClasses(): arcpy.MakeFeatureLayer_management(fc, "lyr") arcpy.SelectLayerByAttribute_management("lyr", "NEW_SELECTION", '"...


3

If you want to get the matching rasters you can zip both lists so you iterate over a list of tuples containing two rasters (one red, one nir) at a time. for rotesband, nirband in zip(liste_rotesband,liste_nirband): print 'red band: {}'.format(rotesband) print 'nir band: {}'.format(nirband) Regarding your edit, you are attempting to use the Float() ...


2

Method "within" works fine, because this script import arcpy import itertools as itt lines="LINES" pgons="PGONS" d=arcpy.Describe(pgons) SR=d.spatialReference g=arcpy.Geometry() curT=arcpy.da.InsertCursor(lines,"Shape@") with arcpy.da.SearchCursor(pgons,"Shape@") as cursor: for row in cursor: pgon=row[0] gList=arcpy....


1

I'd make use of Validate Table Name and GISPro's Alter Domain. You can alter your domain names using Validate Table Name to remove spaces. Untested since I don't have ArcGIS Pro: inGdb = r"Domained\gdb" outGdb = r"output\gdb" #---- print ("importing") import arcpy import os print ("listing domains") domains = [d.name for d in arcpy.da.ListDomains (inGdb)]...


1

In your code Polygon_Neighbors is a table. You'll need a table view to perform your selection. Polygon_Neighbors_tv = arcpy.MakeTableView_management (Polygon_Neighbors, "Polygon_Neighbors_tv") [0] # Process: Select Layer By Attribute arcpy.SelectLayerByAttribute_management(Polygon_Neighbors_tv, "NEW_SELECTION", "src_MapUnit = nbr_MapUnit") Note that you ...


0

Set your python interpreter in File->Settings->Project Interpreter to C:\Python27\ArcGIS10.5\python.exe and you may need to change the run/debug interpreter for your script in Run->Edit Configurations... to the same python.exe.


0

This script worked for me: (inspired by previous answers and from examples here: https://pro.arcgis.com/en/pro-app/arcpy/get-started/writing-geometries.htm) Get the extent of the raster Save extent values as points (coordinates in [x,y]) Create new feature class to store new geometry Insert cursor as geometry to new feature class Script: # Create ...


1

Off course after I've asked the question I know the answer. After using Searchcursor I still have to iterate through it. Changed the last line in the else to this and it works: with arcpy.da.SearchCursor(inl, '*', where_clause=ftext) as feats: featureIterator = [] for f in feats: ...


0

This isn't really an ArcGIS arcpy issue. You'll get the same error if you try to use any python module/package that you haven't imported (into the correct scope). You need to import arcpy at the top of your module (or at the top of any script that uses the arcpy package) i.e # Test.py import sys sys.path.append(r"N:\Common\Script\Drivers") import ...


1

You'll need to create a variable to track your condition. In the examples, I used "failure", which is initialized to False--indicating that no rows are missing a map unit. Later, during the cursor, if any row is missing a map unit, you update the failure variable to True. Then, after your cursor iteration, you can check whether failure is True. If you want ...


2

In ArcGIS Desktop 10.x you use arcpy.mapping.Layer lyr = arcpy.mapping.Layer(r"path\to\file.lyr") print lyr.name In ArcGIS Pro you use arcpy.mp.LayerFile: lyrFile = arcpy.mp.LayerFile(r"path\to\file.lyrx") for lyr in lyrFile.listLayers(): print(lyr.name)


3

The JSON to Features tool won't work for your case. The tool wants either esri JSON or geoJSON. The JSON from that link is neither of those, it's straight up regular JSON. You'll need to find another parser to turn JSON into a shape/fgdb/geo-something. You could research using cursors and building your own featureclass by parsing the JSON manually. There ...


3

Heavy handed solution, no scripting: Spatial join of counties one to many to your culvert lines, i.e.pages will result in 1800 polygons, each having page name. Add polygons to reference dataframe and apply DDP definition query (match) on this layer. I called it MANY_POLYGONS. Use properties of reference dataframe as follows: Works like a charm.


1

Yes, you can do this using a script tool validator. You would also need to configure the parameter (in the tool's properties) to 'Value List' for its 'Filter' property. See the documentation at: Customizing script tool behavior As the doco says, Validation is everything that happens before a tool's OK button is clicked. This can include populating ...


2

You need to specify an output feature class. parcelsFC = os.path.join('temp.gdb',JsonDirectoryLocation) outFc = os.path.join ("temp.gdb", "JsonFeatures") arcpy.JSONToFeatures_conversion(parcelsFC, outFc)


3

sys.exit (1) ends the script. Get rid of this line. with arcpy.da.SearchCursor(MapUnitPolys, ['SHAPE@', 'MapUnit', 'OBJECTID']) as cursor: for row in cursor: #arcpy.AddMessage(str(row[1])) # Does this Polygon have a map unit if row[1] == "" or row[1] is None or row[1] is 'NULL': arcpy.AddMessage('Polygon OBJECT ID:{} ...


0

Instead of name, go with the layer's catalogPath property. This will return the full path of the layer's feature class. If outPath is the full path of the buffer output: for layer in layerList: if arcpy.Describe (layer).catalogPath.lower () == outPath.lower (): arcpy.mapping.RemoveLayer(df, layer) If outPath is the feature class name that ...


0

Just some thoughts about working with graphs in Python. I believe the base ArcGIS Pro and Desktop both come loaded with Numpy and Scipy, so these should be available to everyone. You could consider using a sparse matrix instead of a dictionary of lists. These will use less memory and be faster computing. You can also perform djikstra's shortest path ...


3

In VB .net if you want to save an object to file to be used later, e.g. a dictionary you would serialize it. I believe the equivalent in python is pickle. Be aware not all objects can be "pickled", I would imagine especially anything arcpy related (but I may be wrong). So if you are extracting network topology as dictionaries then you should be able to ...


0

I found that if I create a Unique Field by using "CAST" fixes the issue. Please see the sample script: arcpy.MakeQueryLayer_management(DB, "Layer_Union", """ SELECT CAST(FEAT.EVENT_ID as varchar(10)) as EVENT_ID, SP.MEASURE AS ABS_START, SPL.MEASURE AS ABS_END, FEAT.TYPE_CL AS FEATURE_TYPE, FROM TBL1 FEAT INNER JOIN EVENT_RANGE ER ON FEAT.EVENT_ID = ER....


2

Try instead to put your list of buffered outputs into a list object. You might also set the workspace option before proceeded, otherwise ArcMap will send the output from the union to the default geodatabase. arcpy.env.workspace = "path to output folder or geodatabase" arcpy.Union_analysis([buffer1, buffer2, buffer3], buffered_area) Or if you know the path ...


1

buffer1, 2 and 3 are result objects not the buffer outputs. Try: arcpy.Union_analysis([outpath, outPath1, outPath2], buffered_area, "ALL", "", "GAPS")


1

Never tried it before, but I guess it should be feasible this way: Get the index layer's row object for the active or current page with pageRow property of DataDrivenPages object Get the county name in the row (see here to understand what is a row and how to use it) Select the county in the couty layer using the extracted couty name from the index layer's ...


1

It seems that it only occurs with the combination of *.lyr files and "Local Database" filter, but other types of files are filtered out as expected. The filter works fine for the other workspace type options. As a workaround, you can check by yourself that the input value is indeed a file geodatabase and then use the internal validation of the tool to add a ...


0

I wanted to insert a new answer rather than editing my previous one as this comes with a new solution that should handle the problematic of updating the geometries of polygons with more than one inner ring as well. The OP in the comments pointed out that my other answer didn't work for the case "two donuts in one polygon". Trying myself I was susprised but ...


5

Use a dictionary: The main operations on a dictionary are storing a value with some key and extracting the value given the key. d = {1:"Lightning", 2:"Equipent use", ... } with arcpy.da.UpdateCursor(fc, ["CAUSE_TEXT", "CAUSE"]) as cursor: for row in cursor: if row[1] in d: #Check if value of row[1] exists in dictionary row[0] = ...


1

Your case is very interesting to me as it reveals that explode_to_points=True is indeed "deconstruct(ing) a feature into its individual points or vertices." (as stated in the arcpy.da.UpdateCursor help). HOWEVER as in a Polygon, the first and last vertex of a feature (and all its parts) are coincidents, it seems that updating the geometry of the first ...


4

No, the problem does not have anything to do with ArcGIS or arcpy. SyntaxError means that there is a problem with the syntax of your program and it identifies this error before running anything. In your case, you have an opening parenthesis that should not be there and is triggering the error. On the line: structureMultiplier = (arcpy.GetParameterAsText(5) #...


0

You used to be able to accomplish this in ArcGIS Desktop through an ArcPy Add-in. This allowed you to create a toolbar and capture mouse activity. I'm not familiar enough with ArcGIS Pro, but it doesn't seem to have this available. The alternative seems to be to using their SDK and Microsoft.NET (VB or C#). That would certainly give you the ability to create ...


Top 50 recent answers are included