Skip to content

Commit

Permalink
Continue work on issue #21
Browse files Browse the repository at this point in the history
  • Loading branch information
lbross committed Nov 19, 2015
1 parent aa6b364 commit 30df998
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/BAGIS_ClassLibrary/ConstantsModule.vb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
Public Const BA_FIELD_TIMBER_ELEV As String = "TIMBER_ELEV"
Public Const BA_FIELD_AREA As String = "AREA"
Public Const BA_FIELD_SHAPE_AREA As String = "Shape_Area"
Public Const BA_FIELD_AOI_NAME As String = "AOINAME"

'mapframe
Public Const BA_MAPS_DEFAULT_MAP_NAME As String = "Basin Analysis"
Expand Down
73 changes: 73 additions & 0 deletions src/BAGIS_ClassLibrary/PublicModule.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2298,4 +2298,77 @@ Optional ByVal hasPaddingBackSlach As Boolean = False) As String
End Try
End Function

Public Function BA_DatumMatchFiles(ByVal path1 As String, ByVal type1 As esriDatasetType, ByVal path2 As String, ByVal type2 As esriDatasetType, _
ByVal aoiDatum As String) As Boolean
Dim pGeoDataset As IGeoDataset = Nothing
Dim pGeoDataset2 As IGeoDataset = Nothing
Dim spRef1 As ISpatialReference = Nothing
Dim spRef2 As ISpatialReference = Nothing
Try
'Get the datum for dataset1
Dim wType As WorkspaceType = BA_GetWorkspaceTypeFromPath(path1)
Dim parentPath As String = "PleaseReturn"
Dim fileName As String = BA_GetBareName(path1, parentPath)
Select Case type1
Case esriDatasetType.esriDTFeatureClass, esriDatasetType.esriDTFeatureClass
If wType = WorkspaceType.Raster Then
pGeoDataset = BA_OpenFeatureClassFromFile(parentPath, fileName)
ElseIf wType = WorkspaceType.Geodatabase Then
pGeoDataset = BA_OpenFeatureClassFromGDB(parentPath, fileName)
End If
Case esriDatasetType.esriDTRasterDataset, esriDatasetType.esriDTRasterBand 'raster
If wType = WorkspaceType.Raster Then
pGeoDataset = BA_OpenRasterFromFile(parentPath, fileName)
ElseIf wType = WorkspaceType.Geodatabase Then
pGeoDataset = BA_OpenRasterFromGDB(parentPath, fileName)
End If
Case Else 'unsupported format
Debug.Print("BA_DatumMatchFiles: the datasettype provided is not supported")
End Select
'Spatial reference for the dataset1 in question
spRef1 = pGeoDataset.SpatialReference

'Get the datum for dataset1
wType = BA_GetWorkspaceTypeFromPath(path2)
fileName = BA_GetBareName(path2, parentPath)
Select Case type2
Case esriDatasetType.esriDTFeatureClass, esriDatasetType.esriDTFeatureClass
If wType = WorkspaceType.Raster Then
pGeoDataset2 = BA_OpenFeatureClassFromFile(parentPath, fileName)
ElseIf wType = WorkspaceType.Geodatabase Then
pGeoDataset2 = BA_OpenFeatureClassFromGDB(parentPath, fileName)
End If
Case esriDatasetType.esriDTRasterDataset, esriDatasetType.esriDTRasterBand 'raster
If wType = WorkspaceType.Raster Then
pGeoDataset2 = BA_OpenRasterFromFile(parentPath, fileName)
ElseIf wType = WorkspaceType.Geodatabase Then
pGeoDataset2 = BA_OpenRasterFromGDB(parentPath, fileName)
End If
Case Else 'unsupported format
Debug.Print("BA_DatumMatchFiles: the datasettype2 provided is not supported")
End Select
'Spatial reference for the dataset1 in question
spRef2 = pGeoDataset2.SpatialReference
'Check datums
Dim datumStr1 As String = BA_DatumString(spRef1)
Dim datumStr2 As String = BA_DatumString(spRef2)
If (String.Compare(datumStr1, datumStr2) = 0) Then
Return True
Else
aoiDatum = datumStr1
Return False
End If
Catch ex As Exception
Debug.Print("BA_DatumMatchFiles Exception: " & ex.Message)
Return False
Finally
pGeoDataset = Nothing
pGeoDataset2 = Nothing
spRef1 = Nothing
spRef2 = Nothing
GC.WaitForPendingFinalizers()
GC.Collect()
End Try
End Function

