Skip to content

Commit

Permalink
Synchronize class libraries with BAGIS-P
Browse files Browse the repository at this point in the history
  • Loading branch information
lbross committed Jul 5, 2017
1 parent 538f219 commit ac4f148
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 64 deletions.
1 change: 1 addition & 0 deletions src/BAGIS_ClassLibrary/ConstantsModule.vb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
Public Const BA_MAPS_PS_INDICATOR = "New Pseudo Site Indicator"
Public Const BA_MAPS_PS_PROXIMITY = "Area Included For Proximity"
Public Const BA_MAPS_PS_PRECIPITATION = "Area Included For Precipitation"
Public Const BA_MAPS_PS_LOCATION = "Area Included For Location"

'these constants are used to ID whether a folder is a basin or an AOI or both
Public Const BA_BASIN_DEM_EXTENT_SHAPEFILE As String = "aoi_v" 'vector
Expand Down
127 changes: 84 additions & 43 deletions src/BAGIS_ClassLibrary/GeodatabaseModule.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1957,13 +1957,20 @@ Public Module GeodatabaseModule

Public Function BA_IsRasterEmpty(ByVal rFolder As String, ByVal rFile As String) As Boolean
Dim pRDataset As IGeoDataset = BA_OpenRasterFromGDB(rFolder, rFile)
Dim pBandCol As IRasterBandCollection = CType(pRDataset, IRasterBandCollection)
Dim pRasterBand As IRasterBand = pBandCol.Item(0)
Dim pTable As ITable = pRasterBand.AttributeTable
Dim pTable As ITable = Nothing
Dim pBandCol As IRasterBandCollection = Nothing
Dim pRasterBand As IRasterBand = Nothing
Try
Dim rCount As Integer = pTable.RowCount(Nothing)
If rCount > 0 Then
Return False
If pRDataset IsNot Nothing Then
pBandCol = CType(pRDataset, IRasterBandCollection)
pRasterBand = pBandCol.Item(0)
pTable = pRasterBand.AttributeTable
Dim rCount As Integer = pTable.RowCount(Nothing)
If rCount > 0 Then
Return False
Else
Return True
End If
Else
Return True
End If
Expand All @@ -1980,49 +1987,83 @@ Public Module GeodatabaseModule

Public Function BA_AddUserFieldToRaster(ByVal filepath As String, ByVal FileName As String, ByVal fieldName As String, _
ByVal fieldType As esriFieldType, ByVal fieldLength As Int16, ByVal fieldValue As Object) As BA_ReturnCode

'open raster attribute table
Dim pRDataset As IGeoDataset = BA_OpenRasterFromGDB(filepath, FileName)
Dim pBandCol As IRasterBandCollection = CType(pRDataset, IRasterBandCollection)
Dim pRasterBand As IRasterBand = pBandCol.Item(0)
Dim pTable As ITable = pRasterBand.AttributeTable
Dim pRDataset As IGeoDataset = Nothing
Dim pBandCol As IRasterBandCollection = Nothing
Dim pRasterBand As IRasterBand = Nothing
Dim pCursor As ICursor = Nothing
Dim pTable As ITable = Nothing
Try
Dim idxField As Int16 = pTable.FindField(fieldName)
Dim pField As IField = New Field
Dim pFld As IFieldEdit2 = CType(pField, IFieldEdit2)
Dim pRow As IRow

If idxField < 0 Then
'Define field
pFld.Name_2 = fieldName
pFld.Type_2 = fieldType
pFld.Length_2 = fieldLength
pFld.Required_2 = False
' Add field
pTable.AddField(pFld)
idxField = pTable.FindField(fieldName)
End If
pRDataset = BA_OpenRasterFromGDB(filepath, FileName)
If pRDataset IsNot Nothing Then
pBandCol = CType(pRDataset, IRasterBandCollection)
pRasterBand = pBandCol.Item(0)
'open raster attribute table
pTable = pRasterBand.AttributeTable
Dim idxField As Int16 = pTable.FindField(fieldName)
Dim pField As IField = New Field
Dim pFld As IFieldEdit2 = CType(pField, IFieldEdit2)
Dim pRow As IRow

'Open update cursor
pCursor = pTable.Update(Nothing, False)
pRow = pCursor.NextRow
Do While Not pRow Is Nothing
pRow.Value(idxField) = fieldValue
pCursor.UpdateRow(pRow)
If idxField < 0 Then
'Define field
pFld.Name_2 = fieldName
pFld.Type_2 = fieldType
pFld.Length_2 = fieldLength
pFld.Required_2 = False
' Add field
pTable.AddField(pFld)
idxField = pTable.FindField(fieldName)
End If

'Open update cursor
pCursor = pTable.Update(Nothing, False)
pRow = pCursor.NextRow
Loop
Return BA_ReturnCode.Success
Do While Not pRow Is Nothing
pRow.Value(idxField) = fieldValue
pCursor.UpdateRow(pRow)
pRow = pCursor.NextRow
Loop
Return BA_ReturnCode.Success
Else
Return BA_ReturnCode.UnknownError
End If
Catch ex As Exception
MessageBox.Show("BA_AddFieldToRaster Exception: " + ex.Message)
Return BA_ReturnCode.UnknownError
Finally
pCursor = Nothing
pTable = Nothing
pBandCol = Nothing
pRasterBand = Nothing
pRDataset = Nothing
End Try
End Function

