piper

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 2 Imported by: 0

README

piper

Yet another point in polygon package. Piper makes use of ray casting and does account for holes in polygons.

Forked from github.com/iwpnd/piper

Installation

go get -u github.com/paulstuart/piper

Usage

Vanilla

package main

import (
  "fmt"

  "github.com/paulstuart/piper"
  )

func main() {
  p := []float64{0.5,0.5} // [longitude, latitude]
  polygon := [][][]float64{{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}}

  pip := piper.Pip(p, polygon)
  fmt.Printf("Point in Polygon: %+v\n", pip)
}

Or using github/paulmach/go.geojson

package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"

	"github.com/paulstuart/piper"
	"github.com/paulmach/go.geojson"
)

func main() {
	p := []float64{0.5, 0.5} // [longitude, latitude]

	raw, err := ioutil.ReadFile("my_feature.geojson")
	if err != nil {
		panic("something went wrong")
	}

	var feature geojson.Feature
	err = json.Unmarshal(raw, &feature)
	if err != nil {
		panic("something went wrong")
	}

	pip := piper.Pip(p, feature.Geometry.Polygon)
	fmt.Printf("Point in Polygon: %+v\n", pip)
}

Benchmark

goos: darwin
goarch: amd64
pkg: github.com/iwpnd/piper
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkPipSimpleInside-12              	43108360	        27.73 ns/op
BenchmarkPipSimpleOutside-12             	44025870	        27.53 ns/op
BenchmarkPipSimpleInsideWithHoles-12     	27355524	        42.84 ns/op
BenchmarkPipSimpleOutsideWithHoles-12    	42239286	        28.22 ns/op
BenchmarkPipComplexInside-12             	  474601	        2323 ns/op

License

MIT

Maintainer

Benjamin Ramser - @iwpnd

Project Link: https://github.com/iwpnd/piper

Acknowledgement

Phillip Lemons - Ray Casting Algorithm

Great introduction into the topic with good visualisations.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Debug bool

Functions

func InExtent

func InExtent[T Float](p []T, ring [][]T) bool

InExtent creates a bounding box of the outer ring and returns true if the point is in that box

func InRing

func InRing[T Float](p []T, ring [][]T) bool

func Pip

func Pip[T Float](p []T, polygon [][][]T) bool

Pip checks if Point p is inside input polygon. Does account for holes.

func PipBox

func PipBox[T Float](p []T, polygon [][][]T) bool

PipBox checks if the point falls in the bounding box of the polygon before actually checking the polygon This speeds up operations on complex polygons, insignifically slows down on simple polygons

Types

type Float

type Float = constraints.Float

Jump to

Keyboard shortcuts

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