forked from Riverscapes/RIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_DCE.py
128 lines (99 loc) · 5.07 KB
/
create_DCE.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 14 15:04:43 2020
@author: karen
"""
# Name: new_DCE.py
# Description: Create shapefiles for inundation work
# Import system modules
import os
import arcpy
import sys
from settings import ModelConfig
import uuid
from lib.project import RSProject, RSLayer
from lib.util import safe_makedirs
from lib.loghelper import Logger
import time
import datetime
cfg = ModelConfig('http://xml.riverscapes.xyz/Projects/XSD/V1/Inundation.xsd')
# function for create files
def new_DCE(srs_template, project_path, AP_fold, DCE_fold, image_path):
# LayerTypes = {
# RSLayer(name, id, tag, rel_path)
# 'AP_new': RSLayer(date_name, AP_fold, 'Raster', os.path.join('01_Inputs/01_Imagery', AP_fold, 'imagery.tif')),
# 'INUN_new': RSLayer('Inundation', 'DCE_01_inun', 'Vector', os.path.join('03_Analysis', DCE_fold, 'Shapefiles/inundation.shp')),
# 'DAM_CREST_new': RSLayer('Dam Crests', 'DCE_01_damcrests', 'Vector', os.path.join('03_Analysis', DCE_fold, 'Shapefiles/dam_crests.shp')),
# 'TWG_new': RSLayer('Thalwegs', 'DCE_01_thalwegs', 'Vector', os.path.join('03_Analysis', DCE_fold, 'Shapefiles/thalwegs.shp'))
# }
#log = Logger('edit_xml')
#log.info('Loading the XML to make edits...')
# Load up a new RSProject class
#project = RSProject(cfg, project_path)
log = Logger('new_DCE')
# Set local variables
has_m = "DISABLED"
has_z = "DISABLED"
log.info('before getting spatial reference')
# Use Describe to get a SpatialReference object
spatial_reference = arcpy.Describe(srs_template).spatialReference
log.info('checking if project folders exist')
# check if Inputs, Mapping, and Analysis folders exist, if not create them
folder_list = ['01_Inputs', '02_Mapping', '03_Analysis']
for folder in folder_list:
if not os.path.exists(os.path.join(project_path, folder)):
os.makedirs(os.path.join(project_path, folder))
log.info('Inputs, Mapping, Analysis folders exist')
# set pathway to imagery folder
image_folder = os.path.join(project_path, '01_Inputs/01_Imagery')
# create new AP folder
if not os.path.exists(os.path.join(image_folder, AP_fold)):
os.makedirs(os.path.join(image_folder, AP_fold))
AP_path = os.path.join(image_folder, AP_fold)
else:
AP_path = os.path.join(image_folder, AP_fold)
log.info('copying image to project folder...')
def add_image(image_path, AP_folder):
# put input imagery in folder
if not os.path.exists(os.path.join(AP_folder, 'imagery.png')):
arcpy.CopyRaster_management(image_path, os.path.join(AP_folder, 'imagery.tif'))
else:
print("existing image already exists in this AP folder")
add_image(image_path, AP_path)
# set pathway to mapping folder
map_path = os.path.join(project_path, '02_Mapping')
# check if RS folder exists, if not make one
if not os.path.exists(os.path.join(map_path, 'RS_01')):
os.makedirs(os.path.join(map_path, 'RS_01'))
# create new DCE folder
if not os.path.exists(os.path.join(map_path, DCE_fold)):
log.info('creating new DCE shapefiles...')
os.makedirs(os.path.join(map_path, DCE_fold))
# inundation
arcpy.CreateFeatureclass_management(os.path.join(map_path, DCE_fold), "inundation.shp", "POLYGON", "", has_m, has_z, spatial_reference)
# add field for inundation type
arcpy.AddField_management(os.path.join(map_path, DCE_fold, 'inundation.shp'), 'type', "TEXT")
# dam crests
arcpy.CreateFeatureclass_management(os.path.join(map_path, DCE_fold), "dam_crests.shp", "POLYLINE", "", has_m, has_z, spatial_reference)
# add fields for dam state and crest type
arcpy.AddField_management(os.path.join(map_path, DCE_fold, 'dam_crests.shp'), 'dam_state', "TEXT")
arcpy.AddField_management(os.path.join(map_path, DCE_fold, 'dam_crests.shp'), 'crest_type', "TEXT")
arcpy.AddField_management(os.path.join(map_path, DCE_fold, 'dam_crests.shp'), 'dam_id', "DOUBLE")
# thalwegs
arcpy.CreateFeatureclass_management(os.path.join(map_path, DCE_fold), "thalwegs.shp", "POLYLINE", "", has_m, has_z, spatial_reference)
arcpy.AddField_management(os.path.join(map_path, DCE_fold, 'thalwegs.shp'), 'type', "TEXT")
else:
print("this DCE already exists")
log.info('updating xml with new DCE...')
# create a folder in Analysis for this DCE
analysis_path = os.path.join(project_path, '03_Analysis')
if not os.path.exists(os.path.join(analysis_path, DCE_fold)):
os.makedirs(os.path.join(analysis_path, DCE_fold))
DCEout = os.path.join(analysis_path, DCE_fold)
if not os.path.exists(os.path.join(DCEout, 'shapefiles')):
os.makedirs(os.path.join(DCEout, 'Shapefiles'))
def main():
parser = argparse.ArgumentParser()
parser.add_argument('srs_template', help='path to a shapefile with desired output coordinate system', type=str)
parser.add_argument('project_path', help='path to output folder', type=str)
args = parser.parse_args()