|
POST
|
This was a typo on my part, env.scratchFolder is what I meant. Sorry about that. I will edit the code above since it is marked as the answer. So glad that worked for you! If performance is a problem (ie you do this a lot) you could probably speed it up two ways: 1) Up the aggregate from 5 to 10 or 20 and 2) use the "NO_SIMPLIFY" option to the Raster To Polygon step to avoid the generalizing which for a spatially complicated raster may slow things down a bit. T hough there is no way to speed it up too much because you have to look at every cell to capture all the raster geometry. I just thought of a second approach, which would be to run Zonal Statistics As Table of your raster with the test polygons as zones. This would create a table with one row for every polygon that had an overlap. You could then perform an attribute join from your polygons to the Zonal Statistics As Table output to select the polygons that overlap. This may be much faster as there would be no raster to polygon conversion (only polygon to raster, which should be faster). But of course if your problem is solved, the discussion is kind of academic... I'm into that these days.
... View more
04-27-2019
06:57 AM
|
4
|
1
|
13688
|
|
POST
|
I went so far as to provide the user with a spreadsheet I put together myself: simple name, one column with a one-word name. The issue that caught my eye is not the excel file name, the apostrophe in the path with a folder name ("Annie's Folder"). If you create a folder "Joe's folder" does it work?
... View more
04-27-2019
06:55 AM
|
1
|
0
|
3575
|
|
POST
|
I would run the aggregate tool on your raster with maximum to make a coarse (ie small size) raster, convert this to a polygon. Select By Location against with polygon to select the polygons that overlap with your raster data cells. Note this workflow does require a Spatial Analyst license. (UPDATE fixed a typo in the code the guaranteed writable temp folder path is env.scratchFolder) from arcpy import env
from arcpy.sa import *
lyrPoly = arcpy.MakeFeatureLayer_management("my_featureClass", "lyrPoly")
# create an generalized extent polygon of your raster
tmpAgg = os.path.join(env.scratchFolder, "xagg.tif")
tmpPoly = os.path.join(env.scratchFolder, "xaggpoly.shp")
agg = SetNull(IsNull(Aggregate("my_raster", 5, "MAXIMUM", "EXPAND")), 1)
agg.save(tmpAgg)
arcpy.RasterToPolygon_conversion(tmpAgg, tmpPoly)
# Select polygons that intersect the extent of the raster data areas
arcpy.SelectLayerByLocation(lyrPoly, "INTERSECT", tmpPoly)
arcpy.Delete_management(tmpAgg)
arcpy.Delete_management(tmpPoly)
... View more
04-25-2019
09:46 PM
|
3
|
3
|
13688
|
|
POST
|
I suggest using the extent of the raster as a polygon to select those that overlap before you start processing the polys. Then use the layer (with just the polygons that overlap) for your cursor loop. lyrPoly = arcpy.MakeFeatureLayer_management("my_featureClass", "lyrPoly")
# make a polygon from extent
ext = arcpy.Describe("my_raster").extent
array = arcpy.Array()
array.add(arcpy.Point(ext.XMin, ext.YMin))
array.add(arcpy.Point(ext.XMin, ext.YMax))
array.add(arcpy.Point(ext.XMax, ext.YMax))
array.add(arcpy.Point(ext.XMas, ext.YMin))
array.add(arcpy.Point(ext.XMin, ext.YMin))
extPoly = arcpy.Polygon(array)
# Select polygons that intersect the extent of the raster
arcpy.SelectLayerByLocation(lyrPoly, "INTERSECT", extPoly) http://desktop.arcgis.com/en/arcmap/latest/analyze/python/using-geometry-objects-with-geoprocessing-tools.htm
... View more
04-24-2019
09:07 PM
|
3
|
5
|
13688
|
|
POST
|
Dan's statement seems to suggest you can edit VALUE in the raster attribute table. This is not true, VALUE is derived from the raster data and cannot be modified (like OBJECTID it's a read only field). If you convert to raster using your original field, use the Reclassify tool to convert your raster cell values -- or, add a field to the raster attribute table, populate it for each corresponding VALUE record, and use Lookup (or Lookup() in Raster Calculator) to convert the raster values to your lookup values (1,2,3). I think Reclassify is what you are looking for here. BTW I recommend trying the newer Polygon To Raster tool as it gives you more control over how the conversion happens than the older Feature To Raster tool.
... View more
04-24-2019
07:26 AM
|
0
|
0
|
2211
|
|
POST
|
Dan, I don't understand your suggestion, as MakeXYEventLayer also makes a feature layer. You may have a better luck if you have a better except block, that is, one that will report the error from the copy features tool (or whatever else is failing). It is possible copy features is trying to overwrite a file that has a lock on it or something. Error handling with Python—Help | ArcGIS Desktop Good luck on your last week of class! Ho ho!
... View more
04-23-2019
09:23 PM
|
0
|
0
|
1457
|
|
BLOG
|
This has been great in my educational environment. We use single sign on Enterprise logins now and I turn on Esri access. This has made life so much easier for our students and this part-part-time administrator, all I have to do is invite them, provide some guidance and the students are good to go with desktop products and training. Having the same SSO identity at our university, MyEsri, AGOL, and the training site makes life so much easier. Best of all, I don’t have to disable students when they leave the university, when their university email goes away a semester after they graduate, their accounts are automatically disabled, without me having to do yet another thing.
... View more
04-23-2019
08:34 PM
|
1
|
0
|
1023
|
|
POST
|
I’m really glad this helped you out! However, I do not understand why you are placing a path for the output of the make feature layer tool. The second parameter is a string used to label the layer, not a dataset in the in_memory area or anywhere else. For more details, read the tool help for MakeFeatureLayer. The help talks about “layers in memory” but is important to realize that layers aren’t data, they are an object in memory that points to a source dataset with some wrapper properties of the layer’s own (visible/hidden fields, aliases, selections, etc). I often use the following code pattern to work with layers in Python, the result object lyrFoo gets ‘str()’d when passed a parameter to a tool layer, so I could just as well use “lyrFoo” as lyrFoo -- but I think this way of doing it is very easy to read (and debug): # create a layer "lyrFoo"
lyrFoo = arcpy.MakeFeatureLayer_management("my_points", "lyrFoo")
arcpy.SelectLayerByAttribute(lyrFoo, "", "MOJO > 50000")
# create a new feature class in the current workspace
arcpy.CopyFeatures_management(lyrFoo, "foo_copy")
# delete the layer from memory; the dataset it points to is not affected!
arcpy.Delete_management(lyrFoo)
... View more
04-23-2019
08:18 PM
|
0
|
0
|
3352
|
|
BLOG
|
The 10.5.1/10.6.1 DIP patch is not related to any crashes, just slow operation of any dialog that has to load fonts (which unfortunately includes the layer properties dialog, probably the most commonly used dialog in ArcMap! 10.5.1 is getting so old I would recommend considering an update. Though the reason for your crashes may be something unrelated to version. The mention of a lot of freezes makes me wonder whether you want to look into network file access issues. I highly recommend opening a tech support incident, I think they are awesome and in my experience if they can’t fix the issue they pretty much always can identify the problem and help me with a workflow around it.
... View more
04-23-2019
08:09 PM
|
1
|
0
|
2709
|
|
POST
|
Could it be the use of an apostrophe in the path? I still recommend always starting folder and file names with a letter and only using a-z 0-9. And underscore. No spaces either.
... View more
04-22-2019
05:37 PM
|
1
|
0
|
3575
|
|
BLOG
|
My favorite recent fix is the DIP patch, ArcMap was driving me crazy with its slow opening layer properties these last two years (10.5.1 problem). FINALLY got that fix a few months back.
... View more
04-18-2019
11:42 PM
|
2
|
0
|
2709
|
|
POST
|
It appears you are passing a feature class (not a layer) to your Select Layer tools. This means you are creating a layer (behind the scenes) on every loop and you are most likely filling up memory, slowing things down. I believe you may have better luck I think if you create layers at line 8 before you start and do your selections on those layers. Passing layers (instead of datasets) to tools is generally faster as it speeds up data validation required before the tool can run. I also do not see the purpose the time consuming creation of temporary datasets, I believe layers with selections on them would do just as well, without having to create additional temporary datasets. Hope this helps.
... View more
04-17-2019
09:46 PM
|
2
|
2
|
3352
|
|
POST
|
A helmet won't keep those jerks from running you over. The poor pedestrians need helmets too.
... View more
04-16-2019
04:24 PM
|
2
|
0
|
3173
|
|
POST
|
It would help to see the model and the messages that you are getting before it stops. I would disable background processing (Geoprocessing > Options. uncheck Enable background processing). It is possible the model tool is running, just in the background so it doesn't look like it is running.
... View more
04-16-2019
04:21 PM
|
0
|
0
|
1124
|
|
POST
|
It had no problem using the variable in the new layer name, just wouldn't display the new layer. Have you set add to display on the output feature layer model element? If running as a tool, have you set the model element as an output parameter so it will be added to the map?
... View more
04-16-2019
04:17 PM
|
0
|
3
|
20279
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-11-2021 01:26 PM | |
| 5 | 12-10-2021 04:58 PM | |
| 1 | 02-27-2017 09:30 AM | |
| 2 | 12-04-2023 01:05 PM | |
| 1 | 04-12-2016 10:17 AM |
| Online Status |
Offline
|
| Date Last Visited |
06-19-2024
12:10 AM
|