-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.pyHistory
More file actions
5 lines (5 loc) · 27.3 KB
/
.pyHistory
File metadata and controls
5 lines (5 loc) · 27.3 KB
1
2
3
4
5
# -*- coding: utf-8 -*- """ This script creates a new ArcGIS Pro Toolbox (.atbx) for the EGMTrans tool. """ import arcpy import os # Define paths toolbox_dir = os.path.dirname(os.path.abspath(__file__)) atbx_path = os.path.join(toolbox_dir, "EGMTransToolbox.atbx") script_path = os.path.join(os.path.dirname(toolbox_dir), "EGMTrans.py") icon_path = os.path.join(toolbox_dir, "EGMTrans_icon_32px.png") def create_toolbox(): """Creates the .atbx toolbox and configures the EGMTrans script tool.""" try: # Create the .atbx file if arcpy.Exists(atbx_path): arcpy.Delete_management(atbx_path) arcpy.AddMessage(f"Deleted existing toolbox at: {atbx_path}") arcpy.management.CreateToolbox(toolbox_dir, "EGMTransToolbox.atbx") arcpy.AddMessage(f"Successfully created toolbox at: {atbx_path}") # Define the tool alias tool_alias = "EGMTrans" # Add the script tool to the toolbox arcpy.AddToolbox(atbx_path) arcpy.ImportToolbox(atbx_path) # Add the script tool arcpy.management.AddScript( atbx_path, tool_alias, "EGMTrans Tool", "Transform vertical datum between WGS 84 ellipsoid, EGM96, and EGM2008 for DTED and GeoTIFF files.", script_path ) arcpy.AddMessage(f"Added script tool '{tool_alias}' to the toolbox.") # Set the tool's icon arcpy.management.SetToolIcon(f"{atbx_path}\\{tool_alias}", icon_path) arcpy.AddMessage(f"Set icon for '{tool_alias}'.") # Define and set tool parameters tool = getattr(arcpy, f"{tool_alias}_EGMTransToolbox") # Input File or Folder param_input = arcpy.Parameter( displayName="Input File or Folder", name="input", datatype=["GPRasterLayer", "DEFile", "DEFolder"], parameterType="Required", direction="Input" ) # Output File or Folder param_output = arcpy.Parameter( displayName="Output File or Folder", name="output", datatype=["DEFile", "DEFolder"], parameterType="Required", direction="Output" ) # Source Datum param_source_datum = arcpy.Parameter( displayName="Source Datum", name="source_datum", datatype="GPString", parameterType="Required", direction="Input" ) param_source_datum.filter.type = "ValueList" param_source_datum.filter.list = ["WGS84", "EGM96", "EGM2008"] # Target Datum param_target_datum = arcpy.Parameter( displayName="Target Datum", name="target_datum", datatype="GPString", parameterType="Required", direction="Input" ) param_target_datum.filter.type = "ValueList" param_target_datum.filter.list = ["WGS84", "EGM96", "EGM2008"] # Interpolation Algorithm param_algorithm = arcpy.Parameter( displayName="Interpolation Algorithm", name="algorithm", datatype="GPString", parameterType="Optional", direction="Input" ) param_algorithm.filter.type = "ValueList" param_algorithm.filter.list = ["Bilinear Interpolation", "Thin Plate Spline", "Delaunay Triangulation"] param_algorithm.value = "Bilinear Interpolation" # Minimum Patch Size param_min_patch_size = arcpy.Parameter( displayName="Minimum Patch Size (pixels)", name="min_patch_size", datatype="GPLong", parameterType="Optional", direction="Input" ) param_min_patch_size.value = 16 # Absolute Horizontal Accuracy param_abs_horiz_accuracy = arcpy.Parameter( displayName="Absolute Horizontal Accuracy (applied only if missing)", name="abs_horiz_accuracy", datatype="GPLong", parameterType="Optional", direction="Input" ) # Retain Flat Areas param_flatten = arcpy.Parameter( displayName="Retain Flat Areas", name="flatten", datatype="GPBoolean", parameterType="Optional", direction="Input" ) param_flatten.value = True # Create Mask param_create_mask = arcpy.Parameter( displayName="Create Mask", name="create_mask", datatype="GPBoolean", parameterType="Optional", direction="Input" ) param_create_mask.value = False # Save Log File param_save_log = arcpy.Parameter( displayName="Save Log File", name="save_log", datatype="GPBoolean", parameterType="Optional", direction="Input" ) param_save_log.value = True # Set all parameters tool.parameters = [ param_input, param_output, param_source_datum, param_target_datum, param_algorithm, param_min_patch_size, param_abs_horiz_accuracy, param_flatten, param_create_mask, param_save_log ] arcpy.AddMessage("Successfully set all tool parameters.") except arcpy.ExecuteError: arcpy.AddError(arcpy.GetMessages(2)) except Exception as e: arcpy.AddError(str(e)) if __name__ == "__main__": create_toolbox()
# -*- coding: utf-8 -*- """ This script creates a new ArcGIS Pro Toolbox (.atbx) for the EGMTrans tool. """ import arcpy import os # Define paths toolbox_dir = os.path.dirname(os.path.abspath(__file__)) atbx_path = os.path.join(toolbox_dir, "EGMTransToolbox.atbx") script_path = os.path.join(os.path.dirname(toolbox_dir), "EGMTrans.py") icon_path = os.path.join(toolbox_dir, "EGMTrans_icon_32px.png") def create_toolbox(): """Creates the .atbx toolbox and configures the EGMTrans script tool.""" try: # Create the .atbx file if arcpy.Exists(atbx_path): arcpy.Delete_management(atbx_path) arcpy.AddMessage(f"Deleted existing toolbox at: {atbx_path}") arcpy.management.CreateToolbox(toolbox_dir, "EGMTransToolbox.atbx") arcpy.AddMessage(f"Successfully created toolbox at: {atbx_path}") # Define the tool alias tool_alias = "EGMTrans" # Add the script tool to the toolbox arcpy.AddToolbox(atbx_path) arcpy.ImportToolbox(atbx_path) # Add the script tool arcpy.management.AddScript( atbx_path, tool_alias, "EGMTrans Tool", "Transform vertical datum between WGS 84 ellipsoid, EGM96, and EGM2008 for DTED and GeoTIFF files.", script_path ) arcpy.AddMessage(f"Added script tool '{tool_alias}' to the toolbox.") # Set the tool's icon arcpy.management.SetToolIcon(f"{atbx_path}\\{tool_alias}", icon_path) arcpy.AddMessage(f"Set icon for '{tool_alias}'.") # Define and set tool parameters tool = getattr(arcpy, f"{tool_alias}_EGMTransToolbox") # Input File or Folder param_input = arcpy.Parameter( displayName="Input File or Folder", name="input", datatype=["GPRasterLayer", "DEFile", "DEFolder"], parameterType="Required", direction="Input" ) # Output File or Folder param_output = arcpy.Parameter( displayName="Output File or Folder", name="output", datatype=["DEFile", "DEFolder"], parameterType="Required", direction="Output" ) # Source Datum param_source_datum = arcpy.Parameter( displayName="Source Datum", name="source_datum", datatype="GPString", parameterType="Required", direction="Input" ) param_source_datum.filter.type = "ValueList" param_source_datum.filter.list = ["WGS84", "EGM96", "EGM2008"] # Target Datum param_target_datum = arcpy.Parameter( displayName="Target Datum", name="target_datum", datatype="GPString", parameterType="Required", direction="Input" ) param_target_datum.filter.type = "ValueList" param_target_datum.filter.list = ["WGS84", "EGM96", "EGM2008"] # Interpolation Algorithm param_algorithm = arcpy.Parameter( displayName="Interpolation Algorithm", name="algorithm", datatype="GPString", parameterType="Optional", direction="Input" ) param_algorithm.filter.type = "ValueList" param_algorithm.filter.list = ["Bilinear Interpolation", "Thin Plate Spline", "Delaunay Triangulation"] param_algorithm.value = "Bilinear Interpolation" # Minimum Patch Size param_min_patch_size = arcpy.Parameter( displayName="Minimum Patch Size (pixels)", name="min_patch_size", datatype="GPLong", parameterType="Optional", direction="Input" ) param_min_patch_size.value = 16 # Absolute Horizontal Accuracy param_abs_horiz_accuracy = arcpy.Parameter( displayName="Absolute Horizontal Accuracy (applied only if missing)", name="abs_horiz_accuracy", datatype="GPLong", parameterType="Optional", direction="Input" ) # Retain Flat Areas param_flatten = arcpy.Parameter( displayName="Retain Flat Areas", name="flatten", datatype="GPBoolean", parameterType="Optional", direction="Input" ) param_flatten.value = True # Create Mask param_create_mask = arcpy.Parameter( displayName="Create Mask", name="create_mask", datatype="GPBoolean", parameterType="Optional", direction="Input" ) param_create_mask.value = False # Save Log File param_save_log = arcpy.Parameter( displayName="Save Log File", name="save_log", datatype="GPBoolean", parameterType="Optional", direction="Input" ) param_save_log.value = True # Set all parameters tool.parameters = [ param_input, param_output, param_source_datum, param_target_datum, param_algorithm, param_min_patch_size, param_abs_horiz_accuracy, param_flatten, param_create_mask, param_save_log ] arcpy.AddMessage("Successfully set all tool parameters.") except arcpy.ExecuteError: arcpy.AddError(arcpy.GetMessages(2)) except Exception as e: arcpy.AddError(str(e)) create_toolbox()
import arcpy import os # Define paths toolbox_dir = os.path.dirname("C:/code/EGMTrans/arcgis") atbx_path = os.path.join(toolbox_dir, "EGMTransToolbox.atbx") script_path = os.path.join(os.path.dirname(toolbox_dir), "EGMTrans.py") icon_path = os.path.join(toolbox_dir, "EGMTrans_icon_32px.png") def create_toolbox(): """Creates the .atbx toolbox and configures the EGMTrans script tool.""" try: # Create the .atbx file if arcpy.Exists(atbx_path): arcpy.Delete_management(atbx_path) arcpy.AddMessage(f"Deleted existing toolbox at: {atbx_path}") arcpy.management.CreateToolbox(toolbox_dir, "EGMTransToolbox.atbx") arcpy.AddMessage(f"Successfully created toolbox at: {atbx_path}") # Define the tool alias tool_alias = "EGMTrans" # Add the script tool to the toolbox arcpy.AddToolbox(atbx_path) arcpy.ImportToolbox(atbx_path) # Add the script tool arcpy.management.AddScript( atbx_path, tool_alias, "EGMTrans Tool", "Transform vertical datum between WGS 84 ellipsoid, EGM96, and EGM2008 for DTED and GeoTIFF files.", script_path ) arcpy.AddMessage(f"Added script tool '{tool_alias}' to the toolbox.") # Set the tool's icon arcpy.management.SetToolIcon(f"{atbx_path}\\{tool_alias}", icon_path) arcpy.AddMessage(f"Set icon for '{tool_alias}'.") # Define and set tool parameters tool = getattr(arcpy, f"{tool_alias}_EGMTransToolbox") # Input File or Folder param_input = arcpy.Parameter( displayName="Input File or Folder", name="input", datatype=["GPRasterLayer", "DEFile", "DEFolder"], parameterType="Required", direction="Input" ) # Output File or Folder param_output = arcpy.Parameter( displayName="Output File or Folder", name="output", datatype=["DEFile", "DEFolder"], parameterType="Required", direction="Output" ) # Source Datum param_source_datum = arcpy.Parameter( displayName="Source Datum", name="source_datum", datatype="GPString", parameterType="Required", direction="Input" ) param_source_datum.filter.type = "ValueList" param_source_datum.filter.list = ["WGS84", "EGM96", "EGM2008"] # Target Datum param_target_datum = arcpy.Parameter( displayName="Target Datum", name="target_datum", datatype="GPString", parameterType="Required", direction="Input" ) param_target_datum.filter.type = "ValueList" param_target_datum.filter.list = ["WGS84", "EGM96", "EGM2008"] # Interpolation Algorithm param_algorithm = arcpy.Parameter( displayName="Interpolation Algorithm", name="algorithm", datatype="GPString", parameterType="Optional", direction="Input" ) param_algorithm.filter.type = "ValueList" param_algorithm.filter.list = ["Bilinear Interpolation", "Thin Plate Spline", "Delaunay Triangulation"] param_algorithm.value = "Bilinear Interpolation" # Minimum Patch Size param_min_patch_size = arcpy.Parameter( displayName="Minimum Patch Size (pixels)", name="min_patch_size", datatype="GPLong", parameterType="Optional", direction="Input" ) param_min_patch_size.value = 16 # Absolute Horizontal Accuracy param_abs_horiz_accuracy = arcpy.Parameter( displayName="Absolute Horizontal Accuracy (applied only if missing)", name="abs_horiz_accuracy", datatype="GPLong", parameterType="Optional", direction="Input" ) # Retain Flat Areas param_flatten = arcpy.Parameter( displayName="Retain Flat Areas", name="flatten", datatype="GPBoolean", parameterType="Optional", direction="Input" ) param_flatten.value = True # Create Mask param_create_mask = arcpy.Parameter( displayName="Create Mask", name="create_mask", datatype="GPBoolean", parameterType="Optional", direction="Input" ) param_create_mask.value = False # Save Log File param_save_log = arcpy.Parameter( displayName="Save Log File", name="save_log", datatype="GPBoolean", parameterType="Optional", direction="Input" ) param_save_log.value = True # Set all parameters tool.parameters = [ param_input, param_output, param_source_datum, param_target_datum, param_algorithm, param_min_patch_size, param_abs_horiz_accuracy, param_flatten, param_create_mask, param_save_log ] arcpy.AddMessage("Successfully set all tool parameters.") except arcpy.ExecuteError: arcpy.AddError(arcpy.GetMessages(2)) except Exception as e: arcpy.AddError(str(e)) create_toolbox()
# ArcGIS Pro Toolbox Setup Script # To use: Open the Python window in ArcGIS Pro, then paste and run this entire script. import arcpy import os # --- Configuration --- # The script assumes it is being run in an environment where the project root is discoverable. # If paths are incorrect, you may need to set them manually. try: # This will work if the script is run from a context where the current directory is the project root toolbox_dir = os.path.join(os.getcwd(), "arcgis") if not os.path.isdir(toolbox_dir): # Fallback for when the context is different, assuming a standard project structure toolbox_dir = os.path.dirname(os.path.abspath(__file__)) except NameError: # __file__ is not defined in the ArcGIS Pro Python window, so we must hardcode the path. # IMPORTANT: Replace this with the absolute path to your 'arcgis' directory. toolbox_dir = r"c:\code\EGMTrans\arcgis" atbx_path = os.path.join(toolbox_dir, "EGMTransToolbox.atbx") script_path = os.path.join(os.path.dirname(toolbox_dir), "EGMTrans.py") icon_path = os.path.join(toolbox_dir, "EGMTrans_icon_32px.png") print(f"Toolbox directory: {toolbox_dir}") print(f"Toolbox will be created at: {atbx_path}") print(f"Script path: {script_path}") print(f"Icon path: {icon_path}") # --- Script Execution --- try: # 1. Create the .atbx file if arcpy.Exists(atbx_path): arcpy.management.Delete(atbx_path) print(f"Deleted existing toolbox at: {atbx_path}") arcpy.management.CreateToolbox(toolbox_dir, "EGMTransToolbox") print(f"Successfully created toolbox at: {atbx_path}") # 2. Add the script tool to the toolbox tool_alias = "EGMTrans" arcpy.management.AddScript( toolbox=atbx_path, tool_name=tool_alias, tool_label="EGMTrans Tool", tool_description="Transform vertical datum between WGS 84 ellipsoid, EGM96, and EGM2008 for DTED and GeoTIFF files.", script_file=script_path ) print(f"Added script tool '{tool_alias}' to the toolbox.") # 3. Set the tool's icon tool_path_in_toolbox = f"{atbx_path}\\{tool_alias}" arcpy.management.SetToolIcon(tool_path_in_toolbox, icon_path) print(f"Set icon for '{tool_alias}'.") # 4. Define and set tool parameters # Access the newly created tool t = arcpy.ImportToolbox(atbx_path) tool = t.EGMTrans # Get the parameter objects to modify params = tool.parameters # Parameter 0: Input File or Folder params[0].displayName = "Input File or Folder" params[0].datatype = "GPRasterLayer;DEFile;DEFolder" params[0].parameterType = "Required" params[0].direction = "Input" # Parameter 1: Output File or Folder params[1].displayName = "Output File or Folder" params[1].datatype = "DEFile;DEFolder" params[1].parameterType = "Required" params[1].direction = "Output" # Parameter 2: Source Datum params[2].displayName = "Source Datum" params[2].datatype = "GPString" params[2].parameterType = "Required" params[2].direction = "Input" params[2].filter.type = "ValueList" params[2].filter.list = ["WGS84", "EGM96", "EGM2008"] # Parameter 3: Target Datum params[3].displayName = "Target Datum" params[3].datatype = "GPString" params[3].parameterType = "Required" params[3].direction = "Input" params[3].filter.type = "ValueList" params[3].filter.list = ["WGS84", "EGM96", "EGM2008"] # Parameter 4: Interpolation Algorithm params[4].displayName = "Interpolation Algorithm" params[4].datatype = "GPString" params[4].parameterType = "Optional" params[4].direction = "Input" params[4].filter.type = "ValueList" params[4].filter.list = ["Bilinear Interpolation", "Thin Plate Spline", "Delaunay Triangulation"] params[4].value = "Bilinear Interpolation" # Parameter 5: Minimum Patch Size params[5].displayName = "Minimum Patch Size (pixels)" params[5].datatype = "GPLong" params[5].parameterType = "Optional" params[5].direction = "Input" params[5].value = 16 # Parameter 6: Absolute Horizontal Accuracy params[6].displayName = "Absolute Horizontal Accuracy (applied only if missing)" params[6].datatype = "GPLong" params[6].parameterType = "Optional" params[6].direction = "Input" # Parameter 7: Retain Flat Areas params[7].displayName = "Retain Flat Areas" params[7].datatype = "GPBoolean" params[7].parameterType = "Optional" params[7].direction = "Input" params[7].value = True # Parameter 8: Create Mask params[8].displayName = "Create Mask" params[8].datatype = "GPBoolean" params[8].parameterType = "Optional" params[8].direction = "Input" params[8].value = False # Parameter 9: Save Log File params[9].displayName = "Save Log File" params[9].datatype = "GPBoolean" params[9].parameterType = "Optional" params[9].direction = "Input" params[9].value = True # Save the changes to the tool arcpy.management.SaveToLayerFile(tool, "", "ABSOLUTE") print("Successfully set all tool parameters.") print("\nToolbox setup is complete.") except arcpy.ExecuteError: print("ArcPy Error:") print(arcpy.GetMessages(2)) except Exception as e: print(f"An unexpected error occurred: {e}")
# ArcGIS Pro Toolbox Setup Script # To use: Open the Python window in ArcGIS Pro, then paste and run this entire script. import arcpy import os # --- Configuration --- # The script assumes it is being run in an environment where the project root is discoverable. # If paths are incorrect, you may need to set them manually. try: # This will work if the script is run from a context where the current directory is the project root toolbox_dir = os.path.join(os.getcwd(), "arcgis") if not os.path.isdir(toolbox_dir): # Fallback for when the context is different, assuming a standard project structure toolbox_dir = os.path.dirname(os.path.abspath(__file__)) except NameError: # __file__ is not defined in the ArcGIS Pro Python window, so we must hardcode the path. # IMPORTANT: Replace this with the absolute path to your 'arcgis' directory. toolbox_dir = r"c:\code\EGMTrans\arcgis" atbx_path = os.path.join(toolbox_dir, "EGMTransToolbox.atbx") script_path = os.path.join(os.path.dirname(toolbox_dir), "EGMTrans.py") icon_path = os.path.join(toolbox_dir, "EGMTrans_icon_32px.png") print(f"Toolbox directory: {toolbox_dir}") print(f"Toolbox will be created at: {atbx_path}") print(f"Script path: {script_path}") print(f"Icon path: {icon_path}") # --- Script Execution --- try: # 1. Create the .atbx file if arcpy.Exists(atbx_path): arcpy.Delete_management(atbx_path) print(f"Deleted existing toolbox at: {atbx_path}") arcpy.CreateToolbox_management(toolbox_dir, "EGMTransToolbox") print(f"Successfully created toolbox at: {atbx_path}") # 2. Add the script tool to the toolbox tool_alias = "EGMTrans" arcpy.AddScript_management( toolbox=atbx_path, tool_name=tool_alias, tool_label="EGMTrans Tool", tool_description="Transform vertical datum between WGS 84 ellipsoid, EGM96, and EGM2008 for DTED and GeoTIFF files.", script_file=script_path ) print(f"Added script tool '{tool_alias}' to the toolbox.") # 3. Set the tool's icon tool_path_in_toolbox = f"{atbx_path}\\{tool_alias}" arcpy.SetToolIcon_management(tool_path_in_toolbox, icon_path) print(f"Set icon for '{tool_alias}'.") # 4. Define and set tool parameters # Access the newly created tool t = arcpy.ImportToolbox(atbx_path) tool = t.EGMTrans # Get the parameter objects to modify params = tool.parameters # Parameter 0: Input File or Folder params[0].displayName = "Input File or Folder" params[0].datatype = "GPRasterLayer;DEFile;DEFolder" params[0].parameterType = "Required" params[0].direction = "Input" # Parameter 1: Output File or Folder params[1].displayName = "Output File or Folder" params[1].datatype = "DEFile;DEFolder" params[1].parameterType = "Required" params[1].direction = "Output" # Parameter 2: Source Datum params[2].displayName = "Source Datum" params[2].datatype = "GPString" params[2].parameterType = "Required" params[2].direction = "Input" params[2].filter.type = "ValueList" params[2].filter.list = ["WGS84", "EGM96", "EGM2008"] # Parameter 3: Target Datum params[3].displayName = "Target Datum" params[3].datatype = "GPString" params[3].parameterType = "Required" params[3].direction = "Input" params[3].filter.type = "ValueList" params[3].filter.list = ["WGS84", "EGM96", "EGM2008"] # Parameter 4: Interpolation Algorithm params[4].displayName = "Interpolation Algorithm" params[4].datatype = "GPString" params[4].parameterType = "Optional" params[4].direction = "Input" params[4].filter.type = "ValueList" params[4].filter.list = ["Bilinear Interpolation", "Thin Plate Spline", "Delaunay Triangulation"] params[4].value = "Bilinear Interpolation" # Parameter 5: Minimum Patch Size params[5].displayName = "Minimum Patch Size (pixels)" params[5].datatype = "GPLong" params[5].parameterType = "Optional" params[5].direction = "Input" params[5].value = 16 # Parameter 6: Absolute Horizontal Accuracy params[6].displayName = "Absolute Horizontal Accuracy (applied only if missing)" params[6].datatype = "GPLong" params[6].parameterType = "Optional" params[6].direction = "Input" # Parameter 7: Retain Flat Areas params[7].displayName = "Retain Flat Areas" params[7].datatype = "GPBoolean" params[7].parameterType = "Optional" params[7].direction = "Input" params[7].value = True # Parameter 8: Create Mask params[8].displayName = "Create Mask" params[8].datatype = "GPBoolean" params[8].parameterType = "Optional" params[8].direction = "Input" params[8].value = False # Parameter 9: Save Log File params[9].displayName = "Save Log File" params[9].datatype = "GPBoolean" params[9].parameterType = "Optional" params[9].direction = "Input" params[9].value = True # Save the changes to the tool arcpy.SaveToLayerFile_management(tool, "", "ABSOLUTE") print("Successfully set all tool parameters.") print("\nToolbox setup is complete.") except arcpy.ExecuteError: print("ArcPy Error:") print(arcpy.GetMessages(2)) except Exception as e: print(f"An unexpected error occurred: {e}")