|
POST
|
My response here is mostly an aside to the original dialogue, but there are a couple of things I think are worth bringing up. First, it is helpful to format your code or use syntax highlighting. There are numerous blog posts and comments about how to do it. A good place to start is Curtis Price's blog post, Posting Code blocks in the new GeoNet. Second, most, if not all, ArcGIS geoprocessing tools return a Result object. The interactive Python window hints at that fact by showing <Result '27'> in the window when you run the Get Count tool in your test. Looking at an example might be helpful: >>> tmpTable = arcpy.CreateTable_management('in_memory','temp')
>>> type(tmpTable)
<class 'arcpy.arcobjects.arcobjects.Result'>
>>> tmpTable.__repr__()
"<Result 'in_memory\\\\temp'>"
>>> tmpTable.__str__()
'in_memory\\temp'
>>> As you can see with line #2-3, the Create Table tool returns a Result object. The Result object's representation, via the representation dunder method (object.__repr__), is what users are used to seeing in the interactive Python window (line #5). Whereas the __repr__ method is the “official” string representation of an object, the __str__ method (object.__str__) is the “informal” string representation of an object, which is what geoprocessing tools are using to determine the path to objects and what not when a Result object from one tool is passed to another tool. I mention the above because using the built-in Python delete function won't delete the object being referenced by the Result object. To delete ArcPy/ArcGIS objects, you should use the Delete tool first and then you can delete the variable referencing the result object if you want. >>> arcpy.Delete_management(tmpTable)
<Result 'true'>
>>> tmpTable
<Result 'in_memory\\temp'>
>>> del tmpTable
>>>
... View more
10-13-2015
09:36 AM
|
1
|
3
|
3814
|
|
POST
|
Are you removing or clearing the selection before removing the join? If you make a selection against a Feature Layer or Table View and don't clear it before breaking a join, it seems to hang onto references of the join after you try to remove it.
... View more
10-13-2015
06:48 AM
|
0
|
6
|
3814
|
|
POST
|
Are you interested in randomly placing a point within a Polygon, moving an existing point to a new location while maintaining it attributes, or both? Since the latter question is a bit more straightforward to answer, I will start there. Moving an existing point to a new location while maintaining its attributes.... This can be accomplished using an update cursor, I prefer ArcPy Data Access cursors. Assuming you have an existing list of coincident points to be moved as well as a list of new point locations that are randomly placed with a polygon of interest, the basic structure of an update cursor would look like this: with arcpy.da.UpdateCursor(fc, ["OID@","SHAPE@XY"]) as cur:
for oid, xy in cur:
if oid in move_oid_list:
cur.updateRow([oid, new_xy]) Since you didn't ask about identifying coincident points, I will assume you already have a method of doing that, which leaves the issue of a new random point. Randomly placing a point within a Polygon.... With the limited information provided in the original question, it is hard to know exactly what to suggest. There are built-in tools (Create Random Points), quick-and-dirty approximate methods for moving limited number of points, and of course, one could roll his own based on the many different mathematical approaches found across the web. I sometimes use a random point generator that involves generating points within a polygon's extent and then checking to see whether they are contained within the polygon. def RandomPoints(polygon):
from random import uniform
ext = polygon.extent
while True:
pt = arcpy.Point(uniform(ext.XMin, ext.XMax), uniform(ext.YMin, ext.YMax))
if polygon.contains(pt):
yield pt If you are generating tens of thousands of points or more, performance of the code might become an issue, but it does have an extremely small memory footprint since new points are created on demand instead of the Create Random Points tool that generates all of them at once. The built-in tool, though, takes a more mathematically/statistically rigorous approach so that needs to weigh into one's decision as well. Modifying my update cursor code to use the RandomPoints function would look like: with arcpy.da.UpdateCursor(fc, ["OID@","SHAPE@XY"]) as cur:
for oid, xy in cur:
if oid in move_oid_list:
rndPts = RandomPoints(constraining_polygon)
new_pt = next(rndPts)
new_xy = (new_pt.X, new_pt.Y)
cur.updateRow([oid, new_xy)]) I nested the RandomPoints function within the oid loop under the thought that the constraining polygon could vary by each point being moved. If you are going to use the built-in tool, you can create a feature class of random points in memory and then either use a search cursor to access the points or copy them into a list of points using the Copy Features tool.
... View more
10-12-2015
12:05 PM
|
2
|
0
|
1984
|
|
POST
|
If you hover your mouse over the project, it should say something like "Project Not Found." For any project with that status, clicking on it will prompt you to remove the shortcut from the list. There is also an XML config file you could modify if you are so inclined, but I am guessing discourages it since I haven't seen them mention editing the file in any of their documentation. This issue was brought up during beta testing of ArcGIS Pro 1.0. Several users were interested in having the list only include projects that were accessible/found. Off the top, I can't remember what Esri's response was, but obviously they either think the current functionality is ideal or they just haven't found time to fix it yet.
... View more
10-12-2015
06:33 AM
|
1
|
0
|
880
|
|
POST
|
The error messages give the impression it has something to do with how arguments are being passed. Since "DATA" is the default argument for the ignore_nodata, how about leaving it off in your call outraster = FocalStatistics(inRaster, neighbourHood, "MEAN") or passing as a keyword argument outraster = FocalStatistics(inRaster, neighbourHood, "MEAN", ignore_nodata="DATA") Although not common, I have run across bugs where tools error out when using positional arguments but not keyword arguments for optional parameters. Also, I noticed you are using ArcGIS 10.1. It could be you are running into a bug that has since been addressed in later releases. I don't have all of the "Issues Addressed" documents pulled up, but it might be worth checking to see what Focal Statistics bugs have been fixed since ArcGIS 10.1.
... View more
10-07-2015
12:58 PM
|
0
|
1
|
1571
|
|
POST
|
Instead of getting into the specifics of what works for us, and might not work for others, I encourage you to look over An overview of the Data Comparison toolset if you haven't already. I have used both Feature Compare and Table Compare. Although they require a bit of setup, once done, the tools can be quite efficient. The Detect_Feature_Changes tool has always intrigued me, but I have never taken the time to try it out.
... View more
10-06-2015
09:05 AM
|
1
|
0
|
1873
|
|
POST
|
Can you move it and it doesn't save or can you not even move it in the first place?
... View more
10-06-2015
08:57 AM
|
0
|
0
|
6001
|
|
POST
|
If you click the "Status" icon in the Manage Edits part of the Edit Ribbon, what specific warnings or errors, if any, do you get for the layer you are trying to edit?
... View more
10-05-2015
09:55 AM
|
0
|
6
|
6001
|
|
POST
|
Is this feature class large? Are all the records being altered/modified each day? I ask because completely deleting all records in a feature class only to replace them with many of the same records creates a lot of overhead, especially if the feature class is versioned, even more especially if there are replicas based off of the geodatabase. If most of the records don't change, it might be more efficient to implement a record comparison workflow and only purge and replace records that are different.
... View more
10-02-2015
01:12 PM
|
2
|
4
|
3112
|
|
POST
|
ArcGIS isn't the only software that doesn't like dots/periods in SQL Server object names. In fact, certain Excel tools will error out as well. Although Microsoft doesn't provide any specific guidance against using dots in SQL Server object names, I think you would find a vast majority of SQL Server DBAs, and even some developers, would say it is not a good practice to do so since SQL Server uses dots for very specific reasons in its 4-part object naming convention.
... View more
10-02-2015
07:40 AM
|
1
|
1
|
3944
|
|
POST
|
It seems EXTRACT is working and CURRENT_DATE, is the issue with the DateReported field? Does this work? (EXTRACT(YEAR FROM "DateReported"))
... View more
10-02-2015
07:14 AM
|
0
|
0
|
2818
|
|
POST
|
What about moving the right-parenthesis over to before the less than comparison: (EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM "DateReported")) < 10 AND "Facility" = 'Main' AND ("Cause" = 'Other' OR "DateRepaired" IS NULL)
... View more
10-01-2015
05:50 PM
|
1
|
2
|
2818
|
|
POST
|
OK, a few comments: Trusted_Connection loosely means "Windows Authentication." It appears you want to use SQL Server/database authentication and not operating system authentication. Your connection string has both, and I don't know which one takes priority over the other, so I suggest you drop Trusted_Connection if you want to use database authentication. It could be your "Driver=SQL Server" is causing the issue. As the Connecting to SQL Server from Windows pyodbc covers, there "many SQL Server ODBC drivers written and distributed by Microsoft." The {SQL Server} driver is the oldest and isn't always installed on machines, or doesn't always work well with newer versions of SQL Server when installed. I would recommend updating the connection string to use a newer driver that is likely already installed. You are using backslashes with your SQL Server name, which is common for SQL Server named instances, but in Python backslashes are escape characters for strings. You may need to escape your backslash or use triple quotes for your connection string.
... View more
09-29-2015
08:00 AM
|
1
|
1
|
4759
|
|
POST
|
Is the sample code above what you used to create your code or is it your code? If the former, please post your code. If the latter, start by replacing <server name> with an actual SQL Server instance name. Also, is your password for the sa user really 'sa'?
... View more
09-28-2015
01:20 PM
|
0
|
3
|
4759
|
|
POST
|
Using the SQL WHERE clause in the fashion you describe is inefficient for a couple or more reasons. If the CSV file isn't huge and memory isn't tight, reading the CSV file and loading it into a native Python data structure in-memory would allow you to drop the WHERE clause and iterate over the cursor once doing lookups on the CSV contents that are in memory. Looking up data in Python data structures in memory is much less expensive than re-initializing cursors and passing WHERE clauses for single records. If you must keep your general workflow, then there are some items to experiment with. Have you tried disabling with_undo when starting an edit session? Have you tried multiple edit operations within the same multiple edit session? Can you provide any specific code? It is easier for people to comment on specific code than give statements about general situations.
... View more
09-28-2015
10:57 AM
|
0
|
0
|
2024
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 2 weeks ago | |
| 2 | 4 weeks ago | |
| 1 | 4 weeks ago | |
| 2 | 06-05-2026 10:30 AM | |
| 1 | 05-29-2026 08:22 AM |
| Online Status |
Online
|
| Date Last Visited |
10 hours ago
|