End Module
5 changes: 3 additions & 2 deletions src/BAGIS_P/Forms/FrmExportParametersEwsf.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/BAGIS_P/Forms/FrmPEandSRObs.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 84 additions & 5 deletions src/BAGIS_P/Forms/FrmPEandSRObs.vb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Imports ESRI.ArcGIS.Geometry
Public Class FrmPEandSRObs

Private Const SR_COLUMN_PREFIX As String = "SR"
Private Const MONTHS_3 As Short = 3
Dim m_january As DateTime = New DateTime(2015, 1, 1)
Dim m_aoiParamTable As IDictionary(Of String, AoiParameter)

Public Sub New()
Expand Down Expand Up @@ -115,9 +117,7 @@ Public Class FrmPEandSRObs
Else
MessageBox.Show("The selected layer '" & pDatasetName.Name & "' cannot be used because the projection does not match the AOI projection '" & aoiProjection & _
"'. Please reproject or select another data layer and try again.", "Invalid projection", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If

End Sub

Private Sub BtnSetPE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSetPE.Click
Expand All @@ -142,7 +142,50 @@ Public Class FrmPEandSRObs
Dim pGxDataset As IGxDataset = pGxObject.Next
Dim pDatasetName As IDatasetName = pGxDataset.DatasetName
Dim Data_Path As String = pDatasetName.WorkspaceName.PathName
TxtPEPath.Text = Data_Path & "\" & pDatasetName.Name
Dim fullPath As String = pDatasetName.WorkspaceName.PathName & "\" & pDatasetName.Name

'Ensure selected layer uses the correct projection
Dim aoiGdb As String = BA_GeodatabasePath(TxtAoiPath.Text, GeodatabaseNames.Aoi, True)
Dim aoiDatum As String = Nothing 'Variable to hold PE projection for error message
Dim aoi_v As String = BA_StandardizeShapefileName(BA_EnumDescription(PublicPath.AoiVector), False)
Dim validDatum As Boolean = BA_DatumMatchFiles(fullPath, esriDatasetType.esriDTRasterDataset, aoiGdb & aoi_v, esriDatasetType.esriDTFeatureClass, aoiDatum)

If Not validDatum Then
MessageBox.Show("The selected layer '" & pDatasetName.Name & "' cannot be used because the datum does not match the AOI datum '" & aoiDatum & _
"'. Please reproject or select another data layer and try again.", "Invalid datum", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If

Dim strSearch As String = m_january.Month.ToString("D2")
Dim idxMonth As Integer = pDatasetName.Name.IndexOf(strSearch)
Dim missingMonths As IList(Of String) = New List(Of String)
'We have January, now look for other 11
If idxMonth > -1 Then
Dim prefix As String = pDatasetName.Name.Substring(0, idxMonth)
Dim suffix As String = pDatasetName.Name.Substring(idxMonth + 2, pDatasetName.Name.Length - (idxMonth + 2))
Dim wType As WorkspaceType = BA_GetWorkspaceTypeFromPath(pDatasetName.WorkspaceName.PathName)
For i As Short = 2 To MONTHS_3
Dim fileName As String = prefix & i.ToString("D2") & suffix
If Not BA_File_Exists(pDatasetName.WorkspaceName.PathName & "\" & fileName, wType, esriDatasetType.esriDTRasterDataset) Then
missingMonths.Add(pDatasetName.WorkspaceName.PathName & "\" & fileName)
End If
Next
If missingMonths.Count > 0 Then
Dim errMsg As String = "The The selected layer '" & pDatasetName.Name & "' cannot be used because the following months are missing from the data: " & vbCrLf & vbCrLf
For i As Short = 0 To missingMonths.Count - 1
errMsg += missingMonths(i) & vbCrLf
Next
MessageBox.Show(errMsg, "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Else
MessageBox.Show("The selected layer '" & pDatasetName.Name & "' cannot be used because there is not a '01' in the name indicating that it contains data for January. Please select another data layer", _
"Invalid data", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If

'Passed all the tests!
TxtPEPath.Text = fullPath
End Sub

Private Sub ManageCalculateButton()
Expand Down Expand Up @@ -228,8 +271,9 @@ Public Class FrmPEandSRObs
End Function

Private Sub BtnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCalculate.Click
CalculateSRObs()
SaveValues()
'CalculateSRObs()
'SaveValues()
CalculatePEObs()
End Sub

Private Sub PopulateForm()
Expand Down Expand Up @@ -324,4 +368,39 @@ Public Class FrmPEandSRObs
Dim toolHelpForm As FrmHelp = New FrmHelp(BA_HelpTopics.PeAndObsTool)
toolHelpForm.ShowDialog()
End Sub

Private Function CalculatePEObs() As BA_ReturnCode
Dim tableName As String = "tblPE"
Dim zoneFilePath As String = BA_GeodatabasePath(TxtAoiPath.Text, GeodatabaseNames.Aoi)
Dim zoneFileName As String = BA_StandardizeShapefileName(BA_EnumDescription(PublicPath.AoiVector), False)
Dim snapRasterPath As String = BA_GeodatabasePath(TxtAoiPath.Text, GeodatabaseNames.Aoi, True) & BA_EnumDescription(AOIClipFile.AOIExtentCoverage)
Dim valueFilePath As String = TxtPEPath.Text
Dim success As BA_ReturnCode = BA_ZonalStatisticsAsTable(zoneFilePath, zoneFileName, BA_FIELD_AOI_NAME, valueFilePath, _
zoneFilePath, tableName, snapRasterPath, StatisticsTypeString.MEAN)
Dim pTable As ITable = Nothing
Dim pCursor As ICursor = Nothing
Dim pRow As IRow = Nothing
Try
If success = BA_ReturnCode.Success Then
pTable = BA_OpenTableFromGDB(zoneFilePath, tableName)
If pTable IsNot Nothing Then
Dim idxMean As Integer = pTable.FindField(StatisticsFieldName.MEAN.ToString)
If idxMean > -1 Then
pCursor = pTable.Search(Nothing, False)
pRow = pCursor.NextRow
If pRow IsNot Nothing Then
MessageBox.Show(Convert.ToString(pRow.Value(idxMean)))
End If
End If
End If
End If
Catch ex As Exception
Debug.Print("CalculatePEObs() Exception: " & ex.Message)
Return BA_ReturnCode.UnknownError
Finally

End Try


End Function
End Class
2 changes: 1 addition & 1 deletion src/BAGIS_P/Help/FrmHelp.vb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Public Class FrmHelp
description = "This tool allows users to specify a timberline elevation for each HRU zone in the AOI. The timberline values can be used to assign the Snowmelt Depletion Curve (hru_deplcrv) parameter values used in PRMS. This tool saves the timberline elevation values in the attribute table of the vector HRU featureclass (grid_zones_v). The timberline elevation will be recorded only in the attribute table of this featureclass and not be added to the exported OMS parameter files. A timberline elevation value of 0 indicates that the HRU is a regular HRU (not above timberline). The actual calculation of the hru_deplcrv is done by the hru_deplcrv_treeline parameter models built in ArcGIS ModelBuilder. Users can either use the timberline elevation extracted in this tool or the Landfire vegetation layer to set the values of hru_deplcrv. If the area of an HRU is more then 50% above timberline elevation or not covered by canopy vegetation, then the hru_deplcrv is set to 2, otherwise 1."
Case BA_HelpTopics.PeAndObsTool
Dim sb As StringBuilder = New StringBuilder
sb.Append("This tool allows users to to extract and calculate the Potential Evaporation and Observed Solar Radiation ")
sb.Append("This tool allows users to extract and calculate the Potential Evaporation and Observed Solar Radiation ")
sb.Append("values for an AOI. SR is determined by selecting a value for each month from the observation point located closest to the centroid of the AOI boundary. ")
sb.Append("The source data for PE is assumed to be stored in a group of twelve raster layers. The units are mm/month. ")
sb.Append("The values are converted to inches/day and the mean value is calculated for the area of the AOI for each month." & vbCrLf & vbCrLf)
Expand Down

0 comments on commit 30df998

Please sign in to comment.