|
POST
|
Very helpful! I thought nesting meant what you explained and I thought that's what was happening in the revised script. But it ended, so it's not considered nested anymore. Woohoo! As for your question: I'm not sure what was meant here; this was the part in the revised script where everyone was talking about loading all the data into memory first, so I thought I'd try it. Obviously it didn't work... Thanks, all. Appreciate the help!
... View more
09-19-2023
05:33 AM
|
0
|
0
|
530
|
|
POST
|
I can't thank you all enough for your insights! @HaydenWelch , your edits all make sense. However, when I tried to implement the edits, there were a couple of issues. There was an "EOL: String literal" error after the HUC10_RSTFile_Path after I changed the path to include the "r" at the beginning and removed the duplicate "\" in the path. I reverted back to the original path, which worked. Any idea why this might have errored? Also, why is the "r" solution better? I really like the "loading whole dataset into memory" idea, although the dataset size isn't as large as what you're working with, so it's not extremely necessary. However, I did try to implement it because, why not? There was an error saying that "row" wasn't defined. I thought I had it straight, but I guess I didn't. Here's what I inserted: with arcpy.da.SearchCursor(Point_Buffer_Output, fields) as cursor:
rows = [row for row in rows_to_dict(cursor)]
for row in rows_to_dict(cursor): So, I just wrote it singularly (the whole dataset wasn't loaded into memory). Lastly, the Append didn't work. The fields were added but no shapes/data were appended to the feature class. So, to "fix" my script, I modified the sql expression as @AlfredBaldenweck mentioned. It's running now. However, based on all of the feedback, I know it's not clear/efficient/"good" Python, so I'm interested in your thoughts on my questions above. And last question: in the dialogue between @HaydenWelch and @VinceAngelo , you guys talk about not nesting insert and update cursors. But isn't that what was implemented in my script you modified (lines beginning 115 and 129)?
... View more
09-18-2023
07:49 AM
|
0
|
3
|
3838
|
|
POST
|
I have a Python script I created after my ModelBuilder model got too clunky and slow, but I'm stuck. I have a point shapefile that I want to buffer then run Zonal Statistics on that buffered point. Following that, I need to run raster calculator, int, and raster to polygon geoprocessing tools so the value output by the Zonal Statistics tool can be copied to another shapefile. There is also another attribute that needs to persist throughout. I've been having trouble with SearchCursor; it isn't iterating. It uses all the features in the input shapefile rather than the one it's on. So, I decided to try selecting the row it's on and exporting to a new shapefile, but I don't know how to include row[] in the SQL expression (I know the one in the code is incorrect). I'd appreciate any help--please be kind, though! I'm learning! I've also included a screen shot of my model that works in ModelBuilder, in case that helps. import sys
import arcpy
from arcpy.sa import *
import math
import os
arcpy.env.overwriteOutput = False
# Check out any necessary licenses.
arcpy.CheckOutExtension("spatial")
arcpy.CheckOutExtension("ImageAnalyst")
arcpy.CheckOutExtension("3D")
# Model Environment settings
Depression_NHD_Intersect_Layer = "D:\\Projects\\TESTING_Depression_NHD_Intersect.shp"
AOI_Raster = "D:\\Projects\\0710000404_DeerCreekDesMoinesRiver.tif"
HUC10_RSTFile_Path = "D:\\Projects\\RSTFiles\\"
HUC10_SHPFile_Path = "D:\\Projects\\SHPFiles\\"
Point_Buffer_Output = HUC10_SHPFile_Path + "Buffer.shp"
fields = ['FID', 'DepressFID']
#Create Empty Feature Class
FP_Intersections_Elev = arcpy.management.CreateFeatureclass(HUC10_SHPFile_Path, "FP_Intersections_Elev_TEST.shp", "POLYGON", "D:\\Projects\\FP_Intersections_Elev_TEMPLATE.shp", "DISABLED", "DISABLED", "D:\\Projects\\FP_Intersections_Elev_TEMPLATE.shp")
#Buffer
arcpy.Buffer_analysis(Depression_NHD_Intersect_Layer, Point_Buffer_Output, "3 Meters", "" , "" , "NONE", "" , "PLANAR")
with arcpy.da.SearchCursor(Point_Buffer_Output, fields) as cursor:
for row in cursor:
Make_Feature_Layer = HUC10_SHPFile_Path + str(row[1]) + '.shp'
Single_Buffer_Layer = HUC10_SHPFile_Path + "DepressFID_" + str(row[1]) + '.shp'
Zonal_Stats_Output = HUC10_RSTFile_Path + "ZoneStats_" + str(row[1]) + '.tif'
Raster_Calc_Output = HUC10_RSTFile_Path + "RasterCalc_" + str(row[1]) + '.tif'
Int_Output = HUC10_RSTFile_Path + "Int_" + str(row[1]) + '.tif'
Raster_to_Poly_Output = HUC10_SHPFile_Path + "NHD_Poly_" + str(row[1]) + '.shp'
sql = '"FID" = \'(row[0])\''
#Make Feature Layer
arcpy.Select_analysis(Point_Buffer_Output, Single_Buffer_Layer, sql)
#Zonal Statistics
outZonalStats = ZonalStatistics(Single_Buffer_Layer, "DepressFID", AOI_Raster, "MEAN")
outZonalStats.save(Zonal_Stats_Output)
#Raster Calculator to prepare to change value to integer
outRasCal = RasterCalculator([Zonal_Stats_Output], ["x"], "x*1000000")
outRasCal.save(Raster_Calc_Output)
#Int (integer) Raster
outInt = Int(Raster_Calc_Output)
outInt.save(Int_Output)
#Raster to Polygon
arcpy.conversion.RasterToPolygon(Int_Output, Raster_to_Poly_Output, "NO_SIMPLIFY", "VALUE")
#Add Fields to Polygon Layer
arcpy.management.AddField(Raster_to_Poly_Output, "DepressFID", "LONG")
arcpy.management.AddField(Raster_to_Poly_Output, "gridfloat", "FLOAT")
arcpy.management.AddField(Raster_to_Poly_Output, "elevft", "FLOAT")
#Calculate New Fields
arcpy.management.CalculateField(Raster_to_Poly_Output, "DepressFID", row[1])
arcpy.management.CalculateField(Raster_to_Poly_Output, "gridfloat", "!gridcode!/1000000", "PYTHON3")
arcpy.management.CalculateField(Raster_to_Poly_Output, "elevft", "!gridfloat!*3.2808", "PYTHON3")
#Append shapefile to FP_Intersections_Elev shapefile
arcpy.management.Append(Raster_to_Poly_Output, FP_Intersections_Elev, "TEST", "" , "" , "" , "" , "NOT_UPDATE_GEOMETRY")
#Delete Intermediate Files
arcpy.management.Delete(Zonal_Stats_Output)
arcpy.management.Delete(Raster_Calc_Output)
arcpy.management.Delete(Int_Output)
arcpy.management.Delete(Raster_to_Poly_Output)
print("Completed DepressFID: " + str(row[1]))
print("All DepressFIDs Completed!")
... View more
09-15-2023
11:51 AM
|
0
|
11
|
4501
|
|
POST
|
Thanks for the information! I did notice in the blog post, though, that using the Esri geocoder consumes credits. I was hoping there was a solution that didn't, as I have the county data available to me already. I think the biggest hurdle is trying to get the coordinates of the centroid of my polygon. Any ideas on how to pull that?
... View more
07-21-2023
08:48 AM
|
0
|
0
|
1769
|
|
POST
|
Hello! I've been doing a lot of research this morning on my problem, and I think there's a solution out there but everything I've come across is a little bit different of a situation and I need some help! I have started a survey in Connect. In this survey, the user draws a polygon and answers questions about practices they want to employ in that area. I am using Power Automate to direct the sites to be reviewed by the appropriate person. To utilize this to the fullest extent, I need to have a question about the county the area is in. I currently have it as a question for the user to populate, but I want to make it as automated as possible. I would like a hidden field to be populated with the county name based on the polygon the user draws. I have done this before using a geopoint--that's easy! However, the change to a geoshape makes things a little more tricky. I think the necessary workflow is to first get the centroid of the polygon and then pass those coordinates to another field to get the county name, but I'm not sure. And the things I've tried (e.g. pulldata) haven't worked. Any ideas? I'm open to other workflows, too. @IsmaelChivite
... View more
07-18-2023
07:33 AM
|
1
|
3
|
1806
|
|
POST
|
If it only worked like that every time... I had to do the above workflow twice to get it to "stick." Stinks that you have to close out of the map and reopen just to see if it worked. Would be a nice fix on the next update!
... View more
05-16-2023
12:13 PM
|
4
|
0
|
8265
|
|
POST
|
I am using the new map viewer for creating web maps and I'm pulling my hair out trying to figure out how to update the default map view; that is, the extent that is zoomed to when the "Home" button is clicked. I've read that this can be done in the "Set Extent" in the web map settings page BUT 1) it's not working and 2) my layers don't appear in that view so I can't know where or how far zoomed in I need to be. This workflow is clunky and results in so much extra work. Sometimes the extent is saved when I save the web map but that doesn't happen every time. Anyone have any insights?
... View more
05-16-2023
09:47 AM
|
1
|
5
|
8294
|
|
POST
|
Hello! I am wondering if there is a way to use the "Clip Layers" function (Map Properties, Clip Layers, Clip to an outline) that clips the layer but not the symbology? I have a point layer where there are features right inside of the layer I've used to clip with and the point symbology is cut off. I'd like to see the entire symbol of any feature that lies inside of the clip layer. I know I can export and create a new layer or use a definition query, but I have 20 maps to make and I don't want to have to make new layers for each and the attribute table doesn't have a field that will query out what I need.
... View more
02-14-2023
05:34 AM
|
1
|
2
|
1518
|
|
POST
|
Thanks for the quick reply! Only a single feature. Also not multipart. Yes. However, the behavior is seen whether: The "Allow reshaping without a selection" is checked and a feature is selected The "Allow reshaping without a selection" is not checked and a feature is selected The "Allow reshaping without a selection" is not checked and a feature is not selected It is. Layer is in NAD 1983 HARN Michigan GeoRef (Meters) and the Map is in NAD 1983 StatePlane Michigan Central FIPS (Intl Feet). I did not create this project so I don't know if there's a reason these systems were chosen. No curves involved. This behavior occurs when I use the line or streaming tool within reshape. The streaming tool is using a 5 ft stream tolerance and the smoothing option is checked. Data are stored locally. I delved deeper into point 3. I changed the map coordinate system so it was the same as the layer and the reshape worked. I immediately changed back so it would project on the fly and the reshape didn't work. Might be the culprit right there! Annina
... View more
12-29-2022
11:27 AM
|
1
|
1
|
1935
|
|
POST
|
In case anyone else has this issue... The polygon must surround an entire pixel for this to work. So, what I did was create a new feature class, zoom to each point, and create a square around the pixel that the point was in. In future iterations, I'll probably buffer the point more so I won't have to manually create the training set.
... View more
12-29-2022
10:03 AM
|
2
|
0
|
3424
|
|
POST
|
Hello! I am using ArcGIS Pro 3.0.2 and have been having troubles with using the reshape tool. I try to reshape a polygon but get the following error: "New geometry must intersect the feature in at least two places." However, the geometry does! See the screenshot: This behavior isn't consistent; sometimes it doesn't reshape and sometimes it does. I have tried: 1. Repairing geometry 2. Allow reshaping with and without a selection 3. Drawing the reshape line starting in different locations (thinking maybe the reshape has to follow the same direction the original polygon was drawn in) 4. Reshaping the same area except making it larger rather than smaller Nothing works. I have to split a feature and then delete the portion I don't want. Any ideas on what might be happening?
... View more
12-29-2022
10:00 AM
|
0
|
3
|
1977
|
|
POST
|
Hello all! I am trying to perform an image classification using a supervised, pixel-based configuration. I'm using ArcPro 3.0.2 I have a classification schema and training samples dataset created. Here is the schema: classname: Marsh, classvalue: 0; classname: Water, classvalue: 1. I have created these fields in my training samples dataset; classname as text and classvalue as long integer. The dataset was created by creating random points and then two people interpreted the imagery to classify the points as marsh or open water. This was done for classification accuracy purposes. It was my understanding that these data could be input into the image classification workflow as the training samples rather than manually drawing them in the moment. In the Image Classification Wizard, I can get to the Training Samples Manager section, but can't get any farther. Here is the issue: the schema loads great but my training samples dataset doesn't show up in the bottom half of the window. There is no place even to manually load the data. I've also tried accessing the Training Samples Manager tool by itself (outside of the Image Classification Wizard) but am running into the same issue. I can navigate to my training samples data set and press open, but nothing happens. I have tried point and polygon layers here.
... View more
12-03-2022
09:31 AM
|
0
|
2
|
3517
|
|
POST
|
Answered my own question... Rename outputs in the model without %%. This won't change the actual output name, just how it's seen in ModelBuilder.
... View more
10-04-2021
09:09 AM
|
0
|
0
|
1971
|
|
POST
|
All, I am trying to automate a process in ArcPro and I'm getting an error when running my model that doesn't occur when I tested manually. Here's the basics of what I'm doing: I have one raster (DEM) and one feature class (polygon). I'm iterating through each feature in the feature class and clipping the raster with that individual polygon. I'm using the FID field as the iterating value. Once the raster is clipped to the individual polygon, I need to run an expression using Raster Calculator as follows: Con( "%DrainageDitch1_clp_%FID%.tif%" >= (0.8*( "%DrainageDitch1_clp_%FID%.tif%".maximum - "%DrainageDitch1_clp_%FID%.tif%".minimum) + "%DrainageDitch1_clp_%FID%.tif%".minimum), "%DrainageDitch1_clp_%FID%.tif%") This gives me the cells that have elevations in the top 20% of the polygon area. When this is run manually using Raster Calculator (without the %), it works as expected. However, when run in ModelBuilder, I receive an error: ERROR 000539: Traceback (most recent call last): File "<expression>", line 1, in <module> File "<string>", line 5, in rcexec_DC684390_0C54_4F14_9EBF_B34DF3F2E1B1 AttributeError: 'str' object has no attribute 'maximum' Failed to execute (Raster Calculator). I've tried rewriting the expression in many different ways, including removing the %% and "" around the raster input (except for around FID), and I still get the same error. Also, the iteration runs fine before the Raster Calculator part is added. Ideas to get around this? Thanks, Annina
... View more
10-04-2021
08:33 AM
|
0
|
1
|
1975
|
|
POST
|
Hey all! I am working on a project where I am needing to delineate subwatersheds that take into account agricultural tile drainage lines. I've done a bit of research, but nothing I've found quite gets what I'm after. I don't need to find the tiles; I already have a line dataset that represents the public tile drainage system. The problem is that these tile systems can cross typical surface-flow watershed boundaries. I'd like to create my own subwatersheds and have the tiles be taken into account. Anyone know of how I might be able to accomplish this? See my example below: blue line is NHD, green line is tile, pink is existing HUC8, and yellow area shows drainage direction (and my guess on what should be added to the area to take into account the subsurface drainage). Thanks, Annina
... View more
02-18-2021
10:21 AM
|
0
|
0
|
1126
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-10-2024 05:11 AM | |
| 1 | 09-12-2025 11:19 AM | |
| 1 | 09-12-2025 10:33 AM | |
| 6 | 08-14-2025 11:12 AM | |
| 1 | 08-01-2025 11:13 AM |
| Online Status |
Offline
|
| Date Last Visited |
Friday
|