package geojson import ( "github.com/tidwall/geojson/geometry" "github.com/tidwall/gjson" ) // MultiLineString ... type MultiLineString struct{ collection } // NewMultiLineString ... func NewMultiLineString(lines []*geometry.Line) *MultiLineString { g := new(MultiLineString) for _, line := range lines { g.children = append(g.children, NewLineString(line)) } g.parseInitRectIndex(DefaultParseOptions) return g } // AppendJSON ... func (g *MultiLineString) AppendJSON(dst []byte) []byte { dst = append(dst, `{"type":"MultiLineString","coordinates":[`...) for i, g := range g.children { if i > 0 { dst = append(dst, ',') } dst = append(dst, gjson.GetBytes(g.AppendJSON(nil), "coordinates").String()...) } dst = append(dst, ']') if g.extra != nil { dst = g.extra.appendJSONExtra(dst) } dst = append(dst, '}') return dst } // String ... func (g *MultiLineString) String() string { return string(g.AppendJSON(nil)) } // JSON ... func (g *MultiLineString) JSON() string { return string(g.AppendJSON(nil)) } func parseJSONMultiLineString( keys *parseKeys, opts *ParseOptions, ) (Object, error) { var g MultiLineString var err error if !keys.rCoordinates.Exists() { return nil, errCoordinatesMissing } if !keys.rCoordinates.IsArray() { return nil, errCoordinatesInvalid } var coords []geometry.Point var ex *extra keys.rCoordinates.ForEach(func(_, value gjson.Result) bool { coords, ex, err = parseJSONLineStringCoords(keys, value, opts) if err != nil { return false } if len(coords) < 2 { err = errCoordinatesInvalid return false } line := geometry.NewLine(coords, opts.IndexGeometry) g.children = append(g.children, &LineString{base: *line, extra: ex}) return true }) if err != nil { return nil, err } if err := parseBBoxAndExtras(&g.extra, keys, opts); err != nil { return nil, err } g.parseInitRectIndex(opts) return &g, nil }