yet another point in polygon package

piper

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

Installation

go get -u github.com/iwpnd/piper

Usage

Vanilla

package main

import (
  "fmt"

  "github.com/iwpnd/piper"
  )

func main() {
  p := []float64{0.5,0.5}
  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.geosjon

package main

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

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

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

	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.

Owner
Ben
geographer turned spatial engineer turned data-something turned software developer
Ben
Similar Resources

Polygol - Boolean polygon clipping/overlay operations (union, intersection, difference, xor) on Polygons and MultiPolygons

Polygol - Boolean polygon clipping/overlay operations (union, intersection, difference, xor) on Polygons and MultiPolygons

polygol Boolean polygon clipping/overlay operations (union, intersection, differ

Jan 8, 2023

Yet Another CLi Spinner; providing over 70 easy to use and customizable terminal spinners for multiple OSes

Yet Another CLi Spinner; providing over 70 easy to use and customizable terminal spinners for multiple OSes

Yet Another CLi Spinner (for Go) Package yacspin provides yet another CLi spinner for Go, taking inspiration (and some utility code) from the https://

Dec 25, 2022

An yet-another red-black tree implementation, with a C++ STL-like API.

A red-black tree with an API similar to C++ STL's. INSTALLATION go get github.com/yasushi-saito/rbtree EXAMPLE More examples can be fou

Apr 25, 2022

Yet another Go REPL that works nicely. Featured with line editing, code completion, and more.

  Yet another Go REPL that works nicely. Featured with line editing, code completion, and more.

gore Yet another Go REPL that works nicely. Featured with line editing, code completion, and more. (Screencast taken with cho45/KeyCast) Usage gore Af

Jan 2, 2023

đŸ± yet another collection of go utilities & tools

gut đŸ± Yet another collection of Go utilities & tools. A simple one. Just go with your gut feeling. Shortcuts Symbol đŸ± ćŒćœ“ Document License Build Stat

Sep 26, 2022

Yet Another REST Framework

YARF: Yet Another REST Framework YARF is a fast micro-framework designed to build REST APIs and web services in a fast and simple way. Designed after

Sep 27, 2022

đŸš„ Yet another pinger: A high-performance ICMP ping implementation build on top of BPF technology.

yap Yet-Another-Pinger: A high-performance ICMP ping implementation build on top of BPF technology. yap uses the gopacket library to receive and handl

Nov 9, 2022

Yet another SIP003 plugin for shadowsocks, based on Xray-core

Yet another SIP003 plugin for shadowsocks, based on Xray-core Build go build Usage See command line args for advanced usages.

Jan 8, 2023

yet another rss reader

yet another rss reader

yarr yarr (yet another rss reader) is a web-based feed aggregator which can be used both as a desktop application and a personal self-hosted server. I

Dec 29, 2022

Yet another Go REPL that works nicely. Featured with line editing, code completion, and more.

  Yet another Go REPL that works nicely. Featured with line editing, code completion, and more.

gore Yet another Go REPL that works nicely. Featured with line editing, code completion, and more. (Screencast taken with cho45/KeyCast) Usage gore Af

Jan 7, 2023

Not Yet Another Password Manager written in Go using libsodium

secrets Secure and simple passwords manager written in Go. It aims to be NYAPM (Not Yet Another Password Manager), but tries to be different from othe

May 30, 2022

Yet another codemod alternative

rnm Yet another codemod alternative. Replace all occurrences of a name to another name in your code! Features Support for different case styles See rn

Sep 28, 2022

Yet another Binance Smart Chain client based on TrustFi Network

TrustFi Smart Chain The goal of TrustFi Smart Chain is to bring programmability and interoperability to Binance Chain. In order to embrace the existin

Mar 27, 2021

Yet another netcat for fast file transfer

nyan Yet another netcat for fast file transfer When I need to transfer a file in safe environment (e.g. LAN / VMs), I just want to use a simple comman

Apr 30, 2022

Yet another TCP Port Scanner, but lightning faster.

Fast TCP Port Scanner A highly concurrent TCP port scanner. Run Tests with Code Coverage (Linux) go test -cover Compile (Linux) go build -v -o fglps R

Jul 23, 2022

Yet another semantic version incrementor and tagger for git

git-tag-inc Increments the version number and tags it. (You will need to push) Usage ./git-tag-inc [major] [minor] [release] [test] [uat] git-tag-in

Apr 30, 2022

😎 Yet Another yes clone but in Golang

Yeah Output a string repeatedly until killed. Yet Another yes clone but in Golang. Usage Just like yes: yeah This will print "y" until the process is

Apr 7, 2022

Yet another StructTag, with some features liked cache and alias.

Yet another StructTag, with some features liked cache and alias.

Nov 1, 2021
Comments
  • Incorrect Results

    Incorrect Results

    Hello!

    I was trying to check the validity of the results while using the provided geojson file for Berlin. In fact, here is my code below :

    func main() {
    	p := []float64{52.50341777065819, 13.334090061514702}
    
    	raw, err := ioutil.ReadFile("./testdata/berlin.geojson")
    	if err != nil {
    		panic("something went wrong")
    	}
    
    	var feature geojson.Feature
    	err = json.Unmarshal(raw, &feature)
    	if err != nil {
    		panic("something went wrong")
    	}
    
    	polygon := feature.Geometry.Polygon
    
    	pip := piper.Pip(p, polygon)
    	fmt.Printf("Point in Polygon: %+v\n", pip)
    }
    

    The selected coordinates 52.50341777065819, 13.334090061514702 lie in Berlin (You can check using google maps). Nevertheless, the returned result is false, indicating that this point is not within Berlin.

    Any ideas about this issue? Am I using piper properly?

Package geom implements efficient geometry types for geospatial applications.

go-geom Package geom implements efficient geometry types for geospatial applications. Key features OpenGeo Consortium-style geometries. Support for 2D

Jan 6, 2023
Package kml provides convenince methods for creating and writing KML documents.

go-kml Package kml provides convenience methods for creating and writing KML documents. Key Features Simple API for building arbitrarily complex KML d

Jul 29, 2022
Package polyline implements a Google Maps Encoding Polyline encoder and decoder.

go-polyline Package polyline implements a Google Maps Encoding Polyline encoder and decoder. Encoding example func ExampleEncodeCoords() { coords :=

Dec 1, 2022
A pure Go package for coordinate transformations.

WGS84 A pure Go package for coordinate transformations. go get github.com/wroge/wgs84 Usage east, north, h := wgs84.LonLat().To(wgs84.ETRS89UTM(32)).R

Nov 25, 2022
Build a circular sector polygon feature spanning the angle between two given bearings, a center point and a radius. A pizza piece! 🍕
Build a circular sector polygon feature spanning the angle between two given bearings, a center point and a radius. A pizza piece! 🍕

sectr ?? Build a circular sector polygon feature (pizza piece ?? ) spanning the angle between two given bearings, a radius and a center point. install

Oct 1, 2022
An anonymous, encrypted Point-to-Point (Layer 3) tunnel between two peers.

NKN-Link An anonymous, encrypted Point-to-Point (Layer 3) tunnel between two peers. NKN-Link Table of Contents Preface Description Install Setup Run P

Dec 20, 2022
Wg-configurator - This project makes it easier to configure a fleet of servers interconnected via the WireGuard point-to-point virtual private network.

WireGuard Configurator This project makes it easier to configure a fleet of servers interconnected via the WireGuard point-to-point virtual private ne

Mar 29, 2022
Yet another Go package for working with *.golden test files, with a focus on simplicity.

go-golden Yet another Go package for working with *.golden test files, with a focus on simplicity. Import import "github.com/jimeh/go-golden" Usage fu

Aug 3, 2022
Yet another config package

cfg Yet another config package Features Read from file Read from environment variable Hot reload of the file Usage package main import ( "context"

Jan 16, 2022