From 56664c96219673ba245e71b98399207f99c65fb9 Mon Sep 17 00:00:00 2001 From: christophev-git <147967764+christophev-git@users.noreply.github.com> Date: Tue, 5 Mar 2024 09:22:23 +0100 Subject: [PATCH] JSON JSON file --- Form1.Designer.vb | 47 ++++++++++++ Form1.vb | 27 +++++++ LIDAR.vbproj.user | 3 + PipeLine.vb | 78 ++++++++++++++++++++ VariableGlobale.vb | 180 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 335 insertions(+) create mode 100644 PipeLine.vb create mode 100644 VariableGlobale.vb diff --git a/Form1.Designer.vb b/Form1.Designer.vb index 06888d7..3371ed6 100644 --- a/Form1.Designer.vb +++ b/Form1.Designer.vb @@ -27,6 +27,10 @@ Partial Class Form1 FolderBrowserDialog1 = New FolderBrowserDialog() OpenFileDialog1 = New OpenFileDialog() ProgressBar1 = New ProgressBar() + ListBox1 = New ListBox() + Button2 = New Button() + TBtaille = New TextBox() + Label1 = New Label() CType(DataGridView1, ComponentModel.ISupportInitialize).BeginInit() SuspendLayout() ' @@ -58,11 +62,49 @@ Partial Class Form1 ProgressBar1.Size = New Size(655, 36) ProgressBar1.TabIndex = 2 ' + ' ListBox1 + ' + ListBox1.FormattingEnabled = True + ListBox1.ItemHeight = 15 + ListBox1.Location = New Point(12, 318) + ListBox1.Name = "ListBox1" + ListBox1.Size = New Size(217, 94) + ListBox1.TabIndex = 3 + ' + ' Button2 + ' + Button2.Location = New Point(253, 318) + Button2.Name = "Button2" + Button2.Size = New Size(208, 29) + Button2.TabIndex = 4 + Button2.Text = "Create JSON pipeline" + Button2.UseVisualStyleBackColor = True + ' + ' TBtaille + ' + TBtaille.Location = New Point(398, 287) + TBtaille.Name = "TBtaille" + TBtaille.Size = New Size(63, 23) + TBtaille.TabIndex = 5 + ' + ' Label1 + ' + Label1.AutoSize = True + Label1.Location = New Point(253, 295) + Label1.Name = "Label1" + Label1.Size = New Size(124, 15) + Label1.TabIndex = 6 + Label1.Text = "Taille cellule raster (m)" + ' ' Form1 ' AutoScaleDimensions = New SizeF(7F, 15F) AutoScaleMode = AutoScaleMode.Font ClientSize = New Size(800, 450) + Controls.Add(Label1) + Controls.Add(TBtaille) + Controls.Add(Button2) + Controls.Add(ListBox1) Controls.Add(ProgressBar1) Controls.Add(DataGridView1) Controls.Add(Button1) @@ -70,6 +112,7 @@ Partial Class Form1 Text = "Form1" CType(DataGridView1, ComponentModel.ISupportInitialize).EndInit() ResumeLayout(False) + PerformLayout() End Sub Friend WithEvents Button1 As Button @@ -77,5 +120,9 @@ Partial Class Form1 Friend WithEvents FolderBrowserDialog1 As FolderBrowserDialog Friend WithEvents OpenFileDialog1 As OpenFileDialog Friend WithEvents ProgressBar1 As ProgressBar + Friend WithEvents ListBox1 As ListBox + Friend WithEvents Button2 As Button + Friend WithEvents TBtaille As TextBox + Friend WithEvents Label1 As Label End Class diff --git a/Form1.vb b/Form1.vb index 05d749b..673fd5f 100644 --- a/Form1.vb +++ b/Form1.vb @@ -1,4 +1,6 @@ Public Class Form1 + Private m_classif As Integer = -1 + Private m_nomclassif As String = "" Public ListeDalle As System.Collections.Generic.List(Of dalle_lidar) Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim workpath As String = "" @@ -58,4 +60,29 @@ MsgBox("Téléchargement terminé", vbApplicationModal, vbInformation) End Sub + + Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load + For Each s As String In [Enum].GetNames(GetType(Classification_LIDAR)) + ListBox1.Items.Add(s) + Next + End Sub + + Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click + If TBtaille.Text = "" Then Exit Sub + If ListBox1.SelectedIndex < 0 Then Exit Sub + If ListeDalle Is Nothing Then Exit Sub + If ListeDalle.Count = 0 Then Exit Sub + + m_nomclassif = ListBox1.SelectedItem + m_classif = ListBox1.SelectedIndex + m_classif = [Enum].GetValues(GetType(Classification_LIDAR))(ListBox1.SelectedIndex) + For Each d As dalle_lidar In ListeDalle + + Dim p1 As New PipeLine(d, m_nomclassif, TBtaille.Text, m_classif) + p1.CreatePipeLine() + + Next + + MsgBox("Traitement JSON terminé", vbExclamation) + End Sub End Class diff --git a/LIDAR.vbproj.user b/LIDAR.vbproj.user index c2d5617..e01c3db 100644 --- a/LIDAR.vbproj.user +++ b/LIDAR.vbproj.user @@ -7,5 +7,8 @@ Form + + Form + \ No newline at end of file diff --git a/PipeLine.vb b/PipeLine.vb new file mode 100644 index 0000000..1db19e1 --- /dev/null +++ b/PipeLine.vb @@ -0,0 +1,78 @@ +Imports System.ComponentModel + +Public Class PipeLine + Private m_DalleLidar As dalle_lidar + Public ReadOnly Property DalleLidar() As dalle_lidar + Get + Return m_DalleLidar + End Get + + End Property + + + Private m_OutNameFile As String + Public Property OutNameFile() As String + Get + Return m_OutNameFile + End Get + Set(ByVal value As String) + m_OutNameFile = value + End Set + End Property + + Private m_taillegrille As Double + Public Property TailleGrille() As Double + Get + Return m_taillegrille + End Get + Set(ByVal value As Double) + m_taillegrille = value + End Set + End Property + Private m_classification As Integer + Public Property Classification() As Integer + Get + Return m_classification + End Get + Set(ByVal value As Integer) + m_classification = value + End Set + End Property + + Private m_prefixe As String + Public ReadOnly Property Prefixe() As String + Get + Return m_prefixe + End Get + + End Property + Public Sub CreatePipeLine() + Using F As New System.IO.StreamWriter(m_DalleLidar.WorkPath & "\" & m_prefixe & "_" & m_DalleLidar.Radicale & ".json") + F.WriteLine("{") + F.WriteLine(Chr(34) & "pipeline" & Chr(34) & ": [") + F.WriteLine(Chr(34) & m_DalleLidar.JsonName & Chr(34) & ",") + F.WriteLine("{") + F.WriteLine(Chr(34) & "type" & Chr(34) & ": " & Chr(34) & "filters.range" & Chr(34) & ",") + F.WriteLine(Chr(34) & "limits" & Chr(34) & ": " & Chr(34) & "Classification[" & m_classification & ":" & m_classification & "]" & Chr(34)) + F.WriteLine("},") + F.WriteLine("{") + F.WriteLine(Chr(34) & "filename" & Chr(34) & ": " & Chr(34) & m_OutNameFile & Chr(34) & ",") + F.WriteLine(Chr(34) & "gdaldriver" & Chr(34) & ": " & Chr(34) & "GTiff" & Chr(34) & ",") + F.WriteLine(Chr(34) & "output_type" & Chr(34) & ": " & Chr(34) & "all" & Chr(34) & ",") + F.WriteLine(Chr(34) & "resolution" & Chr(34) & ": " & Chr(34) & m_taillegrille & Chr(34) & ",") + F.WriteLine(Chr(34) & "type" & Chr(34) & ": " & Chr(34) & "writers.gdal" & Chr(34)) + F.WriteLine("}") + F.WriteLine("]") + F.WriteLine("}") + + End Using + End Sub + + Public Sub New(dalle_lid As dalle_lidar, prefixe As String, taille As Double, classif As Integer) + m_DalleLidar = dalle_lid + m_taillegrille = taille + m_classification = classif + m_OutNameFile = Get_JsonFilename(dalle_lid.WorkPath) & "\\" & prefixe & "_" & dalle_lid.Radicale & ".tif" + m_prefixe = prefixe + End Sub +End Class diff --git a/VariableGlobale.vb b/VariableGlobale.vb new file mode 100644 index 0000000..686442f --- /dev/null +++ b/VariableGlobale.vb @@ -0,0 +1,180 @@ +Option Explicit On +Imports System.Security.Policy +Imports Girtec.Geo + +Module VariableGlobale + + + Private Structure STARTUPINFO + Dim cb As Long + Dim lpReserved As String + Dim lpDesktop As String + Dim lpTitle As String + Dim dwX As Long + Dim dwY As Long + Dim dwXSize As Long + Dim dwYSize As Long + Dim dwXCountChars As Long + Dim dwYCountChars As Long + Dim dwFillAttribute As Long + Dim dwFlags As Long + Dim wShowWindow As Integer + Dim cbReserved2 As Integer + Dim lpReserved2 As Long + Dim hStdInput As Long + Dim hStdOutput As Long + Dim hStdError As Long + End Structure + + Private Structure PROCESS_INFORMATION + Dim hProcess As Long + Dim hThread As Long + Dim dwProcessID As Long + Dim dwThreadID As Long + End Structure + + Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _ +hHandle As Long, ByVal dwMilliseconds As Long) As Long + + Private Declare Function CreateProcessA Lib "kernel32" (ByVal _ +lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _ +lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, +ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, +ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, +lpStartupInfo As STARTUPINFO, lpProcessInformation As _ +PROCESS_INFORMATION) As Long + + Private Declare Function CloseHandle Lib "kernel32" (ByVal _ +hObject As Long) As Long + + Private Const NORMAL_PRIORITY_CLASS = &H20& + Private Const INFINITE = -1& + ' Public mFint As FormIntegration + Public typeintegration As Integer = -1 + Public verrou_candidat As New Object + Public verrou_tampon As New Object + Public verrou_parcelle As New Object + Public arret_recherche As Boolean = False + Public finedigeo As Boolean = False + + + Public SRID As Integer = 2154 + Public UserSchemaName As String + + Public RayonSelection As Double = 2 + Public cheminhypo As String = "\\Serveur-ad\ftp\BIA\" + Public SchemaNameA2iA As String = "a2ia" + Public millesime As String = "2023" + + + + Public TopoName As String = "topo2023" + Public TopoGenName As String = "topogen2023" + Public TopoComName As String = "topocommune2023" + + Public ListeDalle As System.Collections.Generic.List(Of dalle_lidar) + + + + + Public Function Get_JsonFilename(pathAndnamefile As String) As String + + Return pathAndnamefile.Replace("\", "\\") + + End Function + + + + + Public Function ColorTranslation(ByVal coloint As Integer) As Color + If Math.Sign(coloint) = -1 Then + Return Color.FromArgb(coloint) + Else + Dim A, R, G, B As Integer + Dim stcolor As String = System.Convert.ToString(coloint, 16) + stcolor = stcolor.PadLeft(6, "0"c) + A = 255 + B = System.Convert.ToInt32(stcolor.Substring(0, 2), 16) + G = System.Convert.ToInt32(stcolor.Substring(2, 2), 16) + R = System.Convert.ToInt32(stcolor.Substring(4, 2), 16) + Return System.Drawing.Color.FromArgb(A, R, G, B) + End If + End Function + + + + + + + + + Function GetUserName() As String + If TypeOf My.User.CurrentPrincipal Is + Security.Principal.WindowsPrincipal Then + ' The application is using Windows authentication. + ' The name format is DOMAIN\USERNAME. + Dim parts() As String = Split(My.User.Name, "\") + Dim username As String = parts(1).ToLower() + Return username + Else + ' The application is using custom authentication. + Return My.User.Name + End If + End Function + + + + + + + + + Private _debugsw As New IO.StreamWriter(Date.Now().ToShortDateString().Replace("/", "-") & "_" & Date.Now().ToShortTimeString().Replace(":", "-") & ".log") With { + .AutoFlush = True + } + Private _debuglock As New Object() + Friend Sub Debug(v As String) + SyncLock _debuglock + _debugsw.WriteLine(v) + End SyncLock + End Sub + + + Public Sub ExecCmd(cmdline As String) + Dim proc As PROCESS_INFORMATION + Dim start As STARTUPINFO + Dim ReturnValue As Integer + + ' Initialize the STARTUPINFO structure: + start.cb = Len(start) + + ' Start the shelled application: + ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, +NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc) + + ' Wait for the shelled application to finish: + Do + ReturnValue = WaitForSingleObject(proc.hProcess, 0) + My.Application.DoEvents() + Loop Until ReturnValue <> 258 + + ReturnValue = CloseHandle(proc.hProcess) + End Sub + + Public Enum Classification_LIDAR + Non_Classe = 1 + Sol = 2 + Veg_b = 3 + Veg_m = 4 + Veg_h = 5 + Bati = 6 + Eau = 9 + Pont = 17 + Sursol = 64 + Artefact = 65 + Pv = 66 + Divers = 67 + End Enum + + +End Module