All Projects → pkinney → envelope_ex

pkinney / envelope_ex

Licence: MIT license
Utilities for calculating and comparing envelopes from geometries

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to envelope ex

Geometry2d
Unity3D: A set of helper classes for 2D geometric calculations.
Stars: ✭ 40 (+166.67%)
Mutual labels:  geometry, polygon
Plexus
Polygonal mesh processing.
Stars: ✭ 90 (+500%)
Mutual labels:  geometry, polygon
Phidl
Python GDS layout and CAD geometry creation
Stars: ✭ 56 (+273.33%)
Mutual labels:  geometry, polygon
Wicket
A modest library for moving between Well-Known Text (WKT) and various framework geometries
Stars: ✭ 484 (+3126.67%)
Mutual labels:  geometry, polygon
osm-static-maps
Openstreetmap static maps is a nodejs lib, CLI and server open source inspired on google static map service
Stars: ✭ 130 (+766.67%)
Mutual labels:  geometry, polygon
Wxdraw
几何画图(微信小程序)
Stars: ✭ 36 (+140%)
Mutual labels:  geometry, polygon
Graphical Debugging
GraphicalDebugging extension for Visual Studio
Stars: ✭ 88 (+486.67%)
Mutual labels:  geometry, polygon
pyprt
Python bindings for the "Procedural Runtime" (PRT) of CityEngine by Esri.
Stars: ✭ 36 (+140%)
Mutual labels:  geometry, gis
Unity.library.eppz.geometry
2D Geometry for Unity. Suited for everyday polygon hassle. Polygon clipping, polygon winding direction, polygon area, polygon centroid, centroid of multiple polygons, line intersection, point-line distance, segment intersection, polygon-point containment, polygon triangulation, polygon Voronoi diagram, polygon offset, polygon outline, polygon buffer, polygon union, polygon substraction, polygon boolean operations, and more. It is a polygon fest.
Stars: ✭ 198 (+1220%)
Mutual labels:  geometry, polygon
Matgeom
Matlab geometry toolbox for 2D/3D geometric computing
Stars: ✭ 168 (+1020%)
Mutual labels:  geometry, polygon
Earcut.hpp
Fast, header-only polygon triangulation
Stars: ✭ 447 (+2880%)
Mutual labels:  geometry, polygon
Geokit
Geo-Toolkit for PHP.
Stars: ✭ 223 (+1386.67%)
Mutual labels:  geometry, polygon
Cga.js
CGA 3D 计算几何算法库 | 3D Compute Geometry Algorithm Library webgl three.js babylon.js等任何库都可以使用
Stars: ✭ 313 (+1986.67%)
Mutual labels:  geometry, gis
Sharpmath
A small .NET math library.
Stars: ✭ 36 (+140%)
Mutual labels:  geometry, polygon
SharpMath2
2D math / geometry collision library for C#, compatable with monogame.
Stars: ✭ 36 (+140%)
Mutual labels:  geometry, polygon
Polyclip Go
Go library for Boolean operations on 2D polygons.
Stars: ✭ 70 (+366.67%)
Mutual labels:  geometry, polygon
Microsoft.SqlServer.Types
a .NET Standard implementation of the spatial types in `Microsoft.SqlServer.Types`
Stars: ✭ 64 (+326.67%)
Mutual labels:  geometry, gis
ludigraphix.github.io
Documentation for Ludigraphix
Stars: ✭ 21 (+40%)
Mutual labels:  geometry, polygon
Polylidar
Polylidar3D - Fast polygon extraction from 3D Data
Stars: ✭ 106 (+606.67%)
Mutual labels:  geometry, polygon
Cgal
The public CGAL repository, see the README below
Stars: ✭ 2,825 (+18733.33%)
Mutual labels:  geometry, polygon

Envelope

CI Hex.pm

A library for calculating envelopes (axis-aligned bounding boxes) of geometries and tools to compare them. This is most useful as an approximation of spacial relationships between more complicated geometries.

Installation

defp deps do
  [{:envelope, "~> 1.4"}]
end

Usage

Full Documentation

The Envelope module provides a method from_geo that accepts a struct generated via the Geo library (https://github.com/bryanjos/geo) and returns an Envelope struct containing the maximum extent in the x and y direction.

Envelope.from_geo( %Geo.Polygon{coordinates: [[{2, -2}, {20, -2}, {11, 11}, {2, -2}]]} )
# => %Envelope{ min_x: 2, min_y: -2, max_x: 20, max_y: 11 }

env = %Envelope{min_x: -1, min_y: 2, max_x: 1, max_y: 5}
Envelope.expand(env, %Geo.Polygon{coordinates: [[{2, -2}, {20, -2}, {11, 11}, {2, -2}]]})
# => %Envelope{ min_x: -1, min_y: -2, max_x: 20, max_y: 11 }

Envelope.empty
|> Envelope.expand(%Envelope{ min_x: 0, min_y: -2, max_x: 12, max_y: 11 })
|> Envelope.expand(%Geo.Polygon{coordinates: [[{2, -2}, {20, -2}, {11, 11}, {2, -2}]]})
|> Envelope.expand(%{type: "Point", coordinates: {-1, 3}})
# => %Envelope{ min_x: -1, min_y: -2, max_x: 20, max_y: 11 }

Envelopes can then be used to estimate spatial relationships between more complex shapes.

Envelope.intersects?(
  %Envelope{ min_x: -1, min_y: -5, max_x: 23, max_y: 14 },
  %Envelope{ min_x: 0, min_y: 3, max_x: 7, max_y: 4 })
# => true

Envelope.contains?(
  %Envelope{ min_x: -1, min_y: 5, max_x: 23, max_y: 14 },
  %{type: "Point", coordinates: {0, 4}})
# => false

Applicaiton

In the context of a larger Geometry/GIS application, Envelopes can be used to drastically decrease processing overhead for comparing two geometries that are likely to be disjoint. For example, determining whether a point enters a complex geofence or finding shape collisions among a large number of spread out polygons.

This is based on the fact that Geometries (Polygon, LineString, MultiPolgyon, etc.) with disjoint Envelopes will be disjoint. Said another way, Geometries will intersect if and only if their Envelopes intersect.

Depending on the unique environment and use case, it will be more efficient to calculate Envelopes on the fly or calculate the Envelope and cache it. Many databases will do an bounding-box check internally, but for those that don't, storing the extents along each axis and preforming a range change before pulling a large geometry from the database will greatly improve performance.

For example, using Topo as and underlying geometry library:

def intersect?(poly1, poly2) do
  # calculate the envelope or (better yet) pull it from cache
  poly1_env = Envelope.from_geo(poly1)
  poly2_env = Envelope.from_geo(poly2)

  case Envelope.intersects?(poly1_env, poly2_env) do
    true -> # envelopes intersect, so let's check the polygons directly
      Topo.intersects?(poly1, poly2)
    false -> # envelopes don't intersect, so no reason to check the polygon intersection
      false
  end
end

or more concisely

Envelope.intersects?(Envelope.from_geo(poly1), Envelope.from_geo(poly2)) && Topo.intersects?(poly1, poly2)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].