FAQ/ PowerShell script to import culvert data into DioVISTA
Similar to the PowerShell script that imports fill data into DioVISTA, is there a way to import culverts in bulk?
response
Try the PowerShell script below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 | #プロジェクトに盛土を追加するスクリプト
# プロジェクトファイルを指定する(入力)
$fsxproj = ".\sample.fsxproj"
# プロジェクトファイルを指定する(出力)
$newFsxproj = ".\sample_addCulvert.fsxproj"
# csvファイルを指定する(入力)
$csv = Import-Csv -Encoding UTF8 ".\Culvert.csv"
#プロジェクトの読み込み
$fsxprojInfo = Get-Item $fsxproj
[xml]$xml = (cat -Encoding UTF8 $fsxproj)
# Culvert.csvから読み込んだデータをカルバートとしてプロジェクトに追加
foreach ($id in ($csv | select -Unique "ID")) {
$CoordInfos = $csv | where { $_.ID -eq $id.ID }
$firstCoordInfo = $CoordInfos[0]
$newCulvert = $xml.CreateElement("culvert")
[void]$xml.floodSim.conditions.culverts.AppendChild($newCulvert)
$attrs = @{
"name" = "カルバート" + $firstCoordInfo.ID.ToString()
"mode" = "0"
"width" = $firstCoordInfo.Width.ToString()
"height" = $firstCoordInfo.Height.ToString()
"diameter" = "1"
"length" = "1"
"roughness" = "0.014"
"lossCoef" = "1"
"valid" = "True"
"lineStyle" = "0 2 200 100 0 255"
}
$attrs.GetEnumerator() | % {
$newAttribute = $xml.CreateAttribute($_.Name)
$newAttribute.Value = $_.Value
[void]$newCulvert.Attributes.Append($newAttribute)
}
$newPts = $xml.CreateElement("pts")
[void]$newCulvert.AppendChild($newPts)
foreach ($coordInfo in $CoordInfos) {
$coords = @{
x = $coordInfo.X0
y = $coordInfo.Y0
},
@{
x = $coordInfo.X1
y = $coordInfo.Y1
}
foreach($c in $coords){
$coordText = "{0:0.000000000000000} {1:0.000000000000000}" -f ([double]$c.y * [Math]::PI / 180.0), ([double]$c.x * [Math]::PI / 180.0)
$coordValue = $xml.CreateTextNode($coordText)
$newCoord = $xml.CreateElement("coord")
[void]$newCoord.AppendChild($coordValue)
[void]$newPts.AppendChild($newCoord)
}
}
}
$xml.Save((Join-Path $fsxprojInfo.DirectoryName $newFsxproj))
|
Here is an example of fill data: Paste it into a text editor and save it as "Culvert.csv". The encoding is UTF8.
| ID,X0,Y0,X1,Y1,Width,Height
1,140,36,140.001,36.001,1,2
2,140.002,36,140.002,36.001,2,3
3,140.003,36,140.004,36.001,3,4
|
column |
substance |
ID |
Calvert ID |
X0 |
Longitude of the starting point (degree) |
Y0 |
Latitude of the starting point (degree) |
X1 |
Longitude of the destination point (degree) |
Y1 |
Latitude of the destination point (degree) |
Width |
Width (m) |
Height |
Height (m) |
When you run the script, culvert 1, culvert 2, and culvert 3 are created. From the left to right: culvert 1, culvert 2, and culvert 3.
Indicates the properties of Culvert 1.
Last update:
2023-03-17