Grid Analysis

Divide a given area into grids, including square grids and hexagonal grids.

parameter

Input parameters: bound (the geomtry information of a given area is converted to bound attributes), cellSize (the side length parameters of squares and hexagons, in meters)

Output parameter: gridGeoms (the geomtry attribute of the divided grid)

Remarks

The input bound information is the coordinates of longitude and latitude, and the coordinates of the output grid are also the coordinates of longitude and latitude;

Example

1. Build a quadrilateral grid

package main

import (
    "fmt"

    "github.com/spatial-go/geoos"
    "github.com/spatial-go/geoos/grid"
)

func main() {
    var cellSize float64 = 10000
    bound := geoos.Bound{Min: geoos.Point{116.315732,39.883937}, Max: geoos.Point{116.443076,39.9791}}
    gotGrids := grid.SquareGrid(bound, cellSize)
    fmt.Println(gotGrids)
}
// [[{[[[116.26220486056086 39.841586339409865] [116.26220486056086 39.9315185] [116.379404 39.9315185] [116.379404 39.841586339409865] [116.26220486056086 39.841586339409865]]]} {[[[116.26220486056086 39.9315185] [116.26220486056086 40.02145066059014] [116.379404 40.02145066059014] [116.379404 39.9315185] [116.26220486056086 39.9315185]]]}] [{[[[116.379404 39.841586339409865] [116.379404 39.9315185] [116.49660313943913 39.9315185] [116.49660313943913 39.841586339409865] [116.379404 39.841586339409865]]]} {[[[116.379404 39.9315185] [116.379404 40.02145066059014] [116.49660313943913 40.02145066059014] [116.49660313943913 39.9315185] [116.379404 39.9315185]]]}]]

2. Build a hexagonal grid

package main

import (
    "fmt"

    "github.com/spatial-go/geoos"
    "github.com/spatial-go/geoos/grid"
)

func main() {
    var cellSize float64 = 10000
    bound := geoos.Bound{Min: geoos.Point{116.315732,39.883937}, Max: geoos.Point{116.443076,39.9791}}
    gotGrids := grid.HexagonGrid(bound, cellSize)
    fmt.Println(gotGrids)
}

// [[{[[[116.37433156971957 39.96182053568833] [116.43293113943913 39.883937] [116.37433156971957 39.806053464311674] [116.25713243028042 39.806053464311674] [116.19853286056086 39.883937] [116.25713243028042 39.96182053568833] [116.37433156971957 39.96182053568833]]]} {[[[116.37433156971957 40.117587607065] [116.43293113943913 40.03970407137667] [116.37433156971957 39.96182053568834] [116.25713243028042 39.96182053568834] [116.19853286056086 40.03970407137667] [116.25713243028042 40.117587607065] [116.37433156971957 40.117587607065]]]}] [{[[[116.55013027887829 40.03970407137666] [116.60872984859785 39.96182053568833] [116.55013027887829 39.883937] [116.43293113943913 39.883937] [116.37433156971957 39.96182053568833] [116.43293113943913 40.03970407137666] [116.55013027887829 40.03970407137666]]]} {[[[116.55013027887829 40.19547114275333] [116.60872984859785 40.117587607065] [116.55013027887829 40.03970407137667] [116.43293113943913 40.03970407137667] [116.37433156971957 40.117587607065] [116.43293113943913 40.19547114275333] [116.55013027887829 40.19547114275333]]]}]]