代码拉取完成,页面将自动刷新
package geojson
import (
"fmt"
"strconv"
"strings"
)
type CRS struct {
Type string `json:"type"`
Properties map[string]string `json:"properties,omitempty"`
}
func NewCRS(srid int) *CRS {
properties := make(map[string]string)
properties["name"] = fmt.Sprintf("EPSG:%d", srid)
crs := &CRS{Type: "name", Properties: properties}
return crs
}
func (c *CRS) SetSrid(srid int) {
c.Type = "name"
c.Properties = map[string]string{"name": fmt.Sprintf("EPSG:%d", srid)}
}
// GetSrid extracts the SRID from the CRS name and returns it as an integer.
func (c *CRS) GetSrid() (int, error) {
if c.Type == "name" {
if len(c.Properties) == 1 {
for k, value := range c.Properties {
if k == "name" {
vv := strings.Split(value, ":")
if len(vv) != 2 || !strings.EqualFold(vv[0], "EPSG") {
return -1, fmt.Errorf("crs name is not in the format EPSG:<SRID>")
}
srid, err := strconv.Atoi(vv[1])
if err != nil {
return -1, fmt.Errorf("crs name is not a valid EPSG SRID")
}
return srid, nil
}
}
}
}
return -1, fmt.Errorf("crs type is not 'name' or properties are not as expected")
}
// Verify checks if the crs is valid and returns true if it is, false otherwise and an error if there is a problem.
func (c *CRS) Verify() (bool, error) {
srid, err := c.GetSrid()
if err != nil {
return false, err
}
if srid == -1 {
return false, fmt.Errorf("crs is not valid")
}
return true, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。