本文整理匯總了Golang中github.com/omniscale/imposm3/element.Relation.Members方法的典型用法代碼示例。如果您正苦於以下問題:Golang Relation.Members方法的具體用法?Golang Relation.Members怎麽用?Golang Relation.Members使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/omniscale/imposm3/element.Relation
的用法示例。
在下文中一共展示了Relation.Members方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestInsertMultipleTags
func TestInsertMultipleTags(t *testing.T) {
w1 := makeWay(1, element.Tags{"landusage": "forest", "highway": "secondary"}, []coord{
{1, 0, 0},
{2, 10, 0},
{3, 10, 10},
})
w2 := makeWay(2, element.Tags{"highway": "secondary"}, []coord{
{3, 10, 10},
{4, 0, 10},
{1, 0, 0},
})
rel := element.Relation{OSMElem: element.OSMElem{Id: 1, Tags: element.Tags{"landusage": "forest"}}}
rel.Members = []element.Member{
{1, element.WAY, "outer", &w1}, // also highway=secondary
{2, element.WAY, "inner", &w2},
}
BuildRelation(&rel, 3857)
g := geos.NewGeos()
defer g.Finish()
if rel.Tags["landusage"] != "forest" {
t.Fatal("wrong rel tags", rel.Tags)
}
if !g.IsValid(rel.Geom.Geom) {
t.Fatal("geometry not valid", g.AsWkt(rel.Geom.Geom))
}
if area := rel.Geom.Geom.Area(); area != 100 {
t.Fatal("area invalid", area)
}
}
示例2: TestSelectRelationPolygonsMultiple
func TestSelectRelationPolygonsMultiple(t *testing.T) {
mapping, err := NewMapping("test_mapping.json")
if err != nil {
t.Fatal(err)
}
r := element.Relation{}
r.Tags = element.Tags{"landuse": "park"}
r.Members = []element.Member{
makeMember(0, element.Tags{"landuse": "park"}),
makeMember(1, element.Tags{"natural": "forest"}),
makeMember(2, element.Tags{"landuse": "park"}),
makeMember(3, element.Tags{"highway": "pedestrian"}),
makeMember(4, element.Tags{"landuse": "park", "layer": "2", "name": "foo"}),
}
filtered := SelectRelationPolygons(
mapping.PolygonMatcher(),
&r,
)
if len(filtered) != 3 {
t.Fatal(filtered)
}
if filtered[0].Id != 0 || filtered[1].Id != 2 || filtered[2].Id != 4 {
t.Fatal(filtered)
}
}
示例3: TestMultiPolygonWithMultipleHoles
func TestMultiPolygonWithMultipleHoles(t *testing.T) {
w1 := makeWay(1, element.Tags{"landusage": "forest"}, []coord{
{1, 0, 0},
{2, 10, 0},
{3, 10, 10},
{4, 0, 10},
{1, 0, 0},
})
w2 := makeWay(1, element.Tags{"water": "basin"}, []coord{
{1, 1, 1},
{2, 2, 1},
{3, 2, 2},
{4, 1, 2},
{1, 1, 1},
})
w3 := makeWay(3, element.Tags{"landusage": "scrub"}, []coord{
{1, 3, 3},
{2, 4, 3},
{3, 4, 4},
{4, 3, 4},
{1, 3, 3},
})
rel := element.Relation{
OSMElem: element.OSMElem{Id: 1, Tags: element.Tags{"landusage": "forest"}}}
rel.Members = []element.Member{
{1, element.WAY, "outer", &w1},
{2, element.WAY, "inner", &w2},
{3, element.WAY, "inner", &w3},
}
geom, err := buildRelation(&rel, 3857)
if err != nil {
t.Fatal(err)
}
g := geos.NewGeos()
defer g.Finish()
// if len(rel.Tags) != 1 {
// t.Fatal("wrong rel tags", rel.Tags)
// }
// if rel.Tags["landusage"] != "forest" {
// t.Fatal("wrong rel tags", rel.Tags)
// }
if !g.IsValid(geom.Geom) {
t.Fatal("geometry not valid", g.AsWkt(geom.Geom))
}
if area := geom.Geom.Area(); area != 100-1-1 {
t.Fatal("area invalid", area)
}
}
示例4: TestTouchingPolygonsWithHole
func TestTouchingPolygonsWithHole(t *testing.T) {
w1 := makeWay(1, element.Tags{"water": "riverbank"}, []coord{
{1, 0, 0},
{2, 10, 0},
{3, 10, 10},
{4, 0, 10},
{1, 0, 0},
})
w2 := makeWay(2, element.Tags{"water": "riverbank"}, []coord{
{2, 10, 0},
{5, 30, 0},
{6, 30, 10},
{3, 10, 10},
{2, 10, 0},
})
w3 := makeWay(3, element.Tags{"landusage": "forest"}, []coord{
{7, 2, 2},
{8, 8, 2},
{9, 8, 8},
{10, 2, 8},
{7, 2, 2},
})
rel := element.Relation{OSMElem: element.OSMElem{Id: 1, Tags: element.Tags{"water": "riverbank"}}}
rel.Members = []element.Member{
{1, element.WAY, "outer", &w1},
{2, element.WAY, "outer", &w2},
{3, element.WAY, "inner", &w3},
}
geom, err := buildRelation(&rel, 3857)
if err != nil {
t.Fatal(err)
}
g := geos.NewGeos()
defer g.Finish()
// if len(rel.Tags) != 1 {
// t.Fatal("wrong rel tags", rel.Tags)
// }
// if rel.Tags["water"] != "riverbank" {
// t.Fatal("wrong rel tags", rel.Tags)
// }
if !g.IsValid(geom.Geom) {
t.Fatal("geometry not valid", g.AsWkt(geom.Geom))
}
if area := geom.Geom.Area(); area != 100+200-36 {
t.Fatal("area invalid", area)
}
}
示例5: TestMultiPolygonWithHoleAndRelName
func TestMultiPolygonWithHoleAndRelName(t *testing.T) {
w1 := makeWay(1, element.Tags{"natural": "forest", "name": "Blackwood"}, []coord{
{1, 0, 0},
{2, 10, 0},
{3, 10, 10},
{4, 0, 10},
{1, 0, 0},
})
w2 := makeWay(1, element.Tags{"landusage": "scrub"}, []coord{
{5, 2, 2},
{6, 8, 2},
{7, 8, 8},
{8, 2, 8},
{5, 2, 2},
})
rel := element.Relation{
OSMElem: element.OSMElem{Id: 1, Tags: element.Tags{"name": "rel"}}}
rel.Members = []element.Member{
{1, element.WAY, "outer", &w1},
{2, element.WAY, "inner", &w2},
}
geom, err := buildRelation(&rel, 3857)
if err != nil {
t.Fatal(err)
}
g := geos.NewGeos()
defer g.Finish()
// if len(rel.Tags) != 2 {
// t.Fatal("wrong rel tags", rel.Tags)
// }
// if rel.Tags["natural"] != "forest" || rel.Tags["name"] != "Blackwood" {
// t.Fatal("wrong rel tags", rel.Tags)
// }
if !g.IsValid(geom.Geom) {
t.Fatal("geometry not valid", g.AsWkt(geom.Geom))
}
if area := geom.Geom.Area(); area != 64 {
t.Fatal("aread not 64", area)
}
}
示例6: TestPolygonFromThreeWays
func TestPolygonFromThreeWays(t *testing.T) {
w1 := makeWay(1, element.Tags{"landusage": "forest"}, []coord{
{1, 0, 0},
{2, 10, 0},
{3, 10, 10},
})
w2 := makeWay(2, element.Tags{"landusage": "water"}, []coord{
{3, 10, 10},
{4, 0, 10},
})
w3 := makeWay(3, element.Tags{"landusage": "forest"}, []coord{
{4, 0, 10},
{1, 0, 0},
})
rel := element.Relation{OSMElem: element.OSMElem{Id: 1}}
rel.Members = []element.Member{
{1, element.WAY, "outer", &w1},
{2, element.WAY, "inner", &w2},
{3, element.WAY, "inner", &w3},
}
geom, err := buildRelation(&rel, 3857)
if err != nil {
t.Fatal(err)
}
g := geos.NewGeos()
defer g.Finish()
if len(rel.Tags) != 1 {
t.Fatal("wrong rel tags", rel.Tags)
}
if rel.Tags["landusage"] != "forest" {
t.Fatal("wrong rel tags", rel.Tags)
}
if !g.IsValid(geom.Geom) {
t.Fatal("geometry not valid", g.AsWkt(geom.Geom))
}
if area := geom.Geom.Area(); area != 100 {
t.Fatal("area invalid", area)
}
}
示例7: TestOpenRing
func TestOpenRing(t *testing.T) {
w1 := makeWay(1, element.Tags{}, []coord{
{1, 0, 0},
{2, 10, 0},
{3, 10, 10},
{4, 0, 10},
})
rel := element.Relation{
OSMElem: element.OSMElem{Id: 1, Tags: element.Tags{}}}
rel.Members = []element.Member{
{1, element.WAY, "outer", &w1},
}
_, err := buildRelation(&rel, 3857)
if err == nil {
t.Fatal("no error from open ring")
}
}
示例8: TestSimplePolygonWithHole
func TestSimplePolygonWithHole(t *testing.T) {
w1 := makeWay(1, element.Tags{}, []coord{
{1, 0, 0},
{2, 10, 0},
{3, 10, 10},
{4, 0, 10},
{1, 0, 0},
})
w2 := makeWay(2, element.Tags{}, []coord{
{5, 2, 2},
{6, 8, 2},
{7, 8, 8},
{8, 2, 8},
{5, 2, 2},
})
rel := element.Relation{
OSMElem: element.OSMElem{Id: 1, Tags: element.Tags{}}}
rel.Members = []element.Member{
{1, element.WAY, "outer", &w1},
{2, element.WAY, "inner", &w2},
}
geom, err := buildRelation(&rel, 3857)
if err != nil {
t.Fatal(err)
}
g := geos.NewGeos()
defer g.Finish()
if len(rel.Tags) != 0 {
t.Fatal("wrong rel tags", rel.Tags)
}
if !g.IsValid(geom.Geom) {
t.Fatal("geometry not valid", g.AsWkt(geom.Geom))
}
if area := geom.Geom.Area(); area != 100-36 {
t.Fatal("area invalid", area)
}
}
示例9: TestInsertedWaysDifferentTags
func TestInsertedWaysDifferentTags(t *testing.T) {
w1 := makeWay(1, element.Tags{"landusage": "forest"}, []coord{
{1, 0, 0},
{2, 10, 0},
{3, 10, 10},
})
w2 := makeWay(2, element.Tags{"highway": "secondary"}, []coord{
{3, 10, 10},
{4, 0, 10},
{1, 0, 0},
})
rel := element.Relation{OSMElem: element.OSMElem{Id: 1, Tags: element.Tags{"landusage": "forest"}}}
rel.Members = []element.Member{
{1, element.WAY, "outer", &w1},
{2, element.WAY, "inner", &w2},
}
geom, err := buildRelation(&rel, 3857)
if err != nil {
t.Fatal(err)
}
g := geos.NewGeos()
defer g.Finish()
// if len(rel.Tags) != 1 {
// t.Fatal("wrong rel tags", rel.Tags)
// }
// if rel.Tags["landusage"] != "forest" {
// t.Fatal("wrong rel tags", rel.Tags)
// }
if !g.IsValid(geom.Geom) {
t.Fatal("geometry not valid", g.AsWkt(geom.Geom))
}
if area := geom.Geom.Area(); area != 100 {
t.Fatal("area invalid", area)
}
}
示例10: TestSelectRelationPolygonsMultipleTags
func TestSelectRelationPolygonsMultipleTags(t *testing.T) {
mapping, err := NewMapping("test_mapping.json")
if err != nil {
t.Fatal(err)
}
r := element.Relation{}
r.Tags = element.Tags{"landuse": "forest", "natural": "scrub"}
r.Members = []element.Member{
makeMember(0, element.Tags{"natural": "scrub"}),
makeMember(1, element.Tags{"landuse": "forest"}),
}
filtered := SelectRelationPolygons(
mapping.PolygonMatcher(),
&r,
)
// TODO both should be filterd out, but we only get one,
// because we match only one tag per table
if len(filtered) != 1 {
t.Fatal(filtered)
}
}
示例11: TestSelectRelationPolygonsUnrelatedTags
func TestSelectRelationPolygonsUnrelatedTags(t *testing.T) {
mapping, err := NewMapping("test_mapping.json")
if err != nil {
t.Fatal(err)
}
r := element.Relation{}
r.Tags = element.Tags{"landuse": "park"}
r.Members = []element.Member{
makeMember(0, element.Tags{"landuse": "park", "layer": "2", "name": "foo"}),
makeMember(1, element.Tags{"landuse": "forest"}),
}
filtered := SelectRelationPolygons(
mapping.PolygonMatcher(),
&r,
)
if len(filtered) != 1 {
t.Fatal(filtered)
}
if filtered[0].Id != 0 {
t.Fatal(filtered)
}
}
示例12: TestClosedAndOpenRing
func TestClosedAndOpenRing(t *testing.T) {
w1 := makeWay(1, element.Tags{}, []coord{
{1, 0, 0},
{2, 10, 0},
{3, 10, 10},
{4, 0, 10},
{1, 0, 0},
})
w2 := makeWay(2, element.Tags{}, []coord{
{5, 0, 0},
{6, -5, -2},
})
rel := element.Relation{
OSMElem: element.OSMElem{Id: 1, Tags: element.Tags{}}}
rel.Members = []element.Member{
{1, element.WAY, "outer", &w1},
{2, element.WAY, "outer", &w2},
}
prep, err := PrepareRelation(&rel, 3857, 0.1)
if err != nil {
t.Fatal(err)
}
// open ring is excluded
if len(prep.rings) != 1 {
t.Fatal("expected single ring")
}
geom, err := prep.Build()
if err != nil {
t.Fatal(err)
}
g := geos.NewGeos()
defer g.Finish()
if !g.IsValid(geom.Geom) {
t.Fatal("geometry not valid", g.AsWkt(geom.Geom))
}
}
示例13: TestSelectRelationPolygonsSimple
func TestSelectRelationPolygonsSimple(t *testing.T) {
mapping, err := NewMapping("test_mapping.json")
if err != nil {
t.Fatal(err)
}
r := element.Relation{}
r.Tags = element.Tags{"landuse": "park"}
r.Members = []element.Member{
makeMember(0, element.Tags{"landuse": "forest"}),
makeMember(1, element.Tags{"landuse": "park"}),
makeMember(2, element.Tags{"waterway": "riverbank"}),
makeMember(4, element.Tags{"foo": "bar"}),
}
filtered := SelectRelationPolygons(
mapping.PolygonMatcher(),
&r,
)
if len(filtered) != 1 {
t.Fatal(filtered)
}
if filtered[0].Id != 1 {
t.Fatal(filtered[0])
}
}
示例14: TestSelectRelationPolygonsMultipleTagsOnWay
func TestSelectRelationPolygonsMultipleTagsOnWay(t *testing.T) {
mapping, err := NewMapping("test_mapping.json")
if err != nil {
t.Fatal(err)
}
r := element.Relation{}
r.Tags = element.Tags{"waterway": "riverbank"}
r.Members = []element.Member{
makeMemberRole(0, element.Tags{"waterway": "riverbank", "natural": "water"}, "outer"),
makeMemberRole(1, element.Tags{"natural": "water"}, "inner"),
makeMemberRole(2, element.Tags{"place": "islet"}, "inner"),
}
filtered := SelectRelationPolygons(
mapping.PolygonMatcher(),
&r,
)
if len(filtered) != 1 {
t.Fatal(filtered)
}
if filtered[0].Id != 0 {
t.Fatal(filtered)
}
}
示例15: TestBrokenPolygonSelfIntersectTriangle
func TestBrokenPolygonSelfIntersectTriangle(t *testing.T) {
// 2###
// # ###4
// # ###3
// 1###
// triangle with four points, minor overlapping
w1 := makeWay(1, element.Tags{}, []coord{
{1, 0, 0},
{2, 0, 100},
{3, 100, 50 - 0.00001},
{4, 100, 50 + 0.00001},
{1, 0, 0},
})
w2 := makeWay(2, element.Tags{}, []coord{
{15, 10, 45},
{16, 10, 55},
{17, 20, 55},
{18, 20, 45},
{15, 10, 45},
})
rel := element.Relation{OSMElem: element.OSMElem{Id: 1}}
rel.Members = []element.Member{
{1, element.WAY, "outer", &w1},
{2, element.WAY, "inner", &w2},
}
geom, err := buildRelation(&rel, 3857)
if err != nil {
t.Fatal(err)
}
g := geos.NewGeos()
defer g.Finish()
if !g.IsValid(geom.Geom) {
t.Fatal("geometry not valid", g.AsWkt(geom.Geom))
}
area := geom.Geom.Area()
// as for python assertAlmostEqual(a, b) round(a-b, 7) == 0
if math.Abs(area-(100*100/2-100)) > 0.01 {
t.Fatal("area invalid", area)
}
// larger overlap
w3 := makeWay(1, element.Tags{}, []coord{
{1, 0, 0},
{2, 0, 100},
{3, 100, 50 - 1},
{4, 100, 50 + 1},
{1, 0, 0},
})
w4 := makeWay(2, element.Tags{}, []coord{
{15, 10, 45},
{16, 10, 55},
{17, 20, 55},
{18, 20, 45},
{15, 10, 45},
})
rel = element.Relation{OSMElem: element.OSMElem{Id: 1}}
rel.Members = []element.Member{
{1, element.WAY, "outer", &w3},
{2, element.WAY, "inner", &w4},
}
geom, err = buildRelation(&rel, 3857)
if err != nil {
t.Fatal(err)
}
if !g.IsValid(geom.Geom) {
t.Fatal("geometry not valid", g.AsWkt(geom.Geom))
}
area = geom.Geom.Area()
if math.Abs((area - (100*98/2 - 100))) > 10 {
t.Fatal("area invalid", area)
}
}