spatial_hash v0.1.6 SpatialHash

Documentation for SpatialHash.

Link to this section Summary

Functions

Returns an array containing the hash elements for the given point for each dimension

Returns array of hash ranges for a given axis-aligned envelope

Convenience function for creating a grid for use with longitude/latitude grids. You can specify a grid spacing, or it will default to 0.001

Link to this section Types

Link to this type

geometry()
geometry() ::
  {number(), number()}
  | %{type: String.t(), coordinates: list()}
  | %Geo.Point{coordinates: term(), properties: term(), srid: term()}
  | %Geo.MultiPoint{coordinates: term(), properties: term(), srid: term()}
  | %Geo.LineString{coordinates: term(), properties: term(), srid: term()}
  | %Geo.MultiLineString{coordinates: term(), properties: term(), srid: term()}
  | %Geo.Polygon{coordinates: term(), properties: term(), srid: term()}
  | %Geo.MultiPolygon{coordinates: term(), properties: term(), srid: term()}

Link to this type

grid()
grid() :: [grid_dim()]

Link to this type

grid_dim()
grid_dim() :: {number(), number(), number()}

Link to this type

point()
point() :: [number()]

Link to this type

point_range()
point_range() :: [%Range{first: term(), last: term()}]

Link to this section Functions

Returns an array containing the hash elements for the given point for each dimension.

Examples

iex> SpatialHash.hash([-0.2, -1.3], [{-180, 180, 0.05}, {-90, 90, 0.2}])
[3596, 443]
iex> SpatialHash.hash([0.2, -80.2], [{-180, 180, 0.05}, {-90, 90, 0.1}])
[3604, 98]
iex> SpatialHash.hash([0.2, -80.2])
[180200, 9800]
Link to this function

hash(list1, list2)
hash(point(), grid()) :: point()

Link to this function

hash_range(shape)

Returns array of hash ranges for a given axis-aligned envelope

Examples

iex> SpatialHash.hash_range(%Envelope{
...>   min_x: -90.082756,
...>   min_y: 29.949766,
...>   max_x: -90.079484,
...>   max_y: 29.952280
...> }, [{-180, 180, 0.01}, {-90, 90, 0.01}])
[8991..8992, 11994..11995]

iex> SpatialHash.hash_range(
...>  %{type: "LineString", coordinates: [
...>    { -90.082746, 29.950955},
...>    {-90.081453, 29.952280},
...>    {-90.079489, 29.949770}
...>  ]})
[89917..89920, 119949..119952]

iex> SpatialHash.hash_range(
...>  %{type: "Point",
...>    coordinates: { -90.082746, 29.950955}})
[89917..89917, 119950..119950]
Link to this function

hash_range(env, dims)
hash_range(
  %Envelope{max_x: term(), max_y: term(), min_x: term(), min_y: term()}
  | geometry(),
  grid()
) :: point_range()

Link to this function

world_grid(step \\ 0.001)
world_grid(number()) :: grid()

Convenience function for creating a grid for use with longitude/latitude grids. You can specify a grid spacing, or it will default to 0.001.

Examples

iex> SpatialHash.world_grid()
[{-180, 180, 0.001}, {-90, 90, 0.001}]

iex> SpatialHash.world_grid(0.03)
[{-180, 180, 0.03}, {-90, 90, 0.03}]