Skip to content

Polygon intersection and containment #193

@atombender

Description

@atombender

I'm looking for a way to use this library to check, using Cartesian coordinates:

  • If two polygons intersect
  • if a polygon fully contains another polygon

I'm not seeing any exported functions for doing this. Is there any support for it, or should I look somewhere else?

From what I can tell, checking if a point is contained in a polygon can be accomplished this way:

func PolygonContainsPoint(polygon *geom.Polygon, p *geom.Point) bool {
	exterior := polygon.LinearRing(0)
	if !xy.IsPointInRing(geom.XY, p.Coords(), exterior.FlatCoords()) {
		return false
	}

	// Next rings are holes
	num := polygon.NumLinearRings()
	for i := 1; i < num; i++ {
		interior := polygon.LinearRing(i)
		if xy.IsPointInRing(geom.XY, p.Coords(), interior.FlatCoords()) {
			return false
		}
	}

	return true
}

Or? I'm not too familiar with rings or if this is how they're intended to be used. Either way, such a function would be a useful addition to this library, I think.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions