Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """"
- Tool Name: Starting Zones to SAMOS
- Source Name: StartingZonesToSamos.py
- Version: ArcGIS 10.3.1
- Author: Icelandic Meteorology Office/Ragnar H. Thrastarson
- Created: 2015-07-20
- Description: A python script tool that uses the ArcPy module
- to convert a polygon feature class to a specific text based
- output. Output includes parameters, number of vertices in each
- feature and X and Y coordinates of each vertex for each feature.
- The output is specific for the avalanche simulation software SAMOS.
- Parameters
- 1 Input feature class. Avalanche Starting zone, must be polygon
- 2 Output feature class. Text based output with REL extension
- 3 Snow depth in m
- 4 Snow density in kg/m3
- 5 Type of starting zone
- """
- import arcpy
- InputFC = arcpy.GetParameterAsText(0) # input feature class, tool parameter needs to be set to polygon only
- OutputFile = arcpy.GetParameterAsText(1) # output file is a text file with or without the REL extension
- Parameter1 = arcpy.GetParameterAsText(2) # Snow depth in m
- Parameter2 = arcpy.GetParameterAsText(3) # Snow density in kg/m3
- Parameter3 = arcpy.GetParameterAsText(4) # Type of starting zone
- # define function
- def FeatureToSamos():
- with open(OutputFile, 'w') as f: # create and open output file in write mode
- for row in arcpy.da.SearchCursor(InputFC, ["SHAPE@"]): # for each feature in feature class
- f.write(str(Parameter1.replace(",", ".")) + " " + str(Parameter2.replace(",", ".")) + " " + str(Parameter3.replace(",", ".")) + "\n") # write parameters in first line and move to next line
- for part in row[0]: # for each feature
- vert_count = len(part) # create a variable with the number of vertices
- f.write(str(vert_count) + "\n") # write the number of vertices and move to next line
- for pnt in part: # for each node
- f.write("{0} {1}".format(pnt.X, pnt.Y) + "\n") # write the coordinates of each node and move to next line
- f.close() # save and close output file
- # test if output file has REL extension
- if OutputFile.lower()[-4:] == ".rel": # if yes, run function
- FeatureToSamos()
- else:
- OutputFile = OutputFile + ".rel" # if no, add the REL extension and run function
- FeatureToSamos()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement