|
IDEA
|
TLDR: ArcPy Cursors do not universally respect Context Managers; Add Appropriate Methods to the Cursor Class to enable graceful exits (discard, disconnect, close) as part of the __exit__() call. Recently an Esri blog was published detailing a relatively common "gotcha" pertaining to cursors applied against a file geodatabase: https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/locked-by-another-application-using-arcpy-and-a-file-geodatabase/ The given solution was to embed a del call within a context manager (a with statement). This idea runs contrary to the syntactic sugar abstraction that is a context manager, or put otherwise, we use a context manager to not have to worry about some of the nitty-gritty of programming details like closing files and cursors. The suggested solution is problematic as it requires a user to have in-depth knowledge of what is likely an oversight due to the long-lived nature of the ArcPy library; further compounded by the lack of documentation outside of the blog's reference. https://realpython.com/python-with-statement/ This idea is to add in certain methods within the ArcPy Cursor Class to have it conform to the Python DBA Specification (https://peps.python.org/pep-0249/); while this sounds like a lot, in reality the additions would be fairly minimal and would be similar to the solution discussed in this blog post: https://dev.to/c_v_ya/sql-cursor-via-context-manager-2gc7 Having an implementation would make the ArcPy library more robust and allow the ArcPy Cursor to behave the same way regardless of the underlying data source-- --which would be the expectation for any other library, a function to behave the same way for all the inputs it is programmed to accept. This would benefit the users as they would not need to have an arcane understanding of a library that is possibly older than some of its users; they would be able to trust that ArcPy cursors comply with context managers which is a common usage pattern since Python 2.5.
... View more
10-03-2023
08:24 AM
|
24
|
2
|
2050
|
|
IDEA
|
So I was doing some work with an end-user and after troubleshooting something to deal with GlobalIDs, I said, no worries just use the search bar and type in: Remove GlobalIDs Surprise. Surprise. This ArcGIS Idea from 2012 still valid and relevant 11 years later. There needs to be an easier way to remove a GlobalID that does not require recreating a feature class.
... View more
09-07-2023
03:20 PM
|
0
|
0
|
4725
|
|
POST
|
Definitely agree about the limitations of GUI-driven SQL, although there are definitely more products out there pushing the envelope on that front. The issue that I tried documenting above was that outside of clause mode, there are potentially huge SQL limitations that would otherwise be possible in a native SQL environment like SSMS. Having the ability to define things within the definition query makes launching web services easier and gets rid of some of the overhead of having to write those views directly on your database. I also agree that users should have an option of what to toggle as a preference for the SQL queries, upvoted.
... View more
09-17-2020
10:59 AM
|
0
|
0
|
3885
|
|
POST
|
Bugs! Lots of Bugs! For anyone else that stumbles on this; these bugs are valid as of 2.6.1 BUG-000133709: 'ArcGIS Pro does not validate complex SQL Queries while SQL Server does' OpenDate >= '2020-08-24 00:00:00' AND
OpenDate < '2020-09-08 00:00:00' AND
(DATEDIFF(
Day, OpenDate, CaseInspectionDate) -
DATEDIFF(Week, OpenDate, CaseInspectionDate)
* 2 <= 1 ) AND
CaseReported IN ('Citizen Complaint', 'City Council') BUG-000133921: 'GETDATE() does not work inside a DATEADD expression for Definition Queries in ArcGIS Pro but validates in SSMS' DateReported > DATEADD(MONTH, -6, GETDATE()) BUG-000133922: 'DATEADD expression for Definition Queries fail with closer time-frames to today's date in ArcGIS Pro but validates in SSMS' DateReported > DATEADD(MONTH, -6, '2020/09/17')
... View more
09-17-2020
08:36 AM
|
1
|
2
|
3885
|
|
POST
|
edit--- let's define complex query as a query that cannot be represented in clause mode; in the steps below I referred to it as a lock, which is not the case. That text lets the user know that it can only offer the SQL screen and not the Clause screen. edit--- And for one final bit of mystery, after removing the "old" query from each layer, only the queries that can be directly interpreted by the SQL Builder were kept. Removing one of the complex queries removed both of them. I can re-create the old one, and it is accepted, but when I alter the date it rejects it. Stuff that works in the builder Now deconstructing the complex one: It will build correctly with the old query Accepted, and will show When you click edit, it shows a clause that will not edit So let's assume that the above is a lock, it'll unlock if you reduce the complexity; here we keep the date math and drop the flag check, which works But it will not unlock for a similar level of complexity, nor allow an incremental adding of complexity And when you try to write in a query exactly similar except for the date range Super odd, no?
... View more
08-24-2020
11:14 AM
|
0
|
0
|
3885
|
|
POST
|
I've noticed that some queries seem to be too complex within the SQL Expression Editor; previously I had issues running a calculation from a datefield that would not work on anything less than 6 months. Here's an example that I'm running into today: I have a map that needs to be updated bi-weekly, it's based on the following query: 2 week range >= and > a diff that calculates one business day turnaround according to two complaint flags OpenDate >= '2020-07-27 00:00:00' And OpenDate < '2020-08-10 00:00:00'
AND (DATEDIFF(Day, OpenDate, CaseInspectionDate) - DATEDIFF(Week, OpenDate, CaseInspectionDate) * 2 <= 1 )
AND CaseReported IN ('Citizen Complaint', 'City Council') Then when I go to make a simple edit, changing the string for date: OpenDate >= '2020-08-10 00:00:00' And OpenDate < '2020-08-24 00:00:00'
AND (DATEDIFF(Day, OpenDate, CaseInspectionDate) - DATEDIFF(Week, OpenDate, CaseInspectionDate) * 2 <= 1 )
AND CaseReported IN ('Citizen Complaint', 'City Council') It flips out like so: Pretty horrible right? Is this a bug? Now if I were limited to the GUI that would be bad. So I went ahead and used the new mp module in ArcPy, because I'm in the process of automating this map anyway: import arcpy
old_query01 = "OpenDate >= '2020-07-27 00:00:00' And OpenDate < '2020-08-10 00:00:00' AND (DATEDIFF(Day, OpenDate, CaseInspectionDate) - DATEDIFF(Week, OpenDate, CaseInspectionDate) * 2 <= 1 ) AND CaseReported IN ('Citizen Complaint', 'City Council')"
old_query02 = "OpenDate >= '2020-07-27 00:00:00' And OpenDate < '2020-08-10 00:00:00'"
old_query03 = "OpenDate >= '2020-07-27 00:00:00' And OpenDate < '2020-08-10 00:00:00' AND CaseReported IN ('Citizen Complaint', 'City Council')"
new_query01 = "OpenDate >= '2020-08-10 00:00:00' And OpenDate < '2020-08-24 00:00:00' AND (DATEDIFF(Day, OpenDate, CaseInspectionDate) - DATEDIFF(Week, OpenDate, CaseInspectionDate) * 2 <= 1 ) AND CaseReported IN ('Citizen Complaint', 'City Council')"
new_query02 = "OpenDate >= '2020-08-10 00:00:00' And OpenDate < '2020-08-24 00:00:00'"
new_query03 = "OpenDate >= '2020-08-10 00:00:00' And OpenDate < '2020-08-24 00:00:00' AND CaseReported IN ('Citizen Complaint', 'City Council')"
aprx = arcpy.mp.ArcGISProject(r"C:\Users\gisspellblade\Desktop\ArcProjects\SolidWaste_EnergovDemo.aprx")
for m in aprx.listMaps():
print(f"Map: {m} Layers")
for lyr in m.listLayers():
print(f"\t{lyr.name}")
if lyr.supports("DEFINITIONQUERY"):
if lyr.name == "Complaint Response One Business Day:":
lyr.definitionQuery = new_query01
print(f"Defintion changed for {lyr.name}: {lyr.definitionQuery}")
if lyr.name == "Cose Total: ":
lyr.definitionQuery = new_query02
print(f"Defintion changed for {lyr.name}: {lyr.definitionQuery}")
if lyr.name == "Complaint Total: ":
lyr.definitionQuery = new_query03
print(f"Defintion changed for {lyr.name}: {lyr.definitionQuery}")
aprx.save() Which at first blush, also did nothing. I ran this several times with no resulting changes in the map. I restarted the program and still nothing. Then, I left the program closed for more than 10 minutes, and when I get back, I have these results: So now I have three questions: If I'm changing the value on lyr.definitionQuery, then I'd think it would be an over-write and not an append? and if lyr.definitionQuery is a read/write; how does one access multiple queries to appropriately delete/add what they need? the documentation here is pretty light; Alphabetical list of arcpy.mp classes—ArcGIS Pro | Documentation unless there's more detailed information lurking just past my level of google-fu Why are these values not showing up immediately within the project? and why do I need a long cold restart to view changes made with ArcPy? this is an issue that I've seen before of needing to close a project for a ArcPy-derived result to appear in previous Pro versions What's with the GUI not accepting changes to complex queries, or refusing to write them in the first place? In ArcGIS Pro 2.6 arcgispro2.6 arcpy #definition expressions #set definition #sql clause #sql query builder
... View more
08-24-2020
10:42 AM
|
0
|
4
|
4031
|
|
POST
|
I definitely need to pick your brain, I'm going to send an email. Edit: I sent a LinkedIn request, you can reach me at my work email [jcarmona@mckinneytexas.org]
... View more
06-03-2020
02:08 PM
|
0
|
0
|
4482
|
|
POST
|
Hi Brian, I was wondering if you had any further experience with this subject since you posted in 2016. I've been running an ETL that uses a cross-database query to create tables directly into the back-end of the enterprise geodatabase. Now that we are upgrading past 10.3, I was looking forward to registering views with the geodatabase to have more live data and to also get past back-end manipulation. I've been playing around with the register views tool today and I don't seem to be able to do the same kind of cowboy queries that I've been getting away with via the back-end create table statements.
... View more
06-03-2020
01:49 PM
|
0
|
2
|
4482
|
|
POST
|
I think that this might be a more satisfying answer to anyone seeking to have a standalone scripting server without paying an additional license fee for a single-use installation. Assuming that you have a Named User login with a remember my password option, this will only operate for 14 days at a time. This clock resets any time the program is opened. So we can use Python to open ArcGIS Pro on an X day schedule and close it afterward. The basic script will look something like this, but obviously you would want to write some logic for logging, emails, and etc. #We'll be using two built-in libraries with this script
import os
import time
#Assign the location on the machine, usually here
ArcGIS_Pro_filepath = r"C:\Program Files\ArcGIS\Pro\bin\ArcGISPro.exe"
#Use os.startfile(), this will launch ArcPro
os.startfile(ArcGIS_Pro_filepath)
#Use time.sleep() to wait 60 seconds, enough time for ArcPro to open properly
time.sleep(60)
#Use os.system() to forcefully quit named process, ArcGISPro.exe
#https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/taskkill
os.system("taskkill /f /im ArcGISPro.exe")
#You can use the following output to determine if the command was successful
#SUCCESS: The process "ArcGISPro.exe with PID 4408 has been terminated This will free up a license that would otherwise only be used to run scripts.
... View more
05-04-2020
08:13 AM
|
0
|
0
|
1053
|
|
POST
|
Our Code Enforcement Officers are transitioning away from iPads to using ToughBook laptops (to enable the use of an enterprise system). We were planning a deployment consisting of Workforce and Tracker to have a better situational awareness and to have a better idea about how long we are at a given location. Are there plans for developing some sort of web-based application for Tracker? What would be your suggestion for path creation using a laptop?
... View more
04-16-2020
08:44 AM
|
0
|
0
|
674
|
|
POST
|
Xander Bakker, Well, I feel less crazy. So that's good? What are the next steps? In the interim, I can always calculate to a new field and run a select by attribute against that.
... View more
11-08-2019
01:06 PM
|
0
|
1
|
442
|
|
POST
|
Hi Xander Bakker, I really like that!, definitely a much more elegant way of handling this. However, I still am not able to access features counts. I also exported this feature to a file geodatabase from our enterprise geodatabase and am still not able to access the counts using an Arcade expression. Below is a screenshot of the new expression in our SDE.
... View more
11-08-2019
09:29 AM
|
0
|
3
|
1521
|
|
POST
|
Hi Xander Bakker, here's what a sample of my data looks like. Let me know if you'd like anything further.
... View more
11-07-2019
11:59 AM
|
0
|
5
|
1521
|
|
POST
|
Hi Michael Volz, this is EnerGov data. We're not generating anything through Pro, we are handling all of the EnerGov-to-GIS stuff through SQL queries and pushing that to our SDE.
... View more
11-06-2019
11:41 AM
|
0
|
0
|
1521
|
|
POST
|
Hi Xander Bakker, Sorry for the slow response on my end, this is the expression that I am using within the Symbology tab: WHEN(
$feature.CASE_STATUS == "Open - Founded", "Open",
$feature.CASE_STATUS == "Open - Pending", "Open",
"Closed") This data is comprised of inspection case records with a possibility of 4 different statuses; however, for reporting purposes, I've been asked to show status as either open/closed. The above snippet changes two of the statuses to a singular: "open" and I rely on the default option to force the others into a "closed" status. When using an Arcade expression, the count data continues to show as a "?" but when using one of the regular columns the count feature works as intended. My band-aid solution was to manually count the records with a selection sort and then write that into the label. Arcade1 Arcade2 Regular Column Let me know what you think, JC
... View more
11-06-2019
10:36 AM
|
0
|
9
|
1521
|
| Title | Kudos | Posted |
|---|---|---|
| 7 | 08-21-2025 02:14 PM | |
| 20 | 07-23-2024 09:30 AM | |
| 12 | 07-09-2024 10:58 AM | |
| 1 | 02-22-2024 10:51 AM | |
| 1 | 03-04-2024 02:59 PM |
| Online Status |
Offline
|
| Date Last Visited |
4 weeks ago
|