Buen dia amigos,
Gracias a aceptarme en la comunidad. Tengo un problema. Estoy intentando hacer un script, donde el objetivo es realizar es una unión espacial en mi caso. entre target = Vias_Join_p (punto de camino) y Join = via_ruta_a (polígono de camino) Esta es la línea, se ejecuta bien en la ventana de comandos en ArcMap, pero cuando intento ejecutar Pythonwin o ejecutar un script en la caja de herramientas, no aparece la unión, solo aparece campos de via_ruta_a con valor 0 en la tabla de Vias_Join_p. 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") Las dos coberturas tienen dominios en sus campo, no se si esto sea un inconveniente, adjunto una imagen con la tabla de resultados. gracias por las respuestas!
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") <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
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 <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
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.
Thanks for your help Randy, it works so good!
import arcpyimport os
# Definicion del espacio de trabajoarcpy.overwriteOutput = Trueruta = arcpy.env.workspace = arcpy.GetParameterAsText(0)
datasets = arcpy.ListDatasets(feature_type='feature')datasets = [''] + datasets if datasets is not None else []for ds in datasets: for fc in arcpy.ListFeatureClasses(feature_dataset=ds): #if fc == "via_ruta_l": #print fc
if ds == "IT_TRANSPORTE_TERRESTRE" and fc == "via_ruta_l": input_dataset = ds input_Fclass = fc topo_name = "Via_l_Topologia" cluster_tol = 0.001 topoReglas = ["Must Not Intersect (Line)","Must Not Self-Intersect (Line)","Must Not Intersect Or Touch Interior (Line)"] validate = "true"
#Crear topologia de Altimetría out_topo = arcpy.CreateTopology_management(input_dataset, topo_name, cluster_tol) #Añadir FeatureClass a la Topologia arcpy.AddFeatureClassToTopology_management(out_topo, fc, 1, 1 ) print(arcpy.GetMessages()) arcpy.AddMessage("Proceso Iniciado") arcpy.AddRuleToTopology_management(out_topo, topoReglas[0], fc,"","","") arcpy.AddRuleToTopology_management(out_topo, topoReglas[1], fc,"","","") arcpy.AddRuleToTopology_management(out_topo, topoReglas[2], fc,"","","") arcpy.ValidateTopology_management(out_topo) arcpy.ExportTopologyErrors_management(out_topo, ds, "Topo_vias") arcpy.MakeFeatureLayer_management("via_ruta_l","via_ruta_l_lyr") arcpy.MakeFeatureLayer_management("Topo_vias_point","Topo_vias_point_lyr") arcpy.AddMessage("1") arcpy.SelectLayerByLocation_management("via_ruta_l_lyr", "INTERSECT", "Topo_vias_point_lyr") arcpy.SplitLineAtPoint_management("via_ruta_l_lyr","Topo_vias_point_lyr",os.path.join(ruta,"IT_TRANSPORTE_TERRESTRE","vias_l_c") ,"0.1 Meters") arcpy.MakeFeatureLayer_management("vias_l_c","vias_l_c_lyr") arcpy.SelectLayerByLocation_management("via_ruta_l_lyr", "INTERSECT", "Topo_vias_point_lyr","","SWITCH_SELECTION")
arcpy.Append_management("via_ruta_l_lyr" , "vias_l_c_lyr" , "NO_TEST", " "," " ) arcpy.AddMessage("2") arcpy.FeatureToPoint_management("vias_l_c_lyr",os.path.join(ruta,"IT_TRANSPORTE_TERRESTRE","vias_l_p"),"INSIDE") #arcpy.MakeFeatureLayer_management("vias_l_p","vias_l_p_lyr") arcpy.AddMessage("3") elif fc == "via_ruta_a": 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") arcpy.AddMessage("4")
#####New Problem when I put this lines, I have an error, that "Vias_Join_p_lyr" its is not supported ###
arcpy.MakeFeatureLayer_management(os.path.join(ruta,"Vias_Join_p"),(os.path.join(ruta, "Vias_Join_p_lyr"))) arcpy.SelectLayerByAttribute_management(os.path.join(ruta, "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") arcpy.SelectLayerByAttribute_management("Vias_Join_p_lyr" , "SWITCH_SELECTION","")
### When I put this lines I have another error arcpy.SelectLayerByAttribute_management(os.path.join(ruta, "Vias_Join_p") , "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")
arcpy.SelectLayerByAttribute_management("Vias_Join_p" , "SWITCH_SELECTION","")
Please Could you help me? I have tried of some ways, but I dont have a good result
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 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialJoin_analysis<SPAN class="punctuation token">(</SPAN> <SPAN class="string token">"vias_l_p"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"via_ruta_a"</SPAN><SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>ruta<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"IT_TRANSPORTE_TERRESTRE"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Vias_Join_p"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"JOIN_ONE_TO_ONE"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"KEEP_ALL"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"INTERSECT"</SPAN> <SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># assuming workspace is: \Some\Path\IT_TRANSPORTE_TERRESTRE</SPAN> <SPAN class="comment token"># my suggestion is to try:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialJoin_analysis<SPAN class="punctuation token">(</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>ruta<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"vias_l_p"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>ruta<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"via_ruta_a"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>ruta<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Vias_Join_p"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="comment token"># or try</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialJoin_analysis<SPAN class="punctuation token">(</SPAN> <SPAN class="string token">"vias_l_p"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"via_ruta_a"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Vias_Join_p"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="comment token"># assuming workspace is: \Some\Path\</SPAN> <SPAN class="comment token"># (does not include "IT_TRANSPORTE_TERRESTRE"</SPAN> <SPAN class="comment token"># my suggestion is to try:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialJoin_analysis<SPAN class="punctuation token">(</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>ruta<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"IT_TRANSPORTE_TERRESTRE"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"vias_l_p"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>ruta<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"IT_TRANSPORTE_TERRESTRE"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"via_ruta_a"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>ruta<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"IT_TRANSPORTE_TERRESTRE"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Vias_Join_p"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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.
<SPAN class="comment token"># another line that didn´t do anything</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN> <SPAN class="string token">"Vias_Join_p_lyr"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"descripcio"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"descripcio_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"nam"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"nam_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"na2"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"na2_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"acc"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"acc_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"rst"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"rst_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"typ"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"typ_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"hct"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"hct_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"wtc"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"wtc_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"loc"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"loc_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"ltn"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"ltn_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"mes"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"mes_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"tuc"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"tuc_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"txt"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"txt_1"</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">"subtipo"</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"subtipo_1"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># for where_clause try:</SPAN> <SPAN class="string token">"descripcio = descripcio_1 AND nam = nam_1 AND na2 = na2_1"</SPAN> <SPAN class="comment token"># continue ....</SPAN> <SPAN class="comment token"># if field names need quotes, escape them using \"</SPAN> <SPAN class="string token">"\"descripcio\" = \"descripcio_1\" AND \"nam = nam_1\" AND \"na2\" = \"na2_1\""</SPAN> <SPAN class="comment token"># continue ....</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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.
Hi Randy, here is the script
datasets = arcpy.ListDatasets(feature_type='feature')datasets = [''] + datasets if datasets is not None else []for ds in datasets: for fc in arcpy.ListFeatureClasses(feature_dataset=ds): #if fc == "via_ruta_l":
#Crear topologia de Vialidad out_topo = arcpy.CreateTopology_management(input_dataset, topo_name, cluster_tol) #Añadir FeatureClass a la Topologia arcpy.AddFeatureClassToTopology_management(out_topo, fc, 1, 1 ) print(arcpy.GetMessages()) arcpy.AddMessage("Proceso Inciado") arcpy.AddRuleToTopology_management(out_topo, topoReglas[0], fc,"","","") arcpy.AddRuleToTopology_management(out_topo, topoReglas[1], fc,"","","") arcpy.AddRuleToTopology_management(out_topo, topoReglas[2], fc,"","","") arcpy.ValidateTopology_management(out_topo) arcpy.ExportTopologyErrors_management(out_topo, ds, "Topo_vias") arcpy.MakeFeatureLayer_management("via_ruta_l","via_ruta_l_lyr") arcpy.MakeFeatureLayer_management("Topo_vias_point","Topo_vias_point_lyr") arcpy.AddMessage("1") arcpy.SelectLayerByLocation_management("via_ruta_l_lyr", "INTERSECT", "Topo_vias_point_lyr") arcpy.SplitLineAtPoint_management("via_ruta_l_lyr","Topo_vias_point_lyr",os.path.join(ruta,"IT_TRANSPORTE_TERRESTRE","vias_l_c") ,"0.1 Meters") arcpy.MakeFeatureLayer_management("vias_l_c","vias_l_c_lyr") arcpy.SelectLayerByLocation_management("via_ruta_l_lyr", "INTERSECT", "Topo_vias_point_lyr","","SWITCH_SELECTION")
arcpy.Append_management("via_ruta_l_lyr" , "vias_l_c_lyr" , "NO_TEST", " "," " ) arcpy.AddMessage("2") arcpy.FeatureToPoint_management("vias_l_c_lyr",os.path.join(ruta,"IT_TRANSPORTE_TERRESTRE","vias_l_p"),"INSIDE") arcpy.AddMessage("3") elif fc == "via_ruta_a": 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")
# the goal of this script is compare each field, here are 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")
In your script, are you using the full path to your target and join features (or an arcpy.env.workspace setting)? Are you receiving any error messages when using Pythonwin; if so, what are they? Can you share a bit more of your script so we can see how the target and join features are initialized before the SpatialJoin. Thanks.
Thanks for the translation!Now, I hope that someone help me with my problem
(an approximate translation to English)
Good day friends,Thank you to accept me in the community. I have a problem. I'm trying to make a script, where the goal is to realize is a spatial union in my case. between target = Vias_Join_p (path point) and Join = via_ruta_a (path polygon) This is the line, it runs well in the command window in ArcMap, but when I try to run Pythonwin or run a script in the toolbox, it does not union appears, only fields of via_ruta_a with value 0 appear in the table of Vias_Join_p.
arcpy<SPAN class="punctuation token">.</SPAN>SpatialJoin_analysis<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"vias_l_p"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"via_route_a"</SPAN><SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join <SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"IT_TRANSPORTE_TERRESTRE"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Vias_Join_p"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"JOIN_ONE_TO_ONE"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"KEEP_ALL"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"INTERSECT"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
The two coverages have domains in the field, I do not know if this is an inconvenience, I attach an image with the results table.Thanks for the answers!
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.