|
POST
|
To use a dictionary instead of a list (assuming the mapping between your two lists), something like this should also work: import arcpy
fc = r'G:\pworks\assetmanagement\Local Gov Info Model\Wastewater\Inputs\Valve_Schema.gdb\SControlValve'
LCStatus = {
'ABN': 'Abandoned',
'ACT': 'Active',
'AB': 'As Built',
'CHGORD': 'Change Order',
'DEM': 'Demolished',
'INA': 'Inactive',
'OTH': 'Other',
'PRP': 'Proposed',
'RMV': 'Removed',
'UNK': 'Unknown',
'FV': 'Field Verification Required',
'FD': 'Future Development'
}
try:
cursor = arcpy.da.UpdateCursor(fc, ["LIFECYCLESTATUS"])
for row in cursor:
row[0] = LCStatus[row[0]]
cursor.updateRow(row)
del row
del cursor
except RuntimeError:
pass
... View more
07-13-2018
09:47 AM
|
2
|
0
|
5419
|
|
POST
|
I haven't worked with topology, but after exploring the documentation, I wonder if "(Line)" should be included in your rules. topoReglas = ["Must Not Overlap (Line)", "Must Not Intersect (Line)", "Must Not Have Dangles (Line)", "Must Not Have Pseudo-Nodes (Line)", "Must Not Self-Overlap (Line)","Must Not Self-Intersect (Line)","Must Not Intersect Or Touch Interior (Line)", "Must Be Single Part (Line)"]
# should it be? :
topoReglas = ["Must Not Overlap", "Must Not Intersect", "Must Not Have Dangles", "Must Not Have Pseudo-Nodes", "Must Not Self-Overlap","Must Not Self-Intersect", "Must Not Intersect Or Touch Interior", "Must Be Single Part"] And it might make your code more readable and indexing simpler ... # instead of:
arcpy.AddRuleToTopology_management(out_topo, topoReglas[0], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[1], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[2], fc,"","","")
...
# try
for regla in topoReglas:
arcpy.AddRuleToTopology_management(out_topo, regla, fc,"","","")
... View more
07-11-2018
03:49 PM
|
1
|
0
|
2254
|
|
POST
|
I have found that it helps if the text elements have a name. import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT"):
if elm.name == "UpdateText":
elm.text = "Halifax"
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
mxd.save()
del mxd
Does the base map you are starting with contain a text element, or are you wanting to add a new text element? Or to add/update 5 overlapping text elements?
... View more
07-11-2018
03:26 PM
|
0
|
6
|
3066
|
|
POST
|
I believe the mxd field aliases are stored in the mxd document and are not available via arcpy. To illustrate, I created a simple point feature with a field named "FieldName" and gave it an alias of "FieldAlias". I added it to an mxd file. In the mxd file, I changed the field's alias to "MxdAlias". When I examine the feature properties in the data base, the alias still shows as "FieldAlias". However, when I examine the contents of the mxd file, I can see the renamed alias listed along with the original field name.
... View more
07-11-2018
12:25 PM
|
2
|
0
|
1524
|
|
POST
|
If you use the "syntax highlighter", your code will be easier for people to make suggestions and comments. Expand the toolbar ... and click on "Syntax highlighter". Once using the highlighter, select "Python" and paste your code in the box. This will provide line numbers that will assist in discussing your code. For more, see: Code Formatting... the basics++
... View more
07-10-2018
10:20 AM
|
1
|
3
|
2254
|
|
POST
|
You might use ArcCatalog to check the status of Toolbox.pyt. It there is an error in the toolbox, indicated by a red x in the catalog icon, it will give a "The toolbox file <Toolbox.pyt> was not found" message even if the path to the file is valid. You can right click in Catalog and "Check Syntax" of the tool.
... View more
07-10-2018
10:06 AM
|
0
|
1
|
5834
|
|
POST
|
The first few lines of the error message indicate the error occurred at (or just before) line 60 in your code, and it gives the text of the line in question. File "D:\Gis_Phyton\Aplicaciones\SCRIPT_FASE_2\Catalogacion_vias_Ayuda_esri_04_07_2018.py", line 60, in <module>
arcpy.SpatialJoin_analysis(os.path.join(ruta, "vias_l_p"),os.path.join(ruta, "via_ruta_a"),os.path.join(ruta, "Vias_Join_p"),"JOIN_ONE_TO_ONE","KEEP_ALL","","INTERSECT")
Then the error message indicates a line number in the SpatialJoin module where the error was triggered. Then the message indicates the specific nature of the problem. ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Target Features: Dataset D:\Gis_Phyton\Aplicaciones\Base_Practica\MEJIA_RUMINAHUI_WGS84_17S_5000.mdb\vias_l_p does not exist or is not supported
In this case, it is suggesting a couple of things. First, the Access database (a personal geodatabase) does not contain a feature named "vias_l_p" or the database does not exist. In this case, check that the workspace, path and feature name are correct. If the path and feature name is correct, then check to see if the type of join you are trying to accomplish is permitted - that includes making sure the "vias_l_p" feature is the correct type, points, etc.
... View more
07-06-2018
10:17 AM
|
1
|
1
|
3667
|
|
POST
|
Puzzling. And the map works as expected on AGOL? Is the field name unusual, a reserved SQL word or something?
... View more
07-05-2018
10:49 AM
|
0
|
3
|
3498
|
|
POST
|
Did you check the map's pop-up display settings? You may need to check the display and edit boxes as this may not be automatic when adding a new field.
... View more
07-05-2018
10:01 AM
|
2
|
9
|
3498
|
|
POST
|
Thanks for posting your code. I noticed a couple of things. First, to your original question. You are indicating that the scrip works well inside ArcMap, but not outside. I suspect it may be with the workspace path that is being created. I do not know if "IT_TRANSPORTE_TERRESTRE" is part of what is assigned to the workspace variable "ruta" or not. ruta = arcpy.env.workspace = arcpy.GetParameterAsText(0)
arcpy.SpatialJoin_analysis(
"vias_l_p",
"via_ruta_a",
os.path.join(ruta,"IT_TRANSPORTE_TERRESTRE","Vias_Join_p"),
"JOIN_ONE_TO_ONE",
"KEEP_ALL",
"",
"INTERSECT"
)
# assuming workspace is: \Some\Path\IT_TRANSPORTE_TERRESTRE
# my suggestion is to try:
arcpy.SpatialJoin_analysis(
os.path.join(ruta, "vias_l_p"),
os.path.join(ruta, "via_ruta_a"),
os.path.join(ruta, "Vias_Join_p"),
....
# or try
arcpy.SpatialJoin_analysis(
"vias_l_p",
"via_ruta_a",
"Vias_Join_p",
....
# assuming workspace is: \Some\Path\
# (does not include "IT_TRANSPORTE_TERRESTRE"
# my suggestion is to try:
arcpy.SpatialJoin_analysis(
os.path.join(ruta,"IT_TRANSPORTE_TERRESTRE","vias_l_p"),
os.path.join(ruta,"IT_TRANSPORTE_TERRESTRE","via_ruta_a"),
os.path.join(ruta,"IT_TRANSPORTE_TERRESTRE","Vias_Join_p"),
.... In your code (at the end) you mentioned having a problem with another line. Here the problem looks like an incorrectly formed where clause. Often the field names should not be quoted, and in SQL the equality symbol is just a single "=". If the SQL server you are using requires quoting field names then you will need to escape them. You should check the documentation for your server. # another line that didn´t do anything
arcpy.SelectLayerByAttribute_management(
"Vias_Join_p_lyr",
"NEW_SELECTION",
"descripcio" == "descripcio_1" and "nam" == "nam_1" and "na2" == "na2_1" and "acc" == "acc_1" and "rst" == "rst_1" and "typ" == "typ_1" and "hct" == "hct_1" and "wtc" == "wtc_1" and "loc" == "loc_1" and "ltn" == "ltn_1" and "mes" == "mes_1" and "tuc" == "tuc_1" and "txt" == "txt_1" and "subtipo" == "subtipo_1")
# for where_clause try:
"descripcio = descripcio_1 AND nam = nam_1 AND na2 = na2_1" # continue ....
# if field names need quotes, escape them using \"
"\"descripcio\" = \"descripcio_1\" AND \"nam = nam_1\" AND \"na2\" = \"na2_1\"" # continue .... If after you try these suggestions, you are still having problems then be sure to include any error messages in your post. Hope this helps.
... View more
06-30-2018
08:42 PM
|
2
|
6
|
3667
|
|
POST
|
As I recall, you should be able to use a script tool either inside or outside of Arc. A shortcut to a python script could activate it. Perhaps ImportToolbox; see last code sample. Edit: Actually, the tool dialog doesn't show outside Arc. For a dialog box, TkFileDialog might provide a similar user experience when outside Arc for searching directories.
... View more
06-29-2018
01:06 PM
|
1
|
0
|
2761
|
|
POST
|
As a reference, here is the script from the link mentioned: arcpy.env.workspace = "e:/crs/mobile/mobile.gdb"
dsc = arcpy.Describe("sap")
lstIndex = [i.name for i in dsc.Indexes][1:]
print lstIndex
arcpy.management.RemoveIndex("sap",lstIndex)
Line 2 is asking for a description of a feature class named "sap" inside the geodatabase. The script then puts the index names in a list starting with the second item. I assume this removes the FDO_OBJECTID from the list, but it keeps other items like FDO_SHAPE which you probably would not want to delete.
... View more
06-29-2018
12:33 PM
|
0
|
0
|
1509
|
|
POST
|
Looks like you are using a command line. Have you considered creating a Python script tool. It offers some parameter checking. See Understanding script tool parameters and related documentation pages.
... View more
06-29-2018
11:51 AM
|
1
|
2
|
2761
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2016 02:23 PM | |
| 1 | 09-09-2017 08:27 PM | |
| 2 | 08-20-2020 06:15 PM | |
| 1 | 10-21-2021 09:15 PM | |
| 1 | 07-19-2018 12:33 PM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
07:13 PM
|