Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement