Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "io/ioutil"
  5. "fmt"
  6. "encoding/json"
  7. )
  8.  
  9. type DatasetType struct {
  10. Fields FieldsType
  11. }
  12.  
  13. type FieldsType struct{
  14. Geo_shape GeoShapeType
  15. }
  16.  
  17. type GeoShapeType struct {
  18. Coordinates []float64
  19. }
  20.  
  21. func convertToMatrix(datasets []DatasetType) [][]float64 {
  22. var result [][]float64
  23. for _,dataset := range datasets{
  24. result = append(result, dataset.Fields.Geo_shape.Coordinates)
  25. }
  26. return result
  27. }
  28.  
  29. func main() {
  30. file, e := ioutil.ReadFile("/home/laurent/projects/ToulouseLights/points-lumineux.json")
  31. if e != nil {
  32. fmt.Printf("File error: %v\n", e)
  33. }
  34.  
  35. var Datasets []DatasetType
  36. json.Unmarshal(file, &Datasets)
  37.  
  38. matrix := convertToMatrix(Datasets)
  39. result, e := json.Marshal(matrix)
  40. if e!= nil {
  41. fmt.Println("Error:", e)
  42. }
  43. e = ioutil.WriteFile("/home/laurent/projects/ToulouseLights/data/light-coordinates.json", result, 0644)
  44. if e!= nil {
  45. fmt.Println("Error:", e)
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement