Sunteți pe pagina 1din 7

DTM CONSTRUCTION

BY ARCPY


Porto, 22nd June 2014

Course Unit
Introduo a Programao em Sistemas de Informao Geogrfica

Students
lio Silva
Jn Veres
Mohamed Mohsen

Teachers
Professor Doutor Antnio Coelho
Dr. Ricardo Baptista
Dr. Joo Carvalho

Contents
Contents of Figures ........................................................................................................................................................... 1
1 - Introduction ................................................................................................................................................................. 2
2 - Objectives .................................................................................................................................................................... 2
3 - Through the process of developing the Python script we defined some goals to ensure the efficiency of the script
with ArcPy, ArcToolbox ..................................................................................................................................................... 2
4 - Operationalization Python Script ................................................................................................................................. 3
4.1 Start Script ............................................................................................................................................................ 3
4.2 - List the files in folder ............................................................................................................................................. 3
4.3 - List Feature Classes ............................................................................................................................................... 3
4.4 - Define coordinate system projection ................................................................................................................... 3
4.5 Project coordinate system of the features .......................................................................................................... 4
4.6 Merge Feature Classes ......................................................................................................................................... 4
4.7 - Create TIN ............................................................................................................................................................. 4
4.8 - Convert TIN to raster (TinGrid) ............................................................................................................................. 4
4.9 - Reclassify The TinGrid ........................................................................................................................................... 4
4.10 Create Slope ....................................................................................................................................................... 4
4.11 Create Hillshade ................................................................................................................................................. 5
4.12 Create Aspect ..................................................................................................................................................... 5
5 - Defining parameter data types in ArcGIS toolbox ....................................................................................................... 5
6 - The main difficulties ..................................................................................................................................................... 6
7 - Bibliography ................................................................................................................................................................. 6

Contents of Figures
Figure 1 - Script in ToolBox ............................................................................................................................................... 5
Figure 2 - Layouts .............................................................................................................................................................. 5










1 - Introduction
ArcPy is to perform geographic data analysis, data conversion, data management, and map automation with Python.
The additional power of using ArcPy within Python is the fact that it is interpreted and dynamically typed and is
suited for interactive work. ArcPy provides access to geoprocessing tools as well as additional functions, classes, and
modules that allow you to create simple or complex workflows quickly and easily. ArcGIS applications and scripts
written using ArcPy benefit from being able to access and work by GIS professionals and programmers from many
different users.
Python is a free, cross-platform, open-source programming language that is both powerful and easy to learn. It is
widely used and supported. ESRI has fully embraced Python for ArcGIS and sees Python as the language that fulfills
the needs of our user community. Python extends across ArcGIS and becomes the language for data analysis, data
conversion, data management, and map automation, helping increase productivity.
In this project we aim to create a Python library capable of performing a specific set of operations for the treatment
of digital terrain models (DTM) for using and incorporating into the library ArcPy ArcGIS 10.1. This library is to
include one or more modules, being the central component of the class "DTMBuilder", which will be endowed with
methods that allow easy setup and access to these operations for treatment of DTMs. In the end, a customizable
toolbox will be created in ArcGIS 10.1 with a script which uses the developed library.
The library will be able to operate on any other sets of altimetry data. In other words, the assignment will work
correctly regardless of the data provided, being able to recognize how many files are present and process them
dynamically in its entirety
2 - Objectives
The main goal of this work is to develop a Python script that can run a MDT, in order to ensure the integrity of MDT
which has a set of tasks to accomplish:
List the files in folder and define the workspace path.
Make Lists of feature Classes depending on its geometry types (points, Polylines).
Define coordinate system projection.
Project features from its original coordinate system to another.
Merge features
Create TIN (Triangulated Irregular Network)
Convert TIN to raster (TinGrid)
Reclassify TinGrid.
Create Slope, using as a base the TinGrid.
Create Hillsade, using as a base the TinGrid.
Create Aspect, using as a base the TinGrid.
3 - Through the process of developing the Python script we defined some goals to ensure
the efficiency of the script with ArcPy, ArcToolbox
(a) Ensure that the script is operating with any different user, regardless changing the workspace or the data.
arcpy.env.workspace = folder
(b) Enable all parameters to use during the tasks which could be defined by the user.
arcpy.GetParameterAsText
(c) Create a geoprocessing informative message that can be accessed with any of the GetMessages functions.
arcpy.AddMessage("")
(d) Once a script is finished with an extension's tools, the CheckInExtension function should be used to return the
license to the License Manager so other applications can use.
arcpy.CheckOutExtension("3D")
(e) Create a logical, functional and easily changed depending on the needs of the user script.
4 - Operationalization Python Script
The script is structured and organized to allow any user to build a MDT by the next steps:
4.1 Start Script
First we have to import ArcPy, we can run all geoprocessing tools found in the standard toolboxes installed with
ArcGIS.
import arcpy, os, string
Control whether tools will automatically overwrite any existing output when run. When set to True, tools will
execute and overwrite the output dataset. When set to False, existing outputs will not be overwritten, and the tool
will return an error.
arcpy.overwriteOutput = True
4.2 - List the files in folder
A cycle loop is ideal for working with a Python list because it can be used to step through the list one item at a time.
A cycle loop iterates through each item in the list.
Make a list of files in the current workspace based on a query string.










4.3 - List Feature Classes
A cycle loop is ideal for working with a Python list because it can be used to step through the list one item at a time.
A cycle loop iterates through each item in the list.
Lists the feature classes in the workspace, limited by name, feature type.
pointlist = arcpy.ListFeatureClasses("","Point")
polylinelist = arcpy.ListFeatureClasses("","Polyline")
4.4 - Define coordinate system projection
All feature classes have a coordinate system that is used throughout ArcGIS to display, measure, and transform
geographic data. And we find that the coordinate system of the given feature classes is unknown, so we can use this
tool to specify the correct coordinate system.


def listfolder(folderpath, extension):
listfiles=[]
filesinfolder=os.listdir(folderpath)
for file in filesinfolder:
if (file.endswith(extension)):
listfiles.append(file)
if len(listfiles)>0:
return listfiles
else:
return False
for fc in pointlist:
arcpy.DefineProjection_management(fc, sys)
for fc in polylinelist:
arcpy.DefineProjection_management(fc, sys)
4.5 Project coordinate system of the features
Project spatial data from the defined coordinate system to another one of user choice.





4.6 Merge Feature Classes
Combine multiple input features of the same data type into a single, new output feature. This tool will combine the
points together in one feature and the polylines together in one feature.
arcpy.Merge_management(fclines, folder +"\\Merged_Files\\" + "cn_merge")
arcpy.Merge_management(fcpoint, folder +"\\Merged_Files\\" + "pc_merge")
4.7 - Create TIN
Create a triangulated irregular network (TIN) feature. But first we need to define the properties of the TIN which
required in the toolbox process.







4.8 - Convert TIN to raster (TinGrid)
Create a raster by interpolating its cell values from the elevation of the input TIN at the specified sampling distance.
How well the raster represents the TIN is dependent on the resolution of the raster which will provide by the user
and the degree and interval of TIN surface variation. Generally, as the resolution is increased, the output raster more
closely represents the TIN surface.
arcpy.TinRaster_3d(folder + "\\TIN_file\\tin\\", folder + "\\Convert_TIN_file\\mde", "INT", "LINEAR", "CELLSIZE " +
CELLSIZE)
4.9 - Reclassify The TinGrid
The Reclass tool allows to reclassify the input cell values to alternative values and the user will provide the number
of classes to accomplish the following:
Group certain values together.
Set specific values to NoData.
arcpy.Slice_3d(folder + "\\Convert_TIN_file\\mde", folder +
"\\Reclass_TinGrid\\Reclas_Mde",number_class,"EQUAL_INTERVAL")
4.10 Create Slope
Slope represents the rate of change of elevation for each digital elevation model (DEM) cell. It's the first derivative of
the DEM. The user will provide the type of the output slop (Degree or Percentage)
arcpy.Slope_3d(folder + "\\Convert_TIN_file\\mde", folder + "\\Slope\\" + "Slope", measurement)
for fc in pointlist:
arcpy.Project_management(fc, folder + "\\Projected_Files\\" + fc, sysproject)
for fc in polylinelist:
arcpy.Project_management(fc, folder + "\\Projected_Files\\" + fc, sysproject)

properties = ""
for fc in arcpy.ListFeatureClasses():
if string.find(fc, "cn_merge") >=0:
properties += fc + " Elevation softline <None>;"
elif string.find(fc, "pc_merge") >=0:
properties += fc + " Elevation masspoints <None>;"
arcpy.CreateTin_3d(folder +"\\TIN_file\\" + "TIN", sysproject, properties, "CONSTRAINED_DELAUNAY")

4.11 Create Hillshade
Create a shaded relief from the surface raster (TINGrid) by considering the illumination source angle and shadows
(Azimuth, Altitude) which will provide by the user.
arcpy.HillShade_3d(folder + "\\Convert_TIN_file\\mde", folder + "\\HillShade\\HShade", default_Azimuth,
default_Altitud)
4.12 Create Aspect
The aspect identifies the downslope direction of the maximum rate of change in value from each cell to its
neighbors. The values of the output raster will be the compass direction of the aspect.
arcpy.Aspect_3d(folder + "\\Convert_TIN_file\\mde", folder + "\\Aspect\\Asp")
5 - Defining parameter data types in ArcGIS toolbox
In the end we have to identify the parameters to accept multiple data types, and for different data which not the
same properties like coordinate system or cell size etc. In a Python toolbox, composite data types are defined by
assigning a list of data types to the parameter's datatype property.

Figure 1 - Script in ToolBox

Figure 2 - Layouts
6 - The main difficulties
1 - The automation of the script will not be achieved if the output folder is not empty, the script not allows the user
to operate the script without remove the files which extracted before.
2 - The function that determines the construction of the DTM does not allow adding files that are not altimetry
(contour lines and elevation points) and river network. The use of other entities such as buildings or roads will be
dependent on changing the script or defining new function that enables the particular edition tin (EditTin_3d).
3 After finishing the script by PyDev Eclipse without any errors and terminated, we found some errors appeared
during convert the script to ArcGIS tool in ArcToolbox and it took a long time to find the error reason and solve it like
the next point.
4 - Once a script is finished with an extension's tools, the CheckInExtension function should be used to return the
license to the License Manager so other applications can use.
5 - Create a triangulated irregular network (TIN) feature. At first we need to define the properties of the TIN which
required in the toolbox Create TIN.
6 We couldnt make a specific classify for the TIN to convert to TINGRID just we able to write the number of the
classes but we are not able to put the new values of the new classifications.
7 It will be too hard if we have different coordinate systems for the feature classes.
8- When we make Aspect in ArcMap there is a default classification appear in the layout (north, northeast ) but by
the script, this default classifications dont appear, we have to make it manually by giving each angle its direction.
7 - Bibliography
- ArcGIS Resource Center:
www.resources.arcgis.com
- Lectures and exercises provided by the professors during classes.
- Python Scripting for ArcGIS, Paul A. Zandbergen, Esri Press, 2013

S-ar putea să vă placă și