|
POST
|
Garret Duffy, thanks for uploading sample data, it helps to troubleshoot and explain what is fouled up. As I suspected, the problem is with the elevation values being returned by the subquery and how the IN clause is structured. The elevation values are fine, in and of themselves, and the subquery and query are returning correct results based on the SQL as written. Let's take a closer look at the example in your attached screenshot: The Sample_Dataset table is in the background with the results of your subquery in the foreground. Although the subquery is calculating the maximum elevation value by the FID_T_25_projected column, it is only returning a result set of elevation values. With the query as written, two rows with FID_T_25_projected equal to 663 are being returned instead of one because there are two 663 records that have an elevation matching one of the elevation values in the subquery. Even if you were to include FID_T_25_projected in the SELECT list of the subquery, the query as written still wouldn't return the results you want. If you were working with one of the database platforms that support multiple column IN clauses, like Oracle, a fairly small change to your SQL would get things workings. Unfortunately, neither file nor personal geodatabases support such functionality. There are numerous ways to solve this riddle using SQL natively within a DBMS, but you are working within the confines of ArcGIS and the limitations that imposes on structuring SQL. Fortunately, you are working with personal geodatabases so there is a fairly straightforward solution: objectid IN (
SELECT objectid
FROM sample_dataset t1
,(SELECT fid_t_25_projected, MAX(elevation) as maxe
FROM sample_dataset
GROUP BY fid_t_25_projected) t2
WHERE t1.fid_t_25_projected = t2.fid_t_25_projected
AND t1.elevation = t2.maxe) The above SQL works with personal geodatabases and desktop geodatabases/personal SDE, but it doesn't work with file geodatabases or shapefiles. I suspect the above SQL would work with all enterprise geodatabases, but I haven't verified it.
... View more
05-10-2015
06:27 PM
|
2
|
3
|
3043
|
|
POST
|
It would be good if you could upload your data or some sample data. To upload an attachment, click on "Use advanced editor" in the upper right corner, and then click on "Attach" in the lower right corner. Without knowing more about your data, I have to speculate. Seeing you have run this query before on different data with expected results, my guess is that you have non-unique elevation values being returned by your subquery (multiple grid boxes have same maximum elevation). The select * part makes it really difficult to understand what you are after and what the unique identifier may be.
... View more
05-08-2015
06:10 PM
|
1
|
5
|
3043
|
|
POST
|
In this situation, arcpy.da.Walk doesn't get you anything over os.walk because arcpy.da.Walk is focused on the contents of geospatial data stores (feature classes, raster catalogs, tables, etc...) and not the data stores themselves (file geodatabases, folders, enterprise geodatabases, etc...). arcpy.da.Walk can do the job, it just does it slower because of the extra overhead from enumerating geospatial data within the data stores. Since you primarily seem interested in only the size of the file geodatabases and not the specifics of what is inside them, I recommend using straight os.walk to find the file geodatabases and determine their sizes. import os
def get_size(start_path = '.'):
total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size
output = #output file
path = #root/parent directory to start recursive search
with open(output, 'w') as f:
for dirpath, dirnames, filenames in os.walk(path):
for dirname in dirnames:
if dirname.endswith('.gdb'):
gdb = os.path.join(dirpath, dirname)
size = get_size(gdb)
f.write("{},{}\n".format(gdb, size)) The get_size function code came from the accepted answer by monkut to the following Stackoverflow post: Calculating a directory size using Python?
... View more
05-08-2015
04:37 PM
|
3
|
1
|
1972
|
|
POST
|
The error alone makes me think it is your data, not your code. You are using the field calculator I assume? That error message is common with the field calculator when there is a newline character of some form in a text field in a table being worked on. If you Google "CalculateField parsing error EOL" or something similar you will find plenty of discussion about how to deal with it. In the past, some folks would say use the VB parser instead of Python, but I consider that poor advice today since VB's sunset is pretty far along. Some folks add additional code to find and replace new line characters, while other folks use an UpdateCursor instead of field calculator. There are lots of suggestions, not sure any one of them is a silver bullet.
... View more
05-08-2015
06:17 AM
|
0
|
0
|
4973
|
|
POST
|
Ah, right, my bad. One of my streams aggregated your post, and I didn't pay close enough attention that you were focused on ArcObjects. As Javier Artero points out, a disjoint mask as he provides should get you on the right path.
... View more
05-08-2015
06:05 AM
|
0
|
0
|
5244
|
|
POST
|
This can be accomplished in two steps using Select By Attribute and Select By Location in ArcMap. First, select all villages having greater than 500. Then, "remove from currently selected features..." the villages that have colleges in them. If scripting, something like: arcpy.SelectLayerByAttribute_management("villages","NEW_SELECTION", "population > 500")
arcpy.SelectLayerByLocation_management("villages", "INTERSECT", "colleges", "", "REMOVE_FROM_SELECTION")
... View more
05-07-2015
05:53 PM
|
0
|
3
|
5244
|
|
POST
|
Cursor.description will provide you the information you need, but you will have to create a mapping between cx_Oracle types and NumPy types. It might also be worth checking out oracle_util.py on GitHub.
... View more
05-07-2015
05:16 PM
|
3
|
1
|
2259
|
|
POST
|
Nothing like a nearly 7-year old bug that was found in ArcGIS 9.3 and still persists in ArcGIS 10.3.x. The bug system says it is "Open: Assigned," which developer is making a career out of this bug? It is obvious Esri has no intent to fix it, they should show the user community a bit more respect and change the status to "Closed: Will not fix."
... View more
05-06-2015
08:04 AM
|
2
|
0
|
1758
|
|
POST
|
Even before ArcGIS Pro, this same situation would occur when installing 64-bit Background Geoprocessing, although those 64-bit libraries broke much less 32-bit code than ArcGIS Pro. The issue arises because the last, or most recently, installed ArcGIS application changes the file-type associations and shortcut targets to the Python interpreter it installs. You can always go into the file-type associations and change the default Python interpreter that is used for running or editing Python scripts.
... View more
05-06-2015
07:45 AM
|
0
|
4
|
4526
|
|
POST
|
Performance wise, I wouldn't be surprised if Append and Copy Rows were comparable, but there is the functional difference where Append requires an existing table/dataset/etc... while Copy Rows has to create a new one. Since the OP's original workflow includes truncating a table instead of deleting it, there may be a requirement that prevents the use of Copy Rows. In terms of the performance of ArcPy Data Access cursors versus ArcPy original/older cursors versus ArcObjects in .NET or C++, there is a post over at GIS StackExchange that discusses the topic: How is the data access cursor performance so enhanced compared to previous versions? Jason Scheirer, one of the arcpy.da developers, explains how they improved the performance of the new cursors, but he also states that ArcObjects in .NET or C++ is still over twice as fast as arcpy.da cursors. Since the Append tool is native ArcObjects, the OP's runtimes seem reasonable, or at least not surprising, when talking about bulk transferring of data.
... View more
05-06-2015
06:52 AM
|
2
|
0
|
2958
|
|
POST
|
Where are you executing this code? As a standalone script? In an ArcGIS Desktop interactive Python window? If the latter, are you running Background Processing? (Not saying any of this is the issue, but it helps to know the specifics of where/how the code is being run). Also, what version of ArcGIS are you running? What happens if you programmatically only pass it SANPETE, i.e., add a WHERE clause to your search cursor to only return SANPETE. Speaking of cursors, I see you are using the older style search cursor. Have you tried using a ArcPy Data Access Search Cursor?
... View more
05-05-2015
05:41 PM
|
0
|
2
|
3581
|
|
POST
|
Curios, what is the specific error message? (By the way, it is a good practice to include specific error messages instead of general comments like "doesn't like."). It could be I just gave some incorrect syntax or names since I was interpreting your original code snippet.
... View more
04-30-2015
10:01 PM
|
0
|
1
|
1801
|
|
POST
|
If I understand correctly what you are trying to do, and using as much of your original code as possible, I roughed out the following: with arcpy.da.SearchCursor(mLanduse, ["SHAPE@", lField]) as cursor:
for row in cursor:
arcpy.SelectLayerByLocation_management(
mSoils_Layer, "WITHIN", row[0]
)
with arcpy.da.UpdateCursor(mSoils_Layer, sField) as cursor2:
for row2 in cursors2:
if row2[0] == '':
row2[0] = row[1]
cursor2.updateRow(row2) If this works, I can explain how your original code had some parts out of order.
... View more
04-30-2015
03:35 PM
|
0
|
3
|
1801
|
|
POST
|
I am glad you found the explanation helpful. Building query expressions in ArcGIS using Python comes up from time to time in the forums, although the specific question usually varies. I have been meaning to write a blog post about it, and your question gave me the chance to do a dry run. Cheers.
... View more
04-30-2015
01:26 PM
|
0
|
0
|
2776
|
|
POST
|
The issue you are running into is less about database or Python requirements and more about Esri requirements. For databases, single quotes are the predominant string delimiter although some database platforms do support using double quotes that way as well. I have read in various places over time that the ANSI SQL standard itself defines double quotes for database object names delimiters and single quotes for string literals. That said, I have never paid to get a copy of the ANSI SQL standard to verify that statement. Looking at the Python documentation for string literals: 2.4.1. String literals .... In plain English: String literals can be enclosed in matching single quotes (') or double quotes ("). They can also be enclosed in matching groups of three single or double quotes (these are generally referred to as triple-quoted strings). The backslash (\) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character. .... In triple-quoted strings, unescaped newlines and quotes are allowed (and are retained), except that three unescaped quotes in a row terminate the string. Outside of raw strings, the backslash is the primary way of escaping special characters like a single quote. Triple quotes can be used, and are even preferred in some specific situations, but backslashes are most commonly used. One interesting behavior with Python is that using one type of quotes to define a string literal means the other type of quotes are interpreted literally within the string: >>> #using backslash to escape single quotes
>>> print 'Let\'s hear it for \'air quotes\'.'
Let's hear it for 'air quotes'.
>>> #using triple quotes to escape single quotes
>>> print '''Let's hear it for 'air quotes'.'''
Let's hear it for 'air quotes'.
>>> #using double quote string literal to allow single quotes
>>> print "Let's hear it for 'air quotes'."
Let's hear it for 'air quotes'.
>>> #using single quote string literal with backslash to allow
>>> #double quotes
>>> print 'Let\'s hear it for "air quotes".'
Let's hear it for "air quotes". (The Jive syntax highlighting is creating an artifact on line 05) Looking at the Esri documentation for query expressions in ArcGIS: Building a query expression .... Searching strings Strings must always be enclosed within single quotes. For example: STATE_NAME = 'California' Strings in expressions are case sensitive except when you're querying personal geodatabase feature classes and tables. .... If the string contains a single quote you will first need to use another single quote as an escape character. For example: NAME = 'Alfie''s Trough' When it comes to building string expressions in Python, for SQL or otherwise, I am a big advocate for using the Python string format method (str.format()). The Python Format Specification Mini-Language is very robust at building expressions, and I find it much more readable than string concatenation in most cases. As long as the strings you are searching on don't have single or double quotes in them, the following code should work to generate a valid SQL expression for you: input_AZ = str(arcpy.GetParameterAsText(0))
sql_exp = "aktenzahl = '{}'".format(input_AZ)
arcpy.SelectLayerByAttribute_management (lyr_postgis, "NEW_SELECTION", sql_exp) In the code above, I am using double quotes for the Python string literal so that I can use single quotes un-escaped to structure the query the way ArcGIS wants.
... View more
04-29-2015
07:38 AM
|
2
|
2
|
2776
|
| Title | Kudos | Posted |
|---|---|---|
| 2 | a week ago | |
| 1 | a week ago | |
| 2 | 06-05-2026 10:30 AM | |
| 1 | 05-29-2026 08:22 AM | |
| 1 | 06-02-2026 06:16 AM |
| Online Status |
Online
|
| Date Last Visited |
2 hours ago
|