CanoPy is the Python module for the Georgia Canopy Analysis 2009 project sponsored by the Georgia Forestry Commission (GFC). For further information about this project, please refer to the CanoPy page.
This document outlines the uses and methodology of the functions contained within the CanoPy module. To learn how to use this module, please read the user manual. Also refer to the tutorial.
We are currently planning on developing a fully open source solution without using ArcGIS and Feature Analyst.
Contained in canopy_config.py
are all the data paths that CanoPy functions operate with. Example configuration can be found in canopy_config-example.py
and copied into canopy_config.py
. This module will be imported by the CanoPy module.
str
NAME
(Text)PHYSIO_ID
(Long)AREA
(Float)phyregs_layer = 'Physiographic_Districts_GA
'str
FileName
(Text)naipqq_layer = 'naip_ga_2009_1m_m4b
'str
naipqq_layer
naipqq_layer
by canopy.assign_phyregs_to_naipqq()
. PHYSIO_ID
s from the physregs_layer
in which a naipqq_layer
polygon is contained are output into this field.,#,#,…,
naipqq_phyregs_field = 'phyregs
'str
F:/Georgia/ga/ 34083/ m_3408301_ne_17_1_20090929.tif m_3408301_ne_17_1_20090930.tif ... 34084/ m_3408407_ne_16_1_20090930.tif m_3408407_nw_16_1_20090930.tif ... ...
naip_path = 'F:/Georgia/ga
'int
spatref_wkid = 102039
str
C:/.../ (project_path) Data/ Physiographic_Districts_GA.shp (added as a layer) Results/ gtpoints_Winder_Slope.shp ... 2009 Analysis/ (analysis_path) Data/ naip_ga_2009_1m_m4b.shp (added as a layer) snaprast.tif (snaprast_path) Results/ (results_path) Winder_Slope/ (physiographic region name) Inputs/ reprojected NAIP tiles Outputs/ intermediate output tiles canopy_2009_Winder_Slope.tif ... 2019 Analysis/ (analysis_path) Data/ naip_ga_2019_1m_m4b.shp (added as a layer) snaprast.tif (snaprast_path) Results/ (results_path) Winder_Slope/ (physiographic region name) Inputs/ reprojected NAIP tiles Outputs/ intermediate output tiles canopy_2019_Winder_Slope.tif ... ...
project_path = 'C:/work/Research/GFC Canopy Assessment
'str
analysis_path_format = '%s/%%d Analysis' % project_path
int
analysis_year = 2009
str
snaprast_path
must be r
+ the filename of an existing original NAIP tile so that canopy.reproject_naip_tiles()
can automatically create it based on the folder structure of the NAIP imagery data (naip_path
).snaprast_path = '%s/Data/rm_3408504_nw_16_1_20090824.tif' % analysis_path
str
results_path = '%s/Results' % analysis_path
All functions designed for preproccessing NAIP imagery and for postprocessing trained/classified canopy tiles in addition to utility functions are contained within canopy.py
.
NOTE: The physregs_layer
and naipqq_layer
must be added to an ArcMap or ArcGIS Pro dataframe for CanoPy functions to run.
This function adds the phyregs field to the NAIP QQ shapefile and populates it with physiographic region IDs that intersect each NAIP tile.
Arguments: None
Config variables assigned with canopy_config
:
phyregs_layer = canopy_config.phyregs_layer
naipqq_layer = canopy_config.naipqq_layer
naipqq_phyregs_field = canopy_config.naipqq_phyregs_field
Process:
arcpy.ListFields
and a new text field titled naip_phyregs_field
is added. If the field already exists, it is deleted and a new field is created.arcpy.CalculateField_managment
, a comma (,
) is inserted into the newly created naip_phyregs_field
. This becomes important as the format for the naip_phyregs_field
must be ,#,#,…,
to allow for SQL statments in following functions to be able to read the naip_phyregs_field
properly. The SQL selections will allow for the right NAIP tiles to be computed as the NAIP QQ shapedfile has a corresponding field for ile names.naip_phyregs_field
filled with the IDs of physiographic regions that the QQ tile intersects.This function reprojects and snaps the NAIP tiles that intersect selected physiographic regions.
Arguments:
phyreg_ids
(list of int
): IDs of physiographic regions to process
Config variables assigned with canopy_config
:
phyregs_layer = canopy_config.phyregs_layer
naipqq_layer = canopy_config.naipqq_layer
naipqq_phyregs_field = canopy_config.naipqq_phyregs_field
spatref_wkid = canopy_config.spatref_wkid
snaprast_path = canopy_config.snaprast_path
naip_path = canopy_config.naip_path
results_path = canopy_config.results_path
Process:
canopy_config
using arcpy.SpatialReference
which reads the WKID.snaprast_path
, it is created and arcpy.env.snapRaster
is used to set all output cell alignments to match the snap.phyreg_ids
are selected using an SQL clause to select the phyreg_ids
.FileName
field from each selected NAIP QQ polygon is read.arcpy.ProjectRaster_managment
, the selected NAIP are reprojected to the specified WKID and saved as outputs and the prefix r
(reprojected) is added to the filename.This function converts Textron's Feature Analyst classified outputs to final GeoTIFF files
Arguments:
phyreg_ids
(list of int
): IDs of physiographic regions to process
Config variables assigned with canopy_config
:
phyregs_layer = canopy_config.phyregs_layer
naipqq_layer = canopy_config.naipqq_layer
naipqq_phyregs_field = canopy_config.naipqq_phyregs_field
snaprast_path = canopy_config.snaprast_path
results_path = canopy_config.results_path
Process:
fr
(final reprojected).This function clips final tiles to their respective NAIP QQ area to eliminate overlap.
Arguments:
phyreg_ids
(list of int
): IDs of physiographic regions to process
Config variables assigned with canopy_config
:
phyregs_layer = canopy_config.phyregs_layer
naipqq_layer = canopy_config.naipqq_layer
naipqq_phyregs_field = canopy_config.naipqq_phyregs_field
snaprast_path = canopy_config.snaprast_path
results_path = canopy_config.results_path
Process:
OID
field of the entire NAIP QQ shapefile is encoded.canopy.convert_afe_to_final_tiles
are looped over and, using the corresponding OID
field, are then clipped to their respective NAIP QQ polygons.cfr
(clipped final reprojected).This function mosaics clipped final GeoTIFF and then clips the mosaicked files to their corresponding physiographic regions
Arguments:
phyreg_ids
(list of int
): IDs of physiographic regions to process
Config variables assigned with canopy_config
:
phyregs_layer = canopy_config.phyregs_layer
naipqq_layer = canopy_config.naipqq_layer
naipqq_phyregs_field = canopy_config.naipqq_phyregs_field
analysis_year = canopy_config.analysis_year
snaprast_path = canopy_config.snaprast_path
results_path = canopy_config.results_path
Process:
canopy_config
file exists, the function ends. If no mosaiked layer with the analysis year exists, the process continues.canopy.clip_final_tiles
with the prefix cfr
.arcpy.MosaicToNewRaster
to create the output raster as a new 2 bit GeoTIFF file.
This function is a wrapper function that converts AFE outputs to the final
canopy GeoTIFF file by invoking convert_afe_to_final_tiles()
,
clip_final_tiles()
, and mosaic_clipped_final_tiles()
in the correct order.
Arguments:
phyreg_ids
(list of int
): IDs of physiographic regions to process
Config variables assigned with canopy_config
:
phyregs_layer = canopy_config.phyregs_layer
naipqq_layer = canopy_config.naipqq_layer
naipqq_phyregs_field = canopy_config.naipqq_phyregs_field
analysis_year = canopy_config.analysis_year
snaprast_path = canopy_config.snaprast_path
results_path = canopy_config.results_path
This function generates randomized points for ground truthing with fields for corresponding years populated with the corresponding canopy value at each point.
Arguments:
phyreg_ids
(list of int
): IDs of physiographic regions to processpoint_density
(int
): Number of randomly generated points per square kilometermax_points
(int, default=400
): Maximum number of points generated per regionmin_points
(int, default=200
): Minimum number of points generated per region
Config variables assigned with canopy_config
:
phyregs_layer = canopy_config.phyregs_layer
naipqq_layer = canopy_config.naipqq_layer
spatref_wkid = canopy_config.spatref_wkid
analysis_year = canopy_config.analysis_year
results_path = canopy_config.results_path
Process:
arcpy.CreateRandomPoints
.GT
(e.g., GT
).naip_layer
are spatially joined with the created random points shapefile and saved as a new point layer. calculate_row_column()
.GT
attribute field of the spatially joined shapefile. FID
, Shape
, and GT
are deleted in the spatially joined shapefile.