-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsplitter.go
More file actions
35 lines (29 loc) · 1.08 KB
/
splitter.go
File metadata and controls
35 lines (29 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
gdj "github.com/pitchinnate/golangGeojsonDijkstra"
)
// Splitter is a function that fc with more than 2 pairs of coordinates into fc with 2 pairs of coordinates
func splitter(fc gdj.FeatureCollection) gdj.FeatureCollection {
var newFc gdj.FeatureCollection
newFc.Type = "FeatureCollection"
// Loop through all features in the feature collection
for _, feature := range fc.Features {
// Loop through all coordinates in the feature
//log.Println("Feature: ", len(feature.Geometry.Coordinates))
lengthOfCoords := len(feature.Geometry.Coordinates)
for i := 0; i < lengthOfCoords-1; i++ {
coord1 := feature.Geometry.Coordinates[i]
coord2 := feature.Geometry.Coordinates[i+1]
// Create a new feature with the first and next coordinate and append it to the new feature collection
newFeature := gdj.Feature{
Geometry: gdj.Geometry{
Type: "LineString",
Coordinates: []gdj.Position{coord1, coord2},
},
}
newFc.Features = append(newFc.Features, newFeature)
}
}
writeOutput(newFc, "dataset/splitCoords.geojson")
return newFc
}