Skip to content

maptile.Layer has no tool for check and fix ring.direction #162

@bochkov-vi

Description

@bochkov-vi

and existing func Ring.Orientation returns wrong value
here is a sample code to solve this problem

func RewindPolygon(geom *orb.Polygon) {
	for i, ring := range *geom {
		Rewind(&ring, i%2 != 0)
	}
}

func Rewind(ring *orb.Ring, clockwise bool) {
	var area = signedArea(*ring)
	if (area < 0) == clockwise {
		ring.Reverse()
	}
}

func signedArea(ring orb.Ring) float64 {
	var sum float64 = 0
	l := len(ring)
	for i := 0; i < l-1; i = i + 1 {
		p1 := ring[i]
		j := i + 1
		p2 := ring[j]
		sum += (p2[0] - p1[0]) * (p1[1] + p2[1])
	}
	return sum
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions