I'm having problems creating a GeoJSON file. I'm looping through video files extracting info such as datetaken, name, coordinates, etc. I want to write this data to a JSON file so I can plot them on googlemaps. But I'm stuck. I can't get the lat/lng in the correct json format.
The GeoJSON structure is as follows:
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Lost Islands"
}
]}
My code, no matter what I try, generates the following or something similar.
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": "System.Collections.Hashtable"
},
"properties": {
"name": "Lost Island"
}
]}
My code (simplified for here):
cls
$dirName = "C:\temp"
$filter = "*.mp4"
$jsonBase = @{}
$features = New-Object System.Collections.ArrayList
$coordinatesList = New-Object System.Collections.ArrayList
$coordinates = New-Object System.Collections.ArrayList
$geometry = New-Object System.Collections.ArrayList
Get-ChildItem $dirName -include $filter -recurse -File | foreach {
$lat = 10.12345
$lng = 20.12345
$vidDate = "2022-09-11T12:00:00.000000Z"
$coordinatesList = New-Object System.Collections.ArrayList
$coordinatesList.Add(@{$lat=$lng;})
$coordinates = New-Object System.Collections.ArrayList
$coordinates.Add(@{"coordinates"=$coordinatesList})
$geometry = @{}
$geometry.Add("coordinates",$coordinates)
$geometry.Add("type","Point")
$features.Add(@{"geometry"=$geometry;
"type" = "Feature";
"properties" = @{"fileName"=($_).Name;"pathToFile"=($_).FullName;"takenDate"=$vidDate;}
})
}
$jsonBase.Add("features",$features)
$jsonstring = $jsonBase | ConvertTo-Json -Depth 3
Write-Host $jsonstring
Any thoughts on where I'm going wrong?