// ToGeoJSON creates a new geojson feature with a multipoint geometry
// containing all the points.
548090
func (ps PointSet) ToGeoJSON() *geojson.Feature {
	f := geojson.NewMultiPointFeature()
	for _, v := range ps {
		f.Geometry.MultiPoint = append(f.Geometry.MultiPoint, []float64{v[0], v[1]})
	}

	return f
}
423574
func (g *Geometry) Decode() (geom.T, error) {
	switch g.Type {
	case "Point":
		if g.Coordinates == nil {
			return geom.NewPoint(geom.NoLayout), nil
		}
		var coords geom.Coord
		if err := json.Unmarshal(*g.Coordinates, &coords); err != nil {
			return nil, err
		}
		layout, err := guessLayout0(coords)
		if err != nil {
			return nil, err
		}
		return geom.NewPoint(layout).SetCoords(coords)
	case "LineString":
		if g.Coordinates == nil {
			return geom.NewLineString(geom.NoLayout), nil
		}
		var coords []geom.Coord
		if err := json.Unmarshal(*g.Coordinates, &coords); err != nil {
			return nil, err
		}
		layout, err := guessLayout1(coords)
		if err != nil {
			return nil, err
		}
		return geom.NewLineString(layout).SetCoords(coords)
	case "Polygon":
		if g.Coordinates == nil {
			return geom.NewPolygon(geom.NoLayout), nil
		}
		var coords [][]geom.Coord
		if err := json.Unmarshal(*g.Coordinates, &coords); err != nil {
			return nil, err
		}
		layout, err := guessLayout2(coords)
		if err != nil {
			return nil, err
		}
		return geom.NewPolygon(layout).SetCoords(coords)
	case "MultiPoint":
		if g.Coordinates == nil {
			return geom.NewMultiPoint(geom.NoLayout), nil
		}
		var coords []geom.Coord
		if err := json.Unmarshal(*g.Coordinates, &coords); err != nil {
			return nil, err
		}
		layout, err := guessLayout1(coords)
		if err != nil {
			return nil, err
		}
		return geom.NewMultiPoint(layout).SetCoords(coords)
	case "MultiLineString":
		if g.Coordinates == nil {
			return geom.NewMultiLineString(geom.NoLayout), nil
		}
		var coords [][]geom.Coord
		if err := json.Unmarshal(*g.Coordinates, &coords); err != nil {
			return nil, err
		}
		layout, err := guessLayout2(coords)
		if err != nil {
			return nil, err
		}
		return geom.NewMultiLineString(layout).SetCoords(coords)
	case "MultiPolygon":
		if g.Coordinates == nil {
			return geom.NewMultiPolygon(geom.NoLayout), nil
		}
		var coords [][][]geom.Coord
		if err := json.Unmarshal(*g.Coordinates, &coords); err != nil {
			return nil, err
		}
		layout, err := guessLayout3(coords)
		if err != nil {
			return nil, err
		}
		return geom.NewMultiPolygon(layout).SetCoords(coords)
	case "GeometryCollection":
		geoms := make([]geom.T, len(g.Geometries))
		for i, subGeometry := range g.Geometries {
			var err error
			geoms[i], err = subGeometry.Decode()
			if err != nil {
				return nil, err
			}
		}
		gc := geom.NewGeometryCollection()
		if err := gc.Push(geoms...); err != nil {
			return nil, err
		}
		return gc, nil
	default:
		return nil, ErrUnsupportedType(g.Type)
	}
}
968049
func (c Configuration) toJSON() (string, error) {
	c.setDefaults()
	jsonBytes, err := json.Marshal(c)
	if err != nil {
		return "", err
	}
	return string(jsonBytes), nil
}
502711
func (g Geometry) MarshalJSON() ([]byte, error) {
	if g.Coordinates == nil && len(g.Geometries) == 0 {
		return []byte(`null`), nil
	}

	ng := &jsonGeometryMarshall{}
	switch g := g.Coordinates.(type) {
	case orb.Ring:
		ng.Coordinates = orb.Polygon{g}
	case orb.Bound:
		ng.Coordinates = g.ToPolygon()
	case orb.Collection:
		ng.Geometries = make([]*Geometry, 0, len(g))
		for _, c := range g {
			ng.Geometries = append(ng.Geometries, NewGeometry(c))
		}
		ng.Type = g.GeoJSONType()
	default:
		ng.Coordinates = g
	}

	if ng.Coordinates != nil {
		ng.Type = ng.Coordinates.GeoJSONType()
	}

	if len(g.Geometries) > 0 {
		ng.Geometries = g.Geometries
		ng.Type = orb.Collection{}.GeoJSONType()
	}
	return json.Marshal(ng)
}
197296
func (b *HttpRequest) ToJson(v interface{}) error {
	data, err := b.Bytes()
	if err != nil {
		return err
	}
	return json.Unmarshal(data, v)
}
148414
func (i IAMPolicyDocument) ToJSON() string {
	buf, err := json.Marshal(i)
	if err != nil {
		panic(err)
	}
	return string(buf)
}
859996
func Geometry(g orb.Geometry, proj orb.Projection) orb.Geometry {
	if g == nil {
		return nil
	}

	switch g := g.(type) {
	case orb.Point:
		return Point(g, proj)
	case orb.MultiPoint:
		return MultiPoint(g, proj)
	case orb.LineString:
		return LineString(g, proj)
	case orb.MultiLineString:
		return MultiLineString(g, proj)
	case orb.Ring:
		return Ring(g, proj)
	case orb.Polygon:
		return Polygon(g, proj)
	case orb.MultiPolygon:
		return MultiPolygon(g, proj)
	case orb.Collection:
		return Collection(g, proj)
	case orb.Bound:
		return Bound(g, proj)
	}

	panic("geometry type not supported")
}
1094838
func (b *Bound) UnmarshalJSON(data []byte) error {
	var points []*Point

	err := json.Unmarshal(data, &points)
	if err != nil {
		return err
	}

	if len(points) > 2 {
		return errors.New("geo: too many points to unmarshal into bound")
	}

	if len(points) < 2 {
		return errors.New("geo: not enough points to unmarshal into bound")
	}

	b.sw = points[0]
	b.ne = points[0].Clone()
	b.Extend(points[1])

	return nil
}
875532
func ToJSON(kvs []*KV) (map[string]interface{}, error) {
	m := make(map[string]interface{})
	for _, kv := range kvs {
		path := strings.Split(kv.Key, "/")
		var parent = m
		for s, segment := range path {
			if s == len(path)-1 {
				parent[segment] = string(kv.Value)
			} else {
				if parent[segment] == nil {
					parent[segment] = make(map[string]interface{})
				}
				switch parent[segment].(type) {
				case map[string]interface{}:
					parent = parent[segment].(map[string]interface{})
				default:
					delete(parent, segment)
				}
			}
		}
	}
	return m, nil
}
318646
func NewMultiPoint(coordinates Coordinates) *MultiPoint {
	if coordinates == nil {
		coordinates = make(Coordinates, 0, INIT_GEOM_CAP)
	}
	return &MultiPoint{Type: "MultiPoint", Coordinates: coordinates}
}
604285
func newGeometry(input interface{}) interface{} {
	var (
		result      interface{}
		coordinates interface{}
	)
	switch it := input.(type) {
	case map[string]interface{}:
		if _, ok := it[COORDINATES]; ok {
			coordinates = interfaceToArray(it[COORDINATES])
		}
		iType := it[TYPE].(string)
		switch iType {
		case POINT:
			result = NewPoint(coordinates.([]float64))
		case LINESTRING:
			result = NewLineString(coordinates.([][]float64))
		case POLYGON:
			result = NewPolygon(coordinates.([][][]float64))
		case MULTIPOINT:
			result = NewMultiPoint(coordinates.([][]float64))
		case MULTILINESTRING:
			result = NewMultiLineString(coordinates.([][][]float64))
		case MULTIPOLYGON:
			result = NewMultiPolygon(coordinates.([][][][]float64))
		case GEOMETRYCOLLECTION:
			geometries := it["geometries"].([]interface{})
			for inx, geometry := range geometries {
				geometries[inx] = newGeometry(geometry)
			}
			result = NewGeometryCollection(geometries)
		}
	case *Point, *LineString, *Polygon, *MultiPoint, *MultiLineString, *MultiPolygon, *GeometryCollection:
		result = it
	}
	return result
}
861619
func (g *MultiPoint) Point(i int) *Point {
	return NewPointFlat(g.layout, g.Coord(i))
}
1219535
func (o InsidePolygonOption) MarshalJSON() ([]byte, error) {
	if o.coordinates != "" {
		return json.Marshal(o.coordinates)
	}
	return json.Marshal(o.polygons)
}
541050
func AsGeoJSON(c aspect.ColumnElem) aspect.ColumnElem {
	return c.SetInner(
		aspect.FuncClause{Inner: c.Inner(), F: "ST_AsGeoJSON"},
	)
}
570092
func Geometry(b orb.Bound, g orb.Geometry) orb.Geometry {
	if g == nil {
		return nil
	}

	if !b.Intersects(g.Bound()) {
		return nil
	}

	switch g := g.(type) {
	case orb.Point:
		return g // Intersect check above
	case orb.MultiPoint:
		mp := MultiPoint(b, g)
		if len(mp) == 1 {
			return mp[0]
		}

		if mp == nil {
			return nil
		}

		return mp
	case orb.LineString:
		mls := LineString(b, g)
		if len(mls) == 1 {
			return mls[0]
		}

		if len(mls) == 0 {
			return nil
		}
		return mls
	case orb.MultiLineString:
		mls := MultiLineString(b, g)
		if len(mls) == 1 {
			return mls[0]
		}

		if mls == nil {
			return nil
		}

		return mls
	case orb.Ring:
		r := Ring(b, g)
		if r == nil {
			return nil
		}

		return r
	case orb.Polygon:
		p := Polygon(b, g)
		if p == nil {
			return nil
		}

		return p
	case orb.MultiPolygon:
		mp := MultiPolygon(b, g)
		if len(mp) == 1 {
			return mp[0]
		}

		if mp == nil {
			return nil
		}

		return mp
	case orb.Collection:
		c := Collection(b, g)
		if len(c) == 1 {
			return c[0]
		}

		if c == nil {
			return nil
		}

		return c
	case orb.Bound:
		b = Bound(b, g)
		if b.IsEmpty() {
			return nil
		}

		return b
	}

	panic(fmt.Sprintf("geometry type not supported: %T", g))
}
176417
func (mp MultiPoint) MarshalJSON() ([]byte, error) {
	return json.Marshal(Geometry{Coordinates: orb.MultiPoint(mp)})
}
1318322
func (mls *MultiLineString) UnmarshalJSON(data []byte) error {
	g := &Geometry{}
	err := json.Unmarshal(data, &g)
	if err != nil {
		return err
	}

	multilineString, ok := g.Coordinates.(orb.MultiLineString)
	if !ok {
		return errors.New("geojson: not a MultiLineString type")
	}

	*mls = MultiLineString(multilineString)
	return nil
}