Пример #1
0
func AsGeomElement(g *geos.Geos, geom *geos.Geom) (*element.Geometry, error) {
	wkb := g.AsEwkbHex(geom)
	if wkb == nil {
		return nil, errors.New("could not create wkb")
	}

	return &element.Geometry{
		Wkb:  wkb,
		Geom: geom,
	}, nil
}
Пример #2
0
func (ww *WayWriter) buildAndInsert(g *geos.Geos, w *element.Way, matches interface{}, isPolygon bool) error {
	var err error
	var geosgeom *geos.Geom
	// make copy to avoid interference with polygon/linestring matches
	way := element.Way(*w)

	if isPolygon {
		geosgeom, err = geom.Polygon(g, way.Nodes)
	} else {
		geosgeom, err = geom.LineString(g, way.Nodes)
	}
	if err != nil {
		return err
	}

	way.Geom, err = geom.AsGeomElement(g, geosgeom)
	if err != nil {
		return err
	}

	if ww.limiter != nil {
		parts, err := ww.limiter.Clip(way.Geom.Geom)
		if err != nil {
			return err
		}
		for _, p := range parts {
			way := element.Way(*w)
			way.Geom = &element.Geometry{Geom: p, Wkb: g.AsEwkbHex(p)}
			if isPolygon {
				if err := ww.inserter.InsertPolygon(way.OSMElem, matches); err != nil {
					return err
				}
			} else {
				if err := ww.inserter.InsertLineString(way.OSMElem, matches); err != nil {
					return err
				}
			}
		}
	} else {
		if isPolygon {
			if err := ww.inserter.InsertPolygon(way.OSMElem, matches); err != nil {
				return err
			}
		} else {
			if err := ww.inserter.InsertLineString(way.OSMElem, matches); err != nil {
				return err
			}
		}
	}
	return nil
}
Пример #3
0
func (ww *WayWriter) buildAndInsert(geos *geos.Geos, w *element.Way, matches []mapping.Match, builder geomBuilder) {
	var err error
	// make copy to avoid interference with polygon/linestring matches
	way := element.Way(*w)
	geosgeom, err := builder(geos, way.Nodes)
	if err != nil {
		if err, ok := err.(ErrorLevel); ok {
			if err.Level() <= 0 {
				return
			}
		}
		log.Println(err)
		return
	}

	way.Geom, err = geom.AsGeomElement(geos, geosgeom)
	if err != nil {
		log.Println(err)
		return
	}

	if ww.limiter != nil {
		parts, err := ww.limiter.Clip(way.Geom.Geom)
		if err != nil {
			log.Println(err)
			return
		}
		for _, g := range parts {
			way := element.Way(*w)
			way.Geom = &element.Geometry{g, geos.AsEwkbHex(g)}
			ww.insertMatches(&way.OSMElem, matches)
		}
	} else {
		ww.insertMatches(&way.OSMElem, matches)
	}
}