POST
|
The script builds a table in a file gdb using other data sources. That table is is joined to the SDE featureclass and then 4 fields in the FC are calculated. In the code below I'm only showing the first of the 4 fields that gets calculated from the join table. The second calculate in row 3 below doesn't use any value from the join table but I need to calculate this value now while the tables are joined. arcpy.AddJoin_management(in_layer_or_view="missu_lyr", in_field="TicketNo", join_table=path_to_join_table, join_field="TicketNo", join_type="KEEP_COMMON") with arcpy.da.Editor(wksp) as edit:
arcpy.CalculateField_management('missu_lyr', sdeFieldPrefix + 'TicketStatus',"!ticketstatus.TicketStatus!",expression_type="PYTHON_9.3",code_block="#")
arcpy.CalculateField_management('missu_lyr', sdeFieldPrefix + 'OpenClosed','"O"',expression_type="PYTHON_9.3",code_block="#") arcpy.RemoveJoin_management('missu_lyr') At this point missu_lyr is still a subset (the subset being that the where_clause when the view was setup had: where_clause = "OpenClosed = 'O' OR OpenClosed IS NULL") of the the entire data without the join now. I just found that if I tried to do a new selection on it arcpy.SelectLayerByAttribute_management("missu_lyr","NEW_SELECTION","TicketStatus = 'Marked' OR TicketStatus = 'Clear/No conflict'") the selection failed. It was only after deleting the view and creating a new view did the selection work.
... View more
10-14-2015
01:26 PM
|
0
|
3
|
742
|
POST
|
Thanks for the link on how to post code because I know that I'm supposed to do that but it was not obvious to me last night as to where I could find it on the editor toolbar.
... View more
10-13-2015
10:24 AM
|
0
|
2
|
1467
|
POST
|
Are you saying that rather than just using arcpy.MakeTableview by itself it would be better to call it while it is being assigned to a variable? I did a test. myvar = arcpy.MakeTableView_management(os.path.join(wksp, targetFC),"missu_lyr",where_clause = "OpenClosed = 'O' OR OpenClosed IS NULL", workspace="") arcpy.GetCount_management("missu_lyr")
<Result '27'>
arcpy.Delete_management('missu_lyr', 'GPTableView')
<Result 'true'> myvar
<Result 'missu_lyr'> # I did not expect to see this arcpy.GetCount_management("missu_lyr")
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 15306, in GetCount
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Rows: Dataset missu_lyr does not exist or is not supported
Failed to execute (GetCount). I did it the other way too. myvar = arcpy.MakeTableView_management(os.path.join(wksp, targetFC),"missu_lyr",where_clause = "OpenClosed = 'O' OR OpenClosed IS NULL", workspace="") arcpy.GetCount_management("missu_lyr")
<Result '27'> del myvar
arcpy.GetCount_management("missu_lyr")
<Result '27'> Maybe this is a case where the variable is just referencing the object and not actually holding it? Deleting the variable just deletes the reference.
... View more
10-13-2015
07:36 AM
|
0
|
4
|
1467
|
POST
|
All I know how to do is use arcpy.Delete_management('missu_lyr') to delete that view. I'm not aware that I can do anything else. Your suggestion of keeping track of locals().keys() is something new for me that I will explore. I think my approach of creating a new view to do selections is reasonable. I'm not processing large files so I'm not worried about running out of memory before the script ends
... View more
10-13-2015
07:11 AM
|
0
|
6
|
1467
|
POST
|
In the first part of my script the view is created with a where clause which I think is like a selection but not something you can really clear. Then I do the join. Then some calculations. Initially I was trying to do a new selection on that view and it was failing even after removing the join. My scenario is a little different from what you are asking although I don't disagree with it. In some earlier versions of my script when I was trying to figure out the correct workflow (I had more selections in the second part) I was intentionally clearing the selections.
... View more
10-13-2015
07:00 AM
|
0
|
5
|
742
|
POST
|
I've been working on a python script for awhile now and I've been stumped for over a week as to why the script would throw an error when I tried to use SelectLayerByAttribute after I removed a join on a tableview that is based on a SDE featureclass. I finally figured out the solution today but I don't really understand why it works. Or, I should say, I don't understand why it didn't work before. The solution was to break my script into two parts: Using one view for the AddJoin and then deleting that view and creating a separate view to perform an action without the join. I had a working script that created a tableview using a where clause from an SDE featureclass, pulled in data from other sources, joined that data to the tableview, did some calculations, then removed the join and deleted the tableview. arcpy.MakeTableView_management(os.path.join(wksp, targetFC),"missu_lyr",where_clause = "OpenClosed = 'O' OR OpenClosed IS NULL", workspace="") Later on I needed to do an additional calculation on the featureclass but I didn't need the table joined anymore. I tried to just continue my workflow by removing that join and using the SelectLayerByAttribute command to get a subset and then calculate the values. However, I kept getting an "ERROR 000358: Invalid expression" on it. arcpy.AddJoin_management(in_layer_or_view="missu_lyr", in_field="TicketNo", join_table=path_to_table, join_field="TicketNo", join_type="KEEP_COMMON")
# do stuff
arcpy.RemoveJoin_management('missu_lyr')
arcpy.SelectLayerByAttribute_management("missu_lyr","NEW_SELECTION","TicketStatus = 'Marked' ") Executing: SelectLayerByAttribute missu_lyr NEW_SELECTION " "TicketStatus" = 'Marked'"
Start Time: Mon Oct 12 17:30:07 2015
ERROR 000358: Invalid expression
An invalid SQL statement was used.
Failed to execute (SelectLayerByAttribute). What really stumped me is that I could run my script to a certain point (I'm using PyScripter) and then try the select command and check the results with GetCount_management and I get what expected. I also did the workflow in the interactive window in ArcMap with no errors. After 37 minutes on the phone with ESRI tech support today I could not give up (they were elevating my issue) and I finally tried removing the join, deleting the view and recreating a new view with a new name and the same syntax. arcpy.MakeTableView_management(os.path.join(wksp, targetFC),"missu_lyr2",where_clause = "OpenClosed = 'O' OR OpenClosed IS NULL", workspace="")
arcpy.SelectLayerByAttribute_management("missu_lyr2","NEW_SELECTION","TicketStatus = 'Marked' ") Then the selection worked. The calculation worked. My script finally worked. Does the act of creating a join and then removing it leave some funny prefixed fieldname behind? Or is it a best practice to always create a new view after a join before doing selections? Message was edited by: Mike Onzay
Edited to add syntax highlighting
... View more
10-12-2015
08:06 PM
|
0
|
17
|
4704
|
POST
|
My admin can see the options now. I agree that if non-admins cannot use it the icon should be hidden. The help guide should also be updated to reflect that you cannot get to the profile page from there.
... View more
12-11-2014
01:36 PM
|
0
|
0
|
447
|
POST
|
While logged into an ArcGIS Online Organizational (AGOL-O) account and viewing My Organization I see a gear icon on every member line. For myself or the administrator nothing happens when clicking on these icons. From the help guide it appears that most of the actions are something an admin would need to do except for modifying a profile. However, if I want to modify my profile I can do that elsewhere. Does the gear icon work for anyone else?
... View more
12-11-2014
12:45 PM
|
0
|
2
|
2077
|
POST
|
How is Geoform different from Collector? Are they complementary?
... View more
10-21-2014
07:57 AM
|
0
|
2
|
3236
|
POST
|
Right. I'm trying to partially replace a string in the path. As I said in my original post the help guide states that it is possible to do partial strings. I need some help figuring out how to do that.
... View more
08-28-2014
08:38 PM
|
0
|
0
|
1004
|
POST
|
I had success earlier today updating the SDE connection files using mxd.replaceWorkspaces. I was trying to do something similar for datasources on a network drive by trying to replace the drive letter with the UNC path. When I try to use lyr in my earlier code (I know I'm using a different method) I get the same or similar ValueError.
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("WORKSPACEPATH"):
wp = lyr.workspacePath
if '@RockGIS2' or 'RockGIS' in wp:
print wp
#mxd.replaceWorkspaces("", "NONE", r"\\gisserver2\GIS_Resources\DirectConnect_ArcCatalog_ConnectionFiles\gisuser@rockgis2.sde","SDE_WORKSPACE")
lyr.findAndReplaceWorkspacePath(wp, r"\\gisserver2\GIS_Resources\DirectConnect_ArcCatalog_ConnectionFiles\gisuser@RockGIS2.sde")
if '@RockRaster' in wp:
... View more
08-28-2014
02:15 PM
|
0
|
2
|
1004
|
POST
|
I want to partially change the path for layers in an mxd from a letter drive to a UNC path. The help page for updating and fixing datasources with arcpy states "...allows you to substitute an entire or partial string for a layer..." but I cannot figure out how to partially replace a path. I have an mxd with one layer that points to W:\Data\City\Planimetric\xyz_planimetric_data_2011.mdb This doesn't change the path.
import arcpy
mxd = arcpy.mapping.MapDocument(r'C:\GIS\test\AppServerConnections.mxd')
for lyr in arcpy.mapping.ListLayers(mxd):
wp = lyr.workspacePath
if 'W:' in wp:
nwp = r"\\\gisserver2" + wp[2:]
mxd.findAndReplaceWorkspacePaths(wp,nwp)
mxd.saveACopy(r"c:\gis\test\test2.mxd")
del mxd
if I substitute add a print statement here
if 'W:' in wp:
nwp = r"\\gisserver2" + wp[2:]
print nwp
it prints as I would expect: \\gisserver2\Data\City\Planimetric\xyz_planimetric_data_2011.mdb What am I missing?
... View more
08-28-2014
01:07 PM
|
0
|
8
|
2831
|
POST
|
I ran into the same problem. My workaround was to use the workspacepath property in the layer class
... View more
08-28-2014
09:19 AM
|
0
|
0
|
628
|
Title | Kudos | Posted |
---|---|---|
10 | 08-12-2024 11:06 AM | |
1 | 02-01-2019 08:27 AM | |
2 | 04-23-2024 08:44 AM | |
1 | 11-07-2023 11:31 AM | |
1 | 11-21-2023 10:17 AM |
Online Status |
Offline
|
Date Last Visited |
09-25-2024
06:17 PM
|