Documentation
¶
Index ¶
- func FormatWKT(wkt string) string
- func UnmarshalGeoJSON(data []byte) (string, interface{}, error)
- type CRS
- type Feature
- func (f *Feature) PropertyBool(key string) (bool, error)
- func (f *Feature) PropertyFloat64(key string) (float64, error)
- func (f *Feature) PropertyInt(key string) (int, error)
- func (f *Feature) PropertyMustBool(key string, def ...bool) bool
- func (f *Feature) PropertyMustFloat64(key string, def ...float64) float64
- func (f *Feature) PropertyMustInt(key string, def ...int) int
- func (f *Feature) PropertyMustString(key string, def ...string) string
- func (f *Feature) PropertyString(key string) (string, error)
- func (f *Feature) SetProperty(key string, value interface{})
- type FeatureCollection
- type GeoJsonType
- type Geometry
- type GeometryType
- type LineString
- type MultiLineString
- type MultiPoint
- type MultiPolygon
- type Point
- type Polygon
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnmarshalGeoJSON ¶
解析 GeoJSON,根据Type返回相应类型和结构体(FeatureCollection或者Feature),便于调用者类型转换 调用示例 geojsonType,f,err := UnmarshalGeoJSON(data)
if err != nil { return nil, err }
switch geojsonType { case "FeatureCollection":
fc := f.(*FeatureCollection) // 处理FeatureCollection
case "Feature":
f := f.(*Feature) // 处理Feature
Types ¶
type CRS ¶
type CRS struct { Type string `json:"type"` Properties map[string]string `json:"properties,omitempty"` }
type Feature ¶
type Feature struct { ID interface{} `json:"id,omitempty"` Type string `json:"type"` Geometry Geometry `json:"geometry"` Properties map[string]interface{} `json:"properties"` }
A Feature corresponds to GeoJSON feature object
func UnmarshalFeature ¶
解析Feature,根据 Geometry 字段选择相应的结构体
func (*Feature) PropertyBool ¶
PropertyBool type asserts a property to `bool`.
func (*Feature) PropertyFloat64 ¶
PropertyFloat64 type asserts a property to `float64`.
func (*Feature) PropertyInt ¶
PropertyInt type asserts a property to `int`.
func (*Feature) PropertyMustBool ¶
PropertyMustBool guarantees the return of a `bool` (with optional default)
useful when you explicitly want a `bool` in a single value return context:
myFunc(f.PropertyMustBool("param1"), f.PropertyMustBool("optional_param", true))
func (*Feature) PropertyMustFloat64 ¶
PropertyMustFloat64 guarantees the return of a `float64` (with optional default)
useful when you explicitly want a `float64` in a single value return context:
myFunc(f.PropertyMustFloat64("param1"), f.PropertyMustFloat64("optional_param", 10.1))
func (*Feature) PropertyMustInt ¶
PropertyMustInt guarantees the return of a `int` (with optional default)
useful when you explicitly want a `int` in a single value return context:
myFunc(f.PropertyMustInt("param1"), f.PropertyMustInt("optional_param", 123))
func (*Feature) PropertyMustString ¶
PropertyMustString guarantees the return of a `string` (with optional default)
useful when you explicitly want a `string` in a single value return context:
myFunc(f.PropertyMustString("param1"), f.PropertyMustString("optional_param", "default"))
func (*Feature) PropertyString ¶
PropertyString type asserts a property to `string`.
func (*Feature) SetProperty ¶
SetProperty provides the inverse of all the property functions and is here for consistency.
type FeatureCollection ¶
type FeatureCollection struct { Type GeoJsonType `json:"type"` Features []*Feature `json:"features"` CRS *CRS `json:"crs,omitempty"` // Coordinate Reference System Objects are not currently supported }
A FeatureCollection correlates to a GeoJSON feature collection.
func UnmarshalFeatureCollection ¶
func UnmarshalFeatureCollection(data []byte) (*FeatureCollection, error)
解析 Geojson到FeatureCollection,如geojson类型为Feature,则创建FeatureCollection,将Feature加入到Features中,CRS默认4326
func UnmarshalFeatureCollectionOnly ¶
func UnmarshalFeatureCollectionOnly(data []byte) (*FeatureCollection, error)
解析Geojson到FeatureCollection(类型必须为FeatureCollection,如geojson类型不为FeatureCollection则报错)
func (*FeatureCollection) MarshalToGeoJSON ¶
func (fc *FeatureCollection) MarshalToGeoJSON() (string, error)
Serialize a FeatureCollection to JSON
type GeoJsonType ¶
type GeoJsonType string
const ( FeatureCollectionType GeoJsonType = "FeatureCollection" FeatureType GeoJsonType = "Feature" )
type Geometry ¶
type Geometry interface { GetType() GeometryType GetCoordinates() interface{} GetWkt() string }
Define Geometry interface, all geometric types must implement this interface
type GeometryType ¶
type GeometryType string
Define GeometryType enum
const ( PointType GeometryType = "Point" MultiPointType GeometryType = "MultiPoint" LineStringType GeometryType = "LineString" MultiLineStringType GeometryType = "MultiLineString" PolygonType GeometryType = "Polygon" MultiPolygonType GeometryType = "MultiPolygon" )
func UnmarshalGeometry ¶
func UnmarshalGeometry(geometryGeoJson []byte) (GeometryType, interface{}, error)
type LineString ¶
type LineString struct { Type GeometryType `json:"type"` Coordinates [][]float64 `json:"coordinates"` }
func (LineString) GetCoordinates ¶
func (l LineString) GetCoordinates() interface{}
func (LineString) GetType ¶
func (l LineString) GetType() GeometryType
func (LineString) GetWkt ¶
func (l LineString) GetWkt() string
type MultiLineString ¶
type MultiLineString struct { Type GeometryType `json:"type"` Coordinates [][][]float64 `json:"coordinates"` }
func (MultiLineString) GetCoordinates ¶
func (m MultiLineString) GetCoordinates() interface{}
func (MultiLineString) GetType ¶
func (m MultiLineString) GetType() GeometryType
func (MultiLineString) GetWkt ¶
func (m MultiLineString) GetWkt() string
type MultiPoint ¶
type MultiPoint struct { Type GeometryType `json:"type"` Coordinates [][]float64 `json:"coordinates"` }
func (MultiPoint) GetCoordinates ¶
func (m MultiPoint) GetCoordinates() interface{}
func (MultiPoint) GetType ¶
func (m MultiPoint) GetType() GeometryType
func (MultiPoint) GetWkt ¶
func (m MultiPoint) GetWkt() string
type MultiPolygon ¶
type MultiPolygon struct { Type GeometryType `json:"type"` Coordinates [][][][]float64 `json:"coordinates"` }
func (MultiPolygon) GetCoordinates ¶
func (m MultiPolygon) GetCoordinates() interface{}
func (MultiPolygon) GetType ¶
func (m MultiPolygon) GetType() GeometryType
func (MultiPolygon) GetWkt ¶
func (m MultiPolygon) GetWkt() string
type Point ¶
type Point struct { Type GeometryType `json:"type"` Coordinates []float64 `json:"coordinates"` }
Define specific geometry types
func (Point) GetCoordinates ¶
func (p Point) GetCoordinates() interface{}
func (Point) GetType ¶
func (p Point) GetType() GeometryType
type Polygon ¶
type Polygon struct { Type GeometryType `json:"type"` Coordinates [][][]float64 `json:"coordinates"` }
func (Polygon) GetCoordinates ¶
func (p Polygon) GetCoordinates() interface{}
func (Polygon) GetType ¶
func (p Polygon) GetType() GeometryType