OmniSciDB  16c4e035a1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExtensionFunctionsGeo.hpp File Reference
#include "Geospatial/CompressionRuntime.h"
#include "Geospatial/Utm.h"
#include <string>
#include "Shared/likely.h"
+ Include dependency graph for ExtensionFunctionsGeo.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  anonymous_namespace{ExtensionFunctionsGeo.hpp}::CoordData
 
struct  anonymous_namespace{ExtensionFunctionsGeo.hpp}::Point2D
 

Namespaces

 anonymous_namespace{ExtensionFunctionsGeo.hpp}
 

Macros

#define DEBUG_STMT(x)
 

Enumerations

enum  anonymous_namespace{ExtensionFunctionsGeo.hpp}::Coords { anonymous_namespace{ExtensionFunctionsGeo.hpp}::None = 0, anonymous_namespace{ExtensionFunctionsGeo.hpp}::Y, anonymous_namespace{ExtensionFunctionsGeo.hpp}::X, anonymous_namespace{ExtensionFunctionsGeo.hpp}::XY }
 
enum  EdgeBehavior { EdgeBehavior::kIncludePointOnEdge, EdgeBehavior::kExcludePointOnEdge }
 

Functions

DEVICE ALWAYS_INLINE double tol (int32_t ic)
 
DEVICE ALWAYS_INLINE double tol (const int32_t ic1, const int32_t ic2)
 
DEVICE ALWAYS_INLINE bool tol_zero (const double x, const double tolerance=TOLERANCE_DEFAULT)
 
DEVICE ALWAYS_INLINE bool tol_eq (const double x, const double y, const double tolerance=TOLERANCE_DEFAULT)
 
DEVICE ALWAYS_INLINE bool tol_le (const double x, const double y, const double tolerance=TOLERANCE_DEFAULT)
 
DEVICE ALWAYS_INLINE bool tol_ge (const double x, const double y, const double tolerance=TOLERANCE_DEFAULT)
 
template<Coords C>
DEVICE ALWAYS_INLINE double decompress_coord (const int8_t *data, const int32_t x_index, const int32_t ic)
 
DEVICE ALWAYS_INLINE int32_t compression_unit_size (const int32_t ic)
 
template<Coords C>
DEVICE ALWAYS_INLINE Point2D conv_4326_900913 (const Point2D point)
 
template<Coords C>
DEVICE ALWAYS_INLINE Point2D conv_4326_utm (const Point2D point, const int32_t utm_srid)
 
template<Coords C>
DEVICE ALWAYS_INLINE Point2D conv_utm_4326 (const Point2D point, const int32_t utm_srid)
 
template<Coords C>
DEVICE ALWAYS_INLINE Point2D transform_point (const Point2D point, const int32_t isr, const int32_t osr)
 
DEVICE ALWAYS_INLINE bool x_and_y_are_dependent (const int32_t isr, const int32_t osr)
 
