gittr

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 5 Imported by: 0

README

gittr

Gittr (from Gitter /ˈɡɪtɐ/, the german word for grid) cuts an input polygon into equal sized grid cells. Grid cells are only created if they either touch or are within the input polygon. It also accounts for polygon holes.

Installation

go get -u github.com/iwpnd/gittr

Usage

package main

import (
	"encoding/json"
	"fmt"

	"github.com/iwpnd/gittr"
)

func main() {
	raw := []byte(`{
              "type": "Feature",
              "properties": {"id": 3},
              "geometry": {
                  "type": "Polygon",
                  "coordinates": [
                      [
                          [13.398424, 52.481369],
                          [13.395336, 52.480271],
                          [13.391905, 52.478598],
                          [13.390017, 52.478076],
                          [13.3871, 52.477971],
                          [13.386929, 52.471384],
                          [13.389503, 52.470338],
                          [13.392076, 52.46924],
                          [13.397395, 52.466626],
                          [13.402971, 52.465527],
                          [13.40992, 52.465789],
                          [13.417384, 52.469867],
                          [13.420558, 52.470338],
                          [13.419185, 52.473946],
                          [13.418499, 52.477501],
                          [13.418756, 52.479592],
                          [13.413781, 52.48048],
                          [13.406489, 52.482153],
                          [13.401856, 52.482728],
                          [13.398424, 52.481369]
                      ],
                      [
                          [13.391561, 52.475096],
                          [13.414552, 52.476194],
                          [13.415324, 52.47107],
                          [13.391647, 52.470756],
                          [13.391561, 52.475096]
                      ]
                  ]
              }
          }`)

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

	// create grid with a cell size of 100m
	grid, err := f.ToGrid(100)
	if err != nil {
		panic(err)
	}

	fmt.Printf("cell count: %v\n", len(grid.Features))
}

License

MIT

Maintainer

Benjamin Ramser - @iwpnd

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

Acknowledgement

Paul Mach - go.geojson

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrUnsupportedGeometry

type ErrUnsupportedGeometry struct {
	Type string
}

ErrUnsupportedGeometry ...

func (ErrUnsupportedGeometry) Error

func (e ErrUnsupportedGeometry) Error() string

type Extent

type Extent struct {
	// contains filtered or unexported fields
}

Extent contains all 4 Positions of a bounding box

type Feature

type Feature geojson.Feature

Feature extends geojson.Feature

func (*Feature) Extent

func (f *Feature) Extent() (*Extent, error)

Extent creates bounding box for input Feature if a bounding box is present, it returns early if theres no bounding box it'll be created an attached

func (*Feature) ToGrid

func (f *Feature) ToGrid(distance float64) (*geojson.FeatureCollection, error)

ToGrid cuts features bounding box into a nxm grid grid cells are only created if the cell either touches the input polygon or is within the input polygon

type SpatialRelation

type SpatialRelation string

SpatialRelation to enumerate the spatial relation between extent and feature

const (
	Touches SpatialRelation = "touches"
	Within  SpatialRelation = "within"
)

Spatial relations

Jump to

Keyboard shortcuts

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