package module
Version: v0.0.0-...-99c4cbb Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2018 License: MIT Imports: 2 Imported by: 4


🎯 Point in Polygon - Go

Detect if a point (X, Y) is within a given polygon (Set of X, Ys) .


import pip

// Polygons are self closing (i.e. you don't need to add first point at end)
rectangle := pip.Polygon{
  Points : []pip.Point {
    pip.Point{X : 1.0, Y : 1.0},
    pip.Point{X : 1.0, Y : 2.0},
    pip.Point{X : 2.0, Y : 2.0},
    pip.Point{X : 2.0, Y : 1.0},

pt1 := pip.Point{X : 1.1,  Y : 1.1}

pip.PointInPolygon(pt1, rectangle) // Test - Should return true


  • Currently no support for holes although this should be easy to account for if the hole is tested as a separate polygon.
  • Currently no support for points that reside on edges (returns outside, i.e. false).
  • Beware of roundoff errors
  • The direction that you list the vertices (clockwise or counterclockwise) does not matter.


Based on the example code given in this article by W. Randolph Franklin. The method is named PNPOLY.


MIT License Original C code : Copyright (c) 1970-2003, Wm. Randolph Franklin Modified Go code: Copyright 2016 James Milner




This section is empty.


This section is empty.


func GetBoundingBoxFromGeoJson

func GetBoundingBoxFromGeoJson(poly [][]float64) []float64

func MaxParallelism

func MaxParallelism() int

func PointInBoundingBox

func PointInBoundingBox(pt Point, bb BoundingBox) bool

func PointInGeoJsonBoundingBox

func PointInGeoJsonBoundingBox(x float64, y float64, bb []float64) bool

func PointInGeoJsonPolygon

func PointInGeoJsonPolygon(pt []float64, poly [][][]float64) bool

func PointInPolygon

func PointInPolygon(pt Point, poly Polygon) bool

func PointInSlice

func PointInSlice(x float64, y float64, poly [][]float64) bool


type BoundingBox

type BoundingBox struct {
	BottomLeft Point
	TopRight   Point

func GetBoundingBox

func GetBoundingBox(poly Polygon) BoundingBox

type Point

type Point struct {
	// A point
	X float64
	Y float64

func PointInPolygonParallel

func PointInPolygonParallel(pts []Point, poly Polygon, numcores int) []Point

type Polygon

type Polygon struct {
	// A polygon
	Points []Point

Source Files


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL