Select to view content in your preferred language

Search and Rescue GPX processing. Add data to map and symbolize

1279
6
01-26-2021 08:47 AM
RDS
by
Emerging Contributor

I'm not a programmer just trying to make somthing work for my sar team. Running ArcGIS pro 2.7 working on the script in spyder 4.2.0 the project is open when testing the script. Eventually I want the script to be a tool in a toolbox in arcgis pro so we can just click it and process the updated gpx files as teams return from a search. What I have below creates the featureclass based on the gpx file name.

My problem looks a lot like the another posted recently so sorry if I should have just added to his.

1. How do I add this to the current map?  I tried .adddatatomap but I guess I do not understand how to use it

2. Once I get it to the map or even before I don't care I want to apply a symbol that I have created and is in F:\GIS\OBSAR\sartraining1.gdb\Green_GPS_Dashed_Line_Symbol each gpx file will have a symbol created for it based on its name so we can quickly see/tell who has covered what areas

 

 

import os
import arcpy

arcpy.env.overwriteOutput = True # allows the script to be ran multiple times without first cleaning up the geodatabase

arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Conversion Tools.tbx")
arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Data Management Tools.tbx")


#arcpy.env.workspace = "F:\GIS\OBSAR\sartraining1.gdb"
arcpy.env.workspace = "F:\GIS\OBSAR\GPX\Contacts"
#arcpy.env.workspace = "F:\GIS\OBSAR\OBSAR.aprx"
#fcs = []
fcs = os.listdir( "F:\GIS\OBSAR\GPX\Contacts")

for I in fcs:

FI = "F:\\GIS\\OBSAR\\GPX\\Contacts\\" + I
FO = arcpy.Describe(I).baseName + "_gpxtofeature"
path = "F:\\GIS\\OBSAR\\GPSactions.gdb\\"
LO = arcpy.Describe(I).baseName + "_PointsToLine"
symin = path + arcpy.Describe(I).baseName

#print(FI)
#print(FO)
#print (LO)
#print (symin)




arcpy.conversion.GPXtoFeatures(Input_GPX_File=FI, Output_Feature_class= path + FO)
arcpy.management.PointsToLine(Input_Features = path + FO, Output_Feature_Class = path + LO, Line_Field="", Sort_Field="", Close_Line="NO_CLOSE")

0 Kudos
6 Replies
DanPatterson
MVP Esteemed Contributor

Code formatting ... the Community Version - GeoNet, The Esri Community will help readability

If you are just running the script in spyder, don't expect to see the results added to Pro.  

You need to attach your script as a custom tool in arctoolbox and run it from there.

An oldie but still applicable

Toolbox creation in ArcGIS Pro - GeoNet, The Esri Community

PS

To set symbology for an output layer, using a *.lyrx file is the easiest.  Scroll far to the right of the parameter dialog to see the option


... sort of retired...
0 Kudos
RDS
by
Emerging Contributor

Thanks for the response. I created a new toolbox and added the script there. When running it as a tool the task hangs and I eventually have to kill the process. The same script ran in spyder takes about a minute to loop through the files in the folder.

Please clarify wouldn't the symbol that you set in the script properties apply the same symbol to each line? I want to apply a custom symbol to each one as it goes through the loop.

This is what it looks like in model builder

# Process: GPX To Features (GPX To Features) (conversion)
Tucker_GPXtoFeatures = "F:\\GIS\\OBSAR\\sartraining1.gdb\\Tucker_GPXtoFeatures"
arcpy.conversion.GPXtoFeatures(Input_GPX_File=Tucker_gpx, Output_Feature_class=Tucker_GPXtoFeatures)

# Process: Points To Line (Points To Line) (management)
Output_Feature_Class_2_ = "F:\\GIS\\OBSAR\\sartraining1.gdb\\Tucker_GPXtoFeatures_PointsToLine"
arcpy.management.PointsToLine(Input_Features=Tucker_GPXtoFeatures, Output_Feature_Class=Output_Feature_Class_2_, Line_Field="", Sort_Field="", Close_Line="NO_CLOSE")

# Process: Apply Symbology From Layer (Apply Symbology From Layer) (management)
Updated_Input_Layer = arcpy.management.ApplySymbologyFromLayer(in_layer=Output_Feature_Class_2_, in_symbology_layer=Green_GPS_Dashed_Line_Symbol, symbology_fields=[], update_symbology="DEFAULT")[0]

0 Kudos
RDS
by
Emerging Contributor
import os
import arcpy

arcpy.env.overwriteOutput = True # allows the script to be ran multiple times without first cleaning up the geodatabase

arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Conversion Tools.tbx")
arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Data Management Tools.tbx")


#arcpy.env.workspace = "F:\GIS\OBSAR\sartraining1.gdb"
arcpy.env.workspace = "F:\GIS\OBSAR\GPX\Contacts"
#arcpy.env.workspace = "F:\GIS\OBSAR\OBSAR.aprx"
#fcs = []
fcs = os.listdir( "F:\GIS\OBSAR\GPX\Contacts")

for I in fcs:
   
    FI = "F:\\GIS\\OBSAR\\GPX\\Contacts\\" + I
    FO = arcpy.Describe(I).baseName + "_gpxtofeature"
    path = "F:\\GIS\\OBSAR\\GPSactions.gdb\\"
    LO = arcpy.Describe(I).baseName + "_PointsToLine"
    symin = path + arcpy.Describe(I).baseName

    #print(FI)
    #print(FO)
    #print (LO)
    #print (symin)
    
 
    
    
    arcpy.conversion.GPXtoFeatures(Input_GPX_File=FI, Output_Feature_class= path + FO)
    arcpy.management.PointsToLine(Input_Features = path + FO, Output_Feature_Class = path + LO, Line_Field="", Sort_Field="", Close_Line="NO_CLOSE")
    
    #Dog_PointsToLine = arcpy.management.ApplySymbologyFromLayer(in_layer=Karen_GPXtoFeatures_PointsToLine, in_symbology_layer=Pink_Line_Symbol, symbology_fields=[], update_symbology="DEFAULT")[0]
0 Kudos
RandyBurton
MVP Alum

You shouldn't have to import the toolboxes at the top of your script.

ImportToolbox says "the core ArcGIS toolboxes are accessible by default in a script".

 




0 Kudos
RDS
by
Emerging Contributor

Thanks, I started with a model builder and it had the toolboxes imported so I did as well.

 

0 Kudos
RDS
by
Emerging Contributor

Still have not gotten this to work, does not seem like it should be this hard.

Here is what I think the workflow should be

Manually copy the GPX files the GPS to a designated folder

Run a tool, it then

1. runs GPX to feature

2. runs points to line works to here

3. adds the newly created lines to the map

4. applies designated symbology to the features

when searchers return I want to just run the tool again and have the updated tracks append to the screen I am running the tools to create the features then running a model to add to map and symbolize. Is my logic wrong, can I do this in python and arcpy???

 

 

 

 

0 Kudos