Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """"
  3. Tool Name: Starting Zones to SAMOS
  4. Source Name: StartingZonesToSamos.py
  5. Version: ArcGIS 10.3.1
  6. Author: Icelandic Meteorology Office/Ragnar H. Thrastarson
  7. Created: 2015-07-20
  8. Description: A python script tool that uses the ArcPy module
  9. to convert a polygon feature class to a specific text based
  10. output. Output includes parameters, number of vertices in each
  11. feature and X and Y coordinates of each vertex for each feature.
  12. The output is specific for the avalanche simulation software SAMOS.
  13.  
  14. Parameters
  15. 1 Input feature class. Avalanche Starting zone, must be polygon
  16. 2 Output feature class. Text based output with REL extension
  17. 3 Snow depth in m
  18. 4 Snow density in kg/m3
  19. 5 Type of starting zone
  20. """
  21.  
  22. import arcpy
  23.  
  24. InputFC = arcpy.GetParameterAsText(0) # input feature class, tool parameter needs to be set to polygon only
  25. OutputFile = arcpy.GetParameterAsText(1) # output file is a text file with or without the REL extension
  26. Parameter1 = arcpy.GetParameterAsText(2) # Snow depth in m
  27. Parameter2 = arcpy.GetParameterAsText(3) # Snow density in kg/m3
  28. Parameter3 = arcpy.GetParameterAsText(4) # Type of starting zone
  29.  
  30. # define function
  31. def FeatureToSamos():
  32. with open(OutputFile, 'w') as f: # create and open output file in write mode
  33. for row in arcpy.da.SearchCursor(InputFC, ["SHAPE@"]): # for each feature in feature class
  34. f.write(str(Parameter1.replace(",", ".")) + " " + str(Parameter2.replace(",", ".")) + " " + str(Parameter3.replace(",", ".")) + "\n") # write parameters in first line and move to next line
  35. for part in row[0]: # for each feature
  36. vert_count = len(part) # create a variable with the number of vertices
  37. f.write(str(vert_count) + "\n") # write the number of vertices and move to next line
  38. for pnt in part: # for each node
  39. f.write("{0} {1}".format(pnt.X, pnt.Y) + "\n") # write the coordinates of each node and move to next line
  40. f.close() # save and close output file
  41.  
  42. # test if output file has REL extension
  43. if OutputFile.lower()[-4:] == ".rel": # if yes, run function
  44. FeatureToSamos()
  45. else:
  46. OutputFile = OutputFile + ".rel" # if no, add the REL extension and run function
  47. FeatureToSamos()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement