OmniSciDB  c1a53651b2
 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_Length_MultiLineString (int8_t *coords, int64_t coords_sz, int8_t *linestring_sizes_in, int64_t linestring_sizes_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)
 
EXTENSION_NOINLINE void ST_Centroid_MultiPoint (int8_t *mp, int32_t mpsize, int32_t ic, int32_t isr, int32_t osr, double *multipoint_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)
 
EXTENSION_NOINLINE double ST_Distance_Point_MultiPoint (int8_t *p, int64_t psize, int8_t *mp, int64_t mpsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Point_MultiPoint_Squared (int8_t *p, int64_t psize, int8_t *mp, int64_t mpsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
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)
 
DEVICE ALWAYS_INLINE double distance_point_multilinestring (int8_t *p, int64_t psize, int8_t *mls, int64_t mls_size, int32_t *mls_ls_sizes, int64_t mls_ls_num, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Point_MultiLineString (int8_t *p, int64_t psize, int8_t *mls, int64_t mls_size, int32_t *mls_ls_sizes, int64_t mls_ls_num, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
DEVICE ALWAYS_INLINE double 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 double 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_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_MultiPoint_Polygon (int8_t *mp, int64_t mpsize, 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_INLINE double ST_Distance_MultiPoint_MultiPolygon (int8_t *mp, int64_t mpsize, 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_MultiPoint (int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int8_t *mp, int64_t mpsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_MultiPolygon_MultiPoint (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 *mp, int64_t mpsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_MultiPoint_Point (int8_t *mp, int64_t mpsize, 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_MultiPoint_Point_Squared (int8_t *mp, int64_t mpsize, 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_MultiPoint_MultiPoint (int8_t *mp1, int64_t mp1size, int8_t *mp2, int64_t mp2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_MultiPoint_MultiPoint_Squared (int8_t *mp1, int64_t mp1size, int8_t *mp2, int64_t mp2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_MultiPoint_LineString (int8_t *mp, int64_t mpsize, 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_MultiPoint_MultiLineString (int8_t *mp, int64_t mpsize, int8_t *mls, int64_t mls_size, int32_t *mls_ls_sizes, int64_t mls_ls_num, 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_INLINE double ST_Distance_LineString_MultiPoint (int8_t *l, int64_t lsize, int8_t *mp, int64_t mpsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_MultiLineString_MultiPoint (int8_t *mls, int64_t mls_size, int32_t *mls_ls_sizes, int64_t mls_ls_num, int8_t *mp, int64_t mpsize, 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_MultiLineString_Point (int8_t *mls, int64_t mls_size, int32_t *mls_ls_sizes, int64_t mls_ls_num, 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_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_NOINLINE double ST_Distance_MultiLineString_MultiLineString (int8_t *mls1, int64_t mls1size, int32_t *mls1_ls_sizes, int64_t mls1_ls_num, int8_t *mls2, int64_t mls2size, int32_t *mls2_ls_sizes, int64_t mls2_ls_num, 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_cIntersects_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_cIntersects_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 HeavyDB_Geo_PolyBoundsPtr (double *bounds, int64_t size)
 
EXTENSION_INLINE int32_t HeavyDB_Geo_PolyRenderGroup (int32_t render_group)
 
EXTENSION_INLINE Array< double > HeavyDB_Geo_PolyCoordsArray (int8_t *mpoly_coords, int64_t mpoly_coords_size, const int32_t ic)
 
EXTENSION_INLINE Array< int32_t > HeavyDB_Geo_PolyRingSizesArray (int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings)
 
EXTENSION_INLINE Array< int32_t > HeavyDB_Geo_PolyPolyRingsArray (int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys)
 
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 1373 of file ExtensionFunctionsGeo.hpp.

References area_ring(), and compression_unit_size().

Referenced by ST_Area_MultiPolygon(), and ST_Area_Polygon().

1379  {
1380  if (poly_num_rings <= 0) {
1381  return 0.0;
1382  }
1383 
1384  double area = 0.0;
1385  auto ring_coords = poly_coords;
1386  auto poly_ring_sizes = reinterpret_cast<int32_t*>(poly_ring_sizes_in);
1387 
1388  // Add up the areas of all rings.
1389  // External ring is CCW, open - positive area.
1390  // Internal rings (holes) are CW, open - negative areas.
1391  for (auto r = 0; r < poly_num_rings; r++) {
1392  auto ring_coords_size = poly_ring_sizes[r] * 2 * compression_unit_size(ic);
1393  area += area_ring(ring_coords, ring_coords_size, ic, isr, osr);
1394  // Advance to the next ring.
1395  ring_coords += ring_coords_size;
1396  }
1397  return area;
1398 }
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 1350 of file ExtensionFunctionsGeo.hpp.

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

Referenced by area_polygon().

1354  {
1355  auto ring_num_coords = ringsize / compression_unit_size(ic);
1356 
1357  if (ring_num_coords < 6) {
1358  return 0.0;
1359  }
1360 
1361  double area = 0.0;
1362 
1363  Point2D p1 = get_point(ring, 0, ic, isr, osr);
1364  Point2D p2 = get_point(ring, 2, ic, isr, osr);
1365  for (int32_t i = 4; i < ring_num_coords; i += 2) {
1366  Point2D p3 = get_point(ring, i, ic, isr, osr);
1367  area += area_triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
1368  p2 = p3;
1369  }
1370  return area;
1371 }
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 1341 of file ExtensionFunctionsGeo.hpp.

Referenced by area_ring().

1346  {
1347  return (x1 * y2 - x2 * y1 + x3 * y1 - x1 * y3 + x2 * y3 - x3 * y2) / 2.0;
1348 }

+ 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 1519 of file ExtensionFunctionsGeo.hpp.

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

Referenced by centroid_add_ring(), and ST_Centroid_LineString().

1528  {
1529  auto l_num_coords = lsize / compression_unit_size(ic);
1530  double length = 0.0;
1531  Point2D const l0 = get_point(l, 0, ic, isr, osr);
1532  Point2D l2 = l0;
1533  for (int32_t i = 2; i < l_num_coords; i += 2) {
1534  Point2D const l1 = l2;
1535  l2 = get_point(l, i, ic, isr, osr);
1536  centroid_add_segment(l1.x, l1.y, l2.x, l2.y, &length, linestring_centroid_sum);
1537  }
1538  if (l_num_coords > 4 && closed) {
1539  // Also add the closing segment between the last and the first points
1540  centroid_add_segment(l2.x, l2.y, l0.x, l0.y, &length, linestring_centroid_sum);
1541  }
1542  *total_length += length;
1543  if (length == 0.0 && l_num_coords > 0) {
1544  *num_points += 1;
1545  point_centroid_sum[0] += l0.x;
1546  point_centroid_sum[1] += l0.y;
1547  }
1548  return true;
1549 }
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 1638 of file ExtensionFunctionsGeo.hpp.

References centroid_add_ring(), and compression_unit_size().

Referenced by ST_Centroid_MultiPolygon(), and ST_Centroid_Polygon().

1650  {
1651  if (poly_num_rings <= 0) {
1652  return false;
1653  }
1654 
1655  auto ring_coords = poly_coords;
1656 
1657  for (auto r = 0; r < poly_num_rings; r++) {
1658  auto ring_coords_size = poly_ring_sizes[r] * 2 * compression_unit_size(ic);
1659  // Shape - positive area, holes - negative areas
1660  double sign = (r == 0) ? 1.0 : -1.0;
1661  centroid_add_ring(ring_coords,
1662  ring_coords_size,
1663  ic,
1664  isr,
1665  osr,
1666  sign,
1667  total_area2,
1668  cg3,
1669  total_length,
1670  linestring_centroid_sum,
1671  num_points,
1672  point_centroid_sum);
1673  // Advance to the next ring.
1674  ring_coords += ring_coords_size;
1675  }
1676  return true;
1677 }
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 1599 of file ExtensionFunctionsGeo.hpp.

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

Referenced by centroid_add_polygon().

1610  {
1611  auto ring_num_coords = ringsize / compression_unit_size(ic);
1612 
1613  if (ring_num_coords < 6) {
1614  return false;
1615  }
1616 
1617  Point2D p1 = get_point(ring, 0, ic, isr, osr);
1618  Point2D p2 = get_point(ring, 2, ic, isr, osr);
1619  for (int32_t i = 4; i < ring_num_coords; i += 2) {
1620  Point2D p3 = get_point(ring, i, ic, isr, osr);
1621  centroid_add_triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, sign, total_area2, cg3);
1622  p2 = p3;
1623  }
1624 
1626  ringsize,
1627  ic,
1628  isr,
1629  osr,
1630  true, // closed
1631  total_length,
1632  linestring_centroid_sum,
1633  num_points,
1634  point_centroid_sum);
1635  return true;
1636 }
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 1504 of file ExtensionFunctionsGeo.hpp.

References distance_point_point().

Referenced by centroid_add_linestring().

1509  {
1510  double ldist = distance_point_point(x1, y1, x2, y2);
1511  *length += ldist;
1512  double segment_midpoint_x = (x1 + x2) / 2.0;
1513  double segment_midpoint_y = (y1 + y2) / 2.0;
1514  linestring_centroid_sum[0] += ldist * segment_midpoint_x;
1515  linestring_centroid_sum[1] += ldist * segment_midpoint_y;
1516  return true;
1517 }
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 1581 of file ExtensionFunctionsGeo.hpp.

Referenced by centroid_add_ring().

1589  {
1590  double cx = x1 + x2 + x3;
1591  double cy = y1 + y2 + y3;
1592  double area2 = x1 * y2 - x2 * y1 + x3 * y1 - x1 * y3 + x2 * y3 - x3 * y2;
1593  cg3[0] += sign * area2 * cx;
1594  cg3[1] += sign * area2 * cy;
1595  *total_area2 += sign * area2;
1596  return true;
1597 }

+ 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)

Definition at line 97 of file ExtensionFunctionsGeo.hpp.

References COMPRESSION_GEOINT32.

Referenced by area_polygon(), area_ring(), centroid_add_linestring(), centroid_add_polygon(), centroid_add_ring(), Contains_MultiPolygon_Point_Impl(), Contains_Polygon_Point_Impl(), distance_point_linestring(), distance_point_multilinestring(), distance_point_multipolygon(), distance_point_polygon(), HeavyDB_Geo_PolyCoordsArray(), length_linestring(), max_distance_point_linestring(), perimeter_multipolygon(), ST_Area_MultiPolygon(), ST_Centroid_MultiPoint(), ST_Centroid_MultiPolygon(), ST_Contains_MultiPolygon_LineString(), ST_Contains_Point_LineString(), ST_Contains_Point_Polygon(), ST_Contains_Polygon_LineString(), ST_Contains_Polygon_Polygon(), ST_Distance_LineString_LineString(), ST_Distance_LineString_MultiPolygon(), ST_Distance_LineString_Polygon(), ST_Distance_MultiPoint_LineString(), ST_Distance_MultiPoint_MultiLineString(), ST_Distance_MultiPoint_MultiPoint(), ST_Distance_MultiPoint_MultiPoint_Squared(), ST_Distance_MultiPoint_MultiPolygon(), ST_Distance_MultiPoint_Polygon(), ST_Distance_MultiPolygon_MultiPolygon(), ST_Distance_Point_LineString_Geodesic(), ST_Distance_Point_MultiPoint(), ST_Distance_Point_MultiPoint_Squared(), ST_Distance_Polygon_MultiPolygon(), ST_Distance_Polygon_Polygon(), ST_DWithin_LineString_MultiPolygon(), ST_DWithin_LineString_Polygon(), ST_Length_MultiLineString(), ST_Perimeter_Polygon(), ST_Perimeter_Polygon_Geodesic(), ST_XMax(), ST_XMin(), ST_YMax(), ST_YMin(), and trim_linestring_to_buffered_box().

97  {
98  if (ic == COMPRESSION_GEOINT32) {
99  return 4;
100  }
101  return 8;
102 }
#define COMPRESSION_GEOINT32

+ Here is the caller graph for this function:

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 4179 of file ExtensionFunctionsGeo.hpp.

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

4194  {
4195  if (mpoly_num_polys <= 0) {
4196  return false;
4197  }
4198 
4199  // TODO: mpoly_bounds could contain individual bounding boxes too:
4200  // first two points - box for the entire multipolygon, then a pair for each polygon
4201  if (mpoly_bounds) {
4202  Point2D const pt = get_point(p, 0, ic2, isr2, osr);
4203  if (!box_contains_point(mpoly_bounds, mpoly_bounds_size, pt.x, pt.y)) {
4204  return false;
4205  }
4206  }
4207 
4208  // Set specific poly pointers as we move through the coords/ringsizes/polyrings
4209  // arrays.
4210  auto next_poly_coords = mpoly_coords;
4211  auto next_poly_ring_sizes = mpoly_ring_sizes;
4212 
4213  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
4214  const auto poly_coords = next_poly_coords;
4215  const auto poly_ring_sizes = next_poly_ring_sizes;
4216  const auto poly_num_rings = mpoly_poly_sizes[poly];
4217  // Count number of coords in all of poly's rings, advance ring size pointer.
4218  int32_t poly_num_coords = 0;
4219  for (auto ring = 0; ring < poly_num_rings; ring++) {
4220  poly_num_coords += 2 * *next_poly_ring_sizes++;
4221  }
4222  const auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
4223  next_poly_coords += poly_coords_size;
4224  // TODO: pass individual bounding boxes for each polygon
4225  if (Contains_Polygon_Point_Impl<T, TEdgeBehavior>(poly_coords,
4226  poly_coords_size,
4227  poly_ring_sizes,
4228  poly_num_rings,
4229  nullptr,
4230  0,
4231  p,
4232  psize,
4233  ic1,
4234  isr1,
4235  ic2,
4236  isr2,
4237  osr)) {
4238  return true;
4239  }
4240  }
4241 
4242  return false;
4243 }
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 3966 of file ExtensionFunctionsGeo.hpp.

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

3978  {
3979  if (poly_bounds) {
3980  // TODO: codegen
3981  Point2D const pt = get_point(p, 0, ic2, isr2, osr);
3982  if (!box_contains_point(poly_bounds, poly_bounds_size, pt.x, pt.y)) {
3983  DEBUG_STMT(printf("Bounding box does not contain point, exiting.\n"));
3984  return false;
3985  }
3986  }
3987 
3988  auto get_x_coord = [=]() -> T {
3989  if constexpr (std::is_floating_point<T>::value) {
3990  return get_point(p, 0, ic2, isr2, osr).x;
3991  } else {
3992  return compressed_coord(p, 0);
3993  }
3994  return T{}; // https://stackoverflow.com/a/64561686/2700898
3995  };
3996 
3997  auto get_y_coord = [=]() -> T {
3998  if constexpr (std::is_floating_point<T>::value) {
3999  return get_point(p, 0, ic2, isr2, osr).y;
4000  } else {
4001  return compressed_coord(p, 1);
4002  }
4003  return T{}; // https://stackoverflow.com/a/64561686/2700898
4004  };
4005 
4006  const T px = get_x_coord();
4007  const T py = get_y_coord();
4008  DEBUG_STMT(printf("pt: %f, %f\n", (double)px, (double)py));
4009 
4010  const auto poly_num_coords = poly_coords_size / compression_unit_size(ic1);
4011  auto exterior_ring_num_coords =
4012  poly_num_rings > 0 ? poly_ring_sizes[0] * 2 : poly_num_coords;
4013 
4014  auto poly = poly_coords;
4015  if (point_in_polygon_winding_number<T, TEdgeBehavior>(
4016  poly, exterior_ring_num_coords, px, py, ic1, isr1, osr)) {
4017  // Inside exterior ring
4018  poly += exterior_ring_num_coords * compression_unit_size(ic1);
4019  // Check that none of the polygon's holes contain that point
4020  for (auto r = 1; r < poly_num_rings; r++) {
4021  const int64_t interior_ring_num_coords = poly_ring_sizes[r] * 2;
4022  if (point_in_polygon_winding_number<T, TEdgeBehavior>(
4023  poly, interior_ring_num_coords, px, py, ic1, isr1, osr)) {
4024  return false;
4025  }
4026  poly += interior_ring_num_coords * compression_unit_size(ic1);
4027  }
4028  return true;
4029  }
4030  return false;
4031 }
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 5066 of file ExtensionFunctionsGeo.hpp.

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

5075  {
5076  const double const1 = 0.017453292519943295769236907684886;
5077  const double const2 = 6372797.560856;
5078  const auto lat = decompress_coord<Y>(p, 0, ic);
5079  const double latdiff = meters / (const1 * const2);
5080  const double newlat =
5081  (lat < 0) ? lat + latdiff : lat - latdiff; // assumes a lat range of [-90, 90]
5082  double t1 = transform_point<Y>({{}, lat}, isr, osr).y;
5083  double t2 = transform_point<Y>({{}, newlat}, isr, osr).y;
5084  const double min_domain_y = transform_point<Y>({{}, min_lat}, isr, osr).y;
5085  const double max_domain_y = transform_point<Y>({{}, max_lat}, isr, osr).y;
5086  const double domain_diff = max_domain_y - min_domain_y;
5087  t1 = ((t1 - min_domain_y) / domain_diff) * static_cast<double>(img_height);
5088  t2 = ((t2 - min_domain_y) / domain_diff) * static_cast<double>(img_height);
5089 
5090  // TODO(croot): need to account for edge cases, such as getting close to the poles.
5091  const double sz = fabs(t1 - t2);
5092  return (sz < min_height ? min_height : sz);
5093 }

+ 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 5034 of file ExtensionFunctionsGeo.hpp.

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

5043  {
5044  const double const1 = 0.017453292519943295769236907684886;
5045  const double const2 = 6372797.560856;
5046  const auto lon = decompress_coord<X>(p, 0, ic);
5047  const auto lat = decompress_coord<Y>(p, 0, ic);
5048  double t1 = sinf(meters / (2.0 * const2));
5049  double t2 = cosf(const1 * lat);
5050  const double newlon = lon - (2.0 * asinf(t1 / t2)) / const1;
5051  t1 = transform_point<X>({lon, {}}, isr, osr).x;
5052  t2 = transform_point<X>({newlon, {}}, isr, osr).x;
5053  const double min_domain_x = transform_point<X>({min_lon, {}}, isr, osr).x;
5054  const double max_domain_x = transform_point<X>({max_lon, {}}, isr, osr).x;
5055  const double domain_diff = max_domain_x - min_domain_x;
5056  t1 = ((t1 - min_domain_x) / domain_diff) * static_cast<double>(img_width);
5057  t2 = ((t2 - min_domain_x) / domain_diff) * static_cast<double>(img_width);
5058 
5059  // TODO(croot): need to account for edge cases, such as getting close to the poles.
5060  const double sz = fabs(t1 - t2);
5061  return (sz < min_width ? min_width : sz);
5062 }

+ 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 1939 of file ExtensionFunctionsGeo.hpp.

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

Referenced by distance_point_multilinestring(), ST_Distance_MultiPoint_LineString(), ST_Distance_Point_ClosedLineString(), and ST_Distance_Point_LineString().

1949  {
1950  Point2D pt = get_point(p, 0, ic1, isr1, osr);
1951 
1952  auto l_num_coords = lsize / compression_unit_size(ic2);
1953 
1954  Point2D l1 = get_point(l, 0, ic2, isr2, osr);
1955  Point2D l2 = get_point(l, 2, ic2, isr2, osr);
1956 
1957  double dist = distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
1958  for (int32_t i = 4; i < l_num_coords; i += 2) {
1959  l1 = l2; // advance one point
1960  l2 = get_point(l, i, ic2, isr2, osr);
1961  double ldist = distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
1962  if (dist > ldist) {
1963  dist = ldist;
1964  }
1965  if (dist <= threshold) {
1966  return dist;
1967  }
1968  }
1969  if (l_num_coords > 4 && check_closed) {
1970  // Also check distance to the closing edge between the first and the last points
1971  l1 = get_point(l, 0, ic2, isr2, osr);
1972  double ldist = distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
1973  if (dist > ldist) {
1974  dist = ldist;
1975  }
1976  }
1977  return dist;
1978 }
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_multilinestring ( int8_t *  p,
int64_t  psize,
int8_t *  mls,
int64_t  mls_size,
int32_t *  mls_ls_sizes,
int64_t  mls_ls_num,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2010 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Distance_MultiPoint_MultiLineString(), and ST_Distance_Point_MultiLineString().

2021  {
2022  if (mls_ls_num <= 0) {
2023  return 0.0;
2024  }
2025  double min_distance = 0.0;
2026 
2027  auto next_linestring_coords = mls;
2028 
2029  for (auto l = 0; l < mls_ls_num; l++) {
2030  auto linestring_coords = next_linestring_coords;
2031  auto linestring_num_points = mls_ls_sizes[l];
2032  auto linestring_num_coords = 2 * linestring_num_points;
2033  auto linestring_coords_size = linestring_num_coords * compression_unit_size(ic2);
2034  next_linestring_coords += linestring_coords_size;
2035  double distance = distance_point_linestring(p,
2036  psize,
2037  linestring_coords,
2038  linestring_coords_size,
2039  ic1,
2040  isr1,
2041  ic2,
2042  isr2,
2043  osr,
2044  false,
2045  threshold);
2046  if (l == 0 || min_distance > distance) {
2047  min_distance = distance;
2048  if (tol_zero(min_distance)) {
2049  min_distance = 0.0;
2050  break;
2051  }
2052  if (min_distance <= threshold) {
2053  break;
2054  }
2055  }
2056  }
2057 
2058  return min_distance;
2059 }
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
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)
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 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 2140 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Distance_MultiPoint_MultiPolygon(), and ST_Distance_Point_MultiPolygon().

2153  {
2154  if (mpoly_num_polys <= 0) {
2155  return 0.0;
2156  }
2157  double min_distance = 0.0;
2158 
2159  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
2160  auto next_poly_coords = mpoly_coords;
2161  auto next_poly_ring_sizes = mpoly_ring_sizes;
2162 
2163  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
2164  auto poly_coords = next_poly_coords;
2165  auto poly_ring_sizes = next_poly_ring_sizes;
2166  auto poly_num_rings = mpoly_poly_sizes[poly];
2167  // Count number of coords in all of poly's rings, advance ring size pointer.
2168  int32_t poly_num_coords = 0;
2169  for (auto ring = 0; ring < poly_num_rings; ring++) {
2170  poly_num_coords += 2 * *next_poly_ring_sizes++;
2171  }
2172  auto poly_coords_size = poly_num_coords * compression_unit_size(ic2);
2173  next_poly_coords += poly_coords_size;
2174  double distance = distance_point_polygon(p,
2175  psize,
2176  poly_coords,
2177  poly_coords_size,
2178  poly_ring_sizes,
2179  poly_num_rings,
2180  ic1,
2181  isr1,
2182  ic2,
2183  isr2,
2184  osr,
2185  threshold);
2186  if (poly == 0 || min_distance > distance) {
2187  min_distance = distance;
2188  if (tol_zero(min_distance)) {
2189  min_distance = 0.0;
2190  break;
2191  }
2192  if (min_distance <= threshold) {
2193  break;
2194  }
2195  }
2196  }
2197 
2198  return min_distance;
2199 }
DEVICE ALWAYS_INLINE double 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:

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(), ST_Distance_MultiPoint_MultiPoint(), ST_Distance_Point_MultiPoint(), 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(), ST_Distance_MultiPoint_MultiPoint_Squared(), ST_Distance_Point_MultiPoint_Squared(), 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 ALWAYS_INLINE double 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 2088 of file ExtensionFunctionsGeo.hpp.

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

Referenced by distance_point_multipolygon(), ST_Distance_MultiPoint_Polygon(), and ST_Distance_Point_Polygon().

2099  {
2100  auto exterior_ring_num_coords = polysize / compression_unit_size(ic2);
2101  if (poly_num_rings > 0) {
2102  exterior_ring_num_coords = poly_ring_sizes[0] * 2;
2103  }
2104  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic2);
2105 
2106  Point2D pt = get_point(p, 0, ic1, isr1, osr);
2108  poly, exterior_ring_num_coords, pt.x, pt.y, ic2, isr2, osr)) {
2109  // Outside the exterior ring
2111  p, psize, poly, exterior_ring_coords_size, ic1, isr1, ic2, isr2, osr, threshold);
2112  }
2113  // Inside exterior ring
2114  // Advance to first interior ring
2115  poly += exterior_ring_coords_size;
2116  // Check if one of the polygon's holes contains that point
2117  for (auto r = 1; r < poly_num_rings; r++) {
2118  auto interior_ring_num_coords = poly_ring_sizes[r] * 2;
2119  auto interior_ring_coords_size =
2120  interior_ring_num_coords * compression_unit_size(ic2);
2122  poly, interior_ring_num_coords, pt.x, pt.y, ic2, isr2, osr)) {
2123  // Inside an interior ring
2125  psize,
2126  poly,
2127  interior_ring_coords_size,
2128  ic1,
2129  isr1,
2130  ic2,
2131  isr2,
2132  osr,
2133  threshold);
2134  }
2135  poly += interior_ring_coords_size;
2136  }
2137  return 0.0;
2138 }
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:

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(), 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(), 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:

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_INLINE int64_t HeavyDB_Geo_PolyBoundsPtr ( double *  bounds,
int64_t  size 
)

Definition at line 4991 of file ExtensionFunctionsGeo.hpp.

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

4991  {
4992  return reinterpret_cast<int64_t>(bounds);
4993 }

+ Here is the caller graph for this function:

EXTENSION_INLINE Array<double> HeavyDB_Geo_PolyCoordsArray ( int8_t *  mpoly_coords,
int64_t  mpoly_coords_size,
const int32_t  ic 
)

Definition at line 5001 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and Array< T >::ptr.

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

5003  {
5004  auto const num_coords = mpoly_coords_size / compression_unit_size(ic);
5005  Array<double> coords_array(num_coords);
5006  double* p_coords = coords_array.ptr;
5007  for (int64_t i = 0; i < num_coords; i += 2) {
5008  Point2D const decompressed{decompress_coord<X>(mpoly_coords, i, ic),
5009  decompress_coord<Y>(mpoly_coords, i, ic)};
5010  *p_coords++ = decompressed.x;
5011  *p_coords++ = decompressed.y;
5012  }
5013  return coords_array;
5014 }
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 Array<int32_t> HeavyDB_Geo_PolyPolyRingsArray ( int32_t *  mpoly_poly_sizes,
int64_t  mpoly_num_polys 
)

Definition at line 5025 of file ExtensionFunctionsGeo.hpp.

References Array< T >::ptr.

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

5026  {
5027  Array<int32_t> poly_rings_array(mpoly_num_polys);
5028  std::memcpy(poly_rings_array.ptr, mpoly_poly_sizes, mpoly_num_polys * sizeof(int32_t));
5029  return poly_rings_array;
5030 }

+ Here is the caller graph for this function:

EXTENSION_INLINE int32_t HeavyDB_Geo_PolyRenderGroup ( int32_t  render_group)

Definition at line 4996 of file ExtensionFunctionsGeo.hpp.

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

4996  {
4997  return render_group;
4998 }

+ Here is the caller graph for this function:

EXTENSION_INLINE Array<int32_t> HeavyDB_Geo_PolyRingSizesArray ( int32_t *  mpoly_ring_sizes,
int64_t  mpoly_num_rings 
)

Definition at line 5017 of file ExtensionFunctionsGeo.hpp.

References Array< T >::ptr.

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

5018  {
5019  Array<int32_t> ring_sizes_array(mpoly_num_rings);
5020  std::memcpy(ring_sizes_array.ptr, mpoly_ring_sizes, mpoly_num_rings * sizeof(int32_t));
5021  return ring_sizes_array;
5022 }

+ Here is the caller graph for this function:

template<typename T >
DEVICE ALWAYS_INLINE T is_left ( const T  lx0,
const T  ly0,
const T  lx1,
const T  ly1,
const T  px,
const T  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 5095 of file ExtensionFunctionsGeo.hpp.

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

5101  {
5102  const auto lon = decompress_coord<X>(p, 0, ic);
5103  const auto lat = decompress_coord<Y>(p, 0, ic);
5104  return !(lon < min_lon || lon > max_lon || lat < min_lat || lat > max_lat);
5105 }

+ 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 5107 of file ExtensionFunctionsGeo.hpp.

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

5114  {
5115  const double const1 = 0.017453292519943295769236907684886;
5116  const double const2 = 6372797.560856;
5117  const auto lon = decompress_coord<X>(p, 0, ic);
5118  const auto lat = decompress_coord<Y>(p, 0, ic);
5119  const double latdiff = meters / (const1 * const2);
5120  const double t1 = sinf(meters / (2.0 * const2));
5121  const double t2 = cosf(const1 * lat);
5122  const double londiff = (2.0 * asinf(t1 / t2)) / const1;
5123  return !(lon + londiff < min_lon || lon - londiff > max_lon ||
5124  lat + latdiff < min_lat || lat - latdiff > max_lat);
5125 }

+ 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(), and get_point().

Referenced by perimeter_multipolygon(), ST_Length_LineString(), ST_Length_LineString_Geodesic(), ST_Length_MultiLineString(), 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(), 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(), 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:

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

Definition at line 3761 of file ExtensionFunctionsGeo.hpp.

References distance_point_point().

Referenced by max_distance_point_linestring().

3766  {
3767  // TODO: switch to squared distances
3768  double length1 = distance_point_point(px, py, l1x, l1y);
3769  double length2 = distance_point_point(px, py, l2x, l2y);
3770  if (length1 > length2) {
3771  return length1;
3772  }
3773  return length2;
3774 }
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 3776 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_MaxDistance_LineString_Point(), and ST_MaxDistance_Point_LineString().

3785  {
3786  // TODO: switch to squared distances
3787  Point2D pt = get_point(p, 0, ic1, isr1, osr);
3788 
3789  auto l_num_coords = lsize / compression_unit_size(ic2);
3790 
3791  Point2D l1 = get_point(l, 0, ic2, isr2, osr);
3792  Point2D l2 = get_point(l, 2, ic2, isr2, osr);
3793 
3794  double max_dist = max_distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
3795  for (int32_t i = 4; i < l_num_coords; i += 2) {
3796  l1 = l2; // advance one point
3797  l2 = get_point(l, i, ic2, isr2, osr);
3798  double ldist = max_distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
3799  if (max_dist < ldist) {
3800  max_dist = ldist;
3801  }
3802  }
3803  if (l_num_coords > 4 && check_closed) {
3804  // Also check distance to the closing edge between the first and the last points
3805  l1 = get_point(l, 0, ic2, isr2, osr);
3806  double ldist = max_distance_point_line(pt.x, pt.y, l1.x, l1.y, l2.x, l2.y);
3807  if (max_dist < ldist) {
3808  max_dist = ldist;
3809  }
3810  }
3811  return max_dist;
3812 }
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:

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 1249 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and length_linestring().

Referenced by ST_Perimeter_MultiPolygon(), and ST_Perimeter_MultiPolygon_Geodesic().

1258  {
1259  if (mpoly_num_polys <= 0 || mpoly_num_rings <= 0) {
1260  return 0.0;
1261  }
1262 
1263  double perimeter = 0.0;
1264 
1265  auto mpoly_ring_sizes = reinterpret_cast<int32_t*>(mpoly_ring_sizes_in);
1266 
1267  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1268  auto next_poly_coords = mpoly_coords;
1269  auto next_poly_ring_sizes = mpoly_ring_sizes;
1270 
1271  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1272  auto poly_coords = next_poly_coords;
1273  auto poly_ring_sizes = next_poly_ring_sizes;
1274  auto poly_num_rings = reinterpret_cast<int32_t*>(mpoly_poly_sizes)[poly];
1275  // Count number of coords in all of poly's rings, advance ring size pointer.
1276  int32_t poly_num_coords = 0;
1277  for (auto ring = 0; ring < poly_num_rings; ring++) {
1278  poly_num_coords += 2 * *next_poly_ring_sizes++;
1279  }
1280  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1281  next_poly_coords += poly_coords_size;
1282 
1283  auto exterior_ring_num_coords = poly_ring_sizes[0] * 2;
1284  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic);
1285 
1286  perimeter += length_linestring(
1287  poly_coords, exterior_ring_coords_size, ic, isr, osr, geodesic, true);
1288  }
1289 
1290  return perimeter;
1291 }
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 T  px,
const T  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, heavydb.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(), 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(), line_intersects_line(), run_benchmark_import::result, tol_eq(), and tol_zero().

Referenced by distance_point_polygon(), and polygon_contains_linestring().

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 1413 of file ExtensionFunctionsGeo.hpp.

References area_polygon(), and compression_unit_size().

1421  {
1422  if (mpoly_num_rings <= 0 || mpoly_num_polys <= 0) {
1423  return 0.0;
1424  }
1425 
1426  double area = 0.0;
1427 
1428  auto mpoly_poly_sizes = reinterpret_cast<int32_t*>(mpoly_poly_sizes_in);
1429 
1430  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1431  auto next_poly_coords = mpoly_coords;
1432  auto next_poly_ring_sizes = reinterpret_cast<int32_t*>(mpoly_ring_sizes);
1433 
1434  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1435  auto poly_coords = next_poly_coords;
1436  auto poly_ring_sizes = next_poly_ring_sizes;
1437  auto poly_num_rings = mpoly_poly_sizes[poly];
1438  // Count number of coords in all of poly's rings, advance ring size pointer.
1439  int32_t poly_num_coords = 0;
1440  for (auto ring = 0; ring < poly_num_rings; ring++) {
1441  poly_num_coords += 2 * *next_poly_ring_sizes++;
1442  }
1443  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1444  next_poly_coords += poly_coords_size;
1445 
1446  area += area_polygon(poly_coords,
1447  poly_coords_size,
1448  reinterpret_cast<int8_t*>(poly_ring_sizes),
1449  poly_num_rings,
1450  ic,
1451  isr,
1452  osr);
1453  }
1454  return area;
1455 }
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 1401 of file ExtensionFunctionsGeo.hpp.

References area_polygon().

1407  {
1408  return area_polygon(
1409  poly_coords, poly_coords_size, poly_ring_sizes, poly_num_rings, ic, isr, osr);
1410 }
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 4279 of file ExtensionFunctionsGeo.hpp.

4293  {
4294  return Contains_MultiPolygon_Point_Impl<int64_t, EdgeBehavior::kExcludePointOnEdge>(
4295  mpoly_coords,
4296  mpoly_coords_size,
4297  mpoly_ring_sizes,
4298  mpoly_num_rings,
4299  mpoly_poly_sizes,
4300  mpoly_num_polys,
4301  mpoly_bounds,
4302  mpoly_bounds_size,
4303  p,
4304  psize,
4305  ic1,
4306  isr1,
4307  ic2,
4308  isr2,
4309  osr);
4310 }
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 4062 of file ExtensionFunctionsGeo.hpp.

4074  {
4075  return Contains_Polygon_Point_Impl<int64_t, EdgeBehavior::kExcludePointOnEdge>(
4076  poly_coords,
4077  poly_coords_size,
4078  poly_ring_sizes,
4079  poly_num_rings,
4080  poly_bounds,
4081  poly_bounds_size,
4082  p,
4083  psize,
4084  ic1,
4085  isr1,
4086  ic2,
4087  isr2,
4088  osr);
4089 }
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 1552 of file ExtensionFunctionsGeo.hpp.

References centroid_add_linestring().

1557  {
1558  double length = 0.0;
1559  double linestring_centroid_sum[2] = {0.0, 0.0};
1560  int64_t num_points = 0;
1561  double point_centroid_sum[2] = {0.0, 0.0};
1562  centroid_add_linestring(coords,
1563  coords_sz,
1564  ic,
1565  isr,
1566  osr,
1567  false, // not closed
1568  &length,
1569  &linestring_centroid_sum[0],
1570  &num_points,
1571  &point_centroid_sum[0]);
1572  if (length > 0) {
1573  linestring_centroid[0] = linestring_centroid_sum[0] / length;
1574  linestring_centroid[1] = linestring_centroid_sum[1] / length;
1575  } else if (num_points > 0) {
1576  linestring_centroid[0] = point_centroid_sum[0] / num_points;
1577  linestring_centroid[1] = point_centroid_sum[1] / num_points;
1578  }
1579 }
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_MultiPoint ( int8_t *  mp,
int32_t  mpsize,
int32_t  ic,
int32_t  isr,
int32_t  osr,
double *  multipoint_centroid 
)

Definition at line 1485 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and get_point().

1490  {
1491  auto mp_num_coords = mpsize / compression_unit_size(ic);
1492  double x = 0.0;
1493  double y = 0.0;
1494  for (int32_t i = 0; i < mp_num_coords; i += 2) {
1495  Point2D mpp = get_point(mp, i, ic, isr, osr);
1496  x += mpp.x; // In case of overflows on large geometries,
1497  y += mpp.y; // move division into the loop
1498  }
1499  auto mp_num_points = mp_num_coords >> 1;
1500  multipoint_centroid[0] = x / mp_num_points;
1501  multipoint_centroid[1] = y / mp_num_points;
1502 }
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_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 1731 of file ExtensionFunctionsGeo.hpp.

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

1740  {
1741  if (mpoly_num_rings <= 0 || mpoly_num_polys <= 0) {
1742  mpoly_centroid[0] = 0.0;
1743  mpoly_centroid[1] = 0.0;
1744  }
1745 
1746  double total_area2 = 0.0;
1747  double cg3[2] = {0.0, 0.0};
1748  double total_length = 0.0;
1749  double linestring_centroid_sum[2] = {0.0, 0.0};
1750  int64_t num_points = 0;
1751  double point_centroid_sum[2] = {0.0, 0.0};
1752 
1753  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1754  auto next_poly_coords = mpoly_coords;
1755  auto next_poly_ring_sizes = mpoly_ring_sizes;
1756 
1757  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1758  auto poly_coords = next_poly_coords;
1759  auto poly_ring_sizes = next_poly_ring_sizes;
1760  auto poly_num_rings = mpoly_poly_sizes[poly];
1761  // Count number of coords in all of poly's rings, advance ring size pointer.
1762  int32_t poly_num_coords = 0;
1763  for (auto ring = 0; ring < poly_num_rings; ring++) {
1764  poly_num_coords += 2 * *next_poly_ring_sizes++;
1765  }
1766  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1767  next_poly_coords += poly_coords_size;
1768 
1769  centroid_add_polygon(poly_coords,
1770  poly_coords_size,
1771  poly_ring_sizes,
1772  poly_num_rings,
1773  ic,
1774  isr,
1775  osr,
1776  &total_area2,
1777  &cg3[0],
1778  &total_length,
1779  &linestring_centroid_sum[0],
1780  &num_points,
1781  &point_centroid_sum[0]);
1782  }
1783 
1784  if (total_area2 != 0.0) {
1785  mpoly_centroid[0] = cg3[0] / 3 / total_area2;
1786  mpoly_centroid[1] = cg3[1] / 3 / total_area2;
1787  } else if (total_length > 0.0) {
1788  // zero-area multipolygon, fall back to linear centroid
1789  mpoly_centroid[0] = linestring_centroid_sum[0] / total_length;
1790  mpoly_centroid[1] = linestring_centroid_sum[1] / total_length;
1791  } else if (num_points > 0) {
1792  // zero-area zero-length multipolygon, fall further back to point centroid
1793  mpoly_centroid[0] = point_centroid_sum[0] / num_points;
1794  mpoly_centroid[1] = point_centroid_sum[1] / num_points;
1795  } else {
1796  Point2D centroid = get_point(mpoly_coords, 0, ic, isr, osr);
1797  mpoly_centroid[0] = centroid.x;
1798  mpoly_centroid[1] = centroid.y;
1799  }
1800 }
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 1473 of file ExtensionFunctionsGeo.hpp.

References get_point().

1478  {
1479  Point2D const centroid = get_point(p, 0, ic, isr, osr);
1480  point_centroid[0] = centroid.x;
1481  point_centroid[1] = centroid.y;
1482 }
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 1680 of file ExtensionFunctionsGeo.hpp.

References centroid_add_polygon(), and get_point().

1687  {
1688  if (poly_num_rings <= 0) {
1689  poly_centroid[0] = 0.0;
1690  poly_centroid[1] = 0.0;
1691  }
1692  double total_area2 = 0.0;
1693  double cg3[2] = {0.0, 0.0};
1694  double total_length = 0.0;
1695  double linestring_centroid_sum[2] = {0.0, 0.0};
1696  int64_t num_points = 0;
1697  double point_centroid_sum[2] = {0.0, 0.0};
1698  centroid_add_polygon(poly_coords,
1699  poly_coords_size,
1700  poly_ring_sizes,
1701  poly_num_rings,
1702  ic,
1703  isr,
1704  osr,
1705  &total_area2,
1706  &cg3[0],
1707  &total_length,
1708  &linestring_centroid_sum[0],
1709  &num_points,
1710  &point_centroid_sum[0]);
1711 
1712  if (total_area2 != 0.0) {
1713  poly_centroid[0] = cg3[0] / 3 / total_area2;
1714  poly_centroid[1] = cg3[1] / 3 / total_area2;
1715  } else if (total_length > 0.0) {
1716  // zero-area polygon, fall back to linear centroid
1717  poly_centroid[0] = linestring_centroid_sum[0] / total_length;
1718  poly_centroid[1] = linestring_centroid_sum[1] / total_length;
1719  } else if (num_points > 0) {
1720  // zero-area zero-length polygon, fall further back to point centroid
1721  poly_centroid[0] = point_centroid_sum[0] / num_points;
1722  poly_centroid[1] = point_centroid_sum[1] / num_points;
1723  } else {
1724  Point2D centroid = get_point(poly_coords, 0, ic, isr, osr);
1725  poly_centroid[0] = centroid.x;
1726  poly_centroid[1] = centroid.y;
1727  }
1728 }
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_cIntersects_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 4826 of file ExtensionFunctionsGeo.hpp.

4840  {
4841  return Contains_MultiPolygon_Point_Impl<int64_t, EdgeBehavior::kIncludePointOnEdge>(
4842  mpoly_coords,
4843  mpoly_coords_size,
4844  mpoly_ring_sizes,
4845  mpoly_num_rings,
4846  mpoly_poly_sizes,
4847  mpoly_num_polys,
4848  mpoly_bounds,
4849  mpoly_bounds_size,
4850  p,
4851  psize,
4852  ic1,
4853  isr1,
4854  ic2,
4855  isr2,
4856  osr);
4857 }
EXTENSION_INLINE bool ST_cIntersects_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 
)

Definition at line 4643 of file ExtensionFunctionsGeo.hpp.

4655  {
4656  return Contains_Polygon_Point_Impl<int64_t, EdgeBehavior::kIncludePointOnEdge>(
4657  poly,
4658  polysize,
4659  poly_ring_sizes,
4660  poly_num_rings,
4661  poly_bounds,
4662  poly_bounds_size,
4663  p,
4664  psize,
4665  ic1,
4666  isr1,
4667  ic2,
4668  isr2,
4669  osr);
4670 }
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 3930 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString(), and tol_zero().

3940  {
3941  return tol_zero(
3942  ST_Distance_Point_LineString(p, psize, l, lsize, ic2, isr2, ic1, isr1, osr, 0.0));
3943 }
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 3946 of file ExtensionFunctionsGeo.hpp.

3960  {
3961  // TODO
3962  return false;
3963 }
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 4313 of file ExtensionFunctionsGeo.hpp.

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

4329  {
4330  if (mpoly_num_polys <= 0) {
4331  return false;
4332  }
4333 
4334  if (mpoly_bounds && lbounds) {
4335  if (!box_contains_box(mpoly_bounds, mpoly_bounds_size, lbounds, lbounds_size)) {
4336  return false;
4337  }
4338  }
4339 
4340  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
4341  auto next_poly_coords = mpoly_coords;
4342  auto next_poly_ring_sizes = mpoly_ring_sizes;
4343 
4344  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
4345  auto poly_coords = next_poly_coords;
4346  auto poly_ring_sizes = next_poly_ring_sizes;
4347  auto poly_num_rings = mpoly_poly_sizes[poly];
4348  // Count number of coords in all of poly's rings, advance ring size pointer.
4349  int32_t poly_num_coords = 0;
4350  for (auto ring = 0; ring < poly_num_rings; ring++) {
4351  poly_num_coords += 2 * *next_poly_ring_sizes++;
4352  }
4353  auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
4354  next_poly_coords += poly_coords_size;
4355 
4356  if (ST_Contains_Polygon_LineString(poly_coords,
4357  poly_coords_size,
4358  poly_ring_sizes,
4359  poly_num_rings,
4360  nullptr,
4361  0,
4362  l,
4363  lsize,
4364  nullptr,
4365  0,
4366  ic1,
4367  isr1,
4368  ic2,
4369  isr2,
4370  osr)) {
4371  return true;
4372  }
4373  }
4374 
4375  return false;
4376 }
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 4246 of file ExtensionFunctionsGeo.hpp.

4260  {
4261  return Contains_MultiPolygon_Point_Impl<double, EdgeBehavior::kExcludePointOnEdge>(
4262  mpoly_coords,
4263  mpoly_coords_size,
4264  mpoly_ring_sizes,
4265  mpoly_num_rings,
4266  mpoly_poly_sizes,
4267  mpoly_num_polys,
4268  mpoly_bounds,
4269  mpoly_bounds_size,
4270  p,
4271  psize,
4272  ic1,
4273  isr1,
4274  ic2,
4275  isr2,
4276  osr);
4277 }
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 3865 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Contains_Point_Polygon().

3875  {
3876  Point2D const pt = get_point(p, 0, ic1, isr1, osr);
3877 
3878  if (lbounds) {
3879  if (tol_eq(pt.x, lbounds[0]) && tol_eq(pt.y, lbounds[1]) &&
3880  tol_eq(pt.x, lbounds[2]) && tol_eq(pt.y, lbounds[3])) {
3881  return true;
3882  }
3883  }
3884 
3885  auto l_num_coords = lsize / compression_unit_size(ic2);
3886  for (int i = 0; i < l_num_coords; i += 2) {
3887  Point2D pl = get_point(l, i, ic2, isr2, osr);
3888  if (tol_eq(pt.x, pl.x) && tol_eq(pt.y, pl.y)) {
3889  continue;
3890  }
3891  return false;
3892  }
3893  return true;
3894 }
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 3849 of file ExtensionFunctionsGeo.hpp.

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

3857  {
3858  Point2D const pt1 = get_point(p1, 0, ic1, isr1, osr);
3859  Point2D const pt2 = get_point(p2, 0, ic2, isr2, osr);
3860  double tolerance = tol(ic1, ic2);
3861  return tol_eq(pt1.x, pt2.x, tolerance) && tol_eq(pt1.y, pt2.y, tolerance);
3862 }
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 3897 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and ST_Contains_Point_LineString().

3909  {
3910  auto exterior_ring_num_coords = poly_coords_size / compression_unit_size(ic2);
3911  if (poly_num_rings > 0) {
3912  exterior_ring_num_coords = poly_ring_sizes[0] * 2;
3913  }
3914  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic2);
3915 
3917  psize,
3918  poly_coords,
3919  exterior_ring_coords_size,
3920  poly_bounds,
3921  poly_bounds_size,
3922  ic1,
3923  isr1,
3924  ic2,
3925  isr2,
3926  osr);
3927 }
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 4092 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().

4106  {
4107  if (poly_num_rings > 1) {
4108  return false; // TODO: support polygons with interior rings
4109  }
4110 
4111  // Bail out if poly bounding box doesn't contain linestring bounding box
4112  if (poly_bounds && lbounds) {
4113  if (!box_contains_box(poly_bounds, poly_bounds_size, lbounds, lbounds_size)) {
4114  return false;
4115  }
4116  }
4117 
4118  const auto poly_num_coords = poly_coords_size / compression_unit_size(ic1);
4119  const auto lnum_coords = lsize / compression_unit_size(ic2);
4120 
4122  poly_coords, poly_num_coords, l, lnum_coords, ic1, isr1, ic2, isr2, osr);
4123 }
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 4033 of file ExtensionFunctionsGeo.hpp.

4045  {
4046  return Contains_Polygon_Point_Impl<double, EdgeBehavior::kExcludePointOnEdge>(
4047  poly_coords,
4048  poly_coords_size,
4049  poly_ring_sizes,
4050  poly_num_rings,
4051  poly_bounds,
4052  poly_bounds_size,
4053  p,
4054  psize,
4055  ic1,
4056  isr1,
4057  ic2,
4058  isr2,
4059  osr);
4060 }
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 4126 of file ExtensionFunctionsGeo.hpp.

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

4142  {
4143  // TODO: needs to be extended, cover more cases
4144  // Right now only checking if simple poly1 (no holes) contains poly2's exterior shape
4145  if (poly1_num_rings > 1) {
4146  return false; // TODO: support polygons with interior rings
4147  }
4148 
4149  if (poly1_bounds && poly2_bounds) {
4150  if (!box_contains_box(
4151  poly1_bounds, poly1_bounds_size, poly2_bounds, poly2_bounds_size)) {
4152  return false;
4153  }
4154  }
4155 
4156  int64_t poly2_exterior_ring_coords_size = poly2_coords_size;
4157  if (poly2_num_rings > 0) {
4158  poly2_exterior_ring_coords_size =
4159  2 * poly2_ring_sizes[0] * compression_unit_size(ic2);
4160  }
4161  return ST_Contains_Polygon_LineString(poly1_coords,
4162  poly1_coords_size,
4163  poly1_ring_sizes,
4164  poly1_num_rings,
4165  poly1_bounds,
4166  poly1_bounds_size,
4167  poly2_coords,
4168  poly2_exterior_ring_coords_size,
4169  poly2_bounds,
4170  poly2_bounds_size,
4171  ic1,
4172  isr1,
4173  ic2,
4174  isr2,
4175  osr);
4176 }
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 2661 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().

2670  {
2671  auto l1_num_coords = l1size / compression_unit_size(ic1);
2672  auto l2_num_coords = l2size / compression_unit_size(ic2);
2673 
2674  double threshold_squared = threshold * threshold;
2675  double dist_squared = 0.0;
2676  Point2D l11 = get_point(l1, 0, ic1, isr1, osr);
2677  for (int32_t i1 = 2; i1 < l1_num_coords; i1 += 2) {
2678  Point2D l12 = get_point(l1, i1, ic1, isr1, osr);
2679  Point2D l21 = get_point(l2, 0, ic2, isr2, osr);
2680  for (int32_t i2 = 2; i2 < l2_num_coords; i2 += 2) {
2681  Point2D l22 = get_point(l2, i2, ic2, isr2, osr);
2682 
2683  // double ldist_squared =
2684  // distance_line_line_squared(l11x, l11y, l12x, l12y, l21x, l21y, l22x, l22y);
2685  // TODO: fix distance_line_line_squared
2686  double ldist =
2687  distance_line_line(l11.x, l11.y, l12.x, l12.y, l21.x, l21.y, l22.x, l22.y);
2688  double ldist_squared = ldist * ldist;
2689 
2690  if (i1 == 2 && i2 == 2) {
2691  dist_squared = ldist_squared; // initialize dist with distance between the first
2692  // two segments
2693  } else if (dist_squared > ldist_squared) {
2694  dist_squared = ldist_squared;
2695  }
2696  if (tol_zero(dist_squared, TOLERANCE_DEFAULT_SQUARED)) {
2697  return 0.0; // Segments touch, short-circuit
2698  }
2699  if (dist_squared <= threshold_squared) {
2700  // If threashold_squared is defined and the calculated dist_squared dips under it,
2701  // short-circuit and return it
2702  return sqrt(dist_squared);
2703  }
2704 
2705  l21 = l22; // advance to the next point on l2
2706  }
2707 
2708  l11 = l12; // advance to the next point on l1
2709  }
2710  return sqrt(dist_squared);
2711 }
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_INLINE double ST_Distance_LineString_MultiPoint ( int8_t *  l,
int64_t  lsize,
int8_t *  mp,
int64_t  mpsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2619 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_MultiPoint_LineString().

2628  {
2630  mp, mpsize, l, lsize, ic2, isr2, ic1, isr1, osr, threshold);
2631 }
EXTENSION_INLINE double ST_Distance_MultiPoint_LineString(int8_t *mp, int64_t mpsize, 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_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 2783 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().

2796  {
2797  // TODO: revisit implementation, cover all cases
2798  double min_distance = 0.0;
2799 
2800  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
2801  auto next_poly_coords = mpoly_coords;
2802  auto next_poly_ring_sizes = mpoly_ring_sizes;
2803 
2804  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
2805  auto poly_coords = next_poly_coords;
2806  auto poly_ring_sizes = next_poly_ring_sizes;
2807  auto poly_num_rings = mpoly_poly_sizes[poly];
2808  // Count number of coords in all of poly's rings, advance ring size pointer.
2809  int32_t poly_num_coords = 0;
2810  for (auto ring = 0; ring < poly_num_rings; ring++) {
2811  poly_num_coords += 2 * *next_poly_ring_sizes++;
2812  }
2813  auto poly_coords_size = poly_num_coords * compression_unit_size(ic2);
2814  next_poly_coords += poly_coords_size;
2815  double distance = ST_Distance_LineString_Polygon(l,
2816  lsize,
2817  poly_coords,
2818  poly_coords_size,
2819  poly_ring_sizes,
2820  poly_num_rings,
2821  ic1,
2822  isr1,
2823  ic2,
2824  isr2,
2825  osr,
2826  threshold);
2827  if (poly == 0 || min_distance > distance) {
2828  min_distance = distance;
2829  if (tol_zero(min_distance)) {
2830  min_distance = 0.0;
2831  break;
2832  }
2833  if (min_distance <= threshold) {
2834  return min_distance;
2835  }
2836  }
2837  }
2838 
2839  return min_distance;
2840 }
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 2604 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString().

2613  {
2615  p, psize, l, lsize, ic2, isr2, ic1, isr1, osr, threshold);
2616 }
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 1869 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString_Geodesic().

1877  {
1878  // Currently only statically indexed LineString is supported
1880  p, psize, l, lsize, ic2, isr2, ic1, isr1, osr);
1881 }
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 2714 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().

2725  {
2726  auto lnum_coords = lsize / compression_unit_size(ic1);
2727  auto psize = 2 * compression_unit_size(ic1);
2728  auto min_distance =
2729  ST_Distance_Point_Polygon(l, // pointer to start of linestring for first point
2730  psize,
2731  poly_coords,
2732  poly_coords_size,
2733  poly_ring_sizes,
2734  poly_num_rings,
2735  ic1,
2736  isr1,
2737  ic2,
2738  isr2,
2739  osr,
2740  threshold);
2741  if (tol_zero(min_distance)) {
2742  // Linestring's first point is inside the poly
2743  return 0.0;
2744  }
2745  if (min_distance <= threshold) {
2746  return min_distance;
2747  }
2748 
2749  // Otherwise, linestring's first point is outside the external ring or inside
2750  // an internal ring. Measure minimum distance between linestring segments and
2751  // poly rings. Crossing a ring zeroes the distance and causes an early return.
2752  auto poly_ring_coords = poly_coords;
2753  for (auto r = 0; r < poly_num_rings; r++) {
2754  int64_t poly_ring_num_coords = poly_ring_sizes[r] * 2;
2755 
2756  auto distance = distance_ring_linestring(poly_ring_coords,
2757  poly_ring_num_coords,
2758  l,
2759  lnum_coords,
2760  ic2,
2761  isr2,
2762  ic1,
2763  isr1,
2764  osr,
2765  threshold);
2766  if (min_distance > distance) {
2767  min_distance = distance;
2768  if (tol_zero(min_distance)) {
2769  return 0.0;
2770  }
2771  if (min_distance <= threshold) {
2772  return min_distance;
2773  }
2774  }
2775 
2776  poly_ring_coords += poly_ring_num_coords * compression_unit_size(ic2);
2777  }
2778 
2779  return min_distance;
2780 }
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_NOINLINE double ST_Distance_MultiLineString_MultiLineString ( int8_t *  mls1,
int64_t  mls1size,
int32_t *  mls1_ls_sizes,
int64_t  mls1_ls_num,
int8_t *  mls2,
int64_t  mls2size,
int32_t *  mls2_ls_sizes,
int64_t  mls2_ls_num,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 3237 of file ExtensionFunctionsGeo.hpp.

3250  {
3251  return 0.0;
3252 }
EXTENSION_INLINE double ST_Distance_MultiLineString_MultiPoint ( int8_t *  mls,
int64_t  mls_size,
int32_t *  mls_ls_sizes,
int64_t  mls_ls_num,
int8_t *  mp,
int64_t  mpsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2634 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_MultiPoint_MultiLineString().

2645  {
2647  mpsize,
2648  mls,
2649  mls_size,
2650  mls_ls_sizes,
2651  mls_ls_num,
2652  ic2,
2653  isr2,
2654  ic1,
2655  isr1,
2656  osr,
2657  threshold);
2658 }
EXTENSION_INLINE double ST_Distance_MultiPoint_MultiLineString(int8_t *mp, int64_t mpsize, int8_t *mls, int64_t mls_size, int32_t *mls_ls_sizes, int64_t mls_ls_num, 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_MultiLineString_Point ( int8_t *  mls,
int64_t  mls_size,
int32_t *  mls_ls_sizes,
int64_t  mls_ls_num,
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 2843 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_MultiLineString().

2854  {
2856  psize,
2857  mls,
2858  mls_size,
2859  mls_ls_sizes,
2860  mls_ls_num,
2861  ic2,
2862  isr2,
2863  ic1,
2864  isr1,
2865  osr,
2866  threshold);
2867 }
EXTENSION_NOINLINE double ST_Distance_Point_MultiLineString(int8_t *p, int64_t psize, int8_t *mls, int64_t mls_size, int32_t *mls_ls_sizes, int64_t mls_ls_num, 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_MultiPoint_LineString ( int8_t *  mp,
int64_t  mpsize,
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 2520 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and distance_point_linestring().

Referenced by ST_Distance_LineString_MultiPoint().

2529  {
2530  auto mp_num_coords = mpsize / compression_unit_size(ic1);
2531  auto* p = mp;
2532  auto const psize = compression_unit_size(ic1) * 2;
2533  auto dist = distance_point_linestring(
2534  p, psize, l, lsize, ic1, isr1, ic2, isr2, osr, true, threshold);
2535  p += psize;
2536  for (int32_t i = 2; i < mp_num_coords; i += 2) {
2537  auto ldist = distance_point_linestring(
2538  p, psize, l, lsize, ic1, isr1, ic2, isr2, osr, true, threshold);
2539  p += psize;
2540  if (dist > ldist) {
2541  dist = ldist;
2542  }
2543  if (dist <= threshold) {
2544  return dist;
2545  }
2546  }
2547  return dist;
2548 }
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)
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_MultiPoint_MultiLineString ( int8_t *  mp,
int64_t  mpsize,
int8_t *  mls,
int64_t  mls_size,
int32_t *  mls_ls_sizes,
int64_t  mls_ls_num,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2551 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and distance_point_multilinestring().

Referenced by ST_Distance_MultiLineString_MultiPoint().

2562  {
2563  auto mp_num_coords = mpsize / compression_unit_size(ic1);
2564  auto* p = mp;
2565  auto const psize = compression_unit_size(ic1) * 2;
2566  auto dist = distance_point_multilinestring(p,
2567  psize,
2568  mls,
2569  mls_size,
2570  mls_ls_sizes,
2571  mls_ls_num,
2572  ic1,
2573  isr1,
2574  ic2,
2575  isr2,
2576  osr,
2577  threshold);
2578  p += psize;
2579  for (int32_t i = 2; i < mp_num_coords; i += 2) {
2580  auto ldist = distance_point_multilinestring(p,
2581  psize,
2582  mls,
2583  mls_size,
2584  mls_ls_sizes,
2585  mls_ls_num,
2586  ic1,
2587  isr1,
2588  ic2,
2589  isr2,
2590  osr,
2591  threshold);
2592  p += psize;
2593  if (dist > ldist) {
2594  dist = ldist;
2595  }
2596  if (dist <= threshold) {
2597  return dist;
2598  }
2599  }
2600  return dist;
2601 }
DEVICE ALWAYS_INLINE double distance_point_multilinestring(int8_t *p, int64_t psize, int8_t *mls, int64_t mls_size, int32_t *mls_ls_sizes, int64_t mls_ls_num, 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:

+ Here is the caller graph for this function:

EXTENSION_NOINLINE double ST_Distance_MultiPoint_MultiPoint ( int8_t *  mp1,
int64_t  mp1size,
int8_t *  mp2,
int64_t  mp2size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2460 of file ExtensionFunctionsGeo.hpp.

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

2469  {
2470  auto mp1_num_coords = mp1size / compression_unit_size(ic1);
2471  auto mp2_num_coords = mp2size / compression_unit_size(ic2);
2472  double dist = -1.0;
2473  for (int32_t i = 0; i < mp1_num_coords; i += 2) {
2474  Point2D mp1p = get_point(mp1, 0, ic1, isr1, osr);
2475  for (int32_t j = 0; j < mp2_num_coords; j += 2) {
2476  Point2D mp2p = get_point(mp2, 0, ic2, isr2, osr);
2477  double ldist = distance_point_point(mp1p.x, mp1p.y, mp2p.x, mp2p.y);
2478  if (dist > ldist || dist < 0.0) {
2479  dist = ldist;
2480  }
2481  if (dist <= threshold) {
2482  return dist;
2483  }
2484  }
2485  }
2486  return dist;
2487 }
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:

EXTENSION_NOINLINE double ST_Distance_MultiPoint_MultiPoint_Squared ( int8_t *  mp1,
int64_t  mp1size,
int8_t *  mp2,
int64_t  mp2size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2490 of file ExtensionFunctionsGeo.hpp.

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

2499  {
2500  auto mp1_num_coords = mp1size / compression_unit_size(ic1);
2501  auto mp2_num_coords = mp2size / compression_unit_size(ic2);
2502  double dist = -1.0;
2503  for (int32_t i = 0; i < mp1_num_coords; i += 2) {
2504  Point2D mp1p = get_point(mp1, i, ic1, isr1, osr);
2505  for (int32_t j = 0; j < mp2_num_coords; j += 2) {
2506  Point2D mp2p = get_point(mp2, j, ic2, isr2, osr);
2507  double ldist = distance_point_point_squared(mp1p.x, mp1p.y, mp2p.x, mp2p.y);
2508  if (dist > ldist || dist < 0.0) {
2509  dist = ldist;
2510  }
2511  if (dist <= threshold) {
2512  return dist;
2513  }
2514  }
2515  }
2516  return dist;
2517 }
DEVICE ALWAYS_INLINE double distance_point_point_squared(double p1x, double p1y, double p2x, double p2y)
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_INLINE double ST_Distance_MultiPoint_MultiPolygon ( int8_t *  mp,
int64_t  mpsize,
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 2313 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and distance_point_multipolygon().

Referenced by ST_Distance_MultiPolygon_MultiPoint().

2326  {
2327  auto mp_num_coords = mpsize / compression_unit_size(ic1);
2328  auto* p = mp;
2329  auto const psize = compression_unit_size(ic1) * 2;
2330  auto dist = distance_point_multipolygon(p,
2331  psize,
2332  mpoly_coords,
2333  mpoly_coords_size,
2334  mpoly_ring_sizes,
2335  mpoly_num_rings,
2336  mpoly_poly_sizes,
2337  mpoly_num_polys,
2338  ic1,
2339  isr1,
2340  ic2,
2341  isr2,
2342  osr,
2343  threshold);
2344  p += psize;
2345  for (int32_t i = 2; i < mp_num_coords; i += 2) {
2346  auto ldist = distance_point_multipolygon(p,
2347  psize,
2348  mpoly_coords,
2349  mpoly_coords_size,
2350  mpoly_ring_sizes,
2351  mpoly_num_rings,
2352  mpoly_poly_sizes,
2353  mpoly_num_polys,
2354  ic1,
2355  isr1,
2356  ic2,
2357  isr2,
2358  osr,
2359  threshold);
2360  p += psize;
2361  if (dist > ldist) {
2362  dist = ldist;
2363  }
2364  if (dist <= threshold) {
2365  return dist;
2366  }
2367  }
2368  return dist;
2369 }
DEVICE ALWAYS_INLINE double 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 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_MultiPoint_Point ( int8_t *  mp,
int64_t  mpsize,
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 2430 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_MultiPoint().

2439  {
2441  p, psize, mp, mpsize, ic2, isr2, ic1, isr1, osr, threshold);
2442 }
EXTENSION_NOINLINE double ST_Distance_Point_MultiPoint(int8_t *p, int64_t psize, int8_t *mp, int64_t mpsize, 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_MultiPoint_Point_Squared ( int8_t *  mp,
int64_t  mpsize,
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 2445 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_MultiPoint_Squared().

2454  {
2456  p, psize, mp, mpsize, ic2, isr2, ic1, isr1, osr, threshold);
2457 }
EXTENSION_NOINLINE double ST_Distance_Point_MultiPoint_Squared(int8_t *p, int64_t psize, int8_t *mp, int64_t mpsize, 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_MultiPoint_Polygon ( int8_t *  mp,
int64_t  mpsize,
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 2260 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and distance_point_polygon().

Referenced by ST_Distance_Polygon_MultiPoint().

2271  {
2272  auto mp_num_coords = mpsize / compression_unit_size(ic1);
2273  auto* p = mp;
2274  auto const psize = compression_unit_size(ic1) * 2;
2275  auto dist = distance_point_polygon(p,
2276  psize,
2277  poly,
2278  polysize,
2279  poly_ring_sizes,
2280  poly_num_rings,
2281  ic1,
2282  isr1,
2283  ic2,
2284  isr2,
2285  osr,
2286  threshold);
2287  p += psize;
2288  for (int32_t i = 2; i < mp_num_coords; i += 2) {
2289  auto ldist = distance_point_polygon(p,
2290  psize,
2291  poly,
2292  polysize,
2293  poly_ring_sizes,
2294  poly_num_rings,
2295  ic1,
2296  isr1,
2297  ic2,
2298  isr2,
2299  osr,
2300  threshold);
2301  p += psize;
2302  if (dist > ldist) {
2303  dist = ldist;
2304  }
2305  if (dist <= threshold) {
2306  return dist;
2307  }
2308  }
2309  return dist;
2310 }
DEVICE ALWAYS_INLINE double 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 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_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 3103 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_LineString_MultiPolygon().

3116  {
3118  lsize,
3119  mpoly_coords,
3120  mpoly_coords_size,
3121  mpoly_ring_sizes,
3122  mpoly_num_rings,
3123  mpoly_poly_sizes,
3124  mpoly_num_polys,
3125  ic2,
3126  isr2,
3127  ic1,
3128  isr1,
3129  osr,
3130  threshold);
3131 }
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_INLINE double ST_Distance_MultiPolygon_MultiPoint ( 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 *  mp,
int64_t  mpsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2399 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_MultiPoint_MultiPolygon().

2412  {
2414  mpsize,
2415  mpoly_coords,
2416  mpoly_coords_size,
2417  mpoly_ring_sizes,
2418  mpoly_num_rings,
2419  mpoly_poly_sizes,
2420  mpoly_num_polys,
2421  ic2,
2422  isr2,
2423  ic1,
2424  isr1,
2425  osr,
2426  threshold);
2427 }
EXTENSION_INLINE double ST_Distance_MultiPoint_MultiPolygon(int8_t *mp, int64_t mpsize, 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 3169 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().

3186  {
3187  double min_distance = 0.0;
3188 
3189  // Set specific poly pointers as we move through mpoly1's coords/ringsizes/polyrings
3190  // arrays.
3191  auto next_poly_coords = mpoly1_coords;
3192  auto next_poly_ring_sizes = mpoly1_ring_sizes;
3193 
3194  for (auto poly = 0; poly < mpoly1_num_polys; poly++) {
3195  auto poly_coords = next_poly_coords;
3196  auto poly_ring_sizes = next_poly_ring_sizes;
3197  auto poly_num_rings = mpoly1_poly_sizes[poly];
3198  // Count number of coords in all of poly's rings, advance ring size pointer.
3199  int32_t poly_num_coords = 0;
3200  for (auto ring = 0; ring < poly_num_rings; ring++) {
3201  poly_num_coords += 2 * *next_poly_ring_sizes++;
3202  }
3203  auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
3204  next_poly_coords += poly_coords_size;
3205  double distance = ST_Distance_Polygon_MultiPolygon(poly_coords,
3206  poly_coords_size,
3207  poly_ring_sizes,
3208  poly_num_rings,
3209  mpoly2_coords,
3210  mpoly2_coords_size,
3211  mpoly2_ring_sizes,
3212  mpoly2_num_rings,
3213  mpoly2_poly_sizes,
3214  mpoly2_num_polys,
3215  ic1,
3216  isr1,
3217  ic2,
3218  isr2,
3219  osr,
3220  threshold);
3221  if (poly == 0 || min_distance > distance) {
3222  min_distance = distance;
3223  if (tol_zero(min_distance)) {
3224  min_distance = 0.0;
3225  break;
3226  }
3227  if (min_distance <= threshold) {
3228  break;
3229  }
3230  }
3231  }
3232 
3233  return min_distance;
3234 }
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 3072 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_MultiPolygon().

3085  {
3087  psize,
3088  mpoly_coords,
3089  mpoly_coords_size,
3090  mpoly_ring_sizes,
3091  mpoly_num_rings,
3092  mpoly_poly_sizes,
3093  mpoly_num_polys,
3094  ic2,
3095  isr2,
3096  ic1,
3097  isr1,
3098  osr,
3099  threshold);
3100 }
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 3134 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Polygon_MultiPolygon().

3149  {
3150  return ST_Distance_Polygon_MultiPolygon(poly1_coords,
3151  poly1_coords_size,
3152  poly1_ring_sizes,
3153  poly1_num_rings,
3154  mpoly_coords,
3155  mpoly_coords_size,
3156  mpoly_ring_sizes,
3157  mpoly_num_rings,
3158  mpoly_poly_sizes,
3159  mpoly_num_polys,
3160  ic2,
3161  isr2,
3162  ic1,
3163  isr1,
3164  osr,
3165  threshold);
3166 }
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 1981 of file ExtensionFunctionsGeo.hpp.

References distance_point_linestring().

Referenced by distance_point_polygon().

1990  {
1992  p, psize, l, lsize, ic1, isr1, ic2, isr2, osr, true, threshold);
1993 }
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 1996 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().

2005  {
2007  p, psize, l, lsize, ic1, isr1, ic2, isr2, osr, false, threshold);
2008 }
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 1852 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Distance_LineString_Point_Geodesic().

1860  {
1861  // Currently only statically indexed LineString is supported
1862  Point2D const pt = get_point(p, 0, ic1, 4326, 4326);
1863  const auto lpoints = lsize / (2 * compression_unit_size(ic2));
1864  Point2D const pl = get_point(l, 2 * (lpoints - 1), ic2, 4326, 4326);
1865  return distance_in_meters(pt.x, pt.y, pl.x, pl.y);
1866 }
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_MultiLineString ( int8_t *  p,
int64_t  psize,
int8_t *  mls,
int64_t  mls_size,
int32_t *  mls_ls_sizes,
int64_t  mls_ls_num,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2062 of file ExtensionFunctionsGeo.hpp.

References distance_point_multilinestring().

Referenced by ST_Distance_MultiLineString_Point().

2073  {
2075  psize,
2076  mls,
2077  mls_size,
2078  mls_ls_sizes,
2079  mls_ls_num,
2080  ic1,
2081  isr1,
2082  ic2,
2083  isr2,
2084  osr,
2085  threshold);
2086 }
DEVICE ALWAYS_INLINE double distance_point_multilinestring(int8_t *p, int64_t psize, int8_t *mls, int64_t mls_size, int32_t *mls_ls_sizes, int64_t mls_ls_num, 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_Point_MultiPoint ( int8_t *  p,
int64_t  psize,
int8_t *  mp,
int64_t  mpsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 1884 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Distance_MultiPoint_Point().

1893  {
1894  Point2D pt = get_point(p, 0, ic1, isr1, osr);
1895  auto mp_num_coords = mpsize / compression_unit_size(ic2);
1896  Point2D mpp = get_point(mp, 0, ic2, isr2, osr);
1897  double dist = distance_point_point(pt.x, pt.y, mpp.x, mpp.y);
1898  for (int32_t i = 2; i < mp_num_coords; i += 2) {
1899  mpp = get_point(mp, i, ic2, isr2, osr);
1900  double ldist = distance_point_point(pt.x, pt.y, mpp.x, mpp.y);
1901  if (dist > ldist) {
1902  dist = ldist;
1903  }
1904  if (dist <= threshold) {
1905  return dist;
1906  }
1907  }
1908  return dist;
1909 }
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:

EXTENSION_NOINLINE double ST_Distance_Point_MultiPoint_Squared ( int8_t *  p,
int64_t  psize,
int8_t *  mp,
int64_t  mpsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 1912 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Distance_MultiPoint_Point_Squared().

1921  {
1922  Point2D pt = get_point(p, 0, ic1, isr1, osr);
1923  auto mp_num_coords = mpsize / compression_unit_size(ic2);
1924  Point2D mpp = get_point(mp, 0, ic2, isr2, osr);
1925  double dist = distance_point_point_squared(pt.x, pt.y, mpp.x, mpp.y);
1926  for (int32_t i = 2; i < mp_num_coords; i += 2) {
1927  mpp = get_point(mp, i, ic2, isr2, osr);
1928  double ldist = distance_point_point_squared(pt.x, pt.y, mpp.x, mpp.y);
1929  if (dist > ldist) {
1930  dist = ldist;
1931  }
1932  if (dist <= threshold) {
1933  return dist;
1934  }
1935  }
1936  return dist;
1937 }
DEVICE ALWAYS_INLINE double distance_point_point_squared(double p1x, double p1y, double p2x, double p2y)
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 2229 of file ExtensionFunctionsGeo.hpp.

References distance_point_multipolygon().

Referenced by ST_Distance_MultiPolygon_Point(), and ST_DWithin_Point_MultiPolygon().

2242  {
2243  return distance_point_multipolygon(p,
2244  psize,
2245  mpoly_coords,
2246  mpoly_coords_size,
2247  mpoly_ring_sizes,
2248  mpoly_num_rings,
2249  mpoly_poly_sizes,
2250  mpoly_num_polys,
2251  ic1,
2252  isr1,
2253  ic2,
2254  isr2,
2255  osr,
2256  threshold);
2257 }
DEVICE ALWAYS_INLINE double 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:

+ 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 1807 of file ExtensionFunctionsGeo.hpp.

References distance_point_point(), and get_point().

Referenced by ST_Intersects_Point_Point().

1815  {
1816  Point2D const pt1 = get_point(p1, 0, ic1, isr1, osr);
1817  Point2D const pt2 = get_point(p2, 0, ic2, isr2, osr);
1818  return distance_point_point(pt1.x, pt1.y, pt2.x, pt2.y);
1819 }
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 1837 of file ExtensionFunctionsGeo.hpp.

References distance_in_meters(), and get_point().

Referenced by ST_DWithin_Point_Point_Geodesic().

1845  {
1846  Point2D const pt1 = get_point(p1, 0, ic1, 4326, 4326);
1847  Point2D const pt2 = get_point(p2, 0, ic2, 4326, 4326);
1848  return distance_in_meters(pt1.x, pt1.y, pt2.x, pt2.y);
1849 }
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 1822 of file ExtensionFunctionsGeo.hpp.

References distance_point_point_squared(), and get_point().

Referenced by ST_DWithin_Point_Point().

1830  {
1831  Point2D const pt1 = get_point(p1, 0, ic1, isr1, osr);
1832  Point2D const pt2 = get_point(p2, 0, ic2, isr2, osr);
1833  return distance_point_point_squared(pt1.x, pt1.y, pt2.x, pt2.y);
1834 }
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 2202 of file ExtensionFunctionsGeo.hpp.

References distance_point_polygon().

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

2213  {
2214  return distance_point_polygon(p,
2215  psize,
2216  poly,
2217  polysize,
2218  poly_ring_sizes,
2219  poly_num_rings,
2220  ic1,
2221  isr1,
2222  ic2,
2223  isr2,
2224  osr,
2225  threshold);
2226 }
DEVICE ALWAYS_INLINE double 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_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 2897 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_LineString_Polygon().

2908  {
2910  lsize,
2911  poly_coords,
2912  poly_coords_size,
2913  poly_ring_sizes,
2914  poly_num_rings,
2915  ic2,
2916  isr2,
2917  ic1,
2918  isr2,
2919  osr,
2920  threshold);
2921 }
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_INLINE double ST_Distance_Polygon_MultiPoint ( int8_t *  poly,
int64_t  polysize,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
int8_t *  mp,
int64_t  mpsize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2372 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_MultiPoint_Polygon().

2383  {
2385  mpsize,
2386  poly,
2387  polysize,
2388  poly_ring_sizes,
2389  poly_num_rings,
2390  ic2,
2391  isr2,
2392  ic1,
2393  isr1,
2394  osr,
2395  threshold);
2396 }
EXTENSION_INLINE double ST_Distance_MultiPoint_Polygon(int8_t *mp, int64_t mpsize, 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:

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,