|
POST
|
I have a pretty simply python script that steps through all of the feature classes in an enterprise GDB having a certain name. When I run this script from the command line using a .bat file to trigger it, it runs great and completes successfully. When I embed the same .bat file that runs the script in Windows (10) Task Scheduler, it fails to return a list of FC names. Please see code and images below: import arcpy
import datetime
f = open ('C:\Scripts\CartegraphIntegration\COJNPDESIntegrationDBLog.txt', 'a+')
f.write("**********Program Started :"+str(datetime.datetime.now())+"**********")
f.write('\n')
# Connection file for ArcPy
CGIntegrationsde = r"z:\Not\A\RealPath\connection.sde"
arcpy.env.workspace = CGIntegrationsde
f.write("Workspace set successfully: " + CGIntegrationsde)
f.write('\n')
#all of the feature classes we want to udpate all start with the word "Spatial"
#but since the names are fully qualified we have to account for other leading characters
featClasses = arcpy.ListFeatureClasses('*Spatial*','','')
f.write("Feature Class List acquired successfully")
f.write('\n')
if not featClasses:
f.write("The list is empty.")
f.write('\n')
else:
for fc in featClasses:
f.write("Updating fields to use appropriate case in FC: " + fc + " :"+str(datetime.datetime.now()))
f.write('\n')
#Script does something ArcPy like here "edited for privacy
f.write("Updates complete in FC: " + fc + " :"+str(datetime.datetime.now()))
f.write('\n')
f.write("**********Completed: "+str(datetime.datetime.now())+"**********")
f.write('\n')
f.close() When I run the script from the command line using a .bat file: "C:\Users\?????\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone1\python.exe" "C:\Scripts\ProjectName\ScriptName.py" I get what I want... The below image shows the log file I write in the above code: When I run it in the Task Scheduler I get information telling me that the list returned from the arcyp.ListFeatureClasses command is empty: Another weird thing is that the task always says "Running" in the scheduler even though it has reached the end of the script. Any thoughts would be appreciated. This is really a hassle that it works when I test it and I think I'm just an "Adding it to the scheduler" step away from being done and then that's the part the bails! K
... View more
05-31-2022
08:37 AM
|
0
|
15
|
9945
|
|
POST
|
You might try Feature Vertices to Points with the (Both Start and End option) to create the end points of your events and then use a spatial join with the Match Option of "Closest". Only problem is when the Start and End points are closer to two different segments.
... View more
05-24-2022
11:04 AM
|
0
|
1
|
1559
|
|
POST
|
There sure is a way using Arcade. I used this article when I first tried it and it worked great. In your case I think the rule would be added to the service line's insert event. Advanced Attribute Rules – Editing features on another class with attribute rules (esri.com)
... View more
05-24-2022
10:36 AM
|
1
|
0
|
1943
|
|
POST
|
I create some quick sample data. Initially I created 2 test feature classes, one containing 20 "Species" points (I named it Test1PointData) that fall with 2 test polygons (Test1PolyData). The unique ID of the polygons is names PolyUID and the "Species" attribute of the points file contains the species name. First I ran a spatial join using the points as the target to add the Unique ID of the polygon they fell within to each point. Then I ran the Summary Statistics tool on the resulting spatially joined points file (the resulting FC being named "Test1PointData_SpatialJoin" in this example). The image below shows the results and the options I used in the Summary Statistics tool. The light blue highlighted records in the upper left are "Test1PointData_SpatialJoin" points that fall within the Test1PolyData polygon having UID "Polygon1". It is just here to illustrate that the returned statistics are correct. Hope this helps.
... View more
05-22-2022
04:21 AM
|
0
|
0
|
636
|
|
POST
|
If I understand your question correctly something like this should work: import arcpy
import os
import glob
import pandas as pd
#concatenate your files (lines 13-22)
#Set your workspace where you are going to create the output feature class
arcpy.env.workspace = r"D:\Test\ESRI Community Helper\ESRI Community Helper.gdb"
#The path to your .csv files goes here
os.chdir(r"D:\Test\CSVTestDirector")
extension = 'csv'
csvAllFiles = [i for i in glob.glob('*.{}'.format(extension))]
#combine all files in the list
combined_csv = pd.concat([pd.read_csv(f) for f in csvAllFiles])
#export to csv
combined_csv.to_csv( "AllCSVs.csv", index=False, encoding='utf-8-sig')
#Create feature class from concatinated csv files
#Update your .csv file path, output file name, "X","Y" column names, and SpatialReference here
arcpy.management.XYTableToPoint(r"D:\Test\CSVTestDirector\AllCSVs.csv", "outputCSV","X","Y","",arcpy.SpatialReference(4759, 115700))
... View more
05-16-2022
09:07 AM
|
1
|
1
|
5230
|
|
POST
|
1) Its a little confusing, but the the first select by attribute selects all points in the HabitatPnts_SJ_GridPolys that have the same value for area as the highest value in the Grid cell you are processing. For instance if the current Grid cell being processed is Grid-25 and the maximum habitat area with this cell is 50 hectares, the first query selects all records in the HabitatPnts_SJ_GridPolys feature class with an Area of 50. That selection set includes the one (or more) points you are interested in returning, plus all other points with an Area of 50. The second select by attribute excludes all points not in Grid-25; leaving you with just the points you want (I.E. those points (one or more) that represent the highest habitat by area in that grid cell). It is confusing why you have to write two queries when SQL Server could so this no problem in just one, but I think the answer is that ArcMap is limited in its ability to do subqueries, so this was the only way I could get it to work. 2) %Value% is a variable in the model. It is set each time the iterator loops. It is the unique identifier of the polygon you are processing this time through the iterator. It is vital that this be set correctly as the "Field" property of the iterator.
... View more
05-13-2022
12:06 PM
|
0
|
0
|
1536
|
|
POST
|
Looks like a combo of the Domain To Table tool to export the existing domain to a table. Then merge those values into your 200 row Excel. Then use Table To Domain to create a new domain with all the values of the original plus all the values in your Excel.
... View more
05-13-2022
03:16 AM
|
1
|
0
|
1083
|
|
POST
|
Your welcome. If my suggestion helped to solve the problem, would you mind also accepting one of my responses as a solution? Thank you.
... View more
05-12-2022
01:29 PM
|
0
|
1
|
1546
|
|
POST
|
If your Grid Cells do not already have a unique ID other than Object ID I would give them one. Backup all of your feature classes first and work on copies of those. Then add a column to your Grid Cells polygon FC called something like GridID (String, 25 length). This will be the equivalent to where I use "MyTestValue". Use Field Calculator to calculate that field equal to the word "GRID-" with a cell number after it. That will give them each an "unchangeable" ID.... ("Grid-1','Grid-2',.....'Grid-500000') You have to use the "Python" and "String" options (highlighted) "Grid-"+ '!OBJECTID!' This will give you a Grid cell feature class (I'm going to call it "GridCellPolys" here for reference) with a unique ID. That maps to "PolygonTest" in my model. Spatial join that polygon feature class to your Habitat points to get the equivalent of my MaxTestPoints_SpatialJoin2 feature class (call it something more appropriate like "HabitatPnts_SJ_GridPolys"). Mapping to the model: PolygonTest = GridCellPolys MaxTestPoints_SpatialJoin2 = HabitatPnts_SJ_GridPolys MyTestValue = GridID Habitat = Habitat Value = Area NOTE: The model does not check for if no points fall within a cell. This will likely cause it to fail. Since I don't think Model Builder had an "If Then" condition in ArcMap 10.3 you'll have to do a select by attribute on you Grid Polygons that have at least one point in them and export that out as your new "PolygonTest" (in my model) feature class. Good luck.
... View more
05-12-2022
10:38 AM
|
0
|
3
|
1553
|
|
POST
|
Using the images of the model I created you can create your own model using Model Builder in ArcMap, but customized to user your own data. The images were meant to provide a blue print and the model is not really "plug and play". You create a model in a tool box you create: In that tool box you create a new model and edit it: The names of the tool in the model (for example "Select by Attribute") can be dragged into the model from the "Search" dialog: The iterator can be added like this: The code I sent for the tools will have to be customized for your data. There are some good model builder videos online.
... View more
05-12-2022
08:58 AM
|
0
|
5
|
1556
|
|
POST
|
Rather then sending the data and the model and trying to get them to work on your system I think I can explain a little clearer. First your questions : 1) I added MyTestValue in PolygonTest to be the unique identifier of the polygon. I am assuming each of your grid cells has a unique ID other than the ObjectID. This is the equivalent of that in the test data. 2) That would be the case in my data if I had added two more polygons. Your data should already have a unique ID assigned to each cell (that is not the ObjectID). 3) ObjectID is a unique Identifier, but Object IDs are not stable and can change when you run analysis (especially analysis that edits or changes the original data) or edit data. Its better to use a stable, user defined, unique ID (like MyTestValue in this case). 4) Here it is. The append tool takes another feature layer as a "Target". I created this as an empty Feature Class to accept the output of the append. I simply created a point Feature Class with columns to accept the values I needed. 5) "(2)" and "(3)" show the same dataset after it has been acted on by a different tool. (3) contains the set of records selected by the first Select by Attribute and (2) contains the set of selected records after the second. The data I used is simply the 13 points in the original post's image and 2 polygons those points fall within. I created the data in a few minutes just to test the model. Here is more detail on the model: The code used in the first Select by Attribute tool (using "New Selection" as the Selection Type) Value = (SELECT MAX(VALUE) FROM MaxTestPoints_SpatialJoin2 WHERE MyTestValue = '%value%') The code of the second Select By attribute (Using "Remove from current selection" as the Selection Type) MyTestValue <> '%value%'
... View more
05-12-2022
07:13 AM
|
0
|
0
|
1563
|
|
POST
|
I'm guess the employee database is a file GDB. Is that correct? Is the geodatabase the 4 users can edit also a file GDB or an enterprise GDB? If it is an enterprise GDB you can create a "Viewer" (just a name I made up, any name will work) version and restricting who can edit it by setting its permissions (Protected ought to do it). You can also control who can edit or view feature classes using the "Change Privileges" tool on enterprise GDB data. If you are using a file geodatabase it gets trickier. As far as I know lock files only exist when a process is holding a feature class in the gdb open, if you can create permanent ones I don't know how. You can compress the file GDB. That will make it read only. Compress File Geodatabase Data (Data Management)—ArcGIS Pro | Documentation If that doesn't work their are other less obvious ways that might work but I've never used them like Licensed file GDBs which sound like they aren't for this purpose, but might work; or setting the Folder that represents the file GDB to read only (but this sounds risky and I wouldn't try it the first time without making a backup of your database).
... View more
05-11-2022
10:55 AM
|
0
|
0
|
3549
|
|
POST
|
Here's the thing about iterators in Model Builder. They run everything in the model, regardless of where that tool or sub model is in relations to the Iterator. For example, my brain would tell me that since model 4 is running before the iterator is fired in Model 3, Model 4 would run once and then Model 3's iterator would loop as many times as necessary, but that is not the case. In your model 3, each time that iterator loops Model 4's iterator will loop. One way to deal with this is don't use a sub model containing an iterator as an input into another model that contains an iterator. For example; have a third "Main" model that calls Model 4 and then calls Model 3 rather than calling Model 4 directly from model 3.
... View more
05-11-2022
08:15 AM
|
3
|
1
|
4098
|
|
POST
|
You can find it under the Utilities menu in the ModelBuilder tab. Try using a capital Y instead of the lower case one I sent earlier. time.strftime("%Y%m%d")
... View more
05-11-2022
07:44 AM
|
0
|
0
|
2407
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 07-25-2025 07:54 AM | |
| 1 | 07-25-2025 10:45 AM | |
| 1 | 05-10-2022 11:06 AM | |
| 1 | 05-09-2022 04:05 AM | |
| 1 | 03-17-2022 04:04 AM |
| Online Status |
Offline
|
| Date Last Visited |
07-25-2025
07:47 AM
|