New answers tagged

0

Thanks a lot for all your advises. I solved my problem with following code: #creating a list ->"mast_value" with unique values of field [ID_1] with arcpy.da.SearchCursor(inLAS[:-4] + '_POLE_POINTS.SHP','ID_1') as max_cursor: for row in max_cursor: mast_value = sorted({row[0] for row in max_cursor}) #iterate through the list ...


2

From the python docs: zip() in conjunction with the * operator can be used to unzip a list: So you could do: with arcpy.da.SearchCursor(fp_in, ['OBJECTID', 'name']) as cursor: rows = [row for row in cursor] # I don't know if zip() works with cursor (can't test) objectid, name = list(zip(*rows)) # If it does work, use objectid, name = list(zip(*...


-1

You can use pyqgis to automate such things. Look at https://kartoza.com/en/blog/how-to-create-a-qgis-pdf-report-with-a-few-lines-of-python/ which was done using QGIS 2 series. You can easily adapt this to the Pyqgis 3 syntax. For a gentle introduction to Pyqgis read https://anitagraser.com/pyqgis-101-introduction-to-qgis-python-programming-for-non-...


1

Use listfields, da.UpdateCursor and strip. import arcpy y=r"shape path" fieldlist= [f.name for f in arcpy.ListFields(y, "", "String" )] with arcpy.da.UpdateCursor(y,fieldlist) as cursor: for row in cursor: row = [val.strip() for val in row] cursor.updateRow(row)


1

cursor.updateRow(row) not being inside the for loop must be causing StopIteration: iteration not started. The iteration is already finished when reaching updateRow in the code. Try indentating it: with arcpy.da.UpdateCursor("C:\Users\daniel.cortes\...",FieldListnames) as cursor: for row in cursor: ConcList = [] for i in ...


0

The following code will insert into an existing point featureclass the points where a Z change of greater than 1 unit occurs based upon the specifications you state in your comments: import arcpy try: myLayer = "fcPolylineZ" prev = -1 heightDiff = 1 pntList = list() with arcpy.da.SearchCursor(myLayer,["SHAPE@"]) as cursor: for ...


1

SHAPE@Z —A double of the feature's z-coordinate. So it is one z value which you cant iterate over. It's like trying to do: for z in 123.456: print(z) builtins.TypeError: 'float' object is not iterable You probably want SHAPE@ —A geometry object for the feature. to later access z of each vertice.


1

ENIAC-6, this maybe a bit long as there's quite a bit of background. Some background arcpy.TestSchemaLock returns True if a lock can be applied, else False. with regards to 64 & 32 bit background processing are not part of the ArcGIS Pro application. They are an ArcGIS Desktop/ArcMap feature. ArcGIS Pro is a multi-threaded application, gp tools (...


0

I've never used scipy but looking at the help file for expi() it says the input is an array and if you follow the code sample it works on the array they demonstrate with. Now if you type type(uw) after the line that creates uw, it returns raster and not array. I suspect thats the source of your problem? You can convert raster into arrays using this ...


3

