-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for importing non-area relations as MultiLineString
- Loading branch information
Showing
12 changed files
with
3,621 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package geom | ||
|
||
import ( | ||
"errors" | ||
"github.com/omniscale/imposm3/element" | ||
"github.com/omniscale/imposm3/geom/geos" | ||
"runtime" | ||
) | ||
|
||
func BuildMultiLinestring(rel *element.Relation, srid int) (*geos.Geom, error) { | ||
g := geos.NewGeos() | ||
g.SetHandleSrid(srid) | ||
defer g.Finish() | ||
|
||
var lines []*geos.Geom | ||
|
||
for _, member := range rel.Members { | ||
if member.Way == nil { | ||
continue | ||
} | ||
|
||
line, err := LineString(g, member.Way.Nodes) | ||
|
||
// Clear the finalizer created in LineString() | ||
// as we want to make the object a part of MultiLineString. | ||
runtime.SetFinalizer(line, nil) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
lines = append(lines, line) | ||
} | ||
|
||
result := g.MultiLineString(lines) | ||
if result == nil { | ||
return nil, errors.New("Error while building multi-linestring.") | ||
} | ||
|
||
g.DestroyLater(result) | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package geom | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/omniscale/imposm3/element" | ||
"github.com/omniscale/imposm3/geom/geos" | ||
) | ||
|
||
func TestSimpleMultiLineString(t *testing.T) { | ||
w1 := makeWay(1, element.Tags{}, []coord{ | ||
{1, 1, 0}, | ||
{2, 2, 0}, | ||
}) | ||
w2 := makeWay(2, element.Tags{}, []coord{ | ||
{3, 2, 0}, | ||
{4, 3, 0}, | ||
}) | ||
|
||
rel := element.Relation{ | ||
OSMElem: element.OSMElem{Id: 1, Tags: element.Tags{}}} | ||
rel.Members = []element.Member{ | ||
{Id: 1, Type: element.WAY, Role: "", Way: &w1}, | ||
{Id: 2, Type: element.WAY, Role: "", Way: &w2}, | ||
} | ||
|
||
geom, err := BuildMultiLinestring(&rel, 3857) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
g := geos.NewGeos() | ||
defer g.Finish() | ||
|
||
if !g.IsValid(geom) { | ||
t.Fatal("geometry not valid", g.AsWkt(geom)) | ||
} | ||
|
||
if length := geom.Length(); length != 2 { | ||
t.Fatal("length invalid", length) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.