DEVICE ALWAYS_INLINE Point2D get_point (const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
 
template<Coords C>
DEVICE ALWAYS_INLINE Point2D coord (const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
 
DEVICE ALWAYS_INLINE int32_t compressed_coord (const int8_t *data, const int32_t index)
 
DEVICE ALWAYS_INLINE double distance_point_point_squared (double p1x, double p1y, double p2x, double p2y)
 
DEVICE ALWAYS_INLINE double distance_point_point (double p1x, double p1y, double p2x, double p2y)
 
DEVICE double distance_point_line (double px, double py, double l1x, double l1y, double l2x, double l2y)
 
DEVICE double distance_point_line_squared (double px, double py, double l1x, double l1y, double l2x, double l2y)
 
DEVICE ALWAYS_INLINE bool on_segment (double px, double py, double qx, double qy, double rx, double ry)
 
DEVICE ALWAYS_INLINE int16_t orientation (double px, double py, double qx, double qy, double rx, double ry)
 
DEVICE bool line_intersects_line (double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)
 
DEVICE bool linestring_intersects_line (int8_t *l, int32_t lnum_coords, double l1x, double l1y, double l2x, double l2y, int32_t ic1, int32_t isr1, int32_t osr)
 
DEVICE bool ring_intersects_line (int8_t *ring, int32_t ring_num_coords, double l1x, double l1y, double l2x, double l2y, int32_t ic1, int32_t isr1, int32_t osr)
 
DEVICE bool linestring_intersects_linestring (int8_t *l, int32_t lnum_coords, double l1x, double l1y, double l2x, double l2y, int32_t ic1, int32_t isr1, int32_t osr)
 
DEVICE double distance_line_line (double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)
 
DEVICE double distance_line_line_squared (double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)
 
DEVICE double distance_ring_linestring (int8_t *ring, int32_t ring_num_coords, int8_t *l, int32_t lnum_coords, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
DEVICE double distance_ring_ring (int8_t *ring1, int32_t ring1_num_coords, int8_t *ring2, int32_t ring2_num_coords, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
template<typename T >
DEVICE ALWAYS_INLINEis_left (const T lx0, const T ly0, const T lx1, const T ly1, const T px, const T py)
 
template<typename T >
DEVICE ALWAYS_INLINE bool tol_zero_template (const T x, const T tolerance=TOLERANCE_DEFAULT)
 
template<typename T , EdgeBehavior TEdgeBehavior>
DEVICE ALWAYS_INLINE bool point_in_polygon_winding_number (const int8_t *poly, const int32_t poly_num_coords, const T px, const T py, const int32_t ic1, const int32_t isr1, const int32_t osr)
 
DEVICE ALWAYS_INLINE bool polygon_contains_point (const int8_t *poly, const int32_t poly_num_coords, const double px, const double py, const int32_t ic1, const int32_t isr1, const int32_t osr)
 
DEVICE bool polygon_contains_linestring (int8_t *poly, int32_t poly_num_coords, int8_t *l, int64_t lnum_coords, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
DEVICE ALWAYS_INLINE bool box_contains_point (const double *bounds, const int64_t bounds_size, const double px, const double py)
 
EXTENSION_NOINLINE bool Point_Overlaps_Box (double *bounds, int64_t bounds_size, double px, double py)
 
DEVICE ALWAYS_INLINE bool box_contains_box (double *bounds1, int64_t bounds1_size, double *bounds2, int64_t bounds2_size)
 
DEVICE ALWAYS_INLINE bool box_contains_box_vertex (double *bounds1, int64_t bounds1_size, double *bounds2, int64_t bounds2_size)
 
DEVICE ALWAYS_INLINE bool box_overlaps_box (double *bounds1, int64_t bounds1_size, double *bounds2, int64_t bounds2_size)
 
DEVICE ALWAYS_INLINE bool point_dwithin_box (int8_t *p1, int64_t p1size, int32_t ic1, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
 
DEVICE ALWAYS_INLINE bool box_dwithin_box (double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
 
DEVICE ALWAYS_INLINE CoordData trim_linestring_to_buffered_box (int8_t *l1, int64_t l1size, int32_t ic1, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
 
EXTENSION_NOINLINE double ST_X_Point (int8_t *p, int64_t psize, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Y_Point (int8_t *p, int64_t psize, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_XMin (int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_YMin (int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_XMax (int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_YMax (int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_INLINE double ST_XMin_Bounds (double *bounds, int64_t size, int32_t isr, int32_t osr)
 
EXTENSION_INLINE double ST_YMin_Bounds (double *bounds, int64_t size, int32_t isr, int32_t osr)
 
EXTENSION_INLINE double ST_XMax_Bounds (double *bounds, int64_t size, int32_t isr, int32_t osr)
 
EXTENSION_INLINE double ST_YMax_Bounds (double *bounds, int64_t size, int32_t isr, int32_t osr)
 
DEVICE ALWAYS_INLINE double length_linestring (int8_t *l, int32_t lsize, int32_t ic, int32_t isr, int32_t osr, bool geodesic, bool check_closed)
 
EXTENSION_NOINLINE double ST_Length_LineString (int8_t *coords, int64_t coords_sz, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Length_LineString_Geodesic (int8_t *coords, int64_t coords_sz, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Perimeter_Polygon (int8_t *poly, int32_t polysize, int8_t *poly_ring_sizes, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Perimeter_Polygon_Geodesic (int8_t *poly, int32_t polysize, int8_t *poly_ring_sizes_in, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
 
DEVICE ALWAYS_INLINE double perimeter_multipolygon (int8_t *mpoly_coords, int32_t mpoly_coords_size, int8_t *mpoly_ring_sizes_in, int32_t mpoly_num_rings, int8_t *mpoly_poly_sizes, int32_t mpoly_num_polys, int32_t ic, int32_t isr, int32_t osr, bool geodesic)
 
EXTENSION_NOINLINE double ST_Perimeter_MultiPolygon (int8_t *mpoly_coords, int32_t mpoly_coords_size, int8_t *mpoly_ring_sizes, int32_t mpoly_num_rings, int8_t *mpoly_poly_sizes, int32_t mpoly_num_polys, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Perimeter_MultiPolygon_Geodesic (int8_t *mpoly_coords, int32_t mpoly_coords_size, int8_t *mpoly_ring_sizes, int32_t mpoly_num_rings, int8_t *mpoly_poly_sizes, int32_t mpoly_num_polys, int32_t ic, int32_t isr, int32_t osr)
 
DEVICE ALWAYS_INLINE double area_triangle (double x1, double y1, double x2, double y2, double x3, double y3)
 
DEVICE ALWAYS_INLINE double area_ring (int8_t *ring, int64_t ringsize, int32_t ic, int32_t isr, int32_t osr)
 
DEVICE ALWAYS_INLINE double area_polygon (int8_t *poly_coords, int32_t poly_coords_size, int8_t *poly_ring_sizes_in, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Area_Polygon (int8_t *poly_coords, int32_t poly_coords_size, int8_t *poly_ring_sizes, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Area_MultiPolygon (int8_t *mpoly_coords, int32_t mpoly_coords_size, int8_t *mpoly_ring_sizes, int32_t mpoly_num_rings, int8_t *mpoly_poly_sizes_in, int32_t mpoly_num_polys, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE void ST_Centroid_Point (int8_t *p, int32_t psize, int32_t ic, int32_t isr, int32_t osr, double *point_centroid)
 
DEVICE ALWAYS_INLINE bool centroid_add_segment (double x1, double y1, double x2, double y2, double *length, double *linestring_centroid_sum)
 
DEVICE ALWAYS_INLINE bool centroid_add_linestring (int8_t *l, int64_t lsize, int32_t ic, int32_t isr, int32_t osr, bool closed, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)
 
EXTENSION_NOINLINE void ST_Centroid_LineString (int8_t *coords, int32_t coords_sz, int32_t ic, int32_t isr, int32_t osr, double *linestring_centroid)
 
DEVICE ALWAYS_INLINE bool centroid_add_triangle (double x1, double y1, double x2, double y2, double x3, double y3, double sign, double *total_area2, double *cg3)
 
DEVICE ALWAYS_INLINE bool centroid_add_ring (int8_t *ring, int64_t ringsize, int32_t ic, int32_t isr, int32_t osr, double sign, double *total_area2, double *cg3, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)
 
DEVICE ALWAYS_INLINE bool centroid_add_polygon (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr, double *total_area2, double *cg3, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)
 
EXTENSION_NOINLINE void ST_Centroid_Polygon (int8_t *poly_coords, int32_t poly_coords_size, int32_t *poly_ring_sizes, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr, double *poly_centroid)
 
EXTENSION_NOINLINE void ST_Centroid_MultiPolygon (int8_t *mpoly_coords, int32_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int32_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int32_t mpoly_num_polys, int32_t ic, int32_t isr, int32_t osr, double *mpoly_centroid)
 
EXTENSION_NOINLINE double ST_Distance_Point_Point (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE double ST_Distance_Point_Point_Squared (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE double ST_Distance_Point_Point_Geodesic (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE double ST_Distance_Point_LineString_Geodesic (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE double ST_Distance_LineString_Point_Geodesic (int8_t *l, int64_t lsize, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
DEVICE ALWAYS_INLINE double distance_point_linestring (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, bool check_closed, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Point_ClosedLineString (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Point_LineString (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Point_Polygon (int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Point_MultiPolygon (int8_t *p, int64_t psize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_LineString_Point (int8_t *l, int64_t lsize, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_LineString_LineString (int8_t *l1, int64_t l1size, int8_t *l2, int64_t l2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_LineString_Polygon (int8_t *l, int64_t lsize, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_LineString_MultiPolygon (int8_t *l, int64_t lsize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_Polygon_Point (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_Polygon_LineString (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Polygon_Polygon (int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int8_t *poly2_coords, int64_t poly2_coords_size, int32_t *poly2_ring_sizes, int64_t poly2_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Polygon_MultiPolygon (int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_MultiPolygon_Point (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_MultiPolygon_LineString (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_MultiPolygon_Polygon (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_MultiPolygon_MultiPolygon (int8_t *mpoly1_coords, int64_t mpoly1_coords_size, int32_t *mpoly1_ring_sizes, int64_t mpoly1_num_rings, int32_t *mpoly1_poly_sizes, int64_t mpoly1_num_polys, int8_t *mpoly2_coords, int64_t mpoly2_coords_size, int32_t *mpoly2_ring_sizes, int64_t mpoly2_num_rings, int32_t *mpoly2_poly_sizes, int64_t mpoly2_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE bool ST_DWithin_Point_Point (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Point_Point_Geodesic (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Point_LineString (int8_t *p1, int64_t p1size, int8_t *l2, int64_t l2size, double *l2bounds, int64_t l2bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Point_Polygon (int8_t *p, int64_t psize, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Point_MultiPolygon (int8_t *p, int64_t psize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_LineString_LineString (int8_t *l1, int64_t l1size, double *l1bounds, int64_t l1bounds_size, int8_t *l2, int64_t l2size, double *l2bounds, int64_t l2bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_LineString_Polygon (int8_t *l1, int64_t l1size, double *l1bounds, int64_t l1bounds_size, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_LineString_MultiPolygon (int8_t *l1, int64_t l1size, double *l1bounds, int64_t l1bounds_size, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Polygon_Polygon (int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, double *poly1_bounds, int64_t poly1_bounds_size, int8_t *poly2_coords, int64_t poly2_coords_size, int32_t *poly2_ring_sizes, int64_t poly2_num_rings, double *poly2_bounds, int64_t poly2_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Polygon_MultiPolygon (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_MultiPolygon_MultiPolygon (int8_t *mpoly1_coords, int64_t mpoly1_coords_size, int32_t *mpoly1_ring_sizes, int64_t mpoly1_num_rings, int32_t *mpoly1_poly_sizes, int64_t mpoly1_num_polys, double *mpoly1_bounds, int64_t mpoly1_bounds_size, int8_t *mpoly2_coords, int64_t mpoly2_coords_size, int32_t *mpoly2_ring_sizes, int64_t mpoly2_num_rings, int32_t *mpoly2_poly_sizes, int64_t mpoly2_num_polys, double *mpoly2_bounds, int64_t mpoly2_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
DEVICE double max_distance_point_line (double px, double py, double l1x, double l1y, double l2x, double l2y)
 
DEVICE ALWAYS_INLINE double max_distance_point_linestring (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, bool check_closed)
 
EXTENSION_NOINLINE double ST_MaxDistance_Point_LineString (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE double ST_MaxDistance_LineString_Point (int8_t *l, int64_t lsize, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Point_Point (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Point_LineString (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Point_Polygon (int8_t *p, int64_t psize, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Contains_LineString_Point (int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_LineString_Polygon (int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
template<typename T , EdgeBehavior TEdgeBehavior>
DEVICE ALWAYS_INLINE bool Contains_Polygon_Point_Impl (const int8_t *poly_coords, const int64_t poly_coords_size, const int32_t *poly_ring_sizes, const int64_t poly_num_rings, const double *poly_bounds, const int64_t poly_bounds_size, const int8_t *p, const int64_t psize, const int32_t ic1, const int32_t isr1, const int32_t ic2, const int32_t isr2, const int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Polygon_Point (const int8_t *poly_coords, const int64_t poly_coords_size, const int32_t *poly_ring_sizes, const int64_t poly_num_rings, const double *poly_bounds, const int64_t poly_bounds_size, const int8_t *p, const int64_t psize, const int32_t ic1, const int32_t isr1, const int32_t ic2, const int32_t isr2, const int32_t osr)
 
EXTENSION_NOINLINE bool ST_cContains_Polygon_Point (const int8_t *poly_coords, const int64_t poly_coords_size, const int32_t *poly_ring_sizes, const int64_t poly_num_rings, const double *poly_bounds, const int64_t poly_bounds_size, const int8_t *p, const int64_t psize, const int32_t ic1, const int32_t isr1, const int32_t ic2, const int32_t isr2, const int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Polygon_LineString (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Polygon_Polygon (int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, double *poly1_bounds, int64_t poly1_bounds_size, int8_t *poly2_coords, int64_t poly2_coords_size, int32_t *poly2_ring_sizes, int64_t poly2_num_rings, double *poly2_bounds, int64_t poly2_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
template<typename T , EdgeBehavior TEdgeBehavior>
DEVICE ALWAYS_INLINE bool Contains_MultiPolygon_Point_Impl (const int8_t *mpoly_coords, const int64_t mpoly_coords_size, const int32_t *mpoly_ring_sizes, const int64_t mpoly_num_rings, const int32_t *mpoly_poly_sizes, const int64_t mpoly_num_polys, const double *mpoly_bounds, const int64_t mpoly_bounds_size, const int8_t *p, const int64_t psize, const int32_t ic1, const int32_t isr1, const int32_t ic2, const int32_t isr2, const int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_MultiPolygon_Point (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_cContains_MultiPolygon_Point (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_MultiPolygon_LineString (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_Point_Point (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_Point_LineString (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_Point_Polygon (int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_Point_MultiPolygon (int8_t *p, int64_t psize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_LineString_Point (int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_LineString_Linestring (int8_t *l1, int64_t l1size, double *l1bounds, int64_t l1bounds_size, int8_t *l2, int64_t l2size, double *l2bounds, int64_t l2bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_LineString_Polygon (int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_LineString_MultiPolygon (int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_Polygon_Point (int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_Polygon_LineString (int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_Polygon_Polygon (int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, double *poly1_bounds, int64_t poly1_bounds_size, int8_t *poly2_coords, int64_t poly2_coords_size, int32_t *poly2_ring_sizes, int64_t poly2_num_rings, double *poly2_bounds, int64_t poly2_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_Polygon_MultiPolygon (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_MultiPolygon_Point (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_MultiPolygon_LineString (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_MultiPolygon_Polygon (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_MultiPolygon_MultiPolygon (int8_t *mpoly1_coords, int64_t mpoly1_coords_size, int32_t *mpoly1_ring_sizes, int64_t mpoly1_num_rings, int32_t *mpoly1_poly_sizes, int64_t mpoly1_num_polys, double *mpoly1_bounds, int64_t mpoly1_bounds_size, int8_t *mpoly2_coords, int64_t mpoly2_coords_size, int32_t *mpoly2_ring_sizes, int64_t mpoly2_num_rings, int32_t *mpoly2_poly_sizes, int64_t mpoly2_num_polys, double *mpoly2_bounds, int64_t mpoly2_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE int64_t OmniSci_Geo_PolyBoundsPtr (double *bounds, int64_t size)
 
EXTENSION_INLINE int32_t OmniSci_Geo_PolyRenderGroup (int32_t render_group)
 
EXTENSION_INLINE int64_t MapD_GeoPolyBoundsPtr (double *bounds, int64_t size)
 
EXTENSION_INLINE int32_t MapD_GeoPolyRenderGroup (int32_t render_group)
 
EXTENSION_NOINLINE double convert_meters_to_pixel_width (const double meters, int8_t *p, const int64_t psize, const int32_t ic, const int32_t isr, const int32_t osr, const double min_lon, const double max_lon, const int32_t img_width, const double min_width)
 
EXTENSION_NOINLINE double convert_meters_to_pixel_height (const double meters, int8_t *p, const int64_t psize, const int32_t ic, const int32_t isr, const int32_t osr, const double min_lat, const double max_lat, const int32_t img_height, const double min_height)
 
EXTENSION_NOINLINE bool is_point_in_view (int8_t *p, const int64_t psize, const int32_t ic, const double min_lon, const double max_lon, const double min_lat, const double max_lat)
 
EXTENSION_NOINLINE bool is_point_size_in_view (int8_t *p, const int64_t psize, const int32_t ic, const double meters, const double min_lon, const double max_lon, const double min_lat, const double max_lat)
 

Macro Definition Documentation

#define DEBUG_STMT (   x)

Enumeration Type Documentation

enum EdgeBehavior
strong
Enumerator
kIncludePointOnEdge 
kExcludePointOnEdge 

Definition at line 563 of file ExtensionFunctionsGeo.hpp.

Function Documentation

DEVICE ALWAYS_INLINE double area_polygon ( int8_t *  poly_coords,
int32_t  poly_coords_size,
int8_t *  poly_ring_sizes_in,
int32_t  poly_num_rings,
int32_t  ic,
int32_t  isr,
int32_t  osr 
)

Definition at line 1343 of file ExtensionFunctionsGeo.hpp.

References area_ring(), and compression_unit_size().

Referenced by ST_Area_MultiPolygon(), and ST_Area_Polygon().

1349  {
1350  if (poly_num_rings <= 0) {
1351  return 0.0;
1352  }
1353 
1354  double area = 0.0;
1355  auto ring_coords = poly_coords;
1356  auto poly_ring_sizes = reinterpret_cast<int32_t*>(poly_ring_sizes_in);
1357 
1358  // Add up the areas of all rings.
1359  // External ring is CCW, open - positive area.
1360  // Internal rings (holes) are CW, open - negative areas.
1361  for (auto r = 0; r < poly_num_rings; r++) {
1362  auto ring_coords_size = poly_ring_sizes[r] * 2 * compression_unit_size(ic);
1363  area += area_ring(ring_coords, ring_coords_size, ic, isr, osr);
1364  // Advance to the next ring.
1365  ring_coords += ring_coords_size;
1366  }
1367  return area;
1368 }
DEVICE ALWAYS_INLINE double area_ring(int8_t *ring, int64_t ringsize, int32_t ic, int32_t isr, int32_t osr)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE double area_ring ( int8_t *  ring,
int64_t  ringsize,
int32_t  ic,
int32_t  isr,
int32_t  osr 
)

Definition at line 1320 of file ExtensionFunctionsGeo.hpp.

References area_triangle(), compression_unit_size(), get_point(), and i.

Referenced by area_polygon().

1324  {
1325  auto ring_num_coords = ringsize / compression_unit_size(ic);
1326 
1327  if (ring_num_coords < 6) {
1328  return 0.0;
1329  }
1330 
1331  double area = 0.0;
1332 
1333  Point2D p1 = get_point(ring, 0, ic, isr, osr);
1334  Point2D p2 = get_point(ring, 2, ic, isr, osr);
1335  for (int32_t i = 4; i < ring_num_coords; i += 2) {
1336  Point2D p3 = get_point(ring, i, ic, isr, osr);
1337  area += area_triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
1338  p2 = p3;
1339  }
1340  return area;
1341 }
DEVICE ALWAYS_INLINE double area_triangle(double x1, double y1, double x2, double y2, double x3, double y3)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE double area_triangle ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)

Definition at line 1311 of file ExtensionFunctionsGeo.hpp.

Referenced by area_ring().

1316  {
1317  return (x1 * y2 - x2 * y1 + x3 * y1 - x1 * y3 + x2 * y3 - x3 * y2) / 2.0;
1318 }

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool box_contains_box ( double *  bounds1,
int64_t  bounds1_size,
double *  bounds2,
int64_t  bounds2_size 
)

Definition at line 870 of file ExtensionFunctionsGeo.hpp.

References box_contains_point().

Referenced by ST_Contains_MultiPolygon_LineString(), ST_Contains_Polygon_LineString(), and ST_Contains_Polygon_Polygon().

873  {
874  // TODO: mixed spatial references
875  return (
877  bounds1, bounds1_size, bounds2[0], bounds2[1]) && // box1 <- box2: xmin, ymin
879  bounds1, bounds1_size, bounds2[2], bounds2[3])); // box1 <- box2: xmax, ymax
880 }
DEVICE ALWAYS_INLINE bool box_contains_point(const double *bounds, const int64_t bounds_size, const double px, const double py)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool box_contains_box_vertex ( double *  bounds1,
int64_t  bounds1_size,
double *  bounds2,
int64_t  bounds2_size 
)

Definition at line 882 of file ExtensionFunctionsGeo.hpp.

References box_contains_point().

885  {
886  // TODO: mixed spatial references
887  return (
889  bounds1, bounds1_size, bounds2[0], bounds2[1]) || // box1 <- box2: xmin, ymin
891  bounds1, bounds1_size, bounds2[2], bounds2[3]) || // box1 <- box2: xmax, ymax
893  bounds1, bounds1_size, bounds2[0], bounds2[3]) || // box1 <- box2: xmin, ymax
895  bounds1, bounds1_size, bounds2[2], bounds2[1])); // box1 <- box2: xmax, ymin
896 }
DEVICE ALWAYS_INLINE bool box_contains_point(const double *bounds, const int64_t bounds_size, const double px, const double py)

+ Here is the call graph for this function:

DEVICE ALWAYS_INLINE bool box_contains_point ( const double *  bounds,
const int64_t  bounds_size,
const double  px,
const double  py 
)

Definition at line 853 of file ExtensionFunctionsGeo.hpp.

References tol_ge(), and tol_le().

Referenced by box_contains_box(), box_contains_box_vertex(), Contains_MultiPolygon_Point_Impl(), Contains_Polygon_Point_Impl(), Point_Overlaps_Box(), and ST_Intersects_Point_LineString().

856  {
857  // TODO: mixed spatial references
858  return (tol_ge(px, bounds[0]) && tol_ge(py, bounds[1]) && tol_le(px, bounds[2]) &&
859  tol_le(py, bounds[3]));
860 }
DEVICE ALWAYS_INLINE bool tol_le(const double x, const double y, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE bool tol_ge(const double x, const double y, const double tolerance=TOLERANCE_DEFAULT)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool box_dwithin_box ( double *  bounds1,
int64_t  bounds1_size,
int32_t  isr1,
double *  bounds2,
int64_t  bounds2_size,
int32_t  isr2,
int32_t  osr,
double  distance 
)

Definition at line 938 of file ExtensionFunctionsGeo.hpp.

Referenced by ST_DWithin_LineString_LineString(), ST_DWithin_LineString_MultiPolygon(), ST_DWithin_LineString_Polygon(), ST_DWithin_MultiPolygon_MultiPolygon(), ST_DWithin_Polygon_MultiPolygon(), and ST_DWithin_Polygon_Polygon().

945  {
946  // TODO: tolerance
947 
948  // Bounds come in corresponding input spatial references.
949  // For example, here the first bounding box may come in 4326, second in 900913:
950  // ST_DWithin(ST_Transform(linestring4326, 900913), linestring900913, 10)
951  // Distance is given in osr spatial reference units, in this case 10 meters.
952  // Bounds should be converted to osr before calculations, if isr != osr.
953 
954  // TODO: revise all other functions that process bounds
955 
956  Point2D const lb1 = transform_point<XY>({bounds1[0], bounds1[1]}, isr1, osr);
957  Point2D const rt1 = transform_point<XY>({bounds1[2], bounds1[3]}, isr1, osr);
958  Point2D const lb2 = transform_point<XY>({bounds2[0], bounds2[1]}, isr2, osr);
959  Point2D const rt2 = transform_point<XY>({bounds2[2], bounds2[3]}, isr2, osr);
960  if (
961  // box1 is left of box2: box1.xmax + distance < box2.xmin
962  rt1.x + distance < lb2.x ||
963  // box1 is right of box2: box1.xmin - distance > box2.xmax
964  lb1.x - distance > rt2.x ||
965  // box1 is below box2: box1.ymax + distance < box2.ymin
966  rt1.y + distance < lb2.y ||
967  // box1 is above box2: box1.ymin - distance > box1.ymax
968  lb1.y - distance > rt2.y) {
969  return false;
970  }
971  return true;
972 }

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool box_overlaps_box ( double *  bounds1,
int64_t  bounds1_size,
double *  bounds2,
int64_t  bounds2_size 
)

Definition at line 898 of file ExtensionFunctionsGeo.hpp.

Referenced by ST_Intersects_LineString_Linestring(), ST_Intersects_LineString_MultiPolygon(), ST_Intersects_LineString_Polygon(), ST_Intersects_MultiPolygon_MultiPolygon(), ST_Intersects_Polygon_MultiPolygon(), and ST_Intersects_Polygon_Polygon().

901  {
902  // TODO: tolerance
903  // TODO: mixed spatial references
904  if (bounds1[2] < bounds2[0] || // box1 is left of box2: box1.xmax < box2.xmin
905  bounds1[0] > bounds2[2] || // box1 is right of box2: box1.xmin > box2.xmax
906  bounds1[3] < bounds2[1] || // box1 is below box2: box1.ymax < box2.ymin
907  bounds1[1] > bounds2[3]) { // box1 is above box2: box1.ymin > box1.ymax
908  return false;
909  }
910  return true;
911 }

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool centroid_add_linestring ( int8_t *  l,
int64_t  lsize,
int32_t  ic,
int32_t  isr,
int32_t  osr,
bool  closed,
double *  total_length,
double *  linestring_centroid_sum,
int64_t *  num_points,
double *  point_centroid_sum 
)

Definition at line 1469 of file ExtensionFunctionsGeo.hpp.

References centroid_add_segment(), compression_unit_size(), get_point(), and i.

Referenced by centroid_add_ring(), and ST_Centroid_LineString().

1478  {
1479  auto l_num_coords = lsize / compression_unit_size(ic);
1480  double length = 0.0;
1481  Point2D const l0 = get_point(l, 0, ic, isr, osr);
1482  Point2D l2 = l0;
1483  for (int32_t i = 2; i < l_num_coords; i += 2) {
1484  Point2D const l1 = l2;
1485  l2 = get_point(l, i, ic, isr, osr);
1486  centroid_add_segment(l1.x, l1.y, l2.x, l2.y, &length, linestring_centroid_sum);
1487  }
1488  if (l_num_coords > 4 && closed) {
1489  // Also add the closing segment between the last and the first points
1490  centroid_add_segment(l2.x, l2.y, l0.x, l0.y, &length, linestring_centroid_sum);
1491  }
1492  *total_length += length;
1493  if (length == 0.0 && l_num_coords > 0) {
1494  *num_points += 1;
1495  point_centroid_sum[0] += l0.x;
1496  point_centroid_sum[1] += l0.y;
1497  }
1498  return true;
1499 }
DEVICE ALWAYS_INLINE bool centroid_add_segment(double x1, double y1, double x2, double y2, double *length, double *linestring_centroid_sum)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool centroid_add_polygon ( int8_t *  poly_coords,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
int32_t  ic,
int32_t  isr,
int32_t  osr,
double *  total_area2,
double *  cg3,
double *  total_length,
double *  linestring_centroid_sum,
int64_t *  num_points,
double *  point_centroid_sum 
)

Definition at line 1588 of file ExtensionFunctionsGeo.hpp.

References centroid_add_ring(), and compression_unit_size().

Referenced by ST_Centroid_MultiPolygon(), and ST_Centroid_Polygon().

1600  {
1601  if (poly_num_rings <= 0) {
1602  return false;
1603  }
1604 
1605  auto ring_coords = poly_coords;
1606 
1607  for (auto r = 0; r < poly_num_rings; r++) {
1608  auto ring_coords_size = poly_ring_sizes[r] * 2 * compression_unit_size(ic);
1609  // Shape - positive area, holes - negative areas
1610  double sign = (r == 0) ? 1.0 : -1.0;
1611  centroid_add_ring(ring_coords,
1612  ring_coords_size,
1613  ic,
1614  isr,
1615  osr,
1616  sign,
1617  total_area2,
1618  cg3,
1619  total_length,
1620  linestring_centroid_sum,
1621  num_points,
1622  point_centroid_sum);
1623  // Advance to the next ring.
1624  ring_coords += ring_coords_size;
1625  }
1626  return true;
1627 }
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE bool centroid_add_ring(int8_t *ring, int64_t ringsize, int32_t ic, int32_t isr, int32_t osr, double sign, double *total_area2, double *cg3, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool centroid_add_ring ( int8_t *  ring,
int64_t  ringsize,
int32_t  ic,
int32_t  isr,
int32_t  osr,
double  sign,
double *  total_area2,
double *  cg3,
double *  total_length,
double *  linestring_centroid_sum,
int64_t *  num_points,
double *  point_centroid_sum 
)

Definition at line 1549 of file ExtensionFunctionsGeo.hpp.

References centroid_add_linestring(), centroid_add_triangle(), compression_unit_size(), get_point(), and i.

Referenced by centroid_add_polygon().

1560  {
1561  auto ring_num_coords = ringsize / compression_unit_size(ic);
1562 
1563  if (ring_num_coords < 6) {
1564  return false;
1565  }
1566 
1567  Point2D p1 = get_point(ring, 0, ic, isr, osr);
1568  Point2D p2 = get_point(ring, 2, ic, isr, osr);
1569  for (int32_t i = 4; i < ring_num_coords; i += 2) {
1570  Point2D p3 = get_point(ring, i, ic, isr, osr);
1571  centroid_add_triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, sign, total_area2, cg3);
1572  p2 = p3;
1573  }
1574 
1576  ringsize,
1577  ic,
1578  isr,
1579  osr,
1580  true, // closed
1581  total_length,
1582  linestring_centroid_sum,
1583  num_points,
1584  point_centroid_sum);
1585  return true;
1586 }
DEVICE ALWAYS_INLINE bool centroid_add_triangle(double x1, double y1, double x2, double y2, double x3, double y3, double sign, double *total_area2, double *cg3)
DEVICE ALWAYS_INLINE bool centroid_add_linestring(int8_t *l, int64_t lsize, int32_t ic, int32_t isr, int32_t osr, bool closed, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool centroid_add_segment ( double  x1,
double  y1,
double  x2,
double  y2,
double *  length,
double *  linestring_centroid_sum 
)

Definition at line 1454 of file ExtensionFunctionsGeo.hpp.

References distance_point_point().

Referenced by centroid_add_linestring().

1459  {
1460  double ldist = distance_point_point(x1, y1, x2, y2);
1461  *length += ldist;
1462  double segment_midpoint_x = (x1 + x2) / 2.0;
1463  double segment_midpoint_y = (y1 + y2) / 2.0;
1464  linestring_centroid_sum[0] += ldist * segment_midpoint_x;
1465  linestring_centroid_sum[1] += ldist * segment_midpoint_y;
1466  return true;
1467 }
DEVICE ALWAYS_INLINE double distance_point_point(double p1x, double p1y, double p2x, double p2y)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool centroid_add_triangle ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3,
double  sign,
double *  total_area2,
double *  cg3 
)

Definition at line 1531 of file ExtensionFunctionsGeo.hpp.

Referenced by centroid_add_ring().

1539  {
1540  double cx = x1 + x2 + x3;
1541  double cy = y1 + y2 + y3;
1542  double area2 = x1 * y2 - x2 * y1 + x3 * y1 - x1 * y3 + x2 * y3 - x3 * y2;
1543  cg3[0] += sign * area2 * cx;
1544  cg3[1] += sign * area2 * cy;
1545  *total_area2 += sign * area2;
1546  return true;
1547 }

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE int32_t compressed_coord ( const int8_t *  data,
const int32_t  index 
)

Definition at line 218 of file ExtensionFunctionsGeo.hpp.

Referenced by Geospatial::compress_latitude_coord_geoint32(), Geospatial::compress_longitude_coord_geoint32(), Contains_Polygon_Point_Impl(), decompress_coord(), and point_in_polygon_winding_number().

218  {
219  const auto compressed_coords = reinterpret_cast<const int32_t*>(data);
220  return compressed_coords[index];
221 }

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE int32_t compression_unit_size ( const int32_t  ic)
template<typename T , EdgeBehavior TEdgeBehavior>
DEVICE ALWAYS_INLINE bool Contains_MultiPolygon_Point_Impl ( const int8_t *  mpoly_coords,
const int64_t  mpoly_coords_size,
const int32_t *  mpoly_ring_sizes,
const int64_t  mpoly_num_rings,
const int32_t *  mpoly_poly_sizes,
const int64_t  mpoly_num_polys,
const double *  mpoly_bounds,
const int64_t  mpoly_bounds_size,
const int8_t *  p,
const int64_t  psize,
const int32_t  ic1,
const int32_t  isr1,
const int32_t  ic2,
const int32_t  isr2,
const int32_t  osr 
)

Definition at line 3508 of file ExtensionFunctionsGeo.hpp.

References box_contains_point(), compression_unit_size(), and get_point().

3523  {
3524  if (mpoly_num_polys <= 0) {
3525  return false;
3526  }
3527 
3528  // TODO: mpoly_bounds could contain individual bounding boxes too:
3529  // first two points - box for the entire multipolygon, then a pair for each polygon
3530  if (mpoly_bounds) {
3531  Point2D const pt = get_point(p, 0, ic2, isr2, osr);
3532  if (!box_contains_point(mpoly_bounds, mpoly_bounds_size, pt.x, pt.y)) {
3533  return false;
3534  }
3535  }
3536 
3537  // Set specific poly pointers as we move through the coords/ringsizes/polyrings
3538  // arrays.
3539  auto next_poly_coords = mpoly_coords;
3540  auto next_poly_ring_sizes = mpoly_ring_sizes;
3541 
3542  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
3543  const auto poly_coords = next_poly_coords;
3544  const auto poly_ring_sizes = next_poly_ring_sizes;
3545  const auto poly_num_rings = mpoly_poly_sizes[poly];
3546  // Count number of coords in all of poly's rings, advance ring size pointer.
3547  int32_t poly_num_coords = 0;
3548  for (auto ring = 0; ring < poly_num_rings; ring++) {
3549  poly_num_coords += 2 * *next_poly_ring_sizes++;
3550  }
3551  const auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
3552  next_poly_coords += poly_coords_size;
3553  // TODO: pass individual bounding boxes for each polygon
3554  if (Contains_Polygon_Point_Impl<T, TEdgeBehavior>(poly_coords,
3555  poly_coords_size,
3556  poly_ring_sizes,
3557  poly_num_rings,
3558  nullptr,
3559  0,
3560  p,
3561  psize,
3562  ic1,
3563  isr1,
3564  ic2,
3565  isr2,
3566  osr)) {
3567  return true;
3568  }
3569  }
3570 
3571  return false;
3572 }
DEVICE ALWAYS_INLINE bool box_contains_point(const double *bounds, const int64_t bounds_size, const double px, const double py)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

template<typename T , EdgeBehavior TEdgeBehavior>
DEVICE ALWAYS_INLINE bool Contains_Polygon_Point_Impl ( const int8_t *  poly_coords,
const int64_t  poly_coords_size,
const int32_t *  poly_ring_sizes,
const int64_t  poly_num_rings,
const double *  poly_bounds,
const int64_t  poly_bounds_size,
const int8_t *  p,
const int64_t  psize,
const int32_t  ic1,
const int32_t  isr1,
const int32_t  ic2,
const int32_t  isr2,
const int32_t  osr 
)

Definition at line 3295 of file ExtensionFunctionsGeo.hpp.

References box_contains_point(), compressed_coord(), compression_unit_size(), DEBUG_STMT, get_point(), and omnisci.dtypes::T.

3307  {
3308  if (poly_bounds) {
3309  // TODO: codegen
3310  Point2D const pt = get_point(p, 0, ic2, isr2, osr);
3311  if (!box_contains_point(poly_bounds, poly_bounds_size, pt.x, pt.y)) {
3312  DEBUG_STMT(printf("Bounding box does not contain point, exiting.\n"));
3313  return false;
3314  }
3315  }
3316 
3317  auto get_x_coord = [=]() -> T {
3318  if constexpr (std::is_floating_point<T>::value) {
3319  return get_point(p, 0, ic2, isr2, osr).x;
3320  } else {
3321  return compressed_coord(p, 0);
3322  }
3323  return T{}; // https://stackoverflow.com/a/64561686/2700898
3324  };
3325 
3326  auto get_y_coord = [=]() -> T {
3327  if constexpr (std::is_floating_point<T>::value) {
3328  return get_point(p, 0, ic2, isr2, osr).y;
3329  } else {
3330  return compressed_coord(p, 1);
3331  }
3332  return T{}; // https://stackoverflow.com/a/64561686/2700898
3333  };
3334 
3335  const T px = get_x_coord();
3336  const T py = get_y_coord();
3337  DEBUG_STMT(printf("pt: %f, %f\n", (double)px, (double)py));
3338 
3339  const auto poly_num_coords = poly_coords_size / compression_unit_size(ic1);
3340  auto exterior_ring_num_coords =
3341  poly_num_rings > 0 ? poly_ring_sizes[0] * 2 : poly_num_coords;
3342 
3343  auto poly = poly_coords;
3344  if (point_in_polygon_winding_number<T, TEdgeBehavior>(
3345  poly, exterior_ring_num_coords, px, py, ic1, isr1, osr)) {
3346  // Inside exterior ring
3347  poly += exterior_ring_num_coords * compression_unit_size(ic1);
3348  // Check that none of the polygon's holes contain that point
3349  for (auto r = 1; r < poly_num_rings; r++) {
3350  const int64_t interior_ring_num_coords = poly_ring_sizes[r] * 2;
3351  if (point_in_polygon_winding_number<T, TEdgeBehavior>(
3352  poly, interior_ring_num_coords, px, py, ic1, isr1, osr)) {
3353  return false;
3354  }
3355  poly += interior_ring_num_coords * compression_unit_size(ic1);
3356  }
3357  return true;
3358  }
3359  return false;
3360 }
DEVICE ALWAYS_INLINE int32_t compressed_coord(const int8_t *data, const int32_t index)
#define DEBUG_STMT(x)
DEVICE ALWAYS_INLINE bool box_contains_point(const double *bounds, const int64_t bounds_size, const double px, const double py)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

template<Coords C>
DEVICE ALWAYS_INLINE Point2D conv_4326_900913 ( const Point2D  point)

Definition at line 105 of file ExtensionFunctionsGeo.hpp.

References conv_4326_900913_x(), conv_4326_900913_y(), anonymous_namespace{ExtensionFunctionsGeo.hpp}::X, and anonymous_namespace{ExtensionFunctionsGeo.hpp}::Y.

105  {
106  Point2D retval;
107  if constexpr (static_cast<bool>(C & Coords::X)) {
108  retval.x = conv_4326_900913_x(point.x);
109  }
110  if constexpr (static_cast<bool>(C & Coords::Y)) {
111  retval.y = conv_4326_900913_y(point.y);
112  }
113  return retval;
114 }
EXTENSION_NOINLINE double conv_4326_900913_y(const double y)
EXTENSION_NOINLINE double conv_4326_900913_x(const double x)

+ Here is the call graph for this function:

template<Coords C>
DEVICE ALWAYS_INLINE Point2D conv_4326_utm ( const Point2D  point,
const int32_t  utm_srid 
)

Definition at line 117 of file ExtensionFunctionsGeo.hpp.

References Transform4326ToUTM::calculateX(), Transform4326ToUTM::calculateY(), anonymous_namespace{ExtensionFunctionsGeo.hpp}::X, and anonymous_namespace{ExtensionFunctionsGeo.hpp}::Y.

117  {
118  Point2D retval;
119  Transform4326ToUTM const utm(utm_srid, point.x, point.y);
120  if constexpr (static_cast<bool>(C & Coords::X)) {
121  retval.x = utm.calculateX();
122  }
123  if constexpr (static_cast<bool>(C & Coords::Y)) {
124  retval.y = utm.calculateY();
125  }
126  return retval;
127 }

+ Here is the call graph for this function:

template<Coords C>
DEVICE ALWAYS_INLINE Point2D conv_utm_4326 ( const Point2D  point,
const int32_t  utm_srid 
)

Definition at line 130 of file ExtensionFunctionsGeo.hpp.

References TransformUTMTo4326::calculateX(), TransformUTMTo4326::calculateY(), anonymous_namespace{ExtensionFunctionsGeo.hpp}::X, and anonymous_namespace{ExtensionFunctionsGeo.hpp}::Y.

130  {
131  Point2D retval;
132  TransformUTMTo4326 const wgs84(utm_srid, point.x, point.y);
133  if constexpr (static_cast<bool>(C & Coords::X)) {
134  retval.x = wgs84.calculateX();
135  }
136  if constexpr (static_cast<bool>(C & Coords::Y)) {
137  retval.y = wgs84.calculateY();
138  }
139  return retval;
140 }

+ Here is the call graph for this function:

EXTENSION_NOINLINE double convert_meters_to_pixel_height ( const double  meters,
int8_t *  p,
const int64_t  psize,
const int32_t  ic,
const int32_t  isr,
const int32_t  osr,
const double  min_lat,
const double  max_lat,
const int32_t  img_height,
const double  min_height 
)

Definition at line 4312 of file ExtensionFunctionsGeo.hpp.

Referenced by com.mapd.calcite.parser.MapDSqlOperatorTable::addUDF().

4321  {
4322  const double const1 = 0.017453292519943295769236907684886;
4323  const double const2 = 6372797.560856;
4324  const auto lat = decompress_coord<Y>(p, 0, ic);
4325  const double latdiff = meters / (const1 * const2);
4326  const double newlat =
4327  (lat < 0) ? lat + latdiff : lat - latdiff; // assumes a lat range of [-90, 90]
4328  double t1 = transform_point<Y>({{}, lat}, isr, osr).y;
4329  double t2 = transform_point<Y>({{}, newlat}, isr, osr).y;
4330  const double min_domain_y = transform_point<Y>({{}, min_lat}, isr, osr).y;
4331  const double max_domain_y = transform_point<Y>({{}, max_lat}, isr, osr).y;
4332  const double domain_diff = max_domain_y - min_domain_y;
4333  t1 = ((t1 - min_domain_y) / domain_diff) * static_cast<double>(img_height);
4334  t2 = ((t2 - min_domain_y) / domain_diff) * static_cast<double>(img_height);
4335 
4336  // TODO(croot): need to account for edge cases, such as getting close to the poles.
4337  const double sz = fabs(t1 - t2);
4338  return (sz < min_height ? min_height : sz);
4339 }

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double convert_meters_to_pixel_width ( const double  meters,
int8_t *  p,
const int64_t  psize,
const int32_t  ic,
const int32_t  isr,
const int32_t  osr,
const double  min_lon,
const double  max_lon,
const int32_t  img_width,
const double  min_width 
)

Definition at line 4280 of file ExtensionFunctionsGeo.hpp.

Referenced by com.mapd.calcite.parser.MapDSqlOperatorTable::addUDF().

4289  {
4290  const double const1 = 0.017453292519943295769236907684886;
4291  const double const2 = 6372797.560856;
4292  const auto lon = decompress_coord<X>(p, 0, ic);
4293  const auto lat = decompress_coord<Y>(p, 0, ic);
4294  double t1 = sinf(meters / (2.0 * const2));
4295  double t2 = cosf(const1 * lat);
4296  const double newlon = lon - (2.0 * asinf(t1 / t2)) / const1;
4297  t1 = transform_point<X>({lon, {}}, isr, osr).x;
4298  t2 = transform_point<X>({newlon, {}}, isr, osr).x;
4299  const double min_domain_x = transform_point<X>({min_lon, {}}, isr, osr).x;
4300  const double max_domain_x = transform_point<X>({max_lon, {}}, isr, osr).x;
4301  const double domain_diff = max_domain_x - min_domain_x;
4302  t1 = ((t1 - min_domain_x) / domain_diff) * static_cast<double>(img_width);
4303  t2 = ((t2 - min_domain_x) / domain_diff) * static_cast<double>(img_width);
4304 
4305  // TODO(croot): need to account for edge cases, such as getting close to the poles.
4306  const double sz = fabs(t1 - t2);
4307  return (sz < min_width ? min_width : sz);
4308 }

+ Here is the caller graph for this function:

template<Coords C>
DEVICE ALWAYS_INLINE Point2D coord ( const int8_t *  data,
const int32_t  x_index,
const int32_t  ic,
const int32_t  isr,
const int32_t  osr 
)

Definition at line 197 of file ExtensionFunctionsGeo.hpp.

References anonymous_namespace{ExtensionFunctionsGeo.hpp}::X, x_and_y_are_dependent(), and anonymous_namespace{ExtensionFunctionsGeo.hpp}::Y.

Referenced by Geospatial::compress_coords().

201  {
202  Point2D decompressed;
203  static_assert(C == Coords::X || C == Coords::Y, "Use get_point() instead of XY.");
204  if (x_and_y_are_dependent(isr, osr)) {
205  decompressed = {decompress_coord<X>(data, x_index, ic),
206  decompress_coord<Y>(data, x_index, ic)};
207  } else {
208  if constexpr (C == Coords::X) {
209  decompressed.x = decompress_coord<X>(data, x_index, ic);
210  } else {
211  decompressed.y = decompress_coord<Y>(data, x_index, ic);
212  }
213  }
214  return transform_point<C>(decompressed, isr, osr);
215 }
DEVICE ALWAYS_INLINE bool x_and_y_are_dependent(const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<Coords C>
DEVICE ALWAYS_INLINE double decompress_coord ( const int8_t *  data,
const int32_t  x_index,
const int32_t  ic 
)

Definition at line 79 of file ExtensionFunctionsGeo.hpp.

References compressed_coord(), COMPRESSION_GEOINT32, Geospatial::decompress_latitude_coord_geoint32(), Geospatial::decompress_longitude_coord_geoint32(), anonymous_namespace{ExtensionFunctionsGeo.hpp}::X, and anonymous_namespace{ExtensionFunctionsGeo.hpp}::Y.

81  {
82  static_assert(C == Coords::X || C == Coords::Y);
83  const int32_t adjusted_index = x_index + (C == Coords::Y);
84  if (ic == COMPRESSION_GEOINT32) {
85  auto compressed_coords = reinterpret_cast<const int32_t*>(data);
86  auto compressed_coord = compressed_coords[adjusted_index];
87  if constexpr (C == Coords::X) {
89  } else {
91  }
92  }
93  auto double_coords = reinterpret_cast<const double*>(data);
94  return double_coords[adjusted_index];
95 }
DEVICE double decompress_latitude_coord_geoint32(const int32_t compressed)
DEVICE ALWAYS_INLINE int32_t compressed_coord(const int8_t *data, const int32_t index)
DEVICE double decompress_longitude_coord_geoint32(const int32_t compressed)
#define COMPRESSION_GEOINT32

+ Here is the call graph for this function:

DEVICE double distance_line_line ( double  l11x,
double  l11y,
double  l12x,
double  l12y,
double  l21x,
double  l21y,
double  l22x,
double  l22y 
)

Definition at line 433 of file ExtensionFunctionsGeo.hpp.

References distance_point_line(), and line_intersects_line().

Referenced by distance_ring_linestring(), distance_ring_ring(), and ST_Distance_LineString_LineString().

440  {
441  if (line_intersects_line(l11x, l11y, l12x, l12y, l21x, l21y, l22x, l22y)) {
442  return 0.0;
443  }
444  double dist12 = fmin(distance_point_line(l11x, l11y, l21x, l21y, l22x, l22y),
445  distance_point_line(l12x, l12y, l21x, l21y, l22x, l22y));
446  double dist21 = fmin(distance_point_line(l21x, l21y, l11x, l11y, l12x, l12y),
447  distance_point_line(l22x, l22y, l11x, l11y, l12x, l12y));
448  return fmin(dist12, dist21);
449 }
DEVICE double distance_point_line(double px, double py, double l1x, double l1y, double l2x, double l2y)
DEVICE bool line_intersects_line(double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE double distance_line_line_squared ( double  l11x,
double  l11y,
double  l12x,
double  l12y,
double  l21x,
double  l21y,
double  l22x,
double  l22y 
)

Definition at line 453 of file ExtensionFunctionsGeo.hpp.

References distance_point_line_squared(), and line_intersects_line().

460  {
461  if (line_intersects_line(l11x, l11y, l12x, l12y, l21x, l21y, l22x, l22y)) {
462  return 0.0;
463  }
464  double dist12 = fmin(distance_point_line_squared(l11x, l11y, l21x, l21y, l22x, l22y),
465  distance_point_line_squared(l12x, l12y, l21x, l21y, l22x, l22y));
466  double dist21 = fmin(distance_point_line_squared(l21x, l21y, l11x, l11y, l12x, l12y),
467  distance_point_line_squared(l22x, l22y, l11x, l11y, l12x, l12y));
468  return fmin(dist12, dist21);
469 }
DEVICE bool line_intersects_line(double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)
DEVICE double distance_point_line_squared(double px, double py, double l1x, double l1y, double l2x, double l2y)

+ Here is the call graph for this function:

DEVICE double distance_point_line ( double  px,
double  py,
double  l1x,
double  l1y,
double  l2x,
double  l2y 
)

Definition at line 250 of file ExtensionFunctionsGeo.hpp.

References distance_point_point(), and tol_zero().

Referenced by distance_line_line(), distance_point_linestring(), and polygon_contains_point().

255  {
256  double length = distance_point_point(l1x, l1y, l2x, l2y);
257  if (tol_zero(length)) {
258  return distance_point_point(px, py, l1x, l1y);
259  }
260 
261  // Find projection of point P onto the line segment AB:
262  // Line containing that segment: A + k * (B - A)
263  // Projection of point P onto the line touches it at
264  // k = dot(P-A,B-A) / length^2
265  // AB segment is represented by k = [0,1]
266  // Clamping k to [0,1] will give the shortest distance from P to AB segment
267  double dotprod = (px - l1x) * (l2x - l1x) + (py - l1y) * (l2y - l1y);
268  double k = dotprod / (length * length);
269  k = fmax(0.0, fmin(1.0, k));
270  double projx = l1x + k * (l2x - l1x);
271  double projy = l1y + k * (l2y - l1y);
272  return distance_point_point(px, py, projx, projy);
273 }
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE double distance_point_point(double p1x, double p1y, double p2x, double p2y)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE double distance_point_line_squared ( double  px,
double  py,
double  l1x,
double  l1y,
double  l2x,
double  l2y 
)

Definition at line 277 of file ExtensionFunctionsGeo.hpp.

References distance_point_point_squared(), tol_zero(), and TOLERANCE_DEFAULT_SQUARED.

Referenced by distance_line_line_squared().

282  {
283  double length = distance_point_point_squared(l1x, l1y, l2x, l2y);
284  if (tol_zero(length, TOLERANCE_DEFAULT_SQUARED)) {
285  return distance_point_point_squared(px, py, l1x, l1y);
286  }
287 
288  // Find projection of point P onto the line segment AB:
289  // Line containing that segment: A + k * (B - A)
290  // Projection of point P onto the line touches it at
291  // k = dot(P-A,B-A) / length^2
292  // AB segment is represented by k = [0,1]
293  // Clamping k to [0,1] will give the shortest distance from P to AB segment
294  double dotprod = (px - l1x) * (l2x - l1x) + (py - l1y) * (l2y - l1y);
295  double k = dotprod / (length * length);
296  k = fmax(0.0, fmin(1.0, k));
297  double projx = l1x + k * (l2x - l1x);
298  double projy = l1y + k * (l2y - l1y);
299  return distance_point_point_squared(px, py, projx, projy);
300 }
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE double distance_point_point_squared(double p1x, double p1y, double p2x, double p2y)
#define TOLERANCE_DEFAULT_SQUARED

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE double distance_point_linestring ( int8_t *  p,
int64_t  psize,
int8_t *  l,
int64_t  lsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
bool  check_closed,
double  threshold 
)

Definition at line 1833 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), distance_point_line(), get_point(), and i.

Referenced by ST_Distance_Point_ClosedLineString(), and ST_Distance_Point_LineString().

1843  {
1844  Point2D pt = get_point(p, 0, ic1, isr1, osr);
1845 
1846  auto l_num_coords = lsize / compression_unit_size(ic2);
1847 
1848  Point2D l1 = get_point(l, 0, ic2, isr2, osr);
1849  Point2D l2 = get_point(l, 2, ic2, isr2, osr);
1850 
1851  double dist = distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
1852  for (int32_t i = 4; i < l_num_coords; i += 2) {
1853  l1 = l2; // advance one point
1854  l2 = get_point(l, i, ic2, isr2, osr);
1855  double ldist = distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
1856  if (dist > ldist) {
1857  dist = ldist;
1858  }
1859  if (dist <= threshold) {
1860  return dist;
1861  }
1862  }
1863  if (l_num_coords > 4 && check_closed) {
1864  // Also check distance to the closing edge between the first and the last points
1865  l1 = get_point(l, 0, ic2, isr2, osr);
1866  double ldist = distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
1867  if (dist > ldist) {
1868  dist = ldist;
1869  }
1870  }
1871  return dist;
1872 }
DEVICE double distance_point_line(double px, double py, double l1x, double l1y, double l2x, double l2y)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE double distance_point_point ( double  p1x,
double  p1y,
double  p2x,
double  p2y 
)

Definition at line 240 of file ExtensionFunctionsGeo.hpp.

References distance_point_point_squared().

Referenced by centroid_add_segment(), distance_point_line(), length_linestring(), max_distance_point_line(), and ST_Distance_Point_Point().

243  {
244  auto d2 = distance_point_point_squared(p1x, p1y, p2x, p2y);
245  return sqrt(d2);
246 }
DEVICE ALWAYS_INLINE double distance_point_point_squared(double p1x, double p1y, double p2x, double p2y)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE double distance_point_point_squared ( double  p1x,
double  p1y,
double  p2x,
double  p2y 
)

Definition at line 224 of file ExtensionFunctionsGeo.hpp.

References tol_zero(), and TOLERANCE_DEFAULT_SQUARED.

Referenced by distance_point_line_squared(), distance_point_point(), and ST_Distance_Point_Point_Squared().

227  {
228  auto x = p1x - p2x;
229  auto y = p1y - p2y;
230  auto x2 = x * x;
231  auto y2 = y * y;
232  auto d2 = x2 + y2;
234  return 0.0;
235  }
236  return d2;
237 }
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
#define TOLERANCE_DEFAULT_SQUARED

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE double distance_ring_linestring ( int8_t *  ring,
int32_t  ring_num_coords,
int8_t *  l,
int32_t  lnum_coords,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 472 of file ExtensionFunctionsGeo.hpp.

References distance_line_line(), get_point(), i, and tol_zero().

Referenced by ST_Distance_LineString_Polygon().

481  {
482  double min_distance = 0.0;
483 
484  Point2D re1 = get_point(ring, ring_num_coords - 2, ic1, isr1, osr);
485  for (auto i = 0; i < ring_num_coords; i += 2) {
486  Point2D re2 = get_point(ring, i, ic1, isr1, osr);
487  Point2D le1 = get_point(l, 0, ic2, isr2, osr);
488  for (auto j = 2; j < lnum_coords; j += 2) {
489  Point2D le2 = get_point(l, j, ic2, isr2, osr);
490  auto distance =
491  distance_line_line(re1.x, re1.y, re2.x, re2.y, le1.x, le1.y, le2.x, le2.y);
492  if ((i == 0 && j == 2) || min_distance > distance) {
493  min_distance = distance;
494  if (tol_zero(min_distance)) {
495  return 0.0;
496  }
497  if (min_distance <= threshold) {
498  return min_distance;
499  }
500  }
501  le1 = le2;
502  }
503  re1 = re2;
504  }
505  return min_distance;
506 }
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE double distance_line_line(double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE double distance_ring_ring ( int8_t *  ring1,
int32_t  ring1_num_coords,
int8_t *  ring2,
int32_t  ring2_num_coords,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 509 of file ExtensionFunctionsGeo.hpp.

References distance_line_line(), get_point(), i, and tol_zero().

Referenced by ST_Distance_Polygon_Polygon().

518  {
519  double min_distance = 0.0;
520  Point2D e11 = get_point(ring1, ring1_num_coords - 2, ic1, isr1, osr);
521  for (auto i = 0; i < ring1_num_coords; i += 2) {
522  Point2D e12 = get_point(ring1, i, ic1, isr1, osr);
523  Point2D e21 = get_point(ring2, ring2_num_coords - 2, ic2, isr2, osr);
524  for (auto j = 0; j < ring2_num_coords; j += 2) {
525  Point2D e22 = get_point(ring2, j, ic2, isr2, osr);
526  auto distance =
527  distance_line_line(e11.x, e11.y, e12.x, e12.y, e21.x, e21.y, e22.x, e22.y);
528  if ((i == 0 && j == 0) || min_distance > distance) {
529  min_distance = distance;
530  if (tol_zero(min_distance)) {
531  return 0.0;
532  }
533  if (min_distance <= threshold) {
534  return min_distance;
535  }
536  }
537  e21 = e22;
538  }
539  e11 = e12;
540  }
541  return min_distance;
542 }
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE double distance_line_line(double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
DEVICE ALWAYS_INLINE T is_left ( const lx0,
const ly0,
const lx1,
const ly1,
const px,
const py 
)

Tests if a point is left, on, or to the right of a 2D line

Returns
>0 if p is left of l, 0 if p is on l, and < 0 if p is right of l

Definition at line 550 of file ExtensionFunctionsGeo.hpp.

Referenced by point_in_polygon_winding_number().

550  {
551  return ((lx1 - lx0) * (py - ly0) - (px - lx0) * (ly1 - ly0));
552 }

+ Here is the caller graph for this function:

EXTENSION_NOINLINE bool is_point_in_view ( int8_t *  p,
const int64_t  psize,
const int32_t  ic,
const double  min_lon,
const double  max_lon,
const double  min_lat,
const double  max_lat 
)

Definition at line 4341 of file ExtensionFunctionsGeo.hpp.

Referenced by com.mapd.calcite.parser.MapDSqlOperatorTable::addUDF().

4347  {
4348  const auto lon = decompress_coord<X>(p, 0, ic);
4349  const auto lat = decompress_coord<Y>(p, 0, ic);
4350  return !(lon < min_lon || lon > max_lon || lat < min_lat || lat > max_lat);
4351 }

+ Here is the caller graph for this function:

EXTENSION_NOINLINE bool is_point_size_in_view ( int8_t *  p,
const int64_t  psize,
const int32_t  ic,
const double  meters,
const double  min_lon,
const double  max_lon,
const double  min_lat,
const double  max_lat 
)

Definition at line 4353 of file ExtensionFunctionsGeo.hpp.

Referenced by com.mapd.calcite.parser.MapDSqlOperatorTable::addUDF().

4360  {
4361  const double const1 = 0.017453292519943295769236907684886;
4362  const double const2 = 6372797.560856;
4363  const auto lon = decompress_coord<X>(p, 0, ic);
4364  const auto lat = decompress_coord<Y>(p, 0, ic);
4365  const double latdiff = meters / (const1 * const2);
4366  const double t1 = sinf(meters / (2.0 * const2));
4367  const double t2 = cosf(const1 * lat);
4368  const double londiff = (2.0 * asinf(t1 / t2)) / const1;
4369  return !(lon + londiff < min_lon || lon - londiff > max_lon ||
4370  lat + latdiff < min_lat || lat - latdiff > max_lat);
4371 }

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE double length_linestring ( int8_t *  l,
int32_t  lsize,
int32_t  ic,
int32_t  isr,
int32_t  osr,
bool  geodesic,
bool  check_closed 
)

Definition at line 1132 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), distance_in_meters(), distance_point_point(), get_point(), and i.

Referenced by perimeter_multipolygon(), ST_Length_LineString(), ST_Length_LineString_Geodesic(), ST_Perimeter_Polygon(), and ST_Perimeter_Polygon_Geodesic().

1138  {
1139  auto l_num_coords = lsize / compression_unit_size(ic);
1140 
1141  double length = 0.0;
1142 
1143  Point2D l0 = get_point(l, 0, ic, isr, osr);
1144  Point2D l2 = l0;
1145  for (int32_t i = 2; i < l_num_coords; i += 2) {
1146  Point2D l1 = l2;
1147  l2 = get_point(l, i, ic, isr, osr);
1148  double ldist = geodesic ? distance_in_meters(l1.x, l1.y, l2.x, l2.y)
1149  : distance_point_point(l1.x, l1.y, l2.x, l2.y);
1150  length += ldist;
1151  }
1152  if (check_closed) {
1153  double ldist = geodesic ? distance_in_meters(l2.x, l2.y, l0.x, l0.y)
1154  : distance_point_point(l2.x, l2.y, l0.x, l0.y);
1155  length += ldist;
1156  }
1157  return length;
1158 }
EXTENSION_NOINLINE double distance_in_meters(const double fromlon, const double fromlat, const double tolon, const double tolat)
Computes the distance, in meters, between two WGS-84 positions.
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double distance_point_point(double p1x, double p1y, double p2x, double p2y)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE bool line_intersects_line ( double  l11x,
double  l11y,
double  l12x,
double  l12y,
double  l21x,
double  l21y,
double  l22x,
double  l22y 
)

Definition at line 328 of file ExtensionFunctionsGeo.hpp.

References on_segment(), and orientation().

Referenced by distance_line_line(), distance_line_line_squared(), linestring_intersects_line(), linestring_intersects_linestring(), polygon_contains_point(), and ring_intersects_line().

335  {
336  auto o1 = orientation(l11x, l11y, l12x, l12y, l21x, l21y);
337  auto o2 = orientation(l11x, l11y, l12x, l12y, l22x, l22y);
338  auto o3 = orientation(l21x, l21y, l22x, l22y, l11x, l11y);
339  auto o4 = orientation(l21x, l21y, l22x, l22y, l12x, l12y);
340 
341  // General case
342  if (o1 != o2 && o3 != o4) {
343  return true;
344  }
345 
346  // Special Cases
347  // l11, l12 and l21 are colinear and l21 lies on segment l11-l12
348  if (o1 == 0 && on_segment(l11x, l11y, l21x, l21y, l12x, l12y)) {
349  return true;
350  }
351 
352  // l11, l12 and l21 are colinear and l22 lies on segment l11-l12
353  if (o2 == 0 && on_segment(l11x, l11y, l22x, l22y, l12x, l12y)) {
354  return true;
355  }
356 
357  // l21, l22 and l11 are colinear and l11 lies on segment l21-l22
358  if (o3 == 0 && on_segment(l21x, l21y, l11x, l11y, l22x, l22y)) {
359  return true;
360  }
361 
362  // l21, l22 and l12 are colinear and l12 lies on segment l21-l22
363  if (o4 == 0 && on_segment(l21x, l21y, l12x, l12y, l22x, l22y)) {
364  return true;
365  }
366 
367  return false;
368 }
DEVICE ALWAYS_INLINE bool on_segment(double px, double py, double qx, double qy, double rx, double ry)
DEVICE ALWAYS_INLINE int16_t orientation(double px, double py, double qx, double qy, double rx, double ry)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE bool linestring_intersects_line ( int8_t *  l,
int32_t  lnum_coords,
double  l1x,
double  l1y,
double  l2x,
double  l2y,
int32_t  ic1,
int32_t  isr1,
int32_t  osr 
)

Definition at line 371 of file ExtensionFunctionsGeo.hpp.

References get_point(), i, and line_intersects_line().

Referenced by ring_intersects_line().

379  {
380  Point2D e1 = get_point(l, 0, ic1, isr1, osr);
381  for (int64_t i = 2; i < lnum_coords; i += 2) {
382  Point2D e2 = get_point(l, i, ic1, isr1, osr);
383  if (line_intersects_line(e1.x, e1.y, e2.x, e2.y, l1x, l1y, l2x, l2y)) {
384  return true;
385  }
386  e1 = e2;
387  }
388  return false;
389 }
DEVICE bool line_intersects_line(double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE bool linestring_intersects_linestring ( int8_t *  l,
int32_t  lnum_coords,
double  l1x,
double  l1y,
double  l2x,
double  l2y,
int32_t  ic1,
int32_t  isr1,
int32_t  osr 
)

Definition at line 411 of file ExtensionFunctionsGeo.hpp.

References get_point(), i, and line_intersects_line().

419  {
420  Point2D e1 = get_point(l, 0, ic1, isr1, osr);
421  for (int64_t i = 2; i < lnum_coords; i += 2) {
422  Point2D e2 = get_point(l, i, ic1, isr1, osr);
423  if (line_intersects_line(e1.x, e1.y, e2.x, e2.y, l1x, l1y, l2x, l2y)) {
424  return true;
425  }
426  e1 = e2;
427  }
428  return false;
429 }
DEVICE bool line_intersects_line(double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

EXTENSION_INLINE int64_t MapD_GeoPolyBoundsPtr ( double *  bounds,
int64_t  size 
)

Definition at line 4269 of file ExtensionFunctionsGeo.hpp.

References OmniSci_Geo_PolyBoundsPtr().

Referenced by com.mapd.calcite.parser.MapDSqlOperatorTable::addUDF().

4269  {
4270  return OmniSci_Geo_PolyBoundsPtr(bounds, size);
4271 }
EXTENSION_INLINE int64_t OmniSci_Geo_PolyBoundsPtr(double *bounds, int64_t size)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE int32_t MapD_GeoPolyRenderGroup ( int32_t  render_group)

Definition at line 4274 of file ExtensionFunctionsGeo.hpp.

References OmniSci_Geo_PolyRenderGroup().

Referenced by com.mapd.calcite.parser.MapDSqlOperatorTable::addUDF().

4274  {
4275  return OmniSci_Geo_PolyRenderGroup(render_group);
4276 }
EXTENSION_INLINE int32_t OmniSci_Geo_PolyRenderGroup(int32_t render_group)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE double max_distance_point_line ( double  px,
double  py,
double  l1x,
double  l1y,
double  l2x,
double  l2y 
)

Definition at line 3090 of file ExtensionFunctionsGeo.hpp.

References distance_point_point().

Referenced by max_distance_point_linestring().

3095  {
3096  // TODO: switch to squared distances
3097  double length1 = distance_point_point(px, py, l1x, l1y);
3098  double length2 = distance_point_point(px, py, l2x, l2y);
3099  if (length1 > length2) {
3100  return length1;
3101  }
3102  return length2;
3103 }
DEVICE ALWAYS_INLINE double distance_point_point(double p1x, double p1y, double p2x, double p2y)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE double max_distance_point_linestring ( int8_t *  p,
int64_t  psize,
int8_t *  l,
int64_t  lsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
bool  check_closed 
)

Definition at line 3105 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), get_point(), i, and max_distance_point_line().

Referenced by ST_MaxDistance_LineString_Point(), and ST_MaxDistance_Point_LineString().

3114  {
3115  // TODO: switch to squared distances
3116  Point2D pt = get_point(p, 0, ic1, isr1, osr);
3117 
3118  auto l_num_coords = lsize / compression_unit_size(ic2);
3119 
3120  Point2D l1 = get_point(l, 0, ic2, isr2, osr);
3121  Point2D l2 = get_point(l, 2, ic2, isr2, osr);
3122 
3123  double max_dist = max_distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
3124  for (int32_t i = 4; i < l_num_coords; i += 2) {
3125  l1 = l2; // advance one point
3126  l2 = get_point(l, i, ic2, isr2, osr);
3127  double ldist = max_distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
3128  if (max_dist < ldist) {
3129  max_dist = ldist;
3130  }
3131  }
3132  if (l_num_coords > 4 && check_closed) {
3133  // Also check distance to the closing edge between the first and the last points
3134  l1 = get_point(l, 0, ic2, isr2, osr);
3135  double ldist = max_distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
3136  if (max_dist < ldist) {
3137  max_dist = ldist;
3138  }
3139  }
3140  return max_dist;
3141 }
DEVICE double max_distance_point_line(double px, double py, double l1x, double l1y, double l2x, double l2y)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE int64_t OmniSci_Geo_PolyBoundsPtr ( double *  bounds,
int64_t  size 
)

Definition at line 4259 of file ExtensionFunctionsGeo.hpp.

Referenced by com.mapd.calcite.parser.MapDSqlOperatorTable::addUDF(), and MapD_GeoPolyBoundsPtr().

4259  {
4260  return reinterpret_cast<int64_t>(bounds);
4261 }

+ Here is the caller graph for this function:

EXTENSION_INLINE int32_t OmniSci_Geo_PolyRenderGroup ( int32_t  render_group)

Definition at line 4264 of file ExtensionFunctionsGeo.hpp.

Referenced by com.mapd.calcite.parser.MapDSqlOperatorTable::addUDF(), and MapD_GeoPolyRenderGroup().

4264  {
4265  return render_group;
4266 }

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool on_segment ( double  px,
double  py,
double  qx,
double  qy,
double  rx,
double  ry 
)

Definition at line 304 of file ExtensionFunctionsGeo.hpp.

References tol_ge(), and tol_le().

Referenced by line_intersects_line().

309  {
310  return (tol_le(qx, fmax(px, rx)) && tol_ge(qx, fmin(px, rx)) &&
311  tol_le(qy, fmax(py, ry)) && tol_ge(qy, fmin(py, ry)));
312 }
DEVICE ALWAYS_INLINE bool tol_le(const double x, const double y, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE bool tol_ge(const double x, const double y, const double tolerance=TOLERANCE_DEFAULT)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE int16_t orientation ( double  px,
double  py,
double  qx,
double  qy,
double  rx,
double  ry 
)

Definition at line 315 of file ExtensionFunctionsGeo.hpp.

References tol_zero().

Referenced by line_intersects_line().

315  {
316  auto val = ((qy - py) * (rx - qx) - (qx - px) * (ry - qy));
317  if (tol_zero(val)) {
318  return 0; // Points p, q and r are colinear
319  }
320  if (val > 0.0) {
321  return 1; // Clockwise point orientation
322  }
323  return 2; // Counterclockwise point orientation
324 }
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE double perimeter_multipolygon ( int8_t *  mpoly_coords,
int32_t  mpoly_coords_size,
int8_t *  mpoly_ring_sizes_in,
int32_t  mpoly_num_rings,
int8_t *  mpoly_poly_sizes,
int32_t  mpoly_num_polys,
int32_t  ic,
int32_t  isr,
int32_t  osr,
bool  geodesic 
)

Definition at line 1219 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and length_linestring().

Referenced by ST_Perimeter_MultiPolygon(), and ST_Perimeter_MultiPolygon_Geodesic().

1228  {
1229  if (mpoly_num_polys <= 0 || mpoly_num_rings <= 0) {
1230  return 0.0;
1231  }
1232 
1233  double perimeter = 0.0;
1234 
1235  auto mpoly_ring_sizes = reinterpret_cast<int32_t*>(mpoly_ring_sizes_in);
1236 
1237  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1238  auto next_poly_coords = mpoly_coords;
1239  auto next_poly_ring_sizes = mpoly_ring_sizes;
1240 
1241  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1242  auto poly_coords = next_poly_coords;
1243  auto poly_ring_sizes = next_poly_ring_sizes;
1244  auto poly_num_rings = reinterpret_cast<int32_t*>(mpoly_poly_sizes)[poly];
1245  // Count number of coords in all of poly's rings, advance ring size pointer.
1246  int32_t poly_num_coords = 0;
1247  for (auto ring = 0; ring < poly_num_rings; ring++) {
1248  poly_num_coords += 2 * *next_poly_ring_sizes++;
1249  }
1250  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1251  next_poly_coords += poly_coords_size;
1252 
1253  auto exterior_ring_num_coords = poly_ring_sizes[0] * 2;
1254  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic);
1255 
1256  perimeter += length_linestring(
1257  poly_coords, exterior_ring_coords_size, ic, isr, osr, geodesic, true);
1258  }
1259 
1260  return perimeter;
1261 }
DEVICE ALWAYS_INLINE double length_linestring(int8_t *l, int32_t lsize, int32_t ic, int32_t isr, int32_t osr, bool geodesic, bool check_closed)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool point_dwithin_box ( int8_t *  p1,
int64_t  p1size,
int32_t  ic1,
int32_t  isr1,
double *  bounds2,
int64_t  bounds2_size,
int32_t  isr2,
int32_t  osr,
double  distance 
)

Definition at line 913 of file ExtensionFunctionsGeo.hpp.

References get_point().

Referenced by ST_DWithin_Point_LineString(), ST_DWithin_Point_MultiPolygon(), and ST_DWithin_Point_Polygon().

921  {
922  // TODO: tolerance
923 
924  // Point has to be uncompressed and transformed to output SR.
925  // Bounding box has to be transformed to output SR.
926  Point2D p = get_point(p1, 0, ic1, isr1, osr);
927  Point2D const lb = transform_point<XY>({bounds2[0], bounds2[1]}, isr2, osr);
928  Point2D const rt = transform_point<XY>({bounds2[2], bounds2[3]}, isr2, osr);
929  if (p.x < lb.x - distance || // point is left of box2: px < box2.xmin - distance
930  p.x > rt.x + distance || // point is right of box2: px > box2.xmax + distance
931  p.y < lb.y - distance || // point is below box2: py < box2.ymin - distance
932  p.y > rt.y + distance) { // point is above box2: py > box2.ymax + distance
933  return false;
934  }
935  return true;
936 }
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T , EdgeBehavior TEdgeBehavior>
DEVICE ALWAYS_INLINE bool point_in_polygon_winding_number ( const int8_t *  poly,
const int32_t  poly_num_coords,
const px,
const py,
const int32_t  ic1,
const int32_t  isr1,
const int32_t  osr 
)

Computes whether the point p is inside the polygon poly using the winding number algorithm. The winding number algorithm efficiently computes the winding number, which is the number of revolutions made around a point P while traveling around the polygon. If the winding number is non-zero, then P must be inside the polygon. The actual algorithm loops over all edges in the polygon, and determines the location of the crossing between a ray from the point P and each edge E of the polygon. In the implementation below, this crossing calculation is performed by assigning a fixed orientation to each edge, then computing the location of the point with respect to that edge. The parameter include_point_on_edge allows the algorithm to work for both point-inside-polygon, or point-on-polygon calculations. The original source and additional detail for this implementation is here: http://geomalgorithms.com/a03-_inclusion.html

Definition at line 579 of file ExtensionFunctionsGeo.hpp.

References compressed_coord(), DEBUG_STMT, get_point(), is_left(), kIncludePointOnEdge, omnisci.dtypes::T, tol_zero_template(), and UNLIKELY.

585  {
586  int32_t wn = 0;
587 
588  constexpr bool include_point_on_edge =
589  TEdgeBehavior == EdgeBehavior::kIncludePointOnEdge;
590 
591  auto get_x_coord = [=](const auto data, const auto index) -> T {
592  if constexpr (std::is_floating_point<T>::value) {
593  return get_point(data, index, ic1, isr1, osr).x;
594  } else {
595  return compressed_coord(data, index);
596  }
597  return T{}; // https://stackoverflow.com/a/64561686/2700898
598  };
599 
600  auto get_y_coord = [=](const auto data, const auto index) -> T {
601  if constexpr (std::is_floating_point<T>::value) {
602  return get_point(data, index, ic1, isr1, osr).y;
603  } else {
604  return compressed_coord(data, index + 1);
605  }
606  return T{}; // https://stackoverflow.com/a/64561686/2700898
607  };
608 
609  DEBUG_STMT(printf("Poly num coords: %d\n", poly_num_coords));
610  const int64_t num_edges = poly_num_coords / 2;
611 
612  int64_t e0_index = 0;
613  T e0x = get_x_coord(poly, e0_index * 2);
614  T e0y = get_y_coord(poly, e0_index * 2);
615 
616  int64_t e1_index;
617  T e1x, e1y;
618 
619  for (int64_t edge = 1; edge <= num_edges; edge++) {
620  DEBUG_STMT(printf("Edge %ld\n", edge));
621  // build the edge
622  e1_index = edge % num_edges;
623  e1x = get_x_coord(poly, e1_index * 2);
624  e1y = get_y_coord(poly, e1_index * 2);
625 
626  DEBUG_STMT(printf("edge 0: %ld : %f, %f\n", e0_index, (double)e0x, (double)e0y));
627  DEBUG_STMT(printf("edge 1: %ld : %f, %f\n", e1_index, (double)e1x, (double)e1y));
628 
629  auto get_epsilon = [=]() -> T {
630  if constexpr (std::is_floating_point<T>::value) {
631  const T edge_vec_magnitude =
632  (e1x - e0x) * (e1x - e0x) + (e1y - e0y) * (e1y - e0y);
633  return 0.003 * edge_vec_magnitude;
634  } else {
635  return T(0);
636  }
637  return T{}; // https://stackoverflow.com/a/64561686/2700898
638  };
639 
640  const T epsilon = get_epsilon();
641  DEBUG_STMT(printf("using epsilon value %e\n", (double)epsilon));
642 
643  if constexpr (include_point_on_edge) {
644  const T xp = (px - e1x) * (e0y - e1y) - (py - e1y) * (e0x - e1x);
645  const T pt_vec_magnitude = (px - e0x) * (px - e0x) + (py - e0y) * (py - e0y);
646  const T edge_vec_magnitude = (e1x - e0x) * (e1x - e0x) + (e1y - e0y) * (e1y - e0y);
647  if (tol_zero_template(xp, epsilon) && (pt_vec_magnitude <= edge_vec_magnitude)) {
648  DEBUG_STMT(printf("point is on edge: %e && %e <= %e\n",
649  (double)xp,
650  (double)pt_vec_magnitude,
651  (double)edge_vec_magnitude));
652  return include_point_on_edge;
653  }
654  }
655 
656  if (e0y <= py) {
657  if (e1y > py) {
658  // upward crossing
659  DEBUG_STMT(printf("upward crossing\n"));
660  const auto is_left_val = is_left(e0x, e0y, e1x, e1y, px, py);
661  DEBUG_STMT(printf("Left val %f and tol zero left val %d\n",
662  (double)is_left_val,
663  tol_zero_template(is_left_val, epsilon)));
664  if (UNLIKELY(tol_zero_template(is_left_val, epsilon))) {
665  // p is on the edge
666  return include_point_on_edge;
667  } else if (is_left_val > T(0)) { // p left of edge
668  // valid up intersection
669  DEBUG_STMT(printf("++wn\n"));
670  ++wn;
671  }
672  }
673  } else if (e1y <= py) {
674  // downward crossing
675  DEBUG_STMT(printf("downward crossing\n"));
676  const auto is_left_val = is_left(e0x, e0y, e1x, e1y, px, py);
677  DEBUG_STMT(printf("Left val %f and tol zero left val %d\n",
678  (double)is_left_val,
679  tol_zero_template(is_left_val, epsilon)));
680  if (UNLIKELY(tol_zero_template(is_left_val, epsilon))) {
681  // p is on the edge
682  return include_point_on_edge;
683  } else if (is_left_val < T(0)) { // p right of edge
684  // valid down intersection
685  DEBUG_STMT(printf("--wn\n"));
686  --wn;
687  }
688  }
689 
690  e0_index = e1_index;
691  e0x = e1x;
692  e0y = e1y;
693  }
694  DEBUG_STMT(printf("wn: %d\n", wn));
695  // wn == 0 --> P is outside the polygon
696  return !(wn == 0);
697 }
DEVICE ALWAYS_INLINE int32_t compressed_coord(const int8_t *data, const int32_t index)
DEVICE ALWAYS_INLINE T is_left(const T lx0, const T ly0, const T lx1, const T ly1, const T px, const T py)
#define DEBUG_STMT(x)
DEVICE ALWAYS_INLINE bool tol_zero_template(const T x, const T tolerance=TOLERANCE_DEFAULT)
#define UNLIKELY(x)
Definition: likely.h:25
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

EXTENSION_NOINLINE bool Point_Overlaps_Box ( double *  bounds,
int64_t  bounds_size,
double  px,
double  py 
)

Definition at line 862 of file ExtensionFunctionsGeo.hpp.

References box_contains_point().

865  {
866  // TODO: mixed spatial references
867  return box_contains_point(bounds, bounds_size, px, py);
868 }
DEVICE ALWAYS_INLINE bool box_contains_point(const double *bounds, const int64_t bounds_size, const double px, const double py)

+ Here is the call graph for this function:

DEVICE bool polygon_contains_linestring ( int8_t *  poly,
int32_t  poly_num_coords,
int8_t *  l,
int64_t  lnum_coords,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 825 of file ExtensionFunctionsGeo.hpp.

References get_point(), i, polygon_contains_point(), and ring_intersects_line().

Referenced by ST_Contains_Polygon_LineString().

833  {
834  // Check that the first point is in the polygon
835  Point2D l1 = get_point(l, 0, ic2, isr2, osr);
836  if (!polygon_contains_point(poly, poly_num_coords, l1.x, l1.y, ic1, isr1, osr)) {
837  return false;
838  }
839 
840  // Go through line segments and check if there are no intersections with poly edges,
841  // i.e. linestring doesn't escape
842  for (int32_t i = 2; i < lnum_coords; i += 2) {
843  Point2D l2 = get_point(l, i, ic2, isr2, osr);
845  poly, poly_num_coords, l1.x, l1.y, l2.x, l2.y, ic1, isr1, osr)) {
846  return false;
847  }
848  l1 = l2;
849  }
850  return true;
851 }
DEVICE ALWAYS_INLINE bool polygon_contains_point(const int8_t *poly, const int32_t poly_num_coords, const double px, const double py, const int32_t ic1, const int32_t isr1, const int32_t osr)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE bool ring_intersects_line(int8_t *ring, int32_t ring_num_coords, double l1x, double l1y, double l2x, double l2y, int32_t ic1, int32_t isr1, int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE bool polygon_contains_point ( const int8_t *  poly,
const int32_t  poly_num_coords,
const double  px,
const double  py,
const int32_t  ic1,
const int32_t  isr1,
const int32_t  osr 
)

Definition at line 713 of file ExtensionFunctionsGeo.hpp.

References distance_point_line(), get_point(), i, line_intersects_line(), run_benchmark_import::result, tol_eq(), and tol_zero().

Referenced by polygon_contains_linestring(), and ST_Distance_Point_Polygon().

719  {
720  bool result = false;
721  int xray_touch = 0;
722  bool horizontal_edge = false;
723  bool yray_intersects = false;
724 
725  Point2D e1 = get_point(poly, poly_num_coords - 2, ic1, isr1, osr);
726  for (int64_t i = 0; i < poly_num_coords; i += 2) {
727  Point2D e2 = get_point(poly, i, ic1, isr1, osr);
728 
729  // Check if point sits on an edge.
730  if (tol_zero(distance_point_line(px, py, e1.x, e1.y, e2.x, e2.y))) {
731  return true;
732  }
733 
734  // Before flipping the switch, check if xray hit a horizontal edge
735  // - If an edge lays on the xray, one of the previous edges touched it
736  // so while moving horizontally we're in 'xray_touch' state
737  // - Last edge that touched xray at (e2.x,e2.y) didn't register intersection
738  // - Next edge that diverges from xray at (e1,e1y) will register intersection
739  // - Can have several horizontal edges, one after the other, keep moving though
740  // in 'xray_touch' state without flipping the switch
741  horizontal_edge = (xray_touch != 0) && tol_eq(py, e1.y) && tol_eq(py, e2.y);
742 
743  // Main probe: xray
744  // Overshoot the xray to detect an intersection if there is one.
745  double xray = fmax(e2.x, e1.x) + 1.0;
746  if (px <= xray && // Only check for intersection if the edge is on the right
747  !horizontal_edge && // Keep moving through horizontal edges
748  line_intersects_line(px, // xray shooting from point p to the right
749  py,
750  xray,
751  py,
752  e1.x, // polygon edge
753  e1.y,
754  e2.x,
755  e2.y)) {
756  // Register intersection
757  result = !result;
758 
759  // Adjust for special cases
760  if (xray_touch == 0) {
761  if (tol_zero(distance_point_line(e2.x, e2.y, px, py, xray + 1.0, py))) {
762  // Xray goes through the edge's second vertex, unregister intersection -
763  // that vertex will be crossed again when we look at the following edge(s)
764  result = !result;
765  // Enter the xray-touch state:
766  // (1) - xray was touched by the edge from above, (-1) from below
767  xray_touch = (e1.y > py) ? 1 : -1;
768  }
769  } else {
770  // Previous edge touched the xray, intersection hasn't been registered,
771  // it has to be registered now if this edge continues across the xray.
772  if (xray_touch > 0) {
773  // Previous edge touched the xray from above
774  if (e2.y <= py) {
775  // Current edge crosses under xray: intersection is already registered
776  } else {
777  // Current edge just touched the xray and pulled up: unregister intersection
778  result = !result;
779  }
780  } else {
781  // Previous edge touched the xray from below
782  if (e2.y > py) {
783  // Current edge crosses over xray: intersection is already registered
784  } else {
785  // Current edge just touched the xray and pulled down: unregister intersection
786  result = !result;
787  }
788  }
789  // Exit the xray-touch state
790  xray_touch = 0;
791  }
792  }
793 
794  // Redundancy: vertical yray down
795  // Main probe xray may hit multiple complex fragments which increases a chance of
796  // error. Perform a simple secondary check for edge intersections to see if point is
797  // outside.
798  if (!yray_intersects) { // Continue checking on yray until intersection is found
799  double yray = fmin(e2.y, e1.y) - 1.0;
800  if (yray <= py) { // Only check for yray intersection if point P is above the edge
801  yray_intersects = line_intersects_line(px, // yray shooting from point P down
802  py,
803  px,
804  yray,
805  e1.x, // polygon edge
806  e1.y,
807  e2.x,
808  e2.y);
809  }
810  }
811 
812  // Advance to the next vertex
813  e1 = e2;
814  }
815  if (!yray_intersects) {
816  // yray has zero intersections - point is outside the polygon
817  return false;
818  }
819  // Otherwise rely on the main probe
820  return result;
821 }
DEVICE double distance_point_line(double px, double py, double l1x, double l1y, double l2x, double l2y)
DEVICE bool line_intersects_line(double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE bool tol_eq(const double x, const double y, const double tolerance=TOLERANCE_DEFAULT)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE bool ring_intersects_line ( int8_t *  ring,
int32_t  ring_num_coords,
double  l1x,
double  l1y,
double  l2x,
double  l2y,
int32_t  ic1,
int32_t  isr1,
int32_t  osr 
)

Definition at line 392 of file ExtensionFunctionsGeo.hpp.

References get_point(), line_intersects_line(), and linestring_intersects_line().

Referenced by polygon_contains_linestring().

400  {
401  Point2D e1 = get_point(ring, ring_num_coords - 2, ic1, isr1, osr);
402  Point2D e2 = get_point(ring, 0, ic1, isr1, osr);
403  if (line_intersects_line(e1.x, e1.y, e2.x, e2.y, l1x, l1y, l2x, l2y)) {
404  return true;
405  }
407  ring, ring_num_coords, l1x, l1y, l2x, l2y, ic1, isr1, osr);
408 }
DEVICE bool linestring_intersects_line(int8_t *l, int32_t lnum_coords, double l1x, double l1y, double l2x, double l2y, int32_t ic1, int32_t isr1, int32_t osr)
DEVICE bool line_intersects_line(double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double ST_Area_MultiPolygon ( int8_t *  mpoly_coords,
int32_t  mpoly_coords_size,
int8_t *  mpoly_ring_sizes,
int32_t  mpoly_num_rings,
int8_t *  mpoly_poly_sizes_in,
int32_t  mpoly_num_polys,
int32_t  ic,
int32_t  isr,
int32_t  osr 
)

Definition at line 1383 of file ExtensionFunctionsGeo.hpp.

References area_polygon(), and compression_unit_size().

1391  {
1392  if (mpoly_num_rings <= 0 || mpoly_num_polys <= 0) {
1393  return 0.0;
1394  }
1395 
1396  double area = 0.0;
1397 
1398  auto mpoly_poly_sizes = reinterpret_cast<int32_t*>(mpoly_poly_sizes_in);
1399 
1400  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1401  auto next_poly_coords = mpoly_coords;
1402  auto next_poly_ring_sizes = reinterpret_cast<int32_t*>(mpoly_ring_sizes);
1403 
1404  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1405  auto poly_coords = next_poly_coords;
1406  auto poly_ring_sizes = next_poly_ring_sizes;
1407  auto poly_num_rings = mpoly_poly_sizes[poly];
1408  // Count number of coords in all of poly's rings, advance ring size pointer.
1409  int32_t poly_num_coords = 0;
1410  for (auto ring = 0; ring < poly_num_rings; ring++) {
1411  poly_num_coords += 2 * *next_poly_ring_sizes++;
1412  }
1413  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1414  next_poly_coords += poly_coords_size;
1415 
1416  area += area_polygon(poly_coords,
1417  poly_coords_size,
1418  reinterpret_cast<int8_t*>(poly_ring_sizes),
1419  poly_num_rings,
1420  ic,
1421  isr,
1422  osr);
1423  }
1424  return area;
1425 }
DEVICE ALWAYS_INLINE double area_polygon(int8_t *poly_coords, int32_t poly_coords_size, int8_t *poly_ring_sizes_in, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)

+ Here is the call graph for this function:

EXTENSION_NOINLINE double ST_Area_Polygon ( int8_t *  poly_coords,
int32_t  poly_coords_size,
int8_t *  poly_ring_sizes,
int32_t  poly_num_rings,
int32_t  ic,
int32_t  isr,
int32_t  osr 
)

Definition at line 1371 of file ExtensionFunctionsGeo.hpp.

References area_polygon().

1377  {
1378  return area_polygon(
1379  poly_coords, poly_coords_size, poly_ring_sizes, poly_num_rings, ic, isr, osr);
1380 }
DEVICE ALWAYS_INLINE double area_polygon(int8_t *poly_coords, int32_t poly_coords_size, int8_t *poly_ring_sizes_in, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)

+ Here is the call graph for this function:

EXTENSION_NOINLINE bool ST_cContains_MultiPolygon_Point ( int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
double *  mpoly_bounds,
int64_t  mpoly_bounds_size,
int8_t *  p,
int64_t  psize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3608 of file ExtensionFunctionsGeo.hpp.

3622  {
3623  return Contains_MultiPolygon_Point_Impl<int64_t, EdgeBehavior::kExcludePointOnEdge>(
3624  mpoly_coords,
3625  mpoly_coords_size,
3626  mpoly_ring_sizes,
3627  mpoly_num_rings,
3628  mpoly_poly_sizes,
3629  mpoly_num_polys,
3630  mpoly_bounds,
3631  mpoly_bounds_size,
3632  p,
3633  psize,
3634  ic1,
3635  isr1,
3636  ic2,
3637  isr2,
3638  osr);
3639 }
EXTENSION_NOINLINE bool ST_cContains_Polygon_Point ( const int8_t *  poly_coords,
const int64_t  poly_coords_size,
const int32_t *  poly_ring_sizes,
const int64_t  poly_num_rings,
const double *  poly_bounds,
const int64_t  poly_bounds_size,
const int8_t *  p,
const int64_t  psize,
const int32_t  ic1,
const int32_t  isr1,
const int32_t  ic2,
const int32_t  isr2,
const int32_t  osr 
)

Definition at line 3391 of file ExtensionFunctionsGeo.hpp.

3403  {
3404  return Contains_Polygon_Point_Impl<int64_t, EdgeBehavior::kExcludePointOnEdge>(
3405  poly_coords,
3406  poly_coords_size,
3407  poly_ring_sizes,
3408  poly_num_rings,
3409  poly_bounds,
3410  poly_bounds_size,
3411  p,
3412  psize,
3413  ic1,
3414  isr1,
3415  ic2,
3416  isr2,
3417  osr);
3418 }
EXTENSION_NOINLINE void ST_Centroid_LineString ( int8_t *  coords,
int32_t  coords_sz,
int32_t  ic,
int32_t  isr,
int32_t  osr,
double *  linestring_centroid 
)

Definition at line 1502 of file ExtensionFunctionsGeo.hpp.

References centroid_add_linestring().

1507  {
1508  double length = 0.0;
1509  double linestring_centroid_sum[2] = {0.0, 0.0};
1510  int64_t num_points = 0;
1511  double point_centroid_sum[2] = {0.0, 0.0};
1512  centroid_add_linestring(coords,
1513  coords_sz,
1514  ic,
1515  isr,
1516  osr,
1517  false, // not closed
1518  &length,
1519  &linestring_centroid_sum[0],
1520  &num_points,
1521  &point_centroid_sum[0]);
1522  if (length > 0) {
1523  linestring_centroid[0] = linestring_centroid_sum[0] / length;
1524  linestring_centroid[1] = linestring_centroid_sum[1] / length;
1525  } else if (num_points > 0) {
1526  linestring_centroid[0] = point_centroid_sum[0] / num_points;
1527  linestring_centroid[1] = point_centroid_sum[1] / num_points;
1528  }
1529 }
DEVICE ALWAYS_INLINE bool centroid_add_linestring(int8_t *l, int64_t lsize, int32_t ic, int32_t isr, int32_t osr, bool closed, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)

+ Here is the call graph for this function:

EXTENSION_NOINLINE void ST_Centroid_MultiPolygon ( int8_t *  mpoly_coords,
int32_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int32_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int32_t  mpoly_num_polys,
int32_t  ic,
int32_t  isr,
int32_t  osr,
double *  mpoly_centroid 
)

Definition at line 1681 of file ExtensionFunctionsGeo.hpp.

References centroid_add_polygon(), compression_unit_size(), and get_point().

1690  {
1691  if (mpoly_num_rings <= 0 || mpoly_num_polys <= 0) {
1692  mpoly_centroid[0] = 0.0;
1693  mpoly_centroid[1] = 0.0;
1694  }
1695 
1696  double total_area2 = 0.0;
1697  double cg3[2] = {0.0, 0.0};
1698  double total_length = 0.0;
1699  double linestring_centroid_sum[2] = {0.0, 0.0};
1700  int64_t num_points = 0;
1701  double point_centroid_sum[2] = {0.0, 0.0};
1702 
1703  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1704  auto next_poly_coords = mpoly_coords;
1705  auto next_poly_ring_sizes = mpoly_ring_sizes;
1706 
1707  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1708  auto poly_coords = next_poly_coords;
1709  auto poly_ring_sizes = next_poly_ring_sizes;
1710  auto poly_num_rings = mpoly_poly_sizes[poly];
1711  // Count number of coords in all of poly's rings, advance ring size pointer.
1712  int32_t poly_num_coords = 0;
1713  for (auto ring = 0; ring < poly_num_rings; ring++) {
1714  poly_num_coords += 2 * *next_poly_ring_sizes++;
1715  }
1716  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1717  next_poly_coords += poly_coords_size;
1718 
1719  centroid_add_polygon(poly_coords,
1720  poly_coords_size,
1721  poly_ring_sizes,
1722  poly_num_rings,
1723  ic,
1724  isr,
1725  osr,
1726  &total_area2,
1727  &cg3[0],
1728  &total_length,
1729  &linestring_centroid_sum[0],
1730  &num_points,
1731  &point_centroid_sum[0]);
1732  }
1733 
1734  if (total_area2 != 0.0) {
1735  mpoly_centroid[0] = cg3[0] / 3 / total_area2;
1736  mpoly_centroid[1] = cg3[1] / 3 / total_area2;
1737  } else if (total_length > 0.0) {
1738  // zero-area multipolygon, fall back to linear centroid
1739  mpoly_centroid[0] = linestring_centroid_sum[0] / total_length;
1740  mpoly_centroid[1] = linestring_centroid_sum[1] / total_length;
1741  } else if (num_points > 0) {
1742  // zero-area zero-length multipolygon, fall further back to point centroid
1743  mpoly_centroid[0] = point_centroid_sum[0] / num_points;
1744  mpoly_centroid[1] = point_centroid_sum[1] / num_points;
1745  } else {
1746  Point2D centroid = get_point(mpoly_coords, 0, ic, isr, osr);
1747  mpoly_centroid[0] = centroid.x;
1748  mpoly_centroid[1] = centroid.y;
1749  }
1750 }
DEVICE ALWAYS_INLINE bool centroid_add_polygon(int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr, double *total_area2, double *cg3, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

EXTENSION_NOINLINE void ST_Centroid_Point ( int8_t *  p,
int32_t  psize,
int32_t  ic,
int32_t  isr,
int32_t  osr,
double *  point_centroid 
)

Definition at line 1443 of file ExtensionFunctionsGeo.hpp.

References get_point().

1448  {
1449  Point2D const centroid = get_point(p, 0, ic, isr, osr);
1450  point_centroid[0] = centroid.x;
1451  point_centroid[1] = centroid.y;
1452 }
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

EXTENSION_NOINLINE void ST_Centroid_Polygon ( int8_t *  poly_coords,
int32_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int32_t  poly_num_rings,
int32_t  ic,
int32_t  isr,
int32_t  osr,
double *  poly_centroid 
)

Definition at line 1630 of file ExtensionFunctionsGeo.hpp.

References centroid_add_polygon(), and get_point().

1637  {
1638  if (poly_num_rings <= 0) {
1639  poly_centroid[0] = 0.0;
1640  poly_centroid[1] = 0.0;
1641  }
1642  double total_area2 = 0.0;
1643  double cg3[2] = {0.0, 0.0};
1644  double total_length = 0.0;
1645  double linestring_centroid_sum[2] = {0.0, 0.0};
1646  int64_t num_points = 0;
1647  double point_centroid_sum[2] = {0.0, 0.0};
1648  centroid_add_polygon(poly_coords,
1649  poly_coords_size,
1650  poly_ring_sizes,
1651  poly_num_rings,
1652  ic,
1653  isr,
1654  osr,
1655  &total_area2,
1656  &cg3[0],
1657  &total_length,
1658  &linestring_centroid_sum[0],
1659  &num_points,
1660  &point_centroid_sum[0]);
1661 
1662  if (total_area2 != 0.0) {
1663  poly_centroid[0] = cg3[0] / 3 / total_area2;
1664  poly_centroid[1] = cg3[1] / 3 / total_area2;
1665  } else if (total_length > 0.0) {
1666  // zero-area polygon, fall back to linear centroid
1667  poly_centroid[0] = linestring_centroid_sum[0] / total_length;
1668  poly_centroid[1] = linestring_centroid_sum[1] / total_length;
1669  } else if (num_points > 0) {
1670  // zero-area zero-length polygon, fall further back to point centroid
1671  poly_centroid[0] = point_centroid_sum[0] / num_points;
1672  poly_centroid[1] = point_centroid_sum[1] / num_points;
1673  } else {
1674  Point2D centroid = get_point(poly_coords, 0, ic, isr, osr);
1675  poly_centroid[0] = centroid.x;
1676  poly_centroid[1] = centroid.y;
1677  }
1678 }
DEVICE ALWAYS_INLINE bool centroid_add_polygon(int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr, double *total_area2, double *cg3, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

EXTENSION_INLINE bool ST_Contains_LineString_Point ( int8_t *  l,
int64_t  lsize,
double *  lbounds,
int64_t  lbounds_size,
int8_t *  p,
int64_t  psize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3259 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString(), and tol_zero().

3269  {
3270  return tol_zero(
3271  ST_Distance_Point_LineString(p, psize, l, lsize, ic2, isr2, ic1, isr1, osr, 0.0));
3272 }
EXTENSION_NOINLINE double ST_Distance_Point_LineString(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)

+ Here is the call graph for this function:

EXTENSION_NOINLINE bool ST_Contains_LineString_Polygon ( int8_t *  l,
int64_t  lsize,
double *  lbounds,
int64_t  lbounds_size,
int8_t *  poly_coords,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
double *  poly_bounds,
int64_t  poly_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3275 of file ExtensionFunctionsGeo.hpp.

3289  {
3290  // TODO
3291  return false;
3292 }
EXTENSION_NOINLINE bool ST_Contains_MultiPolygon_LineString ( int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
double *  mpoly_bounds,
int64_t  mpoly_bounds_size,
int8_t *  l,
int64_t  lsize,
double *  lbounds,
int64_t  lbounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3642 of file ExtensionFunctionsGeo.hpp.

References box_contains_box(), compression_unit_size(), and ST_Contains_Polygon_LineString().

3658  {
3659  if (mpoly_num_polys <= 0) {
3660  return false;
3661  }
3662 
3663  if (mpoly_bounds && lbounds) {
3664  if (!box_contains_box(mpoly_bounds, mpoly_bounds_size, lbounds, lbounds_size)) {
3665  return false;
3666  }
3667  }
3668 
3669  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
3670  auto next_poly_coords = mpoly_coords;
3671  auto next_poly_ring_sizes = mpoly_ring_sizes;
3672 
3673  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
3674  auto poly_coords = next_poly_coords;
3675  auto poly_ring_sizes = next_poly_ring_sizes;
3676  auto poly_num_rings = mpoly_poly_sizes[poly];
3677  // Count number of coords in all of poly's rings, advance ring size pointer.
3678  int32_t poly_num_coords = 0;
3679  for (auto ring = 0; ring < poly_num_rings; ring++) {
3680  poly_num_coords += 2 * *next_poly_ring_sizes++;
3681  }
3682  auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
3683  next_poly_coords += poly_coords_size;
3684 
3685  if (ST_Contains_Polygon_LineString(poly_coords,
3686  poly_coords_size,
3687  poly_ring_sizes,
3688  poly_num_rings,
3689  nullptr,
3690  0,
3691  l,
3692  lsize,
3693  nullptr,
3694  0,
3695  ic1,
3696  isr1,
3697  ic2,
3698  isr2,
3699  osr)) {
3700  return true;
3701  }
3702  }
3703 
3704  return false;
3705 }
EXTENSION_NOINLINE bool ST_Contains_Polygon_LineString(int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE bool box_contains_box(double *bounds1, int64_t bounds1_size, double *bounds2, int64_t bounds2_size)

+ Here is the call graph for this function:

EXTENSION_NOINLINE bool ST_Contains_MultiPolygon_Point ( int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
double *  mpoly_bounds,
int64_t  mpoly_bounds_size,
int8_t *  p,
int64_t  psize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3575 of file ExtensionFunctionsGeo.hpp.

Referenced by ST_Intersects_Point_MultiPolygon().

3589  {
3590  return Contains_MultiPolygon_Point_Impl<double, EdgeBehavior::kExcludePointOnEdge>(
3591  mpoly_coords,
3592  mpoly_coords_size,
3593  mpoly_ring_sizes,
3594  mpoly_num_rings,
3595  mpoly_poly_sizes,
3596  mpoly_num_polys,
3597  mpoly_bounds,
3598  mpoly_bounds_size,
3599  p,
3600  psize,
3601  ic1,
3602  isr1,
3603  ic2,
3604  isr2,
3605  osr);
3606 }

+ Here is the caller graph for this function:

EXTENSION_NOINLINE bool ST_Contains_Point_LineString ( int8_t *  p,
int64_t  psize,
int8_t *  l,
int64_t  lsize,
double *  lbounds,
int64_t  lbounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3194 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), get_point(), i, and tol_eq().

Referenced by ST_Contains_Point_Polygon().

3204  {
3205  Point2D const pt = get_point(p, 0, ic1, isr1, osr);
3206 
3207  if (lbounds) {
3208  if (tol_eq(pt.x, lbounds[0]) && tol_eq(pt.y, lbounds[1]) &&
3209  tol_eq(pt.x, lbounds[2]) && tol_eq(pt.y, lbounds[3])) {
3210  return true;
3211  }
3212  }
3213 
3214  auto l_num_coords = lsize / compression_unit_size(ic2);
3215  for (int i = 0; i < l_num_coords; i += 2) {
3216  Point2D pl = get_point(l, i, ic2, isr2, osr);
3217  if (tol_eq(pt.x, pl.x) && tol_eq(pt.y, pl.y)) {
3218  continue;
3219  }
3220  return false;
3221  }
3222  return true;
3223 }
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE bool tol_eq(const double x, const double y, const double tolerance=TOLERANCE_DEFAULT)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE bool ST_Contains_Point_Point ( int8_t *  p1,
int64_t  p1size,
int8_t *  p2,
int64_t  p2size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3178 of file ExtensionFunctionsGeo.hpp.

References get_point(), tol(), and tol_eq().

3186  {
3187  Point2D const pt1 = get_point(p1, 0, ic1, isr1, osr);
3188  Point2D const pt2 = get_point(p2, 0, ic2, isr2, osr);
3189  double tolerance = tol(ic1, ic2);
3190  return tol_eq(pt1.x, pt2.x, tolerance) && tol_eq(pt1.y, pt2.y, tolerance);
3191 }
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double tol(int32_t ic)
DEVICE ALWAYS_INLINE bool tol_eq(const double x, const double y, const double tolerance=TOLERANCE_DEFAULT)

+ Here is the call graph for this function:

EXTENSION_NOINLINE bool ST_Contains_Point_Polygon ( int8_t *  p,
int64_t  psize,
int8_t *  poly_coords,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
double *  poly_bounds,
int64_t  poly_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3226 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and ST_Contains_Point_LineString().

3238  {
3239  auto exterior_ring_num_coords = poly_coords_size / compression_unit_size(ic2);
3240  if (poly_num_rings > 0) {
3241  exterior_ring_num_coords = poly_ring_sizes[0] * 2;
3242  }
3243  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic2);
3244 
3246  psize,
3247  poly_coords,
3248  exterior_ring_coords_size,
3249  poly_bounds,
3250  poly_bounds_size,
3251  ic1,
3252  isr1,
3253  ic2,
3254  isr2,
3255  osr);
3256 }
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
EXTENSION_NOINLINE bool ST_Contains_Point_LineString(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)

+ Here is the call graph for this function:

EXTENSION_NOINLINE bool ST_Contains_Polygon_LineString ( int8_t *  poly_coords,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
double *  poly_bounds,
int64_t  poly_bounds_size,
int8_t *  l,
int64_t  lsize,
double *  lbounds,
int64_t  lbounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3421 of file ExtensionFunctionsGeo.hpp.

References box_contains_box(), compression_unit_size(), and polygon_contains_linestring().

Referenced by ST_Contains_MultiPolygon_LineString(), and ST_Contains_Polygon_Polygon().

3435  {
3436  if (poly_num_rings > 1) {
3437  return false; // TODO: support polygons with interior rings
3438  }
3439 
3440  // Bail out if poly bounding box doesn't contain linestring bounding box
3441  if (poly_bounds && lbounds) {
3442  if (!box_contains_box(poly_bounds, poly_bounds_size, lbounds, lbounds_size)) {
3443  return false;
3444  }
3445  }
3446 
3447  const auto poly_num_coords = poly_coords_size / compression_unit_size(ic1);
3448  const auto lnum_coords = lsize / compression_unit_size(ic2);
3449 
3451  poly_coords, poly_num_coords, l, lnum_coords, ic1, isr1, ic2, isr2, osr);
3452 }
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE bool polygon_contains_linestring(int8_t *poly, int32_t poly_num_coords, int8_t *l, int64_t lnum_coords, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
DEVICE ALWAYS_INLINE bool box_contains_box(double *bounds1, int64_t bounds1_size, double *bounds2, int64_t bounds2_size)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE bool ST_Contains_Polygon_Point ( const int8_t *  poly_coords,
const int64_t  poly_coords_size,
const int32_t *  poly_ring_sizes,
const int64_t  poly_num_rings,
const double *  poly_bounds,
const int64_t  poly_bounds_size,
const int8_t *  p,
const int64_t  psize,
const int32_t  ic1,
const int32_t  isr1,
const int32_t  ic2,
const int32_t  isr2,
const int32_t  osr 
)

Definition at line 3362 of file ExtensionFunctionsGeo.hpp.

3374  {
3375  return Contains_Polygon_Point_Impl<double, EdgeBehavior::kExcludePointOnEdge>(
3376  poly_coords,
3377  poly_coords_size,
3378  poly_ring_sizes,
3379  poly_num_rings,
3380  poly_bounds,
3381  poly_bounds_size,
3382  p,
3383  psize,
3384  ic1,
3385  isr1,
3386  ic2,
3387  isr2,
3388  osr);
3389 }
EXTENSION_NOINLINE bool ST_Contains_Polygon_Polygon ( int8_t *  poly1_coords,
int64_t  poly1_coords_size,
int32_t *  poly1_ring_sizes,
int64_t  poly1_num_rings,
double *  poly1_bounds,
int64_t  poly1_bounds_size,
int8_t *  poly2_coords,
int64_t  poly2_coords_size,
int32_t *  poly2_ring_sizes,
int64_t  poly2_num_rings,
double *  poly2_bounds,
int64_t  poly2_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3455 of file ExtensionFunctionsGeo.hpp.

References box_contains_box(), compression_unit_size(), and ST_Contains_Polygon_LineString().

3471  {
3472  // TODO: needs to be extended, cover more cases
3473  // Right now only checking if simple poly1 (no holes) contains poly2's exterior shape
3474  if (poly1_num_rings > 1) {
3475  return false; // TODO: support polygons with interior rings
3476  }
3477 
3478  if (poly1_bounds && poly2_bounds) {
3479  if (!box_contains_box(
3480  poly1_bounds, poly1_bounds_size, poly2_bounds, poly2_bounds_size)) {
3481  return false;
3482  }
3483  }
3484 
3485  int64_t poly2_exterior_ring_coords_size = poly2_coords_size;
3486  if (poly2_num_rings > 0) {
3487  poly2_exterior_ring_coords_size =
3488  2 * poly2_ring_sizes[0] * compression_unit_size(ic2);
3489  }
3490  return ST_Contains_Polygon_LineString(poly1_coords,
3491  poly1_coords_size,
3492  poly1_ring_sizes,
3493  poly1_num_rings,
3494  poly1_bounds,
3495  poly1_bounds_size,
3496  poly2_coords,
3497  poly2_exterior_ring_coords_size,
3498  poly2_bounds,
3499  poly2_bounds_size,
3500  ic1,
3501  isr1,
3502  ic2,
3503  isr2,
3504  osr);
3505 }
EXTENSION_NOINLINE bool ST_Contains_Polygon_LineString(int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE bool box_contains_box(double *bounds1, int64_t bounds1_size, double *bounds2, int64_t bounds2_size)

+ Here is the call graph for this function:

EXTENSION_NOINLINE double ST_Distance_LineString_LineString ( int8_t *  l1,
int64_t  l1size,
int8_t *  l2,
int64_t  l2size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2035 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), distance_line_line(), get_point(), tol_zero(), and TOLERANCE_DEFAULT_SQUARED.

Referenced by ST_DWithin_LineString_LineString(), and ST_Intersects_LineString_Linestring().

2044  {
2045  auto l1_num_coords = l1size / compression_unit_size(ic1);
2046  auto l2_num_coords = l2size / compression_unit_size(ic2);
2047 
2048  double threshold_squared = threshold * threshold;
2049  double dist_squared = 0.0;
2050  Point2D l11 = get_point(l1, 0, ic1, isr1, osr);
2051  for (int32_t i1 = 2; i1 < l1_num_coords; i1 += 2) {
2052  Point2D l12 = get_point(l1, i1, ic1, isr1, osr);
2053  Point2D l21 = get_point(l2, 0, ic2, isr2, osr);
2054  for (int32_t i2 = 2; i2 < l2_num_coords; i2 += 2) {
2055  Point2D l22 = get_point(l2, i2, ic2, isr2, osr);
2056 
2057  // double ldist_squared =
2058  // distance_line_line_squared(l11x, l11y, l12x, l12y, l21x, l21y, l22x, l22y);
2059  // TODO: fix distance_line_line_squared
2060  double ldist =
2061  distance_line_line(l11.x, l11.y, l12.x, l12.y, l21.x, l21.y, l22.x, l22.y);
2062  double ldist_squared = ldist * ldist;
2063 
2064  if (i1 == 2 && i2 == 2) {
2065  dist_squared = ldist_squared; // initialize dist with distance between the first
2066  // two segments
2067  } else if (dist_squared > ldist_squared) {
2068  dist_squared = ldist_squared;
2069  }
2070  if (tol_zero(dist_squared, TOLERANCE_DEFAULT_SQUARED)) {
2071  return 0.0; // Segments touch, short-circuit
2072  }
2073  if (dist_squared <= threshold_squared) {
2074  // If threashold_squared is defined and the calculated dist_squared dips under it,
2075  // short-circuit and return it
2076  return sqrt(dist_squared);
2077  }
2078 
2079  l21 = l22; // advance to the next point on l2
2080  }
2081 
2082  l11 = l12; // advance to the next point on l1
2083  }
2084  return sqrt(dist_squared);
2085 }
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
#define TOLERANCE_DEFAULT_SQUARED
DEVICE double distance_line_line(double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double ST_Distance_LineString_MultiPolygon ( int8_t *  l,
int64_t  lsize,
int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2157 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), ST_Distance_LineString_Polygon(), and tol_zero().

Referenced by ST_Distance_MultiPolygon_LineString(), ST_DWithin_LineString_MultiPolygon(), and ST_Intersects_LineString_MultiPolygon().

2170  {
2171  // TODO: revisit implementation, cover all cases
2172  double min_distance = 0.0;
2173 
2174  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
2175  auto next_poly_coords = mpoly_coords;
2176  auto next_poly_ring_sizes = mpoly_ring_sizes;
2177 
2178  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
2179  auto poly_coords = next_poly_coords;
2180  auto poly_ring_sizes = next_poly_ring_sizes;
2181  auto poly_num_rings = mpoly_poly_sizes[poly];
2182  // Count number of coords in all of poly's rings, advance ring size pointer.
2183  int32_t poly_num_coords = 0;
2184  for (auto ring = 0; ring < poly_num_rings; ring++) {
2185  poly_num_coords += 2 * *next_poly_ring_sizes++;
2186  }
2187  auto poly_coords_size = poly_num_coords * compression_unit_size(ic2);
2188  next_poly_coords += poly_coords_size;
2189  double distance = ST_Distance_LineString_Polygon(l,
2190  lsize,
2191  poly_coords,
2192  poly_coords_size,
2193  poly_ring_sizes,
2194  poly_num_rings,
2195  ic1,
2196  isr1,
2197  ic2,
2198  isr2,
2199  osr,
2200  threshold);
2201  if (poly == 0 || min_distance > distance) {
2202  min_distance = distance;
2203  if (tol_zero(min_distance)) {
2204  min_distance = 0.0;
2205  break;
2206  }
2207  if (min_distance <= threshold) {
2208  return min_distance;
2209  }
2210  }
2211  }
2212 
2213  return min_distance;
2214 }
EXTENSION_NOINLINE double ST_Distance_LineString_Polygon(int8_t *l, int64_t lsize, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE double ST_Distance_LineString_Point ( int8_t *  l,
int64_t  lsize,
int8_t *  p,
int64_t  psize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2020 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString().

2029  {
2031  p, psize, l, lsize, ic2, isr2, ic1, isr1, osr, threshold);
2032 }
EXTENSION_NOINLINE double ST_Distance_Point_LineString(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

EXTENSION_INLINE double ST_Distance_LineString_Point_Geodesic ( int8_t *  l,
int64_t  lsize,
int8_t *  p,
int64_t  psize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 1819 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString_Geodesic().

1827  {
1828  // Currently only statically indexed LineString is supported
1830  p, psize, l, lsize, ic2, isr2, ic1, isr1, osr);
1831 }
EXTENSION_NOINLINE double ST_Distance_Point_LineString_Geodesic(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)

+ Here is the call graph for this function:

EXTENSION_NOINLINE double ST_Distance_LineString_Polygon ( int8_t *  l,
int64_t  lsize,
int8_t *  poly_coords,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2088 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), distance_ring_linestring(), ST_Distance_Point_Polygon(), and tol_zero().

Referenced by ST_Distance_LineString_MultiPolygon(), ST_Distance_Polygon_LineString(), ST_DWithin_LineString_Polygon(), and ST_Intersects_LineString_Polygon().

2099  {
2100  auto lnum_coords = lsize / compression_unit_size(ic1);
2101  auto psize = 2 * compression_unit_size(ic1);
2102  auto min_distance =
2103  ST_Distance_Point_Polygon(l, // pointer to start of linestring for first point
2104  psize,
2105  poly_coords,
2106  poly_coords_size,
2107  poly_ring_sizes,
2108  poly_num_rings,
2109  ic1,
2110  isr1,
2111  ic2,
2112  isr2,
2113  osr,
2114  threshold);
2115  if (tol_zero(min_distance)) {
2116  // Linestring's first point is inside the poly
2117  return 0.0;
2118  }
2119  if (min_distance <= threshold) {
2120  return min_distance;
2121  }
2122 
2123  // Otherwise, linestring's first point is outside the external ring or inside
2124  // an internal ring. Measure minimum distance between linestring segments and
2125  // poly rings. Crossing a ring zeroes the distance and causes an early return.
2126  auto poly_ring_coords = poly_coords;
2127  for (auto r = 0; r < poly_num_rings; r++) {
2128  int64_t poly_ring_num_coords = poly_ring_sizes[r] * 2;
2129 
2130  auto distance = distance_ring_linestring(poly_ring_coords,
2131  poly_ring_num_coords,
2132  l,
2133  lnum_coords,
2134  ic2,
2135  isr2,
2136  ic1,
2137  isr1,
2138  osr,
2139  threshold);
2140  if (min_distance > distance) {
2141  min_distance = distance;
2142  if (tol_zero(min_distance)) {
2143  return 0.0;
2144  }
2145  if (min_distance <= threshold) {
2146  return min_distance;
2147  }
2148  }
2149 
2150  poly_ring_coords += poly_ring_num_coords * compression_unit_size(ic2);
2151  }
2152 
2153  return min_distance;
2154 }
EXTENSION_NOINLINE double ST_Distance_Point_Polygon(int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE double distance_ring_linestring(int8_t *ring, int32_t ring_num_coords, int8_t *l, int32_t lnum_coords, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE double ST_Distance_MultiPolygon_LineString ( int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
int8_t *  l,
int64_t  lsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2450 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_LineString_MultiPolygon().

2463  {
2465  lsize,
2466  mpoly_coords,
2467  mpoly_coords_size,
2468  mpoly_ring_sizes,
2469  mpoly_num_rings,
2470  mpoly_poly_sizes,
2471  mpoly_num_polys,
2472  ic2,
2473  isr2,
2474  ic1,
2475  isr1,
2476  osr,
2477  threshold);
2478 }
EXTENSION_NOINLINE double ST_Distance_LineString_MultiPolygon(int8_t *l, int64_t lsize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

EXTENSION_NOINLINE double ST_Distance_MultiPolygon_MultiPolygon ( int8_t *  mpoly1_coords,
int64_t  mpoly1_coords_size,
int32_t *  mpoly1_ring_sizes,
int64_t  mpoly1_num_rings,
int32_t *  mpoly1_poly_sizes,
int64_t  mpoly1_num_polys,
int8_t *  mpoly2_coords,
int64_t  mpoly2_coords_size,
int32_t *  mpoly2_ring_sizes,
int64_t  mpoly2_num_rings,
int32_t *  mpoly2_poly_sizes,
int64_t  mpoly2_num_polys,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2516 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), ST_Distance_Polygon_MultiPolygon(), and tol_zero().

Referenced by ST_DWithin_MultiPolygon_MultiPolygon(), and ST_Intersects_MultiPolygon_MultiPolygon().

2533  {
2534  double min_distance = 0.0;
2535 
2536  // Set specific poly pointers as we move through mpoly1's coords/ringsizes/polyrings
2537  // arrays.
2538  auto next_poly_coords = mpoly1_coords;
2539  auto next_poly_ring_sizes = mpoly1_ring_sizes;
2540 
2541  for (auto poly = 0; poly < mpoly1_num_polys; poly++) {
2542  auto poly_coords = next_poly_coords;
2543  auto poly_ring_sizes = next_poly_ring_sizes;
2544  auto poly_num_rings = mpoly1_poly_sizes[poly];
2545  // Count number of coords in all of poly's rings, advance ring size pointer.
2546  int32_t poly_num_coords = 0;
2547  for (auto ring = 0; ring < poly_num_rings; ring++) {
2548  poly_num_coords += 2 * *next_poly_ring_sizes++;
2549  }
2550  auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
2551  next_poly_coords += poly_coords_size;
2552  double distance = ST_Distance_Polygon_MultiPolygon(poly_coords,
2553  poly_coords_size,
2554  poly_ring_sizes,
2555  poly_num_rings,
2556  mpoly2_coords,
2557  mpoly2_coords_size,
2558  mpoly2_ring_sizes,
2559  mpoly2_num_rings,
2560  mpoly2_poly_sizes,
2561  mpoly2_num_polys,
2562  ic1,
2563  isr1,
2564  ic2,
2565  isr2,
2566  osr,
2567  threshold);
2568  if (poly == 0 || min_distance > distance) {
2569  min_distance = distance;
2570  if (tol_zero(min_distance)) {
2571  min_distance = 0.0;
2572  break;
2573  }
2574  if (min_distance <= threshold) {
2575  break;
2576  }
2577  }
2578  }
2579 
2580  return min_distance;
2581 }
EXTENSION_NOINLINE double ST_Distance_Polygon_MultiPolygon(int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE double ST_Distance_MultiPolygon_Point ( int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
int8_t *  p,
int64_t  psize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2419 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_MultiPolygon().

2432  {
2434  psize,
2435  mpoly_coords,
2436  mpoly_coords_size,
2437  mpoly_ring_sizes,
2438  mpoly_num_rings,
2439  mpoly_poly_sizes,
2440  mpoly_num_polys,
2441  ic2,
2442  isr2,
2443  ic1,
2444  isr1,
2445  osr,
2446  threshold);
2447 }
EXTENSION_NOINLINE double ST_Distance_Point_MultiPolygon(int8_t *p, int64_t psize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

EXTENSION_INLINE double ST_Distance_MultiPolygon_Polygon ( int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
int8_t *  poly1_coords,
int64_t  poly1_coords_size,
int32_t *  poly1_ring_sizes,
int64_t  poly1_num_rings,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2481 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Polygon_MultiPolygon().

2496  {
2497  return ST_Distance_Polygon_MultiPolygon(poly1_coords,
2498  poly1_coords_size,
2499  poly1_ring_sizes,
2500  poly1_num_rings,
2501  mpoly_coords,
2502  mpoly_coords_size,
2503  mpoly_ring_sizes,
2504  mpoly_num_rings,
2505  mpoly_poly_sizes,
2506  mpoly_num_polys,
2507  ic2,
2508  isr2,
2509  ic1,
2510  isr1,
2511  osr,
2512  threshold);
2513 }
EXTENSION_NOINLINE double ST_Distance_Polygon_MultiPolygon(int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

EXTENSION_NOINLINE double ST_Distance_Point_ClosedLineString ( int8_t *  p,
int64_t  psize,
int8_t *  l,
int64_t  lsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 1875 of file ExtensionFunctionsGeo.hpp.

References distance_point_linestring().

Referenced by ST_Distance_Point_Polygon().

1884  {
1886  p, psize, l, lsize, ic1, isr1, ic2, isr2, osr, true, threshold);
1887 }
DEVICE ALWAYS_INLINE double distance_point_linestring(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, bool check_closed, double threshold)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double ST_Distance_Point_LineString ( int8_t *  p,
int64_t  psize,
int8_t *  l,
int64_t  lsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 1890 of file ExtensionFunctionsGeo.hpp.

References distance_point_linestring().

Referenced by ST_Contains_LineString_Point(), ST_Distance_LineString_Point(), ST_DWithin_Point_LineString(), and ST_Intersects_Point_LineString().

1899  {
1901  p, psize, l, lsize, ic1, isr1, ic2, isr2, osr, false, threshold);
1902 }
DEVICE ALWAYS_INLINE double distance_point_linestring(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, bool check_closed, double threshold)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double ST_Distance_Point_LineString_Geodesic ( int8_t *  p,
int64_t  psize,
int8_t *  l,
int64_t  lsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 1802 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), distance_in_meters(), and get_point().

Referenced by ST_Distance_LineString_Point_Geodesic().

1810  {
1811  // Currently only statically indexed LineString is supported
1812  Point2D const pt = get_point(p, 0, ic1, 4326, 4326);
1813  const auto lpoints = lsize / (2 * compression_unit_size(ic2));
1814  Point2D const pl = get_point(l, 2 * (lpoints - 1), ic2, 4326, 4326);
1815  return distance_in_meters(pt.x, pt.y, pl.x, pl.y);
1816 }
EXTENSION_NOINLINE double distance_in_meters(const double fromlon, const double fromlat, const double tolon, const double tolat)
Computes the distance, in meters, between two WGS-84 positions.
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double ST_Distance_Point_MultiPolygon ( int8_t *  p,
int64_t  psize,
int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 1958 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), ST_Distance_Point_Polygon(), and tol_zero().

Referenced by ST_Distance_MultiPolygon_Point(), and ST_DWithin_Point_MultiPolygon().

1971  {
1972  if (mpoly_num_polys <= 0) {
1973  return 0.0;
1974  }
1975  double min_distance = 0.0;
1976 
1977  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1978  auto next_poly_coords = mpoly_coords;
1979  auto next_poly_ring_sizes = mpoly_ring_sizes;
1980 
1981  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1982  auto poly_coords = next_poly_coords;
1983  auto poly_ring_sizes = next_poly_ring_sizes;
1984  auto poly_num_rings = mpoly_poly_sizes[poly];
1985  // Count number of coords in all of poly's rings, advance ring size pointer.
1986  int32_t poly_num_coords = 0;
1987  for (auto ring = 0; ring < poly_num_rings; ring++) {
1988  poly_num_coords += 2 * *next_poly_ring_sizes++;
1989  }
1990  auto poly_coords_size = poly_num_coords * compression_unit_size(ic2);
1991  next_poly_coords += poly_coords_size;
1992  double distance = ST_Distance_Point_Polygon(p,
1993  psize,
1994  poly_coords,
1995  poly_coords_size,
1996  poly_ring_sizes,
1997  poly_num_rings,
1998  ic1,
1999  isr1,
2000  ic2,
2001  isr2,
2002  osr,
2003  threshold);
2004  if (poly == 0 || min_distance > distance) {
2005  min_distance = distance;
2006  if (tol_zero(min_distance)) {
2007  min_distance = 0.0;
2008  break;
2009  }
2010  if (min_distance <= threshold) {
2011  break;
2012  }
2013  }
2014  }
2015 
2016  return min_distance;
2017 }
EXTENSION_NOINLINE double ST_Distance_Point_Polygon(int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double ST_Distance_Point_Point ( int8_t *  p1,
int64_t  p1size,
int8_t *  p2,
int64_t  p2size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 1757 of file ExtensionFunctionsGeo.hpp.

References distance_point_point(), and get_point().

Referenced by ST_Intersects_Point_Point().

1765  {
1766  Point2D const pt1 = get_point(p1, 0, ic1, isr1, osr);
1767  Point2D const pt2 = get_point(p2, 0, ic2, isr2, osr);
1768  return distance_point_point(pt1.x, pt1.y, pt2.x, pt2.y);
1769 }
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double distance_point_point(double p1x, double p1y, double p2x, double p2y)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double ST_Distance_Point_Point_Geodesic ( int8_t *  p1,
int64_t  p1size,
int8_t *  p2,
int64_t  p2size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 1787 of file ExtensionFunctionsGeo.hpp.

References distance_in_meters(), and get_point().

Referenced by ST_DWithin_Point_Point_Geodesic().

1795  {
1796  Point2D const pt1 = get_point(p1, 0, ic1, 4326, 4326);
1797  Point2D const pt2 = get_point(p2, 0, ic2, 4326, 4326);
1798  return distance_in_meters(pt1.x, pt1.y, pt2.x, pt2.y);
1799 }
EXTENSION_NOINLINE double distance_in_meters(const double fromlon, const double fromlat, const double tolon, const double tolat)
Computes the distance, in meters, between two WGS-84 positions.
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double ST_Distance_Point_Point_Squared ( int8_t *  p1,
int64_t  p1size,
int8_t *  p2,
int64_t  p2size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 1772 of file ExtensionFunctionsGeo.hpp.

References distance_point_point_squared(), and get_point().

Referenced by ST_DWithin_Point_Point().

1780  {
1781  Point2D const pt1 = get_point(p1, 0, ic1, isr1, osr);
1782  Point2D const pt2 = get_point(p2, 0, ic2, isr2, osr);
1783  return distance_point_point_squared(pt1.x, pt1.y, pt2.x, pt2.y);
1784 }
DEVICE ALWAYS_INLINE double distance_point_point_squared(double p1x, double p1y, double p2x, double p2y)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double ST_Distance_Point_Polygon ( int8_t *  p,
int64_t  psize,
int8_t *  poly,
int64_t  polysize,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 1905 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), get_point(), polygon_contains_point(), and ST_Distance_Point_ClosedLineString().

Referenced by ST_Distance_LineString_Polygon(), ST_Distance_Point_MultiPolygon(), ST_Distance_Polygon_Point(), and ST_DWithin_Point_Polygon().

1916  {
1917  auto exterior_ring_num_coords = polysize / compression_unit_size(ic2);
1918  if (poly_num_rings > 0) {
1919  exterior_ring_num_coords = poly_ring_sizes[0] * 2;
1920  }
1921  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic2);
1922 
1923  Point2D pt = get_point(p, 0, ic1, isr1, osr);
1925  poly, exterior_ring_num_coords, pt.x, pt.y, ic2, isr2, osr)) {
1926  // Outside the exterior ring
1928  p, psize, poly, exterior_ring_coords_size, ic1, isr1, ic2, isr2, osr, threshold);
1929  }
1930  // Inside exterior ring
1931  // Advance to first interior ring
1932  poly += exterior_ring_coords_size;
1933  // Check if one of the polygon's holes contains that point
1934  for (auto r = 1; r < poly_num_rings; r++) {
1935  auto interior_ring_num_coords = poly_ring_sizes[r] * 2;
1936  auto interior_ring_coords_size =
1937  interior_ring_num_coords * compression_unit_size(ic2);
1939  poly, interior_ring_num_coords, pt.x, pt.y, ic2, isr2, osr)) {
1940  // Inside an interior ring
1942  psize,
1943  poly,
1944  interior_ring_coords_size,
1945  ic1,
1946  isr1,
1947  ic2,
1948  isr2,
1949  osr,
1950  threshold);
1951  }
1952  poly += interior_ring_coords_size;
1953  }
1954  return 0.0;
1955 }
DEVICE ALWAYS_INLINE bool polygon_contains_point(const int8_t *poly, const int32_t poly_num_coords, const double px, const double py, const int32_t ic1, const int32_t isr1, const int32_t osr)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE Point2D get_point(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
EXTENSION_NOINLINE double ST_Distance_Point_ClosedLineString(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE double ST_Distance_Polygon_LineString ( int8_t *  poly_coords,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
int8_t *  l,
int64_t  lsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2244 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_LineString_Polygon().

2255  {
2257  lsize,
2258  poly_coords,
2259  poly_coords_size,
2260  poly_ring_sizes,
2261  poly_num_rings,
2262  ic2,
2263  isr2,
2264  ic1,
2265  isr2,
2266  osr,
2267  threshold);
2268 }
EXTENSION_NOINLINE double ST_Distance_LineString_Polygon(int8_t *l, int64_t lsize, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

EXTENSION_NOINLINE double ST_Distance_Polygon_MultiPolygon ( int8_t *  poly1_coords,
int64_t  poly1_coords_size,
int32_t *  poly1_ring_sizes,
int64_t  poly1_num_rings,
int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2356 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), ST_Distance_Polygon_Polygon(), and tol_zero().

Referenced by ST_Distance_MultiPolygon_MultiPolygon(), ST_Distance_MultiPolygon_Polygon(), ST_DWithin_Polygon_MultiPolygon(), and ST_Intersects_Polygon_MultiPolygon().

2371  {
2372  double min_distance = 0.0;
2373 
2374  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
2375  auto next_poly_coords = mpoly_coords;
2376  auto next_poly_ring_sizes = mpoly_ring_sizes;
2377 
2378  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
2379  auto poly_coords = next_poly_coords;
2380  auto poly_ring_sizes = next_poly_ring_sizes;
2381  auto poly_num_rings = mpoly_poly_sizes[poly];
2382  // Count number of coords in all of poly's rings, advance ring size pointer.
2383  int32_t poly_num_coords = 0;
2384  for (auto ring = 0; ring < poly_num_rings; ring++) {
2385  poly_num_coords += 2 * *next_poly_ring_sizes++;
2386  }
2387  auto poly_coords_size = poly_num_coords * compression_unit_size(ic2);
2388  next_poly_coords += poly_coords_size;
2389  double distance = ST_Distance_Polygon_Polygon(poly1_coords,
2390  poly1_coords_size,
2391  poly1_ring_sizes,
2392  poly1_num_rings,
2393  poly_coords,
2394  poly_coords_size,
2395  poly_ring_sizes,
2396  poly_num_rings,
2397  ic1,
2398  isr1,
2399  ic2,
2400  isr2,
2401  osr,
2402  threshold);
2403  if (poly == 0 || min_distance > distance) {
2404  min_distance = distance;
2405  if (tol_zero(min_distance)) {
2406  min_distance = 0.0;
2407  break;
2408  }
2409  if (min_distance <= threshold) {
2410  break;
2411  }
2412  }
2413  }
2414 
2415  return min_distance;
2416 }
EXTENSION_NOINLINE double ST_Distance_Polygon_Polygon(int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int8_t *poly2_coords, int64_t poly2_coords_size, int32_t *poly2_ring_sizes, int64_t poly2_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE double ST_Distance_Polygon_Point ( int8_t *  poly_coords,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
int8_t *  p,
int64_t  psize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2217 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_Polygon().

Referenced by ST_Distance_Polygon_Polygon().

2228  {
2229  return ST_Distance_Point_Polygon(p,
2230  psize,
2231  poly_coords,
2232  poly_coords_size,
2233  poly_ring_sizes,
2234  poly_num_rings,
2235  ic2,
2236  isr2,
2237  ic1,
2238  isr1,
2239  osr,
2240  threshold);
2241 }
EXTENSION_NOINLINE double ST_Distance_Point_Polygon(int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double ST_Distance_Polygon_Polygon ( int8_t *  poly1_coords,
int64_t  poly1_coords_size,
int32_t *  poly1_ring_sizes,
int64_t  poly1_num_rings,
int8_t *  poly2_coords,
int64_t  poly2_coords_size,
int32_t *  poly2_ring_sizes,
int64_t  poly2_num_rings,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2271 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), distance_ring_ring(), ST_Distance_Polygon_Point(), and tol_zero().

Referenced by ST_Distance_Polygon_MultiPolygon(), ST_DWithin_Polygon_Polygon(), and ST_Intersects_Polygon_Polygon().

2284  {
2285  // Check if poly1 contains the first point of poly2's shape, i.e. the external ring
2286  auto poly2_first_point_coords = poly2_coords;
2287  auto poly2_first_point_coords_size = compression_unit_size(ic2) * 2;
2288  auto min_distance = ST_Distance_Polygon_Point(poly1_coords,
2289  poly1_coords_size,
2290  poly1_ring_sizes,
2291  poly1_num_rings,
2292  poly2_first_point_coords,
2293  poly2_first_point_coords_size,
2294  ic1,
2295  isr1,
2296  ic2,
2297  isr2,
2298  osr,
2299  threshold);
2300  if (tol_zero(min_distance)) {
2301  // Polygons overlap
2302  return 0.0;
2303  }
2304  if (min_distance <= threshold) {
2305  return min_distance;
2306  }
2307 
2308  // Poly2's first point is either outside poly1's external ring or inside one of the
2309  // internal rings. Measure the smallest distance between a poly1 ring (external or
2310  // internal) and a poly2 ring (external or internal). If poly2 is completely outside
2311  // poly1, then the min distance would be between poly1's and poly2's external rings. If
2312  // poly2 is completely inside one of poly1 internal rings then the min distance would be
2313  // between that poly1 internal ring and poly2's external ring. If poly1 is completely
2314  // inside one of poly2 internal rings, min distance is between that internal ring and
2315  // poly1's external ring. In each case other rings don't get in the way. Any ring
2316  // intersection means zero distance - short-circuit and return.
2317 
2318  auto poly1_ring_coords = poly1_coords;
2319  for (auto r1 = 0; r1 < poly1_num_rings; r1++) {
2320  int64_t poly1_ring_num_coords = poly1_ring_sizes[r1] * 2;
2321 
2322  auto poly2_ring_coords = poly2_coords;
2323  for (auto r2 = 0; r2 < poly2_num_rings; r2++) {
2324  int64_t poly2_ring_num_coords = poly2_ring_sizes[r2] * 2;
2325 
2326  auto distance = distance_ring_ring(poly1_ring_coords,
2327  poly1_ring_num_coords,
2328  poly2_ring_coords,
2329  poly2_ring_num_coords,
2330  ic1,
2331  isr1,
2332  ic2,
2333  isr2,
2334  osr,
2335  threshold);
2336  if (min_distance > distance) {
2337  min_distance = distance;
2338  if (tol_zero(min_distance)) {
2339  return 0.0;
2340  }
2341  if (min_distance <= threshold) {
2342  return min_distance;
2343  }
2344  }
2345 
2346  poly2_ring_coords += poly2_ring_num_coords * compression_unit_size(ic2);
2347  }
2348 
2349  poly1_ring_coords += poly1_ring_num_coords * compression_unit_size(ic1);
2350  }
2351 
2352  return min_distance;
2353 }
DEVICE double distance_ring_ring(int8_t *ring1, int32_t ring1_num_coords, int8_t *ring2, int32_t ring2_num_coords, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
EXTENSION_INLINE double ST_Distance_Polygon_Point(int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE bool ST_DWithin_LineString_LineString ( int8_t *  l1,
int64_t  l1size,
double *  l1bounds,
int64_t  l1bounds_size,
int8_t *  l2,
int64_t  l2size,
double *  l2bounds,
int64_t  l2bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2742 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), and ST_Distance_LineString_LineString().

2755  {
2756  if (l1bounds && l2bounds) {
2757  // Bounding boxes need to be transformed to output SR before proximity check
2758  if (!box_dwithin_box(l1bounds,
2759  l1bounds_size,
2760  isr1,
2761  l2bounds,
2762  l2bounds_size,
2763  isr2,
2764  osr,
2765  distance_within)) {
2766  return false;
2767  }
2768  }
2769 
2770  // May need to adjust the threshold by TOLERANCE_DEFAULT
2771  const double threshold = distance_within;
2773  l1, l1size, l2, l2size, ic1, isr1, ic2, isr2, osr, threshold) <=
2774  distance_within;
2775 }
EXTENSION_NOINLINE double ST_Distance_LineString_LineString(int8_t *l1, int64_t l1size, int8_t *l2, int64_t l2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool box_dwithin_box(double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)

+ Here is the call graph for this function:

EXTENSION_INLINE bool ST_DWithin_LineString_MultiPolygon ( int8_t *  l1,
int64_t  l1size,
double *  l1bounds,
int64_t  l1bounds_size,
int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
double *  mpoly_bounds,
int64_t  mpoly_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2843 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), compression_unit_size(), ST_Distance_LineString_MultiPolygon(), and trim_linestring_to_buffered_box().

2860  {
2861  if (l1bounds && mpoly_bounds) {
2862  // Bounding boxes need to be transformed to output SR before proximity check
2863  if (!box_dwithin_box(l1bounds,
2864  l1bounds_size,
2865  isr1,
2866  mpoly_bounds,
2867  mpoly_bounds_size,
2868  isr2,
2869  osr,
2870  distance_within)) {
2871  return false;
2872  }
2873  }
2874 
2875  // First, assume the entire linestring is relevant.
2876  CoordData l1_relevant_section{l1, l1size};
2877  // Mitigation for very long linestrings (5+ segments: think highways, powerlines)
2878  if (mpoly_bounds && l1size > 12 * compression_unit_size(ic1)) {
2879  // Before diving into distance calculations, try to trim the linestring just to
2880  // segments whose bounding boxes overlap the threshold-buffered mpoly bounding box.
2881  l1_relevant_section = trim_linestring_to_buffered_box(l1,
2882  l1size,
2883  ic1,
2884  isr1,
2885  mpoly_bounds,
2886  mpoly_bounds_size,
2887  isr2,
2888  osr,
2889  distance_within);
2890  if (!l1_relevant_section.ptr) {
2891  // The big short-circuit: if not a single segment's bounding box overlaped
2892  // with buffered mpoly bounding box, then it means that the entire linestring
2893  // doesn't come close enough to the multipolygon to be within distance.
2894  // The global bounding boxes for the input geometries may overlap but the linestring
2895  // never gets close enough to the mpoly to require an actual distance calculation.
2896  return false;
2897  }
2898  }
2899 
2900  // Run distance calculation but only on the linestring section that is relevant.
2901  // May need to adjust the threshold by TOLERANCE_DEFAULT
2902  const double threshold = distance_within;
2903  return ST_Distance_LineString_MultiPolygon(l1_relevant_section.ptr,
2904  l1_relevant_section.size,
2905  mpoly_coords,
2906  mpoly_coords_size,
2907  mpoly_ring_sizes,
2908  mpoly_num_rings,
2909  mpoly_poly_sizes,
2910  mpoly_num_polys,
2911  ic1,
2912  isr1,
2913  ic2,
2914  isr2,
2915  osr,
2916  threshold) <= distance_within;
2917 }
DEVICE ALWAYS_INLINE bool box_dwithin_box(double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
DEVICE ALWAYS_INLINE CoordData trim_linestring_to_buffered_box(int8_t *l1, int64_t l1size, int32_t ic1, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
EXTENSION_NOINLINE double ST_Distance_LineString_MultiPolygon(int8_t *l, int64_t lsize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)

+ Here is the call graph for this function:

EXTENSION_INLINE bool ST_DWithin_LineString_Polygon ( int8_t *  l1,
int64_t  l1size,
double *  l1bounds,
int64_t  l1bounds_size,
int8_t *  poly_coords,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
double *  poly_bounds,
int64_t  poly_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2778 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), compression_unit_size(), ST_Distance_LineString_Polygon(), and trim_linestring_to_buffered_box().

2793  {
2794  if (l1bounds && poly_bounds) {
2795  // Bounding boxes need to be transformed to output SR before proximity check
2796  if (!box_dwithin_box(l1bounds,
2797  l1bounds_size,
2798  isr1,
2799  poly_bounds,
2800  poly_bounds_size,
2801  isr2,
2802  osr,
2803  distance_within)) {
2804  return false;
2805  }
2806  }
2807 
2808  // First, assume the entire linestring is relevant.
2809  CoordData l1_relevant_section{l1, l1size};
2810  // Mitigation for very long linestrings (5+ segments: think highways, powerlines)
2811  if (poly_bounds && l1size > 12 * compression_unit_size(ic1)) {
2812  // Before diving into distance calculations, try to trim the linestring just to
2813  // segments whose bounding boxes overlap the threshold-buffered poly bounding box.
2814  l1_relevant_section = trim_linestring_to_buffered_box(
2815  l1, l1size, ic1, isr1, poly_bounds, poly_bounds_size, isr2, osr, distance_within);
2816  if (!l1_relevant_section.ptr) {
2817  // The big short-circuit: if not a single segment's bounding box overlaped
2818  // with buffered poly bounding box, then it means that the entire linestring
2819  // doesn't come close enough to the polygon to be within distance.
2820  // The global bounding boxes for the input geometries may overlap but the linestring
2821  // never gets close enough to the poly to require an actual distance calculation.
2822  return false;
2823  }
2824  }
2825 
2826  // May need to adjust the threshold by TOLERANCE_DEFAULT
2827  const double threshold = distance_within;
2828  return ST_Distance_LineString_Polygon(l1_relevant_section.ptr,
2829  l1_relevant_section.size,
2830  poly_coords,
2831  poly_coords_size,
2832  poly_ring_sizes,
2833  poly_num_rings,
2834  ic1,
2835  isr1,
2836  ic2,
2837  isr2,
2838  osr,
2839  threshold) <= distance_within;
2840 }
DEVICE ALWAYS_INLINE bool box_dwithin_box(double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
DEVICE ALWAYS_INLINE CoordData trim_linestring_to_buffered_box(int8_t *l1, int64_t l1size, int32_t ic1, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
EXTENSION_NOINLINE double ST_Distance_LineString_Polygon(int8_t *l, int64_t lsize, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)

+ Here is the call graph for this function:

EXTENSION_INLINE bool ST_DWithin_MultiPolygon_MultiPolygon ( int8_t *  mpoly1_coords,
int64_t  mpoly1_coords_size,
int32_t *  mpoly1_ring_sizes,
int64_t  mpoly1_num_rings,
int32_t *  mpoly1_poly_sizes,
int64_t  mpoly1_num_polys,
double *  mpoly1_bounds,
int64_t  mpoly1_bounds_size,
int8_t *  mpoly2_coords,
int64_t  mpoly2_coords_size,
int32_t *  mpoly2_ring_sizes,
int64_t  mpoly2_num_rings,
int32_t *  mpoly2_poly_sizes,
int64_t  mpoly2_num_polys,
double *  mpoly2_bounds,
int64_t  mpoly2_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 3026 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), and ST_Distance_MultiPolygon_MultiPolygon().

3047  {
3048  if (mpoly1_bounds && mpoly2_bounds) {
3049  // Bounding boxes need to be transformed to output SR before proximity check
3050  if (!box_dwithin_box(mpoly1_bounds,
3051  mpoly1_bounds_size,
3052  isr1,
3053  mpoly2_bounds,
3054  mpoly2_bounds_size,
3055  isr2,
3056  osr,
3057  distance_within)) {
3058  return false;
3059  }
3060  }
3061 
3062  // May need to adjust the threshold by TOLERANCE_DEFAULT
3063  const double threshold = distance_within;
3064  return ST_Distance_MultiPolygon_MultiPolygon(mpoly1_coords,
3065  mpoly1_coords_size,
3066  mpoly1_ring_sizes,
3067  mpoly1_num_rings,
3068  mpoly1_poly_sizes,
3069  mpoly1_num_polys,
3070  mpoly2_coords,
3071  mpoly2_coords_size,
3072  mpoly2_ring_sizes,
3073  mpoly2_num_rings,
3074  mpoly2_poly_sizes,
3075  mpoly2_num_polys,
3076  ic1,
3077  isr1,
3078  ic2,
3079  isr2,
3080  osr,
3081  threshold) <= distance_within;
3082 }
DEVICE ALWAYS_INLINE bool box_dwithin_box(double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
EXTENSION_NOINLINE double ST_Distance_MultiPolygon_MultiPolygon(int8_t *mpoly1_coords, int64_t mpoly1_coords_size, int32_t *mpoly1_ring_sizes, int64_t mpoly1_num_rings, int32_t *mpoly1_poly_sizes, int64_t mpoly1_num_polys, int8_t *mpoly2_coords, int64_t mpoly2_coords_size, int32_t *mpoly2_ring_sizes, int64_t mpoly2_num_rings, int32_t *mpoly2_poly_sizes, int64_t mpoly2_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

EXTENSION_INLINE bool ST_DWithin_Point_LineString ( int8_t *  p1,
int64_t  p1size,
int8_t *  l2,
int64_t  l2size,
double *  l2bounds,
int64_t  l2bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2620 of file ExtensionFunctionsGeo.hpp.

References point_dwithin_box(), and ST_Distance_Point_LineString().

2631  {
2632  if (l2bounds) {
2633  // Bounding boxes need to be transformed to output SR before proximity check
2634  if (!point_dwithin_box(
2635  p1, p1size, ic1, isr1, l2bounds, l2bounds_size, isr2, osr, distance_within)) {
2636  return false;
2637  }
2638  }
2639 
2640  // May need to adjust the threshold by TOLERANCE_DEFAULT
2641  const double threshold = distance_within;
2643  p1, p1size, l2, l2size, ic1, isr1, ic2, isr2, osr, threshold) <=
2644  distance_within;
2645 }
EXTENSION_NOINLINE double ST_Distance_Point_LineString(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool point_dwithin_box(int8_t *p1, int64_t p1size, int32_t ic1, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)

+ Here is the call graph for this function:

EXTENSION_INLINE bool ST_DWithin_Point_MultiPolygon ( int8_t *  p,
int64_t  psize,
int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
double *  mpoly_bounds,
int64_t  mpoly_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2693 of file ExtensionFunctionsGeo.hpp.

References point_dwithin_box(), and ST_Distance_Point_MultiPolygon().

2708  {
2709  if (mpoly_bounds) {
2710  if (!point_dwithin_box(p,
2711  psize,
2712  ic1,
2713  isr1,
2714  mpoly_bounds,
2715  mpoly_bounds_size,
2716  isr2,
2717  osr,
2718  distance_within)) {
2719  return false;
2720  }
2721  }
2722 
2723  // May need to adjust the threshold by TOLERANCE_DEFAULT
2724  const double threshold = distance_within;
2726  psize,
2727  mpoly_coords,
2728  mpoly_coords_size,
2729  mpoly_ring_sizes,
2730  mpoly_num_rings,
2731  mpoly_poly_sizes,
2732  mpoly_num_polys,
2733  ic1,
2734  isr1,
2735  ic2,
2736  isr2,
2737  osr,
2738  threshold) <= distance_within;
2739 }
EXTENSION_NOINLINE double ST_Distance_Point_MultiPolygon(int8_t *p, int64_t psize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool point_dwithin_box(int8_t *p1, int64_t p1size, int32_t ic1, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)

+ Here is the call graph for this function:

EXTENSION_INLINE bool ST_DWithin_Point_Point ( int8_t *  p1,
int64_t  p1size,
int8_t *  p2,
int64_t  p2size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2588 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_Point_Squared().

2597  {
2599  p1, p1size, p2, p2size, ic1, isr1, ic2, isr2, osr) <=
2600  distance_within * distance_within;
2601 }
EXTENSION_NOINLINE double ST_Distance_Point_Point_Squared(int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)

+ Here is the call graph for this function:

EXTENSION_INLINE bool ST_DWithin_Point_Point_Geodesic ( int8_t *  p1,
int64_t  p1size,
int8_t *  p2,
int64_t  p2size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2604 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_Point_Geodesic().

2613  {
2614  auto dist_meters =
2615  ST_Distance_Point_Point_Geodesic(p1, p1size, p2, p2size, ic1, isr1, ic2, isr2, osr);
2616  return (dist_meters <= distance_within);
2617 }
EXTENSION_NOINLINE double ST_Distance_Point_Point_Geodesic(int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)

+ Here is the call graph for this function:

EXTENSION_INLINE bool ST_DWithin_Point_Polygon ( int8_t *  p,
int64_t  psize,
int8_t *  poly_coords,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
double *  poly_bounds,
int64_t  poly_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2648 of file ExtensionFunctionsGeo.hpp.

References point_dwithin_box(), and ST_Distance_Point_Polygon().

2661  {
2662  if (poly_bounds) {
2663  if (!point_dwithin_box(p,
2664  psize,
2665  ic1,
2666  isr1,
2667  poly_bounds,
2668  poly_bounds_size,
2669  isr2,
2670  osr,
2671  distance_within)) {
2672  return false;
2673  }
2674  }
2675 
2676  // May need to adjust the threshold by TOLERANCE_DEFAULT
2677  const double threshold = distance_within;
2678  return ST_Distance_Point_Polygon(p,
2679  psize,
2680  poly_coords,
2681  poly_coords_size,
2682  poly_ring_sizes,
2683  poly_num_rings,
2684  ic1,
2685  isr1,
2686  ic2,
2687  isr2,
2688  osr,
2689  threshold) <= distance_within;
2690 }
EXTENSION_NOINLINE double ST_Distance_Point_Polygon(int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool point_dwithin_box(int8_t *p1, int64_t p1size, int32_t ic1, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)

+ Here is the call graph for this function:

EXTENSION_INLINE bool ST_DWithin_Polygon_MultiPolygon ( int8_t *  poly_coords,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
double *  poly_bounds,
int64_t  poly_bounds_size,
int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
double *  mpoly_bounds,
int64_t  mpoly_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2971 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), and ST_Distance_Polygon_MultiPolygon().

2990  {
2991  if (poly_bounds && mpoly_bounds) {
2992  // Bounding boxes need to be transformed to output SR before proximity check
2993  if (!box_dwithin_box(poly_bounds,
2994  poly_bounds_size,
2995  isr1,
2996  mpoly_bounds,
2997  mpoly_bounds_size,
2998  isr2,
2999  osr,
3000  distance_within)) {
3001  return false;
3002  }
3003  }
3004 
3005  // May need to adjust the threshold by TOLERANCE_DEFAULT
3006  const double threshold = distance_within;
3007  return ST_Distance_Polygon_MultiPolygon(poly_coords,
3008  poly_coords_size,
3009  poly_ring_sizes,
3010  poly_num_rings,
3011  mpoly_coords,
3012  mpoly_coords_size,
3013  mpoly_ring_sizes,
3014  mpoly_num_rings,
3015  mpoly_poly_sizes,
3016  mpoly_num_polys,
3017  ic1,
3018  isr1,
3019  ic2,
3020  isr2,
3021  osr,
3022  threshold) <= distance_within;
3023 }
DEVICE ALWAYS_INLINE bool box_dwithin_box(double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
EXTENSION_NOINLINE double ST_Distance_Polygon_MultiPolygon(int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

EXTENSION_INLINE bool ST_DWithin_Polygon_Polygon ( int8_t *  poly1_coords,
int64_t  poly1_coords_size,
int32_t *  poly1_ring_sizes,
int64_t  poly1_num_rings,
double *  poly1_bounds,
int64_t  poly1_bounds_size,
int8_t *  poly2_coords,
int64_t  poly2_coords_size,
int32_t *  poly2_ring_sizes,
int64_t  poly2_num_rings,
double *  poly2_bounds,
int64_t  poly2_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2920 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), and ST_Distance_Polygon_Polygon().

2937  {
2938  if (poly1_bounds && poly2_bounds) {
2939  // Bounding boxes need to be transformed to output SR before proximity check
2940  if (!box_dwithin_box(poly1_bounds,
2941  poly1_bounds_size,
2942  isr1,
2943  poly2_bounds,
2944  poly2_bounds_size,
2945  isr2,
2946  osr,
2947  distance_within)) {
2948  return false;
2949  }
2950  }
2951 
2952  // May need to adjust the threshold by TOLERANCE_DEFAULT
2953  const double threshold = distance_within;
2954  return ST_Distance_Polygon_Polygon(poly1_coords,
2955  poly1_coords_size,
2956  poly1_ring_sizes,
2957  poly1_num_rings,
2958  poly2_coords,
2959  poly2_coords_size,
2960  poly2_ring_sizes,
2961  poly2_num_rings,
2962  ic1,
2963  isr1,
2964  ic2,
2965  isr2,
2966  osr,
2967  threshold) <= distance_within;
2968 }
DEVICE ALWAYS_INLINE bool box_dwithin_box(double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
EXTENSION_NOINLINE double ST_Distance_Polygon_Polygon(int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int8_t *poly2_coords, int64_t poly2_coords_size, int32_t *poly2_ring_sizes, int64_t poly2_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

EXTENSION_NOINLINE bool ST_Intersects_LineString_Linestring ( int8_t *  l1,
int64_t  l1size,
double *  l1bounds,
int64_t  l1bounds_size,
int8_t *  l2,
int64_t  l2size,
double *  l2bounds,
int64_t  l2bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3827 of file ExtensionFunctionsGeo.hpp.

References box_overlaps_box(), ST_Distance_LineString_LineString(), and tol_zero().

3839  {
3840  if (l1bounds && l2bounds) {
3841  if (!box_overlaps_box(l1bounds, l1bounds_size, l2bounds, l2bounds_size)) {
3842  return false;
3843  }
3844  }
3845 
3847  l1, l1size, l2, l2size, ic1, isr1, ic2, isr2, osr, 0.0));
3848 }
EXTENSION_NOINLINE double ST_Distance_LineString_LineString(int8_t *l1, int64_t l1size, int8_t *l2, int64_t l2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool box_overlaps_box(double *bounds1, int64_t bounds1_size, double *bounds2, int64_t bounds2_size)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)

+ Here is the call graph for this function:

EXTENSION_NOINLINE bool ST_Intersects_LineString_MultiPolygon ( int8_t *  l,
int64_t  lsize,
double *  lbounds,
int64_t  lbounds_size,
int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings,
int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys,
double *  mpoly_bounds,
int64_t  mpoly_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)