|
POST
|
The performance of the script can be improved by cutting out the search cursor loop. All of the functional code works within a single update cursor: import arcpy
fc = #full path to feature class
fields = ['OBJECTID', 'SRNumber', 'Resolution_Code']
table_rows = []
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if row[1:] in table_rows:
print "Deleting record: OBJECTID = {}".format(row[0])
cursor.deleteRow()
else:
table_rows.append(row[1:])
del table_rows
... View more
08-14-2015
02:14 PM
|
3
|
0
|
3284
|
|
POST
|
What is point, exactly? Your code is point = arcpy.GetParameterAsText(0) # click , but I am unclear what is being returned. Is point supposed to be an ArcPy Point object or a set of coordinates for a location or a name to a feature class containing points? Regarding your original error message, just so you understand why you were getting that error, you were using the SHAPE@XY token. The SHAPE@XY token returns a Python tuple of the x,y coordinates of the point, not an ArcPy Point object or PointGeometry object. As such, there is no 'SHAPE' attribute so an AttributeError is generated.
... View more
08-13-2015
03:44 PM
|
0
|
0
|
1965
|
|
POST
|
Unless you are willing/able to post a subset of the data and a description of what the final product would look like, I am out of ideas. Best of luck.
... View more
08-12-2015
06:44 PM
|
0
|
2
|
1965
|
|
POST
|
Since Arcpy Data Access search cursors return tuples, this specific code will generate a TypeError since tuples don't support item assignment.
... View more
08-12-2015
07:46 AM
|
0
|
4
|
1965
|
|
POST
|
Are POINT_X and POINT_Y populated in point or are they going to be new data in pointFC? If they are NULL in point, why are you retrieving them with the search cursor? In cases like this, posting some sample data and an explanation of what you are trying to accomplish is helpful. It could be your entire approach is off, and people in GeoNet could offer a different way of doing it entirely.
... View more
08-12-2015
07:44 AM
|
0
|
0
|
1965
|
|
POST
|
As Ian Murray points out, Python string formatting would really come in handy in this situation. There are so many single and double quotes in those SQL statements, it will be hard for anyone but the author to follow or maintain that part of the code. Looking at a couple snippets of your code, I think I can illustrate what is going wrong. >>> GFID = 0
>>> pointName = str(GFID)
>>> pointClause = ''' "FID" = '''''' "FID" = '''+ pointName
>>> print pointClause
"FID" = "FID" = 0 Interestingly enough, your code generates a slightly different pointClause expression when I copy and paste it into the interactive Python window. That said, the expression is invalid either way. At this point, I am not sure what to suggest because I am not exactly clear what you are trying to select. For example, are you simply trying to FID = 0 or are you trying to add some values together before selecting. If you are trying a simple FID = x type of selection, the Python string formatting looks like: >>> GFID = 0
>>> pointName = str(GFID)
>>> pointClause = "FID = {}".format(pointName)
>>> print pointClause
FID = 0 For the Select tool, and most other tools, the field name doesn't need to be quoted or escaped. Building expressions for the Calculate Field tool is a bit different than building where clauses for most other tools. I find that commonly trips users up when going back and forth between building expressions and where clauses.
... View more
08-11-2015
06:27 PM
|
1
|
0
|
3290
|
|
POST
|
The ArcPy Data Access Search Cursor documentation states the search cursors next() method "returns the next row as a tuple." Furthermore, the SHAPE@XY token returns a "tuple of the feature's centroid x,y coordinates," which for a point is the point itself. (Note, this isn't necessarily the case with a Multipoint). When a user returns the SHAPE@XY token in a search cursor, like here, there will be a tuple within a tuple. Tuples are a built-in Python data type and one of seven sequence types (Sequence Types — str, unicode, list, tuple, bytearray, buffer, xrange); as such, tuples support indexing, slicing, sequence packing, and more. Darren Wiens' code is accessing the values in the nested or inner tuple by nesting or chaining multiple indexes. With your code, row[2] is retrieving the third element of the tuple returned by the search cursor, which happens to be the tuple containing x,y coordinates. row[2][0] is the first element of that SHAPE@XY tuple, the x coordinate, and row[2][1] is the second element of that tuple, the y coordinate. Since tuples are sequences, you could also use sequence unpacking if you think it would make the code more readable. For example, lines 09-11 could be replaced with: with arcpy.da.SearchCursor(point,['POINT_X','POINT_Y','SHAPE@XY']) as cursor:
for pt_x, pt_y, xy in cursor:
insCursor.insertRow([xy[0], xy[1], xy]) Now that I write it, something seems off, but I think it may be redundant information. That is, 'POINT_X' and 'POINT_Y' are being retrieved in the search cursor but not being used. Anyhow, my point was to point out sequence unpacking and not what the code is doing or not doing (double pun not intended).
... View more
08-01-2015
08:23 AM
|
2
|
13
|
4036
|
|
POST
|
My primary language is now Python, but I didn't start learning programming with it. A couple years back, I came across a really interesting and informative video of Raymond Hettinger: Transforming Code into Beautiful, Idiomatic Python. Raymond is a Python consultant/trainer who is also a Python core developer. He is a very high-energy guy who I think can communicate well to a large range of audiences. For people coming to Python from other languages, I think some unlearning is necessary to write idiomatic Python, and Raymond's talk does a good job of getting you on that path.
... View more
07-31-2015
03:13 PM
|
0
|
1
|
1988
|
|
POST
|
The SciPy2015 conference was hosted in Austin, TX a few weeks back. Unfortunately, I wasn't able to attend, but a small consolation was that the videos were posted the week after the conference: SciPy 2015: Scientific Computing with Python Conference - YouTube. Esri may have had a false start with adding SciPy to ArcGIS 10.3.1, but SciPy will be coming to an ArcGIS Version near you sooner than later. In fact, SciPy and Pandas are included (What's new in ArcGIS Pro) in ArcGIS Pro 1.1 that was released last week. So what is SciPy and what is the big deal about it being added to ArcGIS? "SciPy (pronounced “Sigh Pie”) is a Python-based ecosystem of open-source software for mathematics, science, and engineering." The big deal is that having Esri add it to ArcGIS, instead of having users add it themselves, lowers the bar for accessing and using an impressive and ever growing range of scientific computing libraries with your geospatial data. Although most of the presentations I have watched were interesting and informative, there is one that I think is worth every new ArcGIS scripter's time: Keynote: State of the Tools | SciPy 2015 | Jake VanderPlas. The presenter does an excellent job of summarizing where SciPy is today, how it got here, and where is might go in the future. I think there are lessons to be learned not just from using powerful numerical tools, but also from how a community of people came together to build such a powerful platform, and open source platform at that. Lots to watch, lots to think about, and lots of fun to be had!
... View more
07-24-2015
01:53 PM
|
3
|
4
|
4827
|
|
POST
|
Database and server connections from ArcGIS Desktop can be used by/in ArcGIS Pro without having to import them. If you navigate to a folder in the Project pane that has existing database or server connections, you can just click on them to connect and add data. If you want to include an existing database or server connection in an ArcGIS Pro project, you can just copy and paste the existing file into the root level of the project folder for that project.
... View more
07-18-2015
07:55 PM
|
1
|
1
|
3668
|
|
POST
|
You piqued my interest. Are you interested in making an invalid Polygon, valid MultiPolygon, or both when you mention wanting to try the island in a lake on an island... example? The GeoDjango GEOS API will let you make a Polygon with nested holes, but it will also tell you it isn't valid because of those nested holes if you call the valid_reason method. That is yet another thing lacking from the ArcPy Geometry classes that exists in Shaply and GeoDjango, i.e., the ability to check for valid geometries by simply calling a method or function on the geometry instead of running a geoprocessing tool that has to create an output table with results.
... View more
07-18-2015
07:39 PM
|
0
|
2
|
3587
|
|
POST
|
They announced it, with some fanfare, for ArcGIS 10.3.1, but the fact is it didn't make it into the release. Unfortunately, the news it didn't make the release, well, barely exists. It is in ArcGIS Pro 1.1, and I have been told it will be in ArcGIS 10.4. I don't know whether there will be an ArcGIS 10.3.2 (I could see it going either way given the current ArcGIS 10.4 release schedule); and even if there is, it is unknown whether SciPy would make it into that release.
... View more
07-18-2015
06:30 PM
|
1
|
1
|
3292
|
|
POST
|
Thanks for the heads up. In some respects, I am not surprised. My organization historically had problems with PLTS breaking built-in ArcGIS Desktop functionality, to the point where 2 different sets of ArcGIS Desktop Citrix blades had to be provisioned and managed for years. For that and other reasons, the organization has been weaning employees off of Mapping and Charting extensions unless they are absolutely necessary.
... View more
07-18-2015
06:23 PM
|
0
|
0
|
1472
|
|
POST
|
The Polygon constructor is fairly lenient in terms of ring direction/orientation, but the GEOS Polygon object has a normalize() method that will convert the rings to normal/canonical form in place: >>> ext_coords_cw = ((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))
>>> ext_coords_ccw = ((0, 0), (1, 0), (1, 1), (0, 1), (0, 0))
>>> int_coords_cw = ((0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4), (0.4, 0.4))
>>> poly_cw = Polygon(ext_coords_cw, int_coords_cw)
>>> poly_ccw = Polygon(ext_coords_ccw, int_coords_cw)
>>> poly_cw.coords
(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)), ((0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4), (0.4, 0.4)))
>>> poly_ccw.coords
(((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0)), ((0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4), (0.4, 0.4)))
>>> poly_cw.normalize()
0
>>> poly_cw.coords
(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)), ((0.4, 0.4), (0.6, 0.4), (0.6, 0.6), (0.4, 0.6), (0.4, 0.4)))
>>> poly_ccw.normalize()
0
>>> poly_ccw.coords
(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)), ((0.4, 0.4), (0.6, 0.4), (0.6, 0.6), (0.4, 0.6), (0.4, 0.4))) The GEOS library appears to subscribe to a clockwise outer ring rule, which then makes the inner rings counterclock wise.
... View more
07-16-2015
03:07 PM
|
0
|
0
|
3587
|
|
POST
|
If you are running stand-alone scripts from either Task Scheduler or a batch file, then you will want to focus on file type associations in Windows: Change which programs Windows uses by default. You will want to focus on "Associate a file type with a program." The hard part about knowing which Python environment is associated with Python scripts (*.py) is that both are called "python.exe" so the information provided to the user is rather uninformative: You can use the "Browse" button to find the desired, i.e., 32- or 64-bit, python.exe. I think a better way to handle the situation is to explicitly pick/set the Python environment when you are calling the script from the Task Scheduler or Command Prompt. For example: rem Relying on default file-type association
C:\>tmp\echo_python_version.py
2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)]
rem Explicitly using 32-bit Python
C:\>C:\Python27\ArcGIS10.3\python.exe tmp\echo_python_version.py
2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)]
rem Explicitly using 64-bit Python
C:\>C:\Python27\ArcGISx6410.3\python.exe tmp\echo_python_version.py
2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)]
... View more
07-15-2015
02:24 PM
|
2
|
0
|
3986
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | Friday | |
| 2 | 2 weeks ago | |
| 1 | 2 weeks ago | |
| 2 | 06-05-2026 10:30 AM | |
| 1 | 05-29-2026 08:22 AM |
| Online Status |
Online
|
| Date Last Visited |
yesterday
|