With the help of Midavalo answer, I figured out how to set up autocomplete for my VS Code. In VS Code just go under File -> Preferences -> Settings and then within Settings go for Text Editor -> Suggestions -> Quick Suggestions and open settings.json(Edit in settings.json). Over there add the same line of code that Midavalo posted { "python.pythonPath": '...


8

What I had to do to get IntelliSense working with my arcpy project in VS Code: In my project folder I created a new folder called .vscode In this folder I created a file called settings.json, and added the following to the json file: { "python.pythonPath": "C:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\python.exe" } This is the ...


0

This page has a bunch of relevant examples: https://pro.arcgis.com/en/pro-app/arcpy/get-started/writing-geometries.htm. I modified the final example on the page to match your coords. Though I've no idea what projection (coordinate system) those values are in, so I just picked 26904 out of a hat (you'll need to correct that) I didn't test it, but I think it'...


3

When using ArcPy, instead of using larger/complex datasets (that may have characteristics that are not obvious to anyone not frequently using them), whenever I create a minimal reproducible example or code snippet I try to generate the test data as part of it. I am including below some test code that I used to develop an eLearning lecture named "Creating ...


3

Add this to your code, above your line where you export the table. import arcpy arcpy.env.overwriteOutput = True arcpy.TableToExcel_conversion("UniqueTandR",toolpath+"/FinalResult.xls","ALIAS","DESCRIPTION")


0

I ended up solving this by using the arcpy.Select_analysis tool (https://desktop.arcgis.com/en/arcmap/10.3/tools/analysis-toolbox/select.htm) to replace all of the code I was using in the definition query. This selected everything I was interested in and exported it to a new file. I applied the same logic as before (see lines 3,4 and 8 of my original post) ...


2

I think you need to change: row[1] = scvDict(mxLoc) to row[1] = scvDict[mxLoc] Also, oldAddr is currently unused, which is fine, but you could change this line to use it. print("Looking at row {0} with an address of {1}.".format(mxLoc, oldAddr))


2

Without knowing exactly what error you're getting, it's hard to help troubleshoot for you. However, I noticed that you're passing a list of layers into the AddFieldDelimiters function. You've defined lyrs as a list of layers in the MXD. The tool takes a string as per the documentation. Which, I believe would be l.name, in your case. EDIT: Your MXD is ...


1

I think there are 2 problems: i coming from your rasterList is not being constructed correctly and how you are building your expression to use in CON(). Firstly you create rasterList by searching a workspace and this returns a list of raster names, not the full path to the raster. So your input into your CON() expression should be something like: ...


1

All of the Mosaics are saved to the same output folder. Instead of using dirpath when creating your new raster use the same path each time. outPath = r"C:\some\path" for dirpath, dirnames, filenames in walk: .... #other code arcpy.MosaicToNewRaster_management(rasterList, outPath, "Mosaic.tif", "", "", "", 1) Append the sub-directory name (Ex. ...


1

It looks like you are working with data in a geodatabase. Multiprocessing doesn't work on feature classes in a geodatabase because each update acquires a lock. According to https://www.esri.com/arcgis-blog/products/arcgis-desktop/analytics/multiprocessing-with-arcgis-approaches-and-considerations-part-1/: ...will not work with feature classes in a file ...


1

These are great resources for your issue. https://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-classes/geometry.htm https://pro.arcgis.com/en/pro-app/arcpy/data-access/updatecursor-class.htm import arcpy # Location of point and polygon shapefiles arcpy.env.workspace = r'C:\gispy\stackexchange' Point = 'Point.shp' Polygon = 'Polygon.shp' polyGeom = ...


1

The answer to your question is yes, the Clip Raster tool does exactly that. https://pro.arcgis.com/en/pro-app/tool-reference/data-management/clip.htm Your issue is that you are working with a very large raster from an image service, and running into memory limitations. I think its just going to take a long time. You could try writing the output to memory if ...


0

To add a dash 2 spaces from the left you can do: fc= fc[:-2] + "-" + fc[-2:] Based on your question and example I'm not sure exactly what your goal is, but I think you would want to replace the cursor with the following to get your desired output: with arcpy.da.UpdateCursor(fc, [file_name_field]) as uc: for row in uc: row[1] = (fc[:-2] ...


0

Found a work-around for this issue. A summary of possible solutions is below: The manual way: open the troublesome MXD in ArcMap application, then just save it. With Python script: access MXD and use saveACopy with specific version of the new MXD. In my case (ArcMap 10.6), all MXD files have been saved to ArcMap 10.3 (no idea why 10.4 and 10.5 are not ...


1

Using this answer to Change nameString using arcpy? I was able to solve the problem. In order to not remove the original layer from the Table of Contents it does need to be created with a different name. In my case I just appended "_clip." You can then change the nameString in the following way: desc = arcpy.Describe(lyr_outname) if "_clip" in desc....


2

The aprx.listMaps() methods returns a list object with all the maps for the ArcGIS Projects. If you pass a wildcard, in your case "pdf_template", it will still return a list with all the maps that match the wildcard (even if it is only one). In order to use the listLayers() method, you need to get the map first by indexing the list. For example, to get the ...


1

This should do the trick. It uses a pandas dataframe with the newer da.SearchCursor. import arcpy import pandas as pd df = pd.read_csv(r"path", usecols = ["GISID"]) fc = r".shp" fields = ['GISID'] gis_poles_assets =[] with arcpy.da.SearchCursor(fc, fields) as cursor: for row in cursor: gis_poles_assets.append(row[0]) for index, row in df....


1

You are using the old cursor which is much slower than the data access cursor. Create a view of the csv and use cursors on both shape and view to list all values then compare using sets: import arcpy fc = r'C:\GIS\ArcMap_default_folder\Default.gdb\ak_riks' fcfield = 'polenr' poles_in_fc = [f[0] for f in arcpy.da.SearchCursor(fc, fcfield)] csv = r'C:\GIS\...


1

Use da.SearchCursor with distanceTo and disjoint methods of Polyline object: import arcpy, itertools fc = r'C:\GIS\ArcMap_default_folder\Default.gdb\jl_sample' #Change dist = 300 #Change arcpy.MakeFeatureLayer_management(in_features=fc, out_layer='lyr') linelist = [row for row in arcpy.da.SearchCursor(fc,['OID@','SHAPE@'])] oids_to_select = [] for ...


0

Eventually figured out the answer to this. The product needs to be set to uploaded to the server then the service name had . and - in it. These cause an error in arc pro but not with the python api, until it ends up publishing to the server and then it fails somewhere deep in the guts of the server.


2

This is due to an older version of SQLite distributed with ArcDesktop 10.4 (SQLite version 3.6.21) where 'WITH' statements are not implemented (they were implemented in 3.8.3) If updating SQLite is not an option (as it isn't for me), any SQL using a 'WITH' statement must be rewritten as a subquery. Subqueries may be used in the SELECT, FROM, WHERE, and JOIN ...


1

With if not f.endswith('final.shp') or f.endswith('final.tif'): You are saying: if it does not end with final.shp or: if it does end with final.tif Enclose in parenthesis: if not (f.endswith('final.shp') or f.endswith('final.tif')): Or pass a tuple to endswith: import arcpy, os path = r'C:\GIS\Data' keep = ('final.shp','final.tif','final.TIF') for ...


0

I think the MapSeries class, and creating MapSeries objects using the Layout class, are useful for map series requirements that are relatively straightforward. Whenever, I have more complex requirements, I instead use a SearchCursor to iterate the index layer, and zoom to the extent of each feature in it, before exporting a PDF file for each of those ...


1

You can use the format() method to include specific values inside your strings. Furthermore, I think the field name does not have to be inside quotes but I may be wrong. You could write the following inside your for loop: for row in cursor: fid = row[0].zfill(4) query = '''FID_{}_T <> -1 AND FID_{}_L <> - 1'''.format(fid, fid) arcpy....


2

With cursor = arcpy.da.InsertCursor(out_fd+"/Turn_Lines", ["SHAPE@"]) You already decided to only be able to insert one value: SHAPE@ then you try to insert two: [polyline] and r_UFI You need to include both when creating the cursor: import os cursor = arcpy.da.InsertCursor(os.path.join(out_fd,"Turn_Lines"), ["SHAPE@","somefieldname"]) And the field "...


0

As commented by @BERA: When you do for r in rasters, r will be a single raster. If Sample wants a list of rasters and you are inputing one raster (r) it will not work.


1

I'd find your first geometry with a search cursor. Then iterate how many times desired, create new geometries based on the last iteration, and store those geometries in a list. Finally, use an insertcursor to insert your geometry. #number of iterations iterations = 50 #get first geom with arcpy.da.SearchCursor (infc, "SHAPE@") as curs: lastGeom = curs....


1

There are a few different ways you can get VS Code to work with ArcGIS Pro Python. I'm not going to list them all, just the way I've started using for every thing I do. Make sure you have the Python extension for VS Code installed from the Marketplace Press CTRL + , (comma) to open the settings. From here if you type pythonpath it'll filter down to some ...


0

It's still a bit buggy (remap values don't populate automatically), but I managed to get something working (10.7.1) based on your original code and some help from the ESRI forum. In order to activate the "Classify" button, which is initially grayed out, click on one of the other buttons... "Reverse New Values" or "Precision..." and that should activate the "...


2

The path you're building up is probably NOT correct per: data_dir = r"C:\Users\Stephanie\NOTEBOOKS\FINAL\FSI" item = gis.content.add({}, data_dir + csv) I'd expect this to create a path like: C:\Users\Stephanie\NOTEBOOKS\FINAL\FSImycsv.csv (note the lack of \ separator between path and file name) I'd suggest doing your path like: item = gis.content.add({},...


1

I figured out my issue. The key field in my data was a string, not an integer. Therefore, the key values need to be in single quotations marks in the SQL string. Here is my fix: keyStr = "\'" + "\', \'".join(map(str, pointsArr['KEY'])) + "\'" sql = "key IN ({0})".format(keyStr)


1

The addDataFromPath() method of the Map class expects a path to a dataset like a shapefile rather than a path to a workspace like a folder that contains a shapefile. You are currently providing the latter.


0

After a long time, finally got the answer on my own — you can simply do it like this: File_YouWant_ToGetExtent_From = arcpy.GetParameter(0) .... arcpy.env.extent = File_YouWant_ToGetExtent_From


Top 50 recent answers are included