'Opens a raster and checks the properties to see if it is an integer raster
Public Function BA_HasAttributeTable(ByVal fullLayerFilePath As String) As Boolean
Dim filePath As String = "blank"
Dim fileName As String = BA_GetBareName(fullLayerFilePath, filePath)
Dim pGeoDS As IGeoDataset = Nothing
Dim pRasterBandColl As IRasterBandCollection = Nothing
Dim pRasterBand As IRasterBand = Nothing
Try
pGeoDS = BA_OpenRasterFromGDB(filePath, fileName)
If pGeoDS Is Nothing Then
Return False
End If
pRasterBandColl = CType(pGeoDS, IRasterBandCollection)
pRasterBand = pRasterBandColl.Item(0)
Dim hasTable As Boolean = False
pRasterBand.HasTable(hasTable)
Return hasTable
Catch ex As Exception
MessageBox.Show("BA_AddFieldToRaster Exception: " + ex.Message)
Return BA_ReturnCode.UnknownError
MessageBox.Show("BA_HasAttributeTable Exception: " + ex.Message)
Return False
Finally
pCursor = Nothing
pTable = Nothing
pBandCol = Nothing
pRasterBand = Nothing
pRDataset = Nothing
ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pRasterBand)
ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pRasterBandColl)
ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pGeoDS)
End Try
End Function

End Function
End Module
3 changes: 3 additions & 0 deletions src/BAGIS_ClassLibrary/MapsModule.vb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ Public Module MapsModule
Case MapsDisplayStyle.Yellows 'Pseudo-site proximity Layer (orange)
StyleName = "Yellows"
StyleCategory = "Default Schemes"
Case MapsDisplayStyle.Brown_to_Blue_Green 'Pseudo-site Location Layer (brown)
StyleName = "Brown to Blue Green Diverging, Dark"
StyleCategory = "Dichromatic Ramps"
Case Else
StyleName = "Black to White"
StyleCategory = "Default Ramps"
Expand Down
45 changes: 25 additions & 20 deletions src/BAGIS_ClassLibrary/PublicModule.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1193,9 +1193,12 @@ Public Module PublicModule
' -2 filename error
' -3 not a raster dataset
' , otherwise, the same value as the Action code
'Action code: 0, default add and replace if layer of the same name already added, and zoom to layer
' 1, add and replace only
' 2, add
'add a raster file to the active view
Public Function BA_DisplayRaster(ByVal application As ESRI.ArcGIS.Framework.IApplication, ByVal LayerPathName As String, _
Optional ByVal DisplayName As String = "") As Short
Optional ByVal DisplayName As String = "", Optional ByVal Action As Short = 0) As Short
Dim File_Path As String = "PleaseReturn"
Dim File_Name As String = BA_GetBareName(LayerPathName, File_Path)

Expand Down Expand Up @@ -1247,27 +1250,29 @@ Public Module PublicModule
pMxDoc.AddLayer(pRLayer)
pMxDoc.UpdateContents()

'zoom to layer
'create a buffer around the AOI
pEnv = pRLayer.AreaOfInterest
If Action = 0 Then 'zoom to layer
'zoom to layer
'create a buffer around the AOI
pEnv = pRLayer.AreaOfInterest

Dim urx, llx, lly, ury As Double
Dim xrange, yrange As Double
Dim xoffset, yoffset As Double
Dim urx, llx, lly, ury As Double
Dim xrange, yrange As Double
Dim xoffset, yoffset As Double

pEnv.QueryCoords(llx, lly, urx, ury)
xrange = urx - llx
yrange = ury - lly
xoffset = xrange * (Buffer_Factor - 1) / 2
yoffset = yrange * (Buffer_Factor - 1) / 2
llx = llx - xoffset
lly = lly - yoffset
urx = urx + xoffset
ury = ury + yoffset
pEnv.PutCoords(llx, lly, urx, ury)

pEnv.QueryCoords(llx, lly, urx, ury)
xrange = urx - llx
yrange = ury - lly
xoffset = xrange * (Buffer_Factor - 1) / 2
yoffset = yrange * (Buffer_Factor - 1) / 2
llx = llx - xoffset
lly = lly - yoffset
urx = urx + xoffset
ury = ury + yoffset
pEnv.PutCoords(llx, lly, urx, ury)

pActiveView = pMxDoc.ActiveView
pActiveView.Extent = pEnv
pActiveView = pMxDoc.ActiveView
pActiveView.Extent = pEnv
End If

'refresh the active view
pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, Nothing, Nothing)
Expand Down
1 change: 1 addition & 0 deletions src/BAGIS_ClassLibrary/enumerations/MapsDisplayStyle.vb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
Purple_Blues
Condition_Number
Yellows
Brown_to_Blue_Green
Unknown
End Enum
2 changes: 1 addition & 1 deletion src/BAGIS_ClassLibrary/enumerations/PublicPath.vb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ Public Enum PublicPath
<Description("\task_log.xml")> EBagisTaskLog
<Description("/FeatureServer/0")> FeatureServiceUrl
<Description("\BAGIS\bagis-h-settings.json")> BagisHSettings
<Description("\pseudo_site.xml")> PseudoSiteXml
<Description("\pseudo_sites.xml")> PseudoSitesXml
End Enum

0 comments on commit ac4f148

Please sign in to comment.