Exemplo n.º 1
0
func TestRtreeIntersection(t *testing.T) {
	points := [][]geo.Coordinate{
		{{0, 0}, {1, 1}},
		{{-1, -1}, {0, 0}},
		{{-1, -1}, {1, 1}},
		{{5, 5}, {6, 6}},
	}
	rtree := geo.NewRtree()
	for i, ps := range points {
		shp := geo.NewShape(ps...)
		rtree.Insert(shp, i)
	}
	q := cd(0.5, 0.5)
	if len(rtree.Contains(q)) != 2 {
		t.Errorf("Failed rtree containment: %d wanted 2", len(rtree.Contains(q)))

	}

}
Exemplo n.º 2
0
Arquivo: csv.go Projeto: buckhx/diglet
func (c *CsvSource) featureAdapter(line []string) (feature *geo.Feature, err error) {
	props := make(map[string]interface{}, len(c.headers)) //biggest malloc
	for k, i := range c.headers {
		props[k] = line[i]
	}
	switch {
	case c.fields.HasCoordinates():
		feature = geo.NewPointFeature()
		feature.Properties = props
		lat, err := strconv.ParseFloat(line[c.headers[c.fields["lat"]]], 64)
		if err != nil {
			return nil, err
		}
		lon, err := strconv.ParseFloat(line[c.headers[c.fields["lon"]]], 64)
		if err != nil {
			return nil, err
		}
		point := geo.NewShape(geo.Coordinate{Lat: lat, Lon: lon})
		feature.AddShape(point)
	case c.fields.HasShape():
		g := line[c.headers[c.fields["shape"]]]
		shp, err := geo.ShapeFromString(g)
		if err != nil {
			return nil, util.Errorf("Invalid shape format %+v", g)
		}
		switch {
		case len(shp.Coordinates) == 0:
			feature = geo.NewPointFeature()
		case len(shp.Coordinates) == 1:
			feature = geo.NewPointFeature()
		case shp.Coordinates[0] == shp.Coordinates[len(shp.Coordinates)-1]: //closed
			feature = geo.NewPolygonFeature()
		default:
			feature = geo.NewLineFeature()
		}
		feature.Properties = props
		feature.AddShape(shp)
	default:
		err = util.Errorf("Invalid line")
	}
	return
}