Created
October 1, 2016 13:59
-
-
Save laurent35240/8dfa2f33a478c297fab96ea730d81b42 to your computer and use it in GitHub Desktop.
Tool for extracting only coordinates from json file provided by Toulouse
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
package main | |
import ( | |
"io/ioutil" | |
"fmt" | |
"encoding/json" | |
) | |
type DatasetType struct { | |
Fields FieldsType | |
} | |
type FieldsType struct{ | |
Geo_shape GeoShapeType | |
} | |
type GeoShapeType struct { | |
Coordinates []float64 | |
} | |
func convertToMatrix(datasets []DatasetType) [][]float64 { | |
var result [][]float64 | |
for _,dataset := range datasets{ | |
result = append(result, dataset.Fields.Geo_shape.Coordinates) | |
} | |
return result | |
} | |
func main() { | |
file, e := ioutil.ReadFile("/home/laurent/projects/ToulouseLights/points-lumineux.json") | |
if e != nil { | |
fmt.Printf("File error: %v\n", e) | |
} | |
var Datasets []DatasetType | |
json.Unmarshal(file, &Datasets) | |
matrix := convertToMatrix(Datasets) | |
result, e := json.Marshal(matrix) | |
if e!= nil { | |
fmt.Println("Error:", e) | |
} | |
e = ioutil.WriteFile("/home/laurent/projects/ToulouseLights/data/light-coordinates.json", result, 0644) | |
if e!= nil { | |
fmt.Println("Error:", e) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment