package main
import (
"fmt"
"github.com/peterstace/simplefeatures/geom"
"github.com/twpayne/go-geos"
"github.com/twpayne/go-geos/geojson"
"github.com/twpayne/go-geos/geometry"
)
func gogeos() {
line, _ := geos.NewGeomFromWKT("LINESTRING Z (117.1670175812344 31.70043707 11.85899,117.16700395 31.70044817 12.85899)")
// geom.Destroy()
fmt.Println(line.ToWKT())
interpolate_point := line.Interpolate(0.1)
fmt.Println(interpolate_point.ToWKT())
line_buffer := line.Buffer(0.00005, 1)
fmt.Println(line_buffer.ToWKT())
fmt.Println(line.Type())
coordSeq := line.CoordSeq()
coords := coordSeq.ToCoords()
for i, coord := range coords {
fmt.Println(i, coord)
}
//point.Destroy()
feature := geojson.Feature{Geometry: geometry.Geometry{line}, Properties: map[string]interface{}{"a": 2}}
data, _ := feature.MarshalJSON()
fmt.Println(string(data))
}
func simple() {
point2, _ := geom.UnmarshalWKT("point(1 1)")
fmt.Println(point2.AsText())
feature2 := geom.GeoJSONFeature{Geometry: point2, Properties: map[string]interface{}{"a": 2}}
data, err := feature2.MarshalJSON()
fmt.Println(err)
fmt.Println(string(data))
}
func main() {
gogeos()
rows := []map[string]string{{"lane_id": "1", "lg_id": "2", "seq_num": "2"}, {"lane_id": "1", "lg_id": "2", "seq_num": "22"},
{"lane_id": "13", "lg_id": "2", "seq_num": "222"}}
lgLaneIdsMap := make(map[string]map[string]string)
lgLaneIdsMap2 := make(map[string][]string)
LaneIdMap := make(map[string]any)
for _, row := range rows {
laneId, lgId, seqNum := row["lane_id"], row["lg_id"], row["seq_num"]
if _, ok := lgLaneIdsMap[lgId]; ok {
lgLaneIdsMap[lgId][laneId] = ""
} else {
laneIdsMap := map[string]string{laneId: ""}
lgLaneIdsMap[lgId] = laneIdsMap
}
if _, ok := lgLaneIdsMap2[lgId]; ok {
lgLaneIdsMap2[lgId] = append(lgLaneIdsMap2[lgId], laneId)
} else {
laneIds := []string{laneId}
lgLaneIdsMap2[lgId] = laneIds
}
LaneIdMap[laneId] = []string{lgId, seqNum}
}
for s, m := range lgLaneIdsMap {
fmt.Println(s, m)
}
for s, m := range lgLaneIdsMap2 {
fmt.Println(s, m)
}
for s, a := range LaneIdMap {
fmt.Println(s, a)
}
}
网友评论