/
geo_json.go
50 lines (43 loc) · 1.52 KB
/
geo_json.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package geom
func NewGeoJson(data interface{}) *GeoJson {
switch t := data.(type) {
case *Feature:
return &GeoJson{GeoJson: &GeoJson_Feature{Feature: t}}
case *FeatureCollection:
return &GeoJson{GeoJson: &GeoJson_FeatureCollection{FeatureCollection: t}}
case *Point:
return &GeoJson{GeoJson: &GeoJson_Point{Point: t}}
case *MultiPoint:
return &GeoJson{GeoJson: &GeoJson_MultiPoint{MultiPoint: t}}
case *LineString:
return &GeoJson{GeoJson: &GeoJson_LineString{LineString: t}}
case *MultiLineString:
return &GeoJson{GeoJson: &GeoJson_MultiLineString{MultiLineString: t}}
case *Polygon:
return &GeoJson{GeoJson: &GeoJson_Polygon{Polygon: t}}
case *MultiPolygon:
return &GeoJson{GeoJson: &GeoJson_MultiPolygon{MultiPolygon: t}}
case *GeometryCollection:
return &GeoJson{GeoJson: &GeoJson_GeometryCollection{GeometryCollection: t}}
default:
return nil
}
}
func NewFeatureCollectionGeoJson(features ...*Feature) *GeoJson {
return NewGeoJson(NewFeatureCollection(features...))
}
func NewPointGeoJson(coordinates *LngLat) *GeoJson {
return NewGeoJson(NewPoint(coordinates))
}
func NewPointGeoJsonFrom(coordinates ...float64) *GeoJson {
return NewGeoJson(NewPointFrom(coordinates...))
}
func NewLineStringGeoJson(coordinates ...*LngLat) *GeoJson {
return NewGeoJson(NewLineString(coordinates...))
}
func NewPolygonGeoJson(lineStrings ...*LineString) *GeoJson {
return NewGeoJson(NewPolygon(lineStrings...))
}
func NewPolygonGeoJsonFrom(coordinates ...*LngLat) *GeoJson {
return NewGeoJson(NewPolygonFrom(coordinates...))
}