本文整理匯總了Golang中github.com/omniscale/imposm3/geom/geos.Geos.Clone方法的典型用法代碼示例。如果您正苦於以下問題:Golang Geos.Clone方法的具體用法?Golang Geos.Clone怎麽用?Golang Geos.Clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/omniscale/imposm3/geom/geos.Geos
的用法示例。
在下文中一共展示了Geos.Clone方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: flattenLineStrings
func flattenLineStrings(g *geos.Geos, geoms []*geos.Geom) []*geos.Geom {
var result []*geos.Geom
for _, geom := range geoms {
if g.Type(geom) == "MultiLineString" {
for _, part := range g.Geoms(geom) {
result = append(result, g.Clone(part))
}
g.Destroy(geom)
} else if g.Type(geom) == "LineString" {
result = append(result, geom)
} else {
log.Printf("unexpected geometry type in flattenLineStrings: %s", g.Type(geom))
g.Destroy(geom)
}
}
return result
}
示例2: filterGeometryByType
func filterGeometryByType(g *geos.Geos, geom *geos.Geom, targetType string) []*geos.Geom {
// Filter (multi)geometry for compatible `geom_type`,
// because we can't insert points into linestring tables for example
geomType := g.Type(geom)
if geomType == targetType {
// same type is fine
return []*geos.Geom{geom}
}
if geomType == "Polygon" && targetType == "MultiPolygon" {
// multipolygon mappings also support polygons
return []*geos.Geom{geom}
}
if geomType == "MultiPolygon" && targetType == "Polygon" {
// polygon mappings should also support multipolygons
return []*geos.Geom{geom}
}
if g.NumGeoms(geom) >= 1 {
// GeometryCollection or MultiLineString? return list of geometries
var geoms []*geos.Geom
for _, part := range g.Geoms(geom) {
// only parts with same type
if g.Type(part) == targetType {
geoms = append(geoms, g.Clone(part))
}
}
g.Destroy(geom)
if len(geoms) != 0 {
return geoms
}
return []*geos.Geom{}
}
g.Destroy(geom)
return []*geos.Geom{}
}
示例3: buildRelGeometry
// buildRelGeometry builds the geometry of rel by creating a multipolygon of all rings.
// rings need to be sorted by area (large to small).
func buildRelGeometry(g *geos.Geos, rel *element.Relation, rings []*ring) (*geos.Geom, error) {
totalRings := len(rings)
shells := map[*ring]bool{rings[0]: true}
for i := 0; i < totalRings; i++ {
testGeom := g.Prepare(rings[i].geom)
if testGeom == nil {
return nil, errors.New("Error while preparing geometry")
}
for j := i + 1; j < totalRings; j++ {
if g.PreparedContains(testGeom, rings[j].geom) {
if rings[j].containedBy != -1 {
// j is inside a larger ring, remove that relationship
// e.g. j is hole inside a hole (i)
delete(rings[rings[j].containedBy].holes, rings[j])
delete(shells, rings[j])
}
// remember parent
rings[j].containedBy = i
// add ring as hole or shell
if ringIsHole(rings, j) {
rings[i].holes[rings[j]] = true
rings[i].outer = false
} else {
shells[rings[j]] = true
rings[i].outer = true
}
}
}
if rings[i].containedBy == -1 {
// add as shell if it is not a hole
shells[rings[i]] = true
rings[i].outer = true
}
g.PreparedDestroy(testGeom)
}
var polygons []*geos.Geom
for shell, _ := range shells {
var interiors []*geos.Geom
for hole, _ := range shell.holes {
ring := g.Clone(g.ExteriorRing(hole.geom))
g.Destroy(hole.geom)
if ring == nil {
return nil, errors.New("Error while getting exterior ring.")
}
interiors = append(interiors, ring)
}
exterior := g.Clone(g.ExteriorRing(shell.geom))
g.Destroy(shell.geom)
if exterior == nil {
return nil, errors.New("Error while getting exterior ring.")
}
polygon := g.Polygon(exterior, interiors)
if polygon == nil {
return nil, errors.New("Error while building polygon.")
}
polygons = append(polygons, polygon)
}
var result *geos.Geom
if len(polygons) == 1 {
result = polygons[0]
} else {
result = g.MultiPolygon(polygons)
if result == nil {
return nil, errors.New("Error while building multi-polygon.")
}
}
var err error
result, err = g.MakeValid(result)
if err != nil {
return nil, err
}
g.DestroyLater(result)
outer := make(map[int64]struct{})
for i := range rings {
if rings[i].outer {
for _, w := range rings[i].ways {
outer[w.Id] = struct{}{}
}
}
}
for i := range rel.Members {
mid := rel.Members[i].Id
if _, ok := outer[mid]; ok {
rel.Members[i].Role = "outer"
} else {
rel.Members[i].Role = "inner"
}
}
return result, nil
}