@@ -90,6 +90,10 @@ func (p *Point) Type() string {
90
90
return strings .ToLower (p .Typ )
91
91
}
92
92
93
+ func (p * Point ) Value () ([]byte , error ) {
94
+ return jsoniter .Marshal (p )
95
+ }
96
+
93
97
func NewGeoJsonPoint (v []float64 ) index.GeoJSON {
94
98
rv := & Point {Typ : PointType , Vertices : v }
95
99
rv .init ()
@@ -193,6 +197,10 @@ func (p *MultiPoint) Type() string {
193
197
return strings .ToLower (p .Typ )
194
198
}
195
199
200
+ func (mp * MultiPoint ) Value () ([]byte , error ) {
201
+ return jsoniter .Marshal (mp )
202
+ }
203
+
196
204
func (p * MultiPoint ) Intersects (other index.GeoJSON ) (bool , error ) {
197
205
p .init ()
198
206
@@ -268,6 +276,10 @@ func (ls *LineString) Type() string {
268
276
return strings .ToLower (ls .Typ )
269
277
}
270
278
279
+ func (ls * LineString ) Value () ([]byte , error ) {
280
+ return jsoniter .Marshal (ls )
281
+ }
282
+
271
283
func (ls * LineString ) Marshal () ([]byte , error ) {
272
284
ls .init ()
273
285
@@ -323,6 +335,10 @@ func (mls *MultiLineString) Type() string {
323
335
return strings .ToLower (mls .Typ )
324
336
}
325
337
338
+ func (mls * MultiLineString ) Value () ([]byte , error ) {
339
+ return jsoniter .Marshal (mls )
340
+ }
341
+
326
342
func (mls * MultiLineString ) Marshal () ([]byte , error ) {
327
343
mls .init ()
328
344
@@ -402,6 +418,10 @@ func (p *Polygon) Type() string {
402
418
return strings .ToLower (p .Typ )
403
419
}
404
420
421
+ func (p * Polygon ) Value () ([]byte , error ) {
422
+ return jsoniter .Marshal (p )
423
+ }
424
+
405
425
func (p * Polygon ) Marshal () ([]byte , error ) {
406
426
p .init ()
407
427
@@ -465,6 +485,10 @@ func (p *MultiPolygon) Type() string {
465
485
return strings .ToLower (p .Typ )
466
486
}
467
487
488
+ func (p * MultiPolygon ) Value () ([]byte , error ) {
489
+ return jsoniter .Marshal (p )
490
+ }
491
+
468
492
func (p * MultiPolygon ) Marshal () ([]byte , error ) {
469
493
p .init ()
470
494
@@ -542,6 +566,10 @@ func (gc *GeometryCollection) Type() string {
542
566
return strings .ToLower (gc .Typ )
543
567
}
544
568
569
+ func (gc * GeometryCollection ) Value () ([]byte , error ) {
570
+ return jsoniter .Marshal (gc )
571
+ }
572
+
545
573
func (gc * GeometryCollection ) Members () []index.GeoJSON {
546
574
shapes := make ([]index.GeoJSON , 0 , len (gc .Shapes ))
547
575
for _ , shape := range gc .Shapes {
@@ -721,24 +749,35 @@ func (gc *GeometryCollection) UnmarshalJSON(data []byte) error {
721
749
type Circle struct {
722
750
Typ string `json:"type"`
723
751
Vertices []float64 `json:"coordinates"`
724
- RadiusInMeters float64 `json:"radiusInMeters"`
752
+ Radius string `json:"radius"`
753
+ radiusInMeters float64
725
754
s2cap * s2.Cap
726
755
}
727
756
728
757
func NewGeoCircle (points []float64 ,
729
- radiusInMeter float64 ) index.GeoJSON {
758
+ radius string ) index.GeoJSON {
759
+ r , err := ParseDistance (radius )
760
+ if err != nil {
761
+ return nil
762
+ }
763
+
730
764
return & Circle {Typ : CircleType ,
731
765
Vertices : points ,
732
- RadiusInMeters : radiusInMeter }
766
+ Radius : radius ,
767
+ radiusInMeters : r }
733
768
}
734
769
735
770
func (c * Circle ) Type () string {
736
771
return strings .ToLower (c .Typ )
737
772
}
738
773
774
+ func (c * Circle ) Value () ([]byte , error ) {
775
+ return jsoniter .Marshal (c )
776
+ }
777
+
739
778
func (c * Circle ) init () {
740
779
if c .s2cap == nil {
741
- c .s2cap = s2Cap (c .Vertices , c .RadiusInMeters )
780
+ c .s2cap = s2Cap (c .Vertices , c .radiusInMeters )
742
781
}
743
782
}
744
783
@@ -770,10 +809,9 @@ func (c *Circle) Contains(other index.GeoJSON) (bool, error) {
770
809
771
810
func (c * Circle ) UnmarshalJSON (data []byte ) error {
772
811
tmp := struct {
773
- Typ string `json:"type"`
774
- Vertices []float64 `json:"coordinates"`
775
- Radius string `json:"radius"`
776
- RadiusInMeters float64 `json:"radiusInMeters"`
812
+ Typ string `json:"type"`
813
+ Vertices []float64 `json:"coordinates"`
814
+ Radius string `json:"radius"`
777
815
}{}
778
816
779
817
err := jsoniter .Unmarshal (data , & tmp )
@@ -782,9 +820,9 @@ func (c *Circle) UnmarshalJSON(data []byte) error {
782
820
}
783
821
c .Typ = tmp .Typ
784
822
c .Vertices = tmp .Vertices
785
- c .RadiusInMeters = tmp .RadiusInMeters
823
+ c .Radius = tmp .Radius
786
824
if tmp .Radius != "" {
787
- c .RadiusInMeters , err = ParseDistance (tmp .Radius )
825
+ c .radiusInMeters , err = ParseDistance (tmp .Radius )
788
826
}
789
827
790
828
return err
@@ -807,6 +845,10 @@ func (e *Envelope) Type() string {
807
845
return strings .ToLower (e .Typ )
808
846
}
809
847
848
+ func (e * Envelope ) Value () ([]byte , error ) {
849
+ return jsoniter .Marshal (e )
850
+ }
851
+
810
852
func (e * Envelope ) init () {
811
853
if e .r == nil {
812
854
e .r = s2RectFromBounds (e .Vertices [0 ], e .Vertices [1 ])
0 commit comments