42
42
__DEBUG__ = False # true outputs debug-level messages to stderr
43
43
44
44
# NRCS AWDB network codes to download
45
- NETWORKS = ["SNTL" , "SNOW" , "USGS" , "COOP" , "SCAN" , "SNTLT" , "OTHER" , "BOR" ,
46
- "MPRC" , "MSNT" ]
47
- # NETWORKS = ["USGS"]
45
+ # NETWORKS = ["SNTL", "SNOW", "USGS", "COOP", "SCAN", "SNTLT", "OTHER", "BOR",
46
+ # "MPRC", "MSNT"]
47
+ NETWORKS = ["USGS" ]
48
48
49
49
50
50
## Dictionaries of the station fields
@@ -719,7 +719,7 @@ def get_USGS_metadata(usgs_fc):
719
719
cursor .updateRow (row )
720
720
721
721
def create_forecast_point_ws ():
722
- from arcpy import CopyFeatures_management
722
+ from arcpy import CopyFeatures_management , AddField_management , Append_management , Delete_management , AddJoin_management , CalculateField_management
723
723
import arcpy
724
724
725
725
bUSGSExists = False
@@ -733,6 +733,8 @@ def create_forecast_point_ws():
733
733
if arcpy .Exists (os .path .join (settings .AWDB_FGDB_PATH , BOR_Active )):
734
734
bBORExists = True
735
735
FCST_Active = "active_stations_FCST"
736
+ FCST_Active_Temp = "active_stations_FCST_Temp"
737
+ FCST_Active_Ref = "active_stations_FCST_Ref"
736
738
737
739
if (bUSGSExists and bBORExists ):
738
740
client = Client (settings .WDSL_URL )
@@ -749,9 +751,9 @@ def create_forecast_point_ws():
749
751
numberofstations = len (data )
750
752
LOGGER .info ('We processed %d records' , numberofstations )
751
753
LOGGER .info ('%d records in array' , len (forecastIDs ))
752
- BOR_Temp_Active = "temp_" + BOR_Active
754
+ BOR_Active_Temp = BOR_Active + "_Temp"
753
755
sourceFc = os .path .join (settings .AWDB_FGDB_PATH , USGS_Active )
754
- targetFc = os .path .join (settings .AWDB_FGDB_PATH , FCST_Active )
756
+ targetFc = os .path .join (settings .AWDB_FGDB_PATH , FCST_Active_Temp )
755
757
CopyFeatures_management (sourceFc , targetFc )
756
758
LOGGER .info ("Before %d records" , getCount (targetFc ))
757
759
with arcpy .da .UpdateCursor (targetFc , ('stationTriplet' )) as curs :
@@ -761,7 +763,7 @@ def create_forecast_point_ws():
761
763
curs .deleteRow ()
762
764
LOGGER .info ("After %d records" , getCount (targetFc ))
763
765
sourceFc = os .path .join (settings .AWDB_FGDB_PATH , BOR_Active )
764
- targetFc = os .path .join (settings .AWDB_FGDB_PATH , BOR_Temp_Active )
766
+ targetFc = os .path .join (settings .AWDB_FGDB_PATH , BOR_Active_Temp )
765
767
CopyFeatures_management (sourceFc , targetFc )
766
768
forecastIDs .clear ()
767
769
data = client .service .getForecastPoints (networkCds = "BOR" ,logicalAnd = "true" )
@@ -779,9 +781,29 @@ def create_forecast_point_ws():
779
781
if (test_triplet not in forecastIDs ):
780
782
curs .deleteRow ()
781
783
LOGGER .info ("After %d records" , getCount (targetFc ))
782
-
783
-
784
-
784
+ tmpForecastFc = os .path .join (settings .AWDB_FGDB_PATH , FCST_Active_Temp )
785
+ Append_management ([os .path .join (settings .AWDB_FGDB_PATH , BOR_Active_Temp )], tmpForecastFc )
786
+ Delete_management (os .path .join (settings .AWDB_FGDB_PATH , BOR_Active_Temp ))
787
+ FCST_FIELDS = [
788
+ {"field_name" : "winter_start_month" , "field_type" : "SHORT" }, # 0
789
+ {"field_name" : "winter_end_month" , "field_type" : "SHORT" }, # 1
790
+ {"field_name" : "huc2" , "field_type" : "TEXT" , "field_length" : 2 } #2
791
+ ]
792
+ LOGGER .info ("Adding attribute fields to feature class..." )
793
+ for field in FCST_FIELDS :
794
+ AddField_management (tmpForecastFc , ** field )
795
+ #This doesn't seem to do anything
796
+ #AssignDefaultToField_management(tmpForecastFc, "winter_start_month", "11")
797
+ #AssignDefaultToField_management(tmpForecastFc, "winter_end_month", "3")
798
+ joined_table = AddJoin_management (tmpForecastFc , "stationTriplet" , os .path .join (settings .AWDB_FGDB_PATH , FCST_Active_Ref ), "stationTriplet" )
799
+ expression = "reclass(!active_stations_FCST_Ref.huc2!)"
800
+ codeblock = """
801
+ def reclass(huc2):
802
+ if (huc2 != None):
803
+ return huc2
804
+ else:
805
+ return None"""
806
+ CalculateField_management (joined_table , "active_stations_FCST_Temp.huc2" , expression , "PYTHON3" , codeblock )
785
807
786
808
else :
787
809
LOGGER .error ("unable to locate {0} and or {1}. Forecast service will not be updated" .format (USGS_Active , BOM_Active ))
@@ -932,7 +954,7 @@ def main():
932
954
933
955
# create forecast webservice
934
956
# Commenting out. Not ready to use yet
935
- # create_forecast_point_ws()
957
+ create_forecast_point_ws ()
936
958
937
959
if wfsupdatelist :
938
960
LOGGER .info ("\n Updating AGOL feature services in update list..." )
0 commit comments