예제 #1
0
파일: map.go 프로젝트: samlecuyer/ecumene
func (m *Map) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	var err error
	for _, attr := range start.Attr {
		if attr.Name.Local == "extent" {
			m.setBounds(attr.Value)
		}
		if attr.Name.Local == "bgcolor" {
			m.BgColor = color.Hex(attr.Value)
		}
		if attr.Name.Local == "srs" {
			m.Srs, _ = proj.NewProjection(attr.Value)
		}
	}
	if m.Srs == nil {
		m.Srs, err = proj.NewProjection(defaultSrsOut)
		if err != nil {
			fmt.Println(err.Error())
		}
	}

	for {
		e, err := d.Token()
		if err != nil {
			return err
		}
		switch e := e.(type) {
		case xml.EndElement:
			if e.Name.Local == start.Name.Local {
				return nil
			}
		case xml.StartElement:
			switch e.Name.Local {
			case "Style":
				style := new(Style)
				if err := d.DecodeElement(style, &e); err != nil {
					return err
				}
				m.Styles = append(m.Styles, style)
			case "Layer":
				layer := new(Layer)
				if err := d.DecodeElement(layer, &e); err != nil {
					return err
				}
				m.Layers = append(m.Layers, layer)
			case "Include":
				var name string
				if err := d.DecodeElement(&name, &e); err != nil {
					return err
				}
				include, err := loadInclude(name)
				if err != nil {
					return err
				}
				m.Styles = append(m.Styles, include.Styles...)
				m.Layers = append(m.Layers, include.Layers...)
			}
		}
	}
	return d.Skip()
}
예제 #2
0
파일: shp.go 프로젝트: samlecuyer/ecumene
func createShpSource(name string) (DataSource, error) {
	f, err := shp.Open(name)
	if err != nil {
		return nil, err
	}
	srs, _ := projectron.NewProjection(defaultSrs)
	return &shpSource{r: f, srs: srs}, nil
}