### Install Topo Geometry Library for Elixir Source: https://github.com/pkinney/topo/blob/master/README.md This code snippet shows how to add the Topo geometry library as a dependency in an Elixir project's `mix.exs` file. It specifies the library name and the desired version. ```elixir defp deps do [{:topo, "~> 1.0"}] end ``` -------------------------------- ### Example Usage of Topo Geometry Equality Source: https://github.com/pkinney/topo/blob/master/doc/Topo.html Demonstrates how to use the Topo.equals?/2 function in Elixir to check if two geometries are equivalent. It shows examples using both a Map representation and a Geo.Polygon struct, highlighting that the function returns true if they represent the same set of points regardless of type. ```elixir a = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} b = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} Topo.equals? a, b # => true ``` -------------------------------- ### Example Usage of Topo Intersects Function Source: https://github.com/pkinney/topo/blob/master/doc/Topo.html Illustrates the usage of the Topo.intersects?/2 function in Elixir, showing that it can accept a geometry and a single coordinate. The example checks if a Polygon geometry intersects with a given coordinate point. ```elixir a = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} Topo.intersects? a, {4, 6} # => true ``` -------------------------------- ### Using GeoJSON-like Map Format for Topo Geometries Source: https://context7.com/pkinney/topo/llms.txt Demonstrates how Topo functions accept geometries defined as maps with 'type' and 'coordinates' keys, adhering to GeoJSON conventions. This includes examples for Point, MultiPoint, LineString, MultiLineString, Polygon, Polygon with holes, and MultiPolygon. ```elixir # Point point = %{type: "Point", coordinates: {2, -1}} # MultiPoint multi_point = %{type: "MultiPoint", coordinates: [{2, 2}, {20, 2}, {11, 11}]} # LineString line = %{type: "LineString", coordinates: [{2, 2}, {20, 2}, {11, 11}, {2, 2}]} # MultiLineString multi_line = %{ type: "MultiLineString", coordinates: [ [{2, 2}, {20, 2}, {11, 11}], [{1, -2}, {3, 1}] ] } # Polygon (first ring is exterior, subsequent rings are holes) polygon = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} # Polygon with hole polygon_with_hole = %{ type: "Polygon", coordinates: [ [{60, 120}, {60, 40}, {160, 40}, {160, 120}, {60, 120}], [{140, 100}, {80, 100}, {80, 60}, {140, 60}, {140, 100}] ] } # MultiPolygon multi_polygon = %{ type: "MultiPolygon", coordinates: [ [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]], [[{1, -2}, {3, 1}, {0, 0}]] ] } ``` -------------------------------- ### Using Geo Library Structs for Topo Geometries Source: https://context7.com/pkinney/topo/llms.txt Shows how Topo functions seamlessly accept Elixir Geo library structs, ensuring type safety and interoperability within the Elixir Geo ecosystem. Examples cover Point, MultiPoint, LineString, MultiLineString, Polygon, and MultiPolygon structs. ```elixir # Point geo_point = %Geo.Point{coordinates: {2, -1}} # MultiPoint geo_multi_point = %Geo.MultiPoint{coordinates: [{2, 2}, {20, 2}, {11, 11}]} # LineString geo_line = %Geo.LineString{coordinates: [{2, 2}, {20, 2}, {11, 11}, {2, 2}]} # MultiLineString geo_multi_line = %Geo.MultiLineString{ coordinates: [ [{2, 2}, {20, 2}, {11, 11}], [{1, -2}, {3, 1}] ] } # Polygon geo_polygon = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} # MultiPolygon geo_multi_polygon = %Geo.MultiPolygon{ coordinates: [ [[{2, 2}, {20, 2}, {11, 11}]], [[{1, -2}, {3, 1}, {0, 0}, {1, -2}]] ] } # All formats work interchangeably map_format = %{type: "Point", coordinates: {5, 10}} geo_format = %Geo.Point{coordinates: {5, 10}} tuple_format = {5, 10} Topo.equals?(map_format, geo_format) # => true Topo.equals?(geo_format, tuple_format) # => true Topo.equals?(map_format, tuple_format) # => true ``` -------------------------------- ### Elixir: Check if Geometries are Equal using Topo Source: https://github.com/pkinney/topo/blob/master/README.md Demonstrates using the `Topo.equals?/2` function in Elixir to check if two geometries are equivalent. It shows examples using both Map-based geometry representation and Geo library structs. The function accepts various geometry types. ```elixir a = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} b = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} Topo.equals? a, b # => true ``` -------------------------------- ### Dark Theme Initialization (JavaScript) Source: https://github.com/pkinney/topo/blob/master/doc/search.html Initializes the dark theme for the Topo documentation based on user settings or system preferences. It attempts to parse settings from localStorage and applies a 'dark' class to the body if the theme is set to dark, system, or null and the system prefers dark mode. Errors during parsing are silently ignored. ```javascript try { var settings = JSON.parse(localStorage.getItem('ex_doc:settings') || '{}'); if (settings.theme === 'dark' || ((settings.theme === 'system' || settings.theme == null) && window.matchMedia('(prefers-color-scheme: dark)').matches) ) { document.body.classList.add('dark') } } catch (error) { } ``` -------------------------------- ### Initialize Dark Mode Settings (JavaScript) Source: https://github.com/pkinney/topo/blob/master/doc/api-reference.html This snippet initializes dark mode settings based on local storage or system preferences. It parses settings from localStorage and applies a 'dark' class to the body if the theme is set to dark or system default and the system prefers dark mode. It includes error handling for JSON parsing. ```javascript try { var settings = JSON.parse(localStorage.getItem('ex_doc:settings') || '{}'); if (settings.theme === 'dark' || ((settings.theme === 'system' || settings.theme == null) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { document.body.classList.add('dark') } } catch (error) { } ``` -------------------------------- ### Initialize Dark Mode Settings Source: https://github.com/pkinney/topo/blob/master/doc/Topo.html Attempts to parse localStorage for theme settings and applies the 'dark' class to the body if the theme is set to 'dark' or 'system' and the system prefers dark mode. This snippet handles potential errors during JSON parsing or localStorage access. ```javascript try { var settings = JSON.parse(localStorage.getItem('ex_doc:settings') || '{}'); if (settings.theme === 'dark' || ((settings.theme === 'system' || settings.theme == null) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { document.body.classList.add('dark'); } } catch (error) {} ``` -------------------------------- ### Run Topo Library Tests in Elixir Source: https://github.com/pkinney/topo/blob/master/README.md A simple bash command to execute the test suite for the Topo geometry library using Mix, Elixir's build tool. This command is typically run from the project's root directory. ```bash > mix test ``` -------------------------------- ### Using Coordinate Tuples as Points with Topo Source: https://context7.com/pkinney/topo/llms.txt Demonstrates how Topo can interpret standard Elixir tuples as points for spatial queries like containment, intersection, and disjointness. It highlights the flexibility of Topo's input handling. ```elixir polygon = %{type: "Polygon", coordinates: [[{0, 0}, {10, 0}, {10, 10}, {0, 10}, {0, 0}]]} Topo.contains?(polygon, {5, 5}) # => true Topo.intersects?({2, 3}, polygon) # => true Topo.disjoint?({20, 20}, polygon) # => true ``` -------------------------------- ### Using Coordinate Tuple Shorthand for Points in Topo Source: https://context7.com/pkinney/topo/llms.txt Highlights that Topo allows using simple coordinate tuples `{x, y}` directly as Point geometries in functions, eliminating the need to explicitly wrap them in a geometry structure for point-based operations. ```elixir # Example usage would be within a Topo function call like Topo.within? or Topo.equals? # e.g., Topo.equals?({5, 10}, %Geo.Point{coordinates: {5, 10}}) # This shorthand is specifically for Point geometries. ``` -------------------------------- ### Compare Geometries for Spatial Equivalence with Topo.equals? Source: https://context7.com/pkinney/topo/llms.txt Illustrates the use of Topo.equals? to check if two geometries are spatially equivalent, meaning they cover the exact same set of points. This comparison works across different geometry types and formats, including automatically handling closing rings and cleaning up MultiPolygons. ```elixir point = %{type: "Point", coordinates: {2, -3}} multi_point = %{type: "MultiPoint", coordinates: [{2, -3}]} Topo.equals?(point, multi_point) # => true map_poly = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} geo_poly = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} Topo.equals?(map_poly, geo_poly) # => true poly1 = %{type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]]} poly2 = %{type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]]} Topo.equals?(poly1, poly2) # => false line1 = %Geo.LineString{coordinates: [{0, 0}, {5, 5}, {10, 0}]} line2 = %Geo.LineString{coordinates: [{10, 0}, {5, 5}, {0, 0}]} Topo.equals?(line1, line2) # => false (different direction) mp1 = %{type: "MultiPolygon", coordinates: [ [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]], [[{1, -2}, {3, 1}, {0, 0}]] ]} mp2 = %Geo.MultiPolygon{coordinates: [ [[{2, 2}, {20, 2}, {11, 11}]], [[{1, -2}, {3, 1}, {0, 0}, {1, -2}]] ]} Topo.equals?(mp1, mp2) # => true (automatically closed and cleaned) ``` -------------------------------- ### Comparing Point Tuples with Point Geometries using Topo Source: https://context7.com/pkinney/topo/llms.txt Illustrates the `Topo.equals?` function comparing an Elixir tuple representing a point with a `Geo.Point` struct. This showcases Topo's ability to equate different representations of the same geometric point. ```elixir point_tuple = {2, -1} point_struct = %Geo.Point{coordinates: {2, -1}} Topo.equals?(point_tuple, point_struct) # => true ``` -------------------------------- ### Configure Epsilon for Floating Point Precision in Topo Source: https://context7.com/pkinney/topo/llms.txt Explains how to configure the epsilon value for handling floating-point precision issues in Topo's line segment intersection calculations. This is crucial for avoiding incorrect results due to strict floating-point comparisons. ```elixir # In config/config.exs config :topo, epsilon: true # Default is strict comparison (false) config :topo, epsilon: false # After changing configuration, recompile dependencies # mix deps.clean topo --build # mix deps.compile topo ``` -------------------------------- ### Configure Epsilon for Float Precision in Topo Elixir Source: https://github.com/pkinney/topo/blob/master/README.md This Elixir configuration shows how to enable a less strict floating-point comparison for line segment intersection in the Topo library by setting an `:epsilon` value. This is done in the application's configuration file and may require recompilation. ```elixir config :topo, epsilon: true ``` -------------------------------- ### Elixir: Check for Intersection with a Point using Topo Source: https://github.com/pkinney/topo/blob/master/README.md Illustrates how the `Topo.intersects?/2` function in Elixir can check for intersection between a Polygon and a single coordinate Point. The function is flexible and can accept simple coordinates as input. ```elixir a = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} Topo.intersects? a, {4, 6} # => true ``` -------------------------------- ### Topo Geometry Functions Source: https://github.com/pkinney/topo/blob/master/doc/Topo.html This section details the core functions of the Topo library for performing geometric relationship checks. These functions accept various geometry representations, including Maps, Geo structs, and simple coordinates. ```APIDOC ## Topo Geometry Functions ### Description Provides functions to check spatial relationships between two geometries. ### Geometry Types - `geometry()`: Can be a coordinate tuple `{x, y}`, a Map with `:type` and `:coordinates`, or a Geo struct (e.g., `%Geo.Polygon`). ### Functions #### `contains?(a, b)` ##### Description Returns `true` if all points of geometry **B** lie within geometry **A**. ##### Method ELIXIR.FUNCTION ##### Parameters - **a** (geometry()) - The first geometry. - **b** (geometry()) - The second geometry. ##### Example ```elixir a = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} b = %{type: "Polygon", coordinates: [[{4, 4}, {10, 4}, {10, 10}, {4, 4}]]} Topo.contains?(a, b) # => true ``` #### `disjoint?(a, b)` ##### Description Returns `true` if geometries **A** and **B** do not have any points in common. ##### Method ELIXIR.FUNCTION ##### Parameters - **a** (geometry()) - The first geometry. - **b** (geometry()) - The second geometry. ##### Example ```elixir a = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} b = %{type: "Polygon", coordinates: [[{30, 30}, {40, 30}, {40, 40}, {30, 40}]]} Topo.disjoint?(a, b) # => true ``` #### `equals?(a, b)` ##### Description Geometries **A** and **B** are equivalent and cover the exact same set of points. Equality does not necessarily mean that the geometries are of the same type. ##### Method ELIXIR.FUNCTION ##### Parameters - **a** (geometry()) - The first geometry. - **b** (geometry()) - The second geometry. ##### Example ```elixir a = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} b = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} Topo.equals?(a, b) # => true ``` #### `intersects?(a, b)` ##### Description Returns `true` if geometries **A** and **B** share at least one point in common. ##### Method ELIXIR.FUNCTION ##### Parameters - **a** (geometry()) - The first geometry. - **b** (geometry()) - The second geometry. ##### Example ```elixir a = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} b = {4, 6} Topo.intersects?(a, b) # => true ``` #### `within?(a, b)` ##### Description This is the direct converse of `contains?`. All points of geometry **A** lie within geometry **B**. ##### Method ELIXIR.FUNCTION ##### Parameters - **a** (geometry()) - The first geometry. - **b** (geometry()) - The second geometry. ##### Example ```elixir a = %{type: "Polygon", coordinates: [[{4, 4}, {10, 4}, {10, 10}, {4, 4}]]} b = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} Topo.within?(a, b) # => true ``` ``` -------------------------------- ### Check if geometries A and B are equal (Elixir) Source: https://github.com/pkinney/topo/blob/master/doc/Topo.html The `equals?/2` function checks if geometries A and B cover the exact same set of points. Geometries are considered equal if each contains the other, regardless of their specific type (e.g., a Point can be equal to a MultiPoint containing only that Point). This function is provided by the `topo` library. ```elixir iex> Topo.equals?( ...> %{type: "Point", coordinates: {2, -3}}, ...> %{type: "MultiPoint", coordinates: [{2, -3}]} ...> ) true iex> Topo.equals?( ...> %{type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]]}, ...> %{type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]]} ...> ) false ``` -------------------------------- ### Topo.disjoint?/2 Source: https://context7.com/pkinney/topo/llms.txt Checks if two geometries have no points in common. This is the inverse of `intersects?`. ```APIDOC ## Topo.disjoint?/2 ### Description Returns `true` if geometries A and B do not share any points in common. This is the logical inverse of `intersects?` and is useful for spatial filtering operations. ### Method `Topo.disjoint?(geometry_a, geometry_b)` ### Parameters - **geometry_a**: (map or Geo struct) The first geometry. - **geometry_b**: (map or Geo struct) The second geometry. ### Request Example ```elixir point = {1, -3} multi_point = %{type: "MultiPoint", coordinates: [{70, 35}, {100, 80}]} Topo.disjoint?(point, multi_point) # => true poly1 = %{type: "Polygon", coordinates: [[{0, 0}, {2, 0}, {2, 2}, {0, 2}, {0, 0}]]} poly2 = %{type: "Polygon", coordinates: [[{2, 0}, {4, 0}, {4, 2}, {2, 2}, {2, 0}]]} Topo.disjoint?(poly1, poly2) # => false (they share the edge) ``` ### Response #### Success Response (Boolean) - **result**: (boolean) `true` if the geometries are disjoint, `false` otherwise. #### Response Example ```elixir true ``` ``` -------------------------------- ### Check if a Point is within a Polygon using Topo Source: https://context7.com/pkinney/topo/llms.txt Demonstrates using Topo.within? to determine if a point, LineString, or other geometry is spatially contained within a polygon. This function supports various geometry types as input. ```elixir point = {100, 100} polygon = %{type: "Polygon", coordinates: [[{0, 0}, {200, 0}, {200, 200}, {0, 200}, {0, 0}]]} Topo.within?(point, polygon) # => true line = %Geo.LineString{coordinates: [{50, 50}, {100, 100}, {150, 50}]} Topo.within?(line, polygon) # => true small_poly = %{type: "Polygon", coordinates: [[{40, 40}, {160, 40}, {160, 120}, {40, 120}, {40, 40}]]} Topo.within?(line, small_poly) # => true ``` -------------------------------- ### Define Topo Geometry Type Source: https://github.com/pkinney/topo/blob/master/doc/Topo.html Defines the 'geometry()' type for the Topo Elixir library. This type can represent a coordinate tuple, a Map with 'type' and 'coordinates' keys, or various Geo structs including Point, MultiPoint, LineString, MultiLineString, Polygon, and MultiPolygon. It also includes properties and SRID for Geo structs. ```elixir @type 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]()} ``` -------------------------------- ### Elixir: Polygon Does Not Contain Its Boundary with Topo Source: https://github.com/pkinney/topo/blob/master/README.md This Elixir code snippet demonstrates a specific behavior of the `Topo.contains?/2` function where a Polygon does not contain its exact boundary LineString. It also shows that `Topo.intersects?/2` returns true in this case. ```elixir a = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} b = %Geo.LineString{coordinates: [{2, 2}, {20, 2}, {11, 11}, {2, 2}]} Topo.contains? a, b # => false Topo.intersects? a, b # => true ``` -------------------------------- ### Topo.intersects?/2 Source: https://context7.com/pkinney/topo/llms.txt Checks if two geometries share at least one point in common. Supports GeoJSON-like maps and Geo structs. ```APIDOC ## Topo.intersects?/2 ### Description Returns `true` if geometries A and B share at least one point in common. This is a fundamental spatial predicate for determining if two shapes have any overlap or touch at any location. ### Method `Topo.intersects?(geometry_a, geometry_b)` ### Parameters - **geometry_a**: (map or Geo struct) The first geometry. - **geometry_b**: (map or Geo struct) The second geometry. ### Request Example ```elixir polygon = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} line = %{type: "LineString", coordinates: [{11, 10}, {4, 2.5}, {16, 2.5}, {11, 10}]} Topo.intersects?(polygon, line) # => true geo_polygon = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} geo_line = %Geo.LineString{coordinates: [{2, 2}, {20, 2}]} Topo.intersects?(geo_polygon, geo_line) # => true ``` ### Response #### Success Response (Boolean) - **result**: (boolean) `true` if the geometries intersect, `false` otherwise. #### Response Example ```elixir true ``` ``` -------------------------------- ### Geometry Within Check Source: https://github.com/pkinney/topo/blob/master/doc/Topo.html Checks if all points of the first geometry lie within the second geometry. This is the converse of the `contains?` function. ```APIDOC ## within? / 2 ### Description Determines if the first geometry is entirely contained within the second geometry. This is the direct converse of `contains?`. ### Method `Topo.within?(geometry_a, geometry_b)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```elixir Topo.within?( %{type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]]}, %{type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]]} ) Topo.within?( %{type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]]}, %{type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]]} ) ``` ### Response #### Success Response (boolean) - **boolean** (boolean) - `true` if `geometry_a` is within `geometry_b`, `false` otherwise. #### Response Example ```elixir false true ``` ``` -------------------------------- ### Topo.contains?/2 Source: https://context7.com/pkinney/topo/llms.txt Checks if one geometry completely contains another. A geometry does not contain its boundary. ```APIDOC ## Topo.contains?/2 ### Description Returns `true` if all points of geometry B lie within geometry A. Important: a polygon does not contain its own boundary, and a LineString does not contain its first and last points unless they form a closed ring. ### Method `Topo.contains?(container_geometry, contained_geometry)` ### Parameters - **container_geometry**: (map or Geo struct) The geometry that might contain the other. - **contained_geometry**: (map or Geo struct) The geometry that might be contained. ### Request Example ```elixir large = %{ type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]] } small = %{ type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]] } Topo.contains?(large, small) # => true polygon = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} boundary = %Geo.LineString{coordinates: [{2, 2}, {20, 2}, {11, 11}, {2, 2}]} Topo.contains?(polygon, boundary) # => false ``` ### Response #### Success Response (Boolean) - **result**: (boolean) `true` if `container_geometry` contains `contained_geometry`, `false` otherwise. #### Response Example ```elixir true ``` ``` -------------------------------- ### Check if Geometries are Disjoint - Topo Elixir Source: https://context7.com/pkinney/topo/llms.txt Verifies if two geometries have no points in common, meaning they do not overlap or touch. This is the inverse of the `intersects?` predicate. It supports various geometry types and input formats, including map-based and Geo.Structs. ```elixir point = {1, -3} multi_point = %{type: "MultiPoint", coordinates: [{70, 35}, {100, 80}]} Topo.disjoint?(point, multi_point) # => true polygon_with_hole = %{ type: "Polygon", coordinates: [ [{60, 120}, {60, 40}, {160, 40}, {160, 120}, {60, 120}], [{140, 100}, {80, 100}, {80, 60}, {140, 60}, {140, 100}] ] } points = %Geo.MultiPoint{coordinates: [{70, 35}, {100, 80}]} Topo.disjoint?(polygon_with_hole, points) # => true poly1 = %{type: "Polygon", coordinates: [[{0, 0}, {2, 0}, {2, 2}, {0, 2}, {0, 0}]]} poly2 = %{type: "Polygon", coordinates: [[{2, 0}, {4, 0}, {4, 2}, {2, 2}, {2, 0}]]} Topo.disjoint?(poly1, poly2) # => false (they share the edge) ``` -------------------------------- ### Topo.within?/2 Source: https://context7.com/pkinney/topo/llms.txt Checks if geometry A is entirely within geometry B. This is the converse of `contains?`. ```APIDOC ## Topo.within?/2 ### Description Returns `true` if all points of geometry A lie within geometry B. This is the direct converse of `contains?` where the arguments are reversed. ### Method `Topo.within?(inner_geometry, outer_geometry)` ### Parameters - **inner_geometry**: (map or Geo struct) The geometry that might be within the other. - **outer_geometry**: (map or Geo struct) The geometry that might contain the other. ### Request Example ```elixir large = %{ type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]] } small = %{ type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]] } Topo.within?(small, large) # => true Topo.within?(large, small) # => false ``` ### Response #### Success Response (Boolean) - **result**: (boolean) `true` if `inner_geometry` is within `outer_geometry`, `false` otherwise. #### Response Example ```elixir true ``` ``` -------------------------------- ### Elixir: LineString Does Not Contain Its Endpoints with Topo Source: https://github.com/pkinney/topo/blob/master/README.md Shows an edge case with the `Topo.contains?/2` function in Elixir: a LineString does not contain its own first and last points unless it forms a closed LinearRing. `Topo.intersects?/2` correctly identifies intersection with these points. ```elixir a = %Geo.LineString{coordinates: [{1, 3}, {2, -1}, {0, -1}]} b = %Geo.LineString{coordinates: [{1, 3}, {2, -1}, {0, -1}, {1, 3}]} Topo.contains? a, {1, 3} # => false Topo.intersects? a, {1, 3} # => true Topo.contains? b, {1, 3} # => true ``` -------------------------------- ### Check if Geometry Contains Another - Topo Elixir Source: https://context7.com/pkinney/topo/llms.txt Tests if all points of geometry B are contained within geometry A. A polygon does not contain its boundary, and an open LineString does not contain its endpoints. Accepts map-based and Geo.Structs. ```elixir large = %{ type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]] } small = %{ type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]] } Topo.contains?(large, small) # => true Topo.contains?(small, large) # => false polygon = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} boundary = %Geo.LineString{coordinates: [{2, 2}, {20, 2}, {11, 11}, {2, 2}]} Topo.contains?(polygon, boundary) # => false Topo.intersects?(polygon, boundary) # => true open_line = %Geo.LineString{coordinates: [{1, 3}, {2, -1}, {0, -1}]} closed_line = %Geo.LineString{coordinates: [{1, 3}, {2, -1}, {0, -1}, {1, 3}]} Topo.contains?(open_line, {1, 3}) # => false Topo.contains?(closed_line, {1, 3}) # => true Topo.contains?(polygon, {10, 5}) # => true ``` -------------------------------- ### Check if geometries A and B intersect (Elixir) Source: https://github.com/pkinney/topo/blob/master/doc/Topo.html The `intersects?/2` function returns `true` if geometries A and B share at least one point in common. This is a fundamental check for spatial overlap. The function is part of the `topo` library and handles various geometry types. ```elixir iex> Topo.intersects?( ...> %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]}, ...> %{type: "LineString", coordinates: [{11, 10}, {4, 2.5}, {16, 2.5}, {11, 10}]} ...> ) true iex> Topo.intersects?( ...> %{type: "Polygon", coordinates: [ ...> [{60, 120}, {60, 40}, {160, 40}, {160, 120}, {60, 120}], ...> [{140, 100}, {80, 100}, {80, 60}, {140, 60}, {140, 100}]]}, ...> %{type: "MultiPoint", coordinates: [{70, 35}, {100, 80}]} ...> ) false ``` -------------------------------- ### Check if Geometry A is within Geometry B (Elixir) Source: https://github.com/pkinney/topo/blob/master/doc/Topo.html The `within?/2` function checks if all points of the first geometry argument are contained within the second geometry argument. This function is the direct opposite of `contains?/2`. It expects two arguments of type `geometry` and returns a `boolean`. ```elixir iex> Topo.within?( ...> %{type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]]}, ...> %{type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]]} ...> ) false iex> Topo.within?( ...> %{type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]]}, ...> %{type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]]} ...> ) true ``` -------------------------------- ### Check if Geometries Intersect - Topo Elixir Source: https://context7.com/pkinney/topo/llms.txt Determines if two geometries share at least one common point. Supports various geometry types like Polygon, LineString, and Point, accepting both map-based GeoJSON-like structures and Geo.Structs. The function automatically cleans input geometries before calculation. ```elixir polygon = %{type: "Polygon", coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} line = %{type: "LineString", coordinates: [{11, 10}, {4, 2.5}, {16, 2.5}, {11, 10}]} Topo.intersects?(polygon, line) # => true polygon_with_hole = %{ type: "Polygon", coordinates: [ [{60, 120}, {60, 40}, {160, 40}, {160, 120}, {60, 120}], [{140, 100}, {80, 100}, {80, 60}, {140, 60}, {140, 100}] ] } points = %{type: "MultiPoint", coordinates: [{70, 35}, {100, 80}]} Topo.intersects?(polygon_with_hole, points) # => false Topo.intersects?(polygon, {4, 6}) # => true geo_polygon = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} geo_line = %Geo.LineString{coordinates: [{2, 2}, {20, 2}]} Topo.intersects?(geo_polygon, geo_line) # => true ``` -------------------------------- ### Check if geometries A and B are disjoint (Elixir) Source: https://github.com/pkinney/topo/blob/master/doc/Topo.html The `disjoint?/2` function returns `true` if geometries A and B do not share any common points. This function is useful for determining if two spatial entities do not overlap at all. It is part of the `topo` library. ```elixir iex> Topo.disjoint?({1, -3}, %{type: "MultiPoint", coordinates: [{70, 35}, {100, 80}]}) true iex> Topo.disjoint?( ...> %{type: "Polygon", coordinates: [ ...> [{60, 120}, {60, 40}, {160, 40}, {160, 120}, {60, 120}], ...> [{140, 100}, {80, 100}, {80, 60}, {140, 60}, {140, 100}]]}, ...> %Geo.MultiPoint{coordinates: [{70, 35}, {100, 80}]} ...> ) true ``` -------------------------------- ### Check if Geometry is Within Another - Topo Elixir Source: https://context7.com/pkinney/topo/llms.txt Determines if all points of geometry A are contained within geometry B. This is the converse of the `contains?` function. It supports various geometry types and input formats, including map-based and Geo.Structs. ```elixir large = %{ type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]] } small = %{ type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]] } Topo.within?(small, large) # => true Topo.within?(large, small) # => false ``` -------------------------------- ### Check if geometry B is contained within geometry A (Elixir) Source: https://github.com/pkinney/topo/blob/master/doc/Topo.html The `contains?/2` function determines if all points of geometry B are located within geometry A. Note that polygons do not contain their own boundaries, and LineStrings do not contain their own start/end points unless they form a LinearRing. This function relies on the `topo` library. ```elixir a = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]} b = %Geo.LineString{coordinates: [{2, 2}, {20, 2}, {11, 11}, {2, 2}]} Topo.contains? a, b # => false a = %Geo.LineString{coordinates: [{1, 3}, {2, -1}, {0, -1}]} b = %Geo.LineString{coordinates: [{1, 3}, {2, -1}, {0, -1}, {1, 3}]} Topo.contains? a, {1, 3} # => false Topo.contains? b, {1, 3} # => true iex> Topo.contains?( ...> %{type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]]}, ...> %{type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]]} ...> ) true iex> Topo.contains?( ...> %{type: "Polygon", coordinates: [[{160, 60}, {20, 20}, {100, 140}, {160, 60}]]}, ...> %{type: "Polygon", coordinates: [[{20, 20}, {20, 180}, {220, 180}, {220, 20}, {20, 20}]]} ...> ) false ```