Imports System
Imports System.Windows.Forms
Imports ThinkGeo.MapSuite.Core
Imports ThinkGeo.MapSuite.DesktopEdition
Namespace VBSampleApps
Public Class DisplayShapeMap
Inherits UserControl
Public Sub New()
InitializeComponent()
End Sub
'set as your csv data folder
Dim HurrevacAppDataDirectory As String = "D:\issues\post10664"
Dim point As New MultipointShape
Dim poly5 As New MultipointShape
Dim poly10 As New MultipointShape
Dim poly20 As New MultipointShape
Dim poly30 As New MultipointShape
Dim poly40 As New MultipointShape
Dim poly50 As New MultipointShape
Dim poly60 As New MultipointShape
Dim poly70 As New MultipointShape
Dim poly80 As New MultipointShape
Dim poly90 As New MultipointShape
Private Sub DisplayMap_Load(ByVal sender As Object, ByVal e As EventArgs)
winformsMap1.MapUnit = GeographyUnit.DecimalDegree
winformsMap1.BackgroundOverlay.BackgroundBrush = New GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean)
ShowWindProjections()
winformsMap1.CurrentExtent = New RectangleShape(-139.2, 92.4, 120.9, -93.2)
winformsMap1.Refresh()
End Sub
Protected Sub ShowWindProjections()
Dim overlayWindProjections As New LayerOverlay
Dim layerWindProjections As New InMemoryFeatureLayer
Dim hourToUse As Integer = 19
Dim hourlyProjections34k() As Dictionary(Of PointShape, Double) = Me.LoadWindProjections(34)
Dim hourlyProjections50k() As Dictionary(Of PointShape, Double) = Me.LoadWindProjections(50)
Dim hourlyProjections64k() As Dictionary(Of PointShape, Double) = Me.LoadWindProjections(64)
Dim layerWindProjections5 As New InMemoryFeatureLayer
Dim layerWindProjections10 As New InMemoryFeatureLayer
Dim layerWindProjections20 As New InMemoryFeatureLayer
Dim layerWindProjections30 As New InMemoryFeatureLayer
Dim layerWindProjections40 As New InMemoryFeatureLayer
Dim layerWindProjections50 As New InMemoryFeatureLayer
Dim layerWindProjections60 As New InMemoryFeatureLayer
Dim layerWindProjections70 As New InMemoryFeatureLayer
Dim layerWindProjections80 As New InMemoryFeatureLayer
Dim layerWindProjections90 As New InMemoryFeatureLayer
AddPoints(hourlyProjections34k(hourToUse))
'AddPoints(hourlyProjections50k(hourToUse))
'AddPoints(hourlyProjections64k(hourToUse))
SetLayerStyle(layerWindProjections5, GeoColor.FromArgb(100, GeoColor.StandardColors.DarkGreen))
SetLayerStyle(layerWindProjections10, GeoColor.FromArgb(100, GeoColor.StandardColors.Green))
SetLayerStyle(layerWindProjections20, GeoColor.FromArgb(100, GeoColor.StandardColors.LightGreen))
SetLayerStyle(layerWindProjections30, GeoColor.FromArgb(100, GeoColor.StandardColors.Yellow))
SetLayerStyle(layerWindProjections40, GeoColor.FromArgb(100, GeoColor.StandardColors.Gold))
SetLayerStyle(layerWindProjections50, GeoColor.FromArgb(100, GeoColor.StandardColors.SandyBrown))
SetLayerStyle(layerWindProjections60, GeoColor.FromArgb(100, GeoColor.StandardColors.Orange))
SetLayerStyle(layerWindProjections70, GeoColor.FromArgb(100, GeoColor.StandardColors.Red))
SetLayerStyle(layerWindProjections80, GeoColor.FromArgb(100, GeoColor.StandardColors.Maroon))
SetLayerStyle(layerWindProjections90, GeoColor.FromArgb(100, GeoColor.StandardColors.Purple))
overlayWindProjections.Layers.Add(Me.WindProbabilityLayer(poly5, layerWindProjections5))
overlayWindProjections.Layers.Add(Me.WindProbabilityLayer(poly10, layerWindProjections10))
overlayWindProjections.Layers.Add(Me.WindProbabilityLayer(poly20, layerWindProjections20))
overlayWindProjections.Layers.Add(Me.WindProbabilityLayer(poly30, layerWindProjections30))
overlayWindProjections.Layers.Add(Me.WindProbabilityLayer(poly40, layerWindProjections40))
overlayWindProjections.Layers.Add(Me.WindProbabilityLayer(poly50, layerWindProjections50))
overlayWindProjections.Layers.Add(Me.WindProbabilityLayer(poly60, layerWindProjections60))
overlayWindProjections.Layers.Add(Me.WindProbabilityLayer(poly70, layerWindProjections70))
overlayWindProjections.Layers.Add(Me.WindProbabilityLayer(poly80, layerWindProjections80))
overlayWindProjections.Layers.Add(Me.WindProbabilityLayer(poly90, layerWindProjections90))
Me.winformsMap1.Overlays.Add(overlayWindProjections)
End Sub
Private Sub SetLayerStyle(layerWindProjections5 As InMemoryFeatureLayer, geoColor As GeoColor)
layerWindProjections5.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(geoColor)
layerWindProjections5.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
End Sub
Private Sub AddPoints(points As Dictionary(Of PointShape, Double))
For Each proj As KeyValuePair(Of PointShape, Double) In points
Select Case proj.Value
Case 5 To 9.9
If proj.Key.X < 0 Then
poly5.Points.Add(New PointShape(proj.Key.X, proj.Key.Y))
End If
Case 10 To 19.9
If proj.Key.X < 0 Then
poly10.Points.Add(New PointShape(proj.Key.X, proj.Key.Y))
End If
Case 20 To 29.9
If proj.Key.X < 0 Then
poly20.Points.Add(New PointShape(proj.Key.X, proj.Key.Y))
End If
Case 30 To 39.9
If proj.Key.X < 0 Then
poly30.Points.Add(New PointShape(proj.Key.X, proj.Key.Y))
End If
Case 40 To 49.9
If proj.Key.X < 0 Then
poly40.Points.Add(New PointShape(proj.Key.X, proj.Key.Y))
End If
Case 50 To 59.9
If proj.Key.X < 0 Then
poly50.Points.Add(New PointShape(proj.Key.X, proj.Key.Y))
End If
Case 60 To 69.9
If proj.Key.X < 0 Then
poly60.Points.Add(New PointShape(proj.Key.X, proj.Key.Y))
End If
Case 70 To 79.9
If proj.Key.X < 0 Then
poly70.Points.Add(New PointShape(proj.Key.X, proj.Key.Y))
End If
Case 80 To 89.9
If proj.Key.X < 0 Then
poly80.Points.Add(New PointShape(proj.Key.X, proj.Key.Y))
End If
Case 90 To 100
If proj.Key.X < 0 Then
poly90.Points.Add(New PointShape(proj.Key.X, proj.Key.Y))
End If
End Select
Next
End Sub
Private Function WindProbabilityLayer(points As MultipointShape, layer As InMemoryFeatureLayer) As InMemoryFeatureLayer
For Each point As PointShape In points.Points
layer.InternalFeatures.Add(New Feature(New RectangleShape(point.X - 0.5, point.Y + 0.5, point.X + 0.5, point.Y - 0.5)))
Next
Return layer
End Function
Private Function LoadWindProjections(windSpeed As Integer) As Dictionary(Of PointShape, Double)()
Dim probFile As String = HurrevacAppDataDirectory & "\LatestWindProbs\Latest_" & windSpeed.ToString & "k.csv"
If Not IO.File.Exists(probFile) Then Return Nothing
Dim reader As New IO.StreamReader(probFile)
Dim line As String
Dim probs() As String
Dim windProjections(19) As Dictionary(Of PointShape, Double)
'initialize the dictionary items
For x As Integer = 0 To windProjections.Length - 1
windProjections(x) = New Dictionary(Of PointShape, Double)
Next
Using reader
While Not reader.EndOfStream
line = reader.ReadLine
probs = line.Split(",")
If probs.Length = 22 Then
point.Points.Add(New PointShape(Double.Parse(probs(1)), Double.Parse(probs(0))))
'look for probs > 0, add to dictionary
For x As Integer = 0 To 19
If CDec(probs(x + 2)) > 0 Then
windProjections(x).Add(New PointShape(Double.Parse(probs(1)), Double.Parse(probs(0))), Double.Parse(probs(x + 2)))
End If
Next
End If
End While
End Using
Return windProjections
End Function
#Region "Component Designer generated code"
Private components As System.ComponentModel.IContainer = Nothing
Private winformsMap1 As WinformsMap
'''
''' Clean up any resources being used.
'''
''' true if managed resources should be disposed; otherwise, false.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso (components IsNot Nothing) Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'''
''' Required method for Designer support - do not modify
''' the contents of this method with the code editor.
'''
Private Sub InitializeComponent()
Dim resources As New System.ComponentModel.ComponentResourceManager(GetType(DisplayShapeMap))
winformsMap1 = New WinformsMap()
SuspendLayout()
'
' winformsMap1
'
winformsMap1.Location = New System.Drawing.Point(0, 0)
winformsMap1.Name = "winformsMap1"
winformsMap1.Size = New System.Drawing.Size(740, 528)
winformsMap1.TabIndex = 0
winformsMap1.Text = "winformsMap1"
'
' DisplayShapeMap
'
AutoScaleDimensions = New System.Drawing.SizeF(6.0F, 13.0F)
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Controls.Add(winformsMap1)
Name = "DisplayShapeMap"
Size = New System.Drawing.Size(740, 528)
AddHandler Load, AddressOf DisplayMap_Load
ResumeLayout(False)
End Sub
#End Region
End Class
End Namespace