Created
February 19, 2016 06:00
-
-
Save KMR-zoar/4d7b6dac65e7089472b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$filename = $ARGS[0] | |
$elements = @("id", "lat", "lon", "created_at", "closed_at") | |
if ((Test-Path $filename) -eq $false) | |
{ | |
Write-Host "File is not exist or access denied." | |
exit | |
} | |
Write-Output ("{") | |
Write-Output (" `"type`": `"FeatureCollection`",") | |
Write-Output (" `"features`": [") | |
$xml = Get-Content $filename | |
foreach ($items in $xml) | |
{ | |
if ($items.indexof("<note") -ne -1 ) | |
{ | |
$item = $items -split " " | |
$feature = @{} | |
foreach ($element in $item) | |
{ | |
foreach ($ele in $elements) | |
{ | |
if ($element.contains("$ele=")) | |
{ | |
$feature.add($ele, $element.Replace("$ele=","").Replace(">","").Replace("`"","")) | |
} | |
} | |
} | |
Write-Output ("{") | |
Write-Output (" `"type`": `"Feature`",") | |
Write-Output (" `"id`": " + $feature.id + ",") | |
Write-Output (" `"properties`": {") | |
Write-Output (" `"id`":" + $feature.id + ",") | |
Write-Output (" `"create`": `"" + $feature.created_at + "`",") | |
if ($feature.closed_at) | |
{ | |
Write-Output (" `"close`": `"" + $feature.closed_at + "`",") | |
} | |
Else | |
{ | |
Write-Output (" `"close`": Null,") | |
} | |
# Write-Output (" `"longitude`": `"" + $feature.lon + "`",") | |
# Write-Output (" `"latitude`": `"" + $feature.lat + "`",") | |
Write-Output (" },") | |
Write-Output (" `"geometry`": {") | |
Write-Output (" `"type`": `"Point`",") | |
Write-Output (" `"coordinates`": [") | |
Write-Output (" " + $feature.lon + ",") | |
Write-Output (" " + $feature.lat) | |
Write-Output (" ]") | |
Write-Output (" }") | |
Write-Output ("},") | |
} | |
} | |
Write-Output (" ]") | |
Write-Output ("}") | |
#ムシャクシャしてやった。後悔はしていない |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment