OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExtensionFunctionsGeo.hpp File Reference
+ 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.

Macros

#define DEBUG_STMT(x)
 

Enumerations

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)
 
DEVICE ALWAYS_INLINE double decompress_coord (const int8_t *data, const int32_t index, const int32_t ic, const bool x)
 
DEVICE ALWAYS_INLINE int32_t compression_unit_size (const int32_t ic)
 
DEVICE ALWAYS_INLINE double transform_coord (const double coord, const int32_t isr, const int32_t osr, const bool x)
 
DEVICE ALWAYS_INLINE double transform_coord_x (const double coord, const int32_t isr, const int32_t osr)
 
DEVICE ALWAYS_INLINE double transform_coord_y (const double coord, const int32_t isr, const int32_t osr)
 
DEVICE ALWAYS_INLINE double coord_x (const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
 
DEVICE ALWAYS_INLINE double coord_y (const int8_t *data, const int32_t 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)
 
EXTENSION_NOINLINE double ST_X_Point (int8_t *p, int64_t psize, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Y_Point (int8_t *p, int64_t psize, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_XMin (int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_YMin (int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_XMax (int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_YMax (int8_t *coords, int64_t size, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_INLINE double ST_XMin_Bounds (double *bounds, int64_t size, int32_t isr, int32_t osr)
 
EXTENSION_INLINE double ST_YMin_Bounds (double *bounds, int64_t size, int32_t isr, int32_t osr)
 
EXTENSION_INLINE double ST_XMax_Bounds (double *bounds, int64_t size, int32_t isr, int32_t osr)
 
EXTENSION_INLINE double ST_YMax_Bounds (double *bounds, int64_t size, int32_t isr, int32_t osr)
 
DEVICE ALWAYS_INLINE double length_linestring (int8_t *l, int32_t lsize, int32_t ic, int32_t isr, int32_t osr, bool geodesic, bool check_closed)
 
EXTENSION_NOINLINE double ST_Length_LineString (int8_t *coords, int64_t coords_sz, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Length_LineString_Geodesic (int8_t *coords, int64_t coords_sz, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Perimeter_Polygon (int8_t *poly, int32_t polysize, int8_t *poly_ring_sizes, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Perimeter_Polygon_Geodesic (int8_t *poly, int32_t polysize, int8_t *poly_ring_sizes_in, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
 
DEVICE ALWAYS_INLINE double perimeter_multipolygon (int8_t *mpoly_coords, int32_t mpoly_coords_size, int8_t *mpoly_ring_sizes_in, int32_t mpoly_num_rings, int8_t *mpoly_poly_sizes, int32_t mpoly_num_polys, int32_t ic, int32_t isr, int32_t osr, bool geodesic)
 
EXTENSION_NOINLINE double ST_Perimeter_MultiPolygon (int8_t *mpoly_coords, int32_t mpoly_coords_size, int8_t *mpoly_ring_sizes, int32_t mpoly_num_rings, int8_t *mpoly_poly_sizes, int32_t mpoly_num_polys, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Perimeter_MultiPolygon_Geodesic (int8_t *mpoly_coords, int32_t mpoly_coords_size, int8_t *mpoly_ring_sizes, int32_t mpoly_num_rings, int8_t *mpoly_poly_sizes, int32_t mpoly_num_polys, int32_t ic, int32_t isr, int32_t osr)
 
DEVICE ALWAYS_INLINE double area_triangle (double x1, double y1, double x2, double y2, double x3, double y3)
 
DEVICE ALWAYS_INLINE double area_ring (int8_t *ring, int64_t ringsize, int32_t ic, int32_t isr, int32_t osr)
 
DEVICE ALWAYS_INLINE double area_polygon (int8_t *poly_coords, int32_t poly_coords_size, int8_t *poly_ring_sizes_in, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Area_Polygon (int8_t *poly_coords, int32_t poly_coords_size, int8_t *poly_ring_sizes, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Area_MultiPolygon (int8_t *mpoly_coords, int32_t mpoly_coords_size, int8_t *mpoly_ring_sizes, int32_t mpoly_num_rings, int8_t *mpoly_poly_sizes_in, int32_t mpoly_num_polys, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE void ST_Centroid_Point (int8_t *p, int32_t psize, int32_t ic, int32_t isr, int32_t osr, double *point_centroid)
 
DEVICE ALWAYS_INLINE bool centroid_add_segment (double x1, double y1, double x2, double y2, double *length, double *linestring_centroid_sum)
 
DEVICE ALWAYS_INLINE bool centroid_add_linestring (int8_t *l, int64_t lsize, int32_t ic, int32_t isr, int32_t osr, bool closed, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)
 
EXTENSION_NOINLINE void ST_Centroid_LineString (int8_t *coords, int32_t coords_sz, int32_t ic, int32_t isr, int32_t osr, double *linestring_centroid)
 
DEVICE ALWAYS_INLINE bool centroid_add_triangle (double x1, double y1, double x2, double y2, double x3, double y3, double sign, double *total_area2, double *cg3)
 
DEVICE ALWAYS_INLINE bool centroid_add_ring (int8_t *ring, int64_t ringsize, int32_t ic, int32_t isr, int32_t osr, double sign, double *total_area2, double *cg3, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)
 
DEVICE ALWAYS_INLINE bool centroid_add_polygon (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr, double *total_area2, double *cg3, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)
 
EXTENSION_NOINLINE void ST_Centroid_Polygon (int8_t *poly_coords, int32_t poly_coords_size, int32_t *poly_ring_sizes, int32_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr, double *poly_centroid)
 
EXTENSION_NOINLINE void ST_Centroid_MultiPolygon (int8_t *mpoly_coords, int32_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int32_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int32_t mpoly_num_polys, int32_t ic, int32_t isr, int32_t osr, double *mpoly_centroid)
 
EXTENSION_NOINLINE double ST_Distance_Point_Point (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE double ST_Distance_Point_Point_Squared (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE double ST_Distance_Point_Point_Geodesic (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE double ST_Distance_Point_LineString_Geodesic (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE double ST_Distance_LineString_Point_Geodesic (int8_t *l, int64_t lsize, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
DEVICE ALWAYS_INLINE double distance_point_linestring (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, bool check_closed, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Point_ClosedLineString (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Point_LineString (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Point_Polygon (int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Point_MultiPolygon (int8_t *p, int64_t psize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_LineString_Point (int8_t *l, int64_t lsize, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_LineString_LineString (int8_t *l1, int64_t l1size, int8_t *l2, int64_t l2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_LineString_Polygon (int8_t *l, int64_t lsize, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_LineString_MultiPolygon (int8_t *l, int64_t lsize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_Polygon_Point (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_Polygon_LineString (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Polygon_Polygon (int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int8_t *poly2_coords, int64_t poly2_coords_size, int32_t *poly2_ring_sizes, int64_t poly2_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_Polygon_MultiPolygon (int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_MultiPolygon_Point (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_MultiPolygon_LineString (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE double ST_Distance_MultiPolygon_Polygon (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_NOINLINE double ST_Distance_MultiPolygon_MultiPolygon (int8_t *mpoly1_coords, int64_t mpoly1_coords_size, int32_t *mpoly1_ring_sizes, int64_t mpoly1_num_rings, int32_t *mpoly1_poly_sizes, int64_t mpoly1_num_polys, int8_t *mpoly2_coords, int64_t mpoly2_coords_size, int32_t *mpoly2_ring_sizes, int64_t mpoly2_num_rings, int32_t *mpoly2_poly_sizes, int64_t mpoly2_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
 
EXTENSION_INLINE bool ST_DWithin_Point_Point (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Point_Point_Geodesic (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Point_LineString (int8_t *p1, int64_t p1size, int8_t *l2, int64_t l2size, double *l2bounds, int64_t l2bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Point_Polygon (int8_t *p, int64_t psize, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Point_MultiPolygon (int8_t *p, int64_t psize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_LineString_LineString (int8_t *l1, int64_t l1size, double *l1bounds, int64_t l1bounds_size, int8_t *l2, int64_t l2size, double *l2bounds, int64_t l2bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_LineString_Polygon (int8_t *l1, int64_t l1size, double *l1bounds, int64_t l1bounds_size, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_LineString_MultiPolygon (int8_t *l1, int64_t l1size, double *l1bounds, int64_t l1bounds_size, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Polygon_Polygon (int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, double *poly1_bounds, int64_t poly1_bounds_size, int8_t *poly2_coords, int64_t poly2_coords_size, int32_t *poly2_ring_sizes, int64_t poly2_num_rings, double *poly2_bounds, int64_t poly2_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_Polygon_MultiPolygon (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
EXTENSION_INLINE bool ST_DWithin_MultiPolygon_MultiPolygon (int8_t *mpoly1_coords, int64_t mpoly1_coords_size, int32_t *mpoly1_ring_sizes, int64_t mpoly1_num_rings, int32_t *mpoly1_poly_sizes, int64_t mpoly1_num_polys, double *mpoly1_bounds, int64_t mpoly1_bounds_size, int8_t *mpoly2_coords, int64_t mpoly2_coords_size, int32_t *mpoly2_ring_sizes, int64_t mpoly2_num_rings, int32_t *mpoly2_poly_sizes, int64_t mpoly2_num_polys, double *mpoly2_bounds, int64_t mpoly2_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double distance_within)
 
DEVICE double max_distance_point_line (double px, double py, double l1x, double l1y, double l2x, double l2y)
 
DEVICE ALWAYS_INLINE double max_distance_point_linestring (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, bool check_closed)
 
EXTENSION_NOINLINE double ST_MaxDistance_Point_LineString (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE double ST_MaxDistance_LineString_Point (int8_t *l, int64_t lsize, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Point_Point (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Point_LineString (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Point_Polygon (int8_t *p, int64_t psize, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Contains_LineString_Point (int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_LineString_Polygon (int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
template<typename T , EdgeBehavior TEdgeBehavior>
DEVICE ALWAYS_INLINE bool Contains_Polygon_Point_Impl (const int8_t *poly_coords, const int64_t poly_coords_size, const int32_t *poly_ring_sizes, const int64_t poly_num_rings, const double *poly_bounds, const int64_t poly_bounds_size, const int8_t *p, const int64_t psize, const int32_t ic1, const int32_t isr1, const int32_t ic2, const int32_t isr2, const int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Polygon_Point (const int8_t *poly_coords, const int64_t poly_coords_size, const int32_t *poly_ring_sizes, const int64_t poly_num_rings, const double *poly_bounds, const int64_t poly_bounds_size, const int8_t *p, const int64_t psize, const int32_t ic1, const int32_t isr1, const int32_t ic2, const int32_t isr2, const int32_t osr)
 
EXTENSION_NOINLINE bool ST_cContains_Polygon_Point (const int8_t *poly_coords, const int64_t poly_coords_size, const int32_t *poly_ring_sizes, const int64_t poly_num_rings, const double *poly_bounds, const int64_t poly_bounds_size, const int8_t *p, const int64_t psize, const int32_t ic1, const int32_t isr1, const int32_t ic2, const int32_t isr2, const int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Polygon_LineString (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_Polygon_Polygon (int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, double *poly1_bounds, int64_t poly1_bounds_size, int8_t *poly2_coords, int64_t poly2_coords_size, int32_t *poly2_ring_sizes, int64_t poly2_num_rings, double *poly2_bounds, int64_t poly2_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
template<typename T , EdgeBehavior TEdgeBehavior>
DEVICE ALWAYS_INLINE bool Contains_MultiPolygon_Point_Impl (const int8_t *mpoly_coords, const int64_t mpoly_coords_size, const int32_t *mpoly_ring_sizes, const int64_t mpoly_num_rings, const int32_t *mpoly_poly_sizes, const int64_t mpoly_num_polys, const double *mpoly_bounds, const int64_t mpoly_bounds_size, const int8_t *p, const int64_t psize, const int32_t ic1, const int32_t isr1, const int32_t ic2, const int32_t isr2, const int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_MultiPolygon_Point (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_cContains_MultiPolygon_Point (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Contains_MultiPolygon_LineString (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_Point_Point (int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_Point_LineString (int8_t *p, int64_t psize, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_Point_Polygon (int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_Point_MultiPolygon (int8_t *p, int64_t psize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_LineString_Point (int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_LineString_Linestring (int8_t *l1, int64_t l1size, double *l1bounds, int64_t l1bounds_size, int8_t *l2, int64_t l2size, double *l2bounds, int64_t l2bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_LineString_Polygon (int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_LineString_MultiPolygon (int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_Polygon_Point (int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_Polygon_LineString (int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_Polygon_Polygon (int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, double *poly1_bounds, int64_t poly1_bounds_size, int8_t *poly2_coords, int64_t poly2_coords_size, int32_t *poly2_ring_sizes, int64_t poly2_num_rings, double *poly2_bounds, int64_t poly2_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE bool ST_Intersects_Polygon_MultiPolygon (int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_MultiPolygon_Point (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_MultiPolygon_LineString (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *l, int64_t lsize, double *lbounds, int64_t lbounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_MultiPolygon_Polygon (int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, double *mpoly_bounds, int64_t mpoly_bounds_size, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, double *poly_bounds, int64_t poly_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE bool ST_Intersects_MultiPolygon_MultiPolygon (int8_t *mpoly1_coords, int64_t mpoly1_coords_size, int32_t *mpoly1_ring_sizes, int64_t mpoly1_num_rings, int32_t *mpoly1_poly_sizes, int64_t mpoly1_num_polys, double *mpoly1_bounds, int64_t mpoly1_bounds_size, int8_t *mpoly2_coords, int64_t mpoly2_coords_size, int32_t *mpoly2_ring_sizes, int64_t mpoly2_num_rings, int32_t *mpoly2_poly_sizes, int64_t mpoly2_num_polys, double *mpoly2_bounds, int64_t mpoly2_bounds_size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_INLINE int64_t OmniSci_Geo_PolyBoundsPtr (double *bounds, int64_t size)
 
EXTENSION_INLINE int32_t OmniSci_Geo_PolyRenderGroup (int32_t render_group)
 
EXTENSION_INLINE int64_t MapD_GeoPolyBoundsPtr (double *bounds, int64_t size)
 
EXTENSION_INLINE int32_t MapD_GeoPolyRenderGroup (int32_t render_group)
 
EXTENSION_NOINLINE double convert_meters_to_pixel_width (const double meters, int8_t *p, const int64_t psize, const int32_t ic, const int32_t isr, const int32_t osr, const double min_lon, const double max_lon, const int32_t img_width, const double min_width)
 
EXTENSION_NOINLINE double convert_meters_to_pixel_height (const double meters, int8_t *p, const int64_t psize, const int32_t ic, const int32_t isr, const int32_t osr, const double min_lat, const double max_lat, const int32_t img_height, const double min_height)
 
EXTENSION_NOINLINE bool is_point_in_view (int8_t *p, const int64_t psize, const int32_t ic, const double min_lon, const double max_lon, const double min_lat, const double max_lat)
 
EXTENSION_NOINLINE bool is_point_size_in_view (int8_t *p, const int64_t psize, const int32_t ic, const double meters, const double min_lon, const double max_lon, const double min_lat, const double max_lat)
 

Macro Definition Documentation

#define DEBUG_STMT (   x)

Enumeration Type Documentation

enum EdgeBehavior
strong
Enumerator
kIncludePointOnEdge 
kExcludePointOnEdge 

Definition at line 514 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 1239 of file ExtensionFunctionsGeo.hpp.

References area_ring(), and compression_unit_size().

Referenced by ST_Area_MultiPolygon(), and ST_Area_Polygon().

1245  {
1246  if (poly_num_rings <= 0) {
1247  return 0.0;
1248  }
1249 
1250  double area = 0.0;
1251  auto ring_coords = poly_coords;
1252  auto poly_ring_sizes = reinterpret_cast<int32_t*>(poly_ring_sizes_in);
1253 
1254  // Add up the areas of all rings.
1255  // External ring is CCW, open - positive area.
1256  // Internal rings (holes) are CW, open - negative areas.
1257  for (auto r = 0; r < poly_num_rings; r++) {
1258  auto ring_coords_size = poly_ring_sizes[r] * 2 * compression_unit_size(ic);
1259  area += area_ring(ring_coords, ring_coords_size, ic, isr, osr);
1260  // Advance to the next ring.
1261  ring_coords += ring_coords_size;
1262  }
1263  return area;
1264 }
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 1212 of file ExtensionFunctionsGeo.hpp.

References area_triangle(), compression_unit_size(), coord_x(), coord_y(), and i.

Referenced by area_polygon().

1216  {
1217  auto ring_num_coords = ringsize / compression_unit_size(ic);
1218 
1219  if (ring_num_coords < 6) {
1220  return 0.0;
1221  }
1222 
1223  double area = 0.0;
1224 
1225  double x1 = coord_x(ring, 0, ic, isr, osr);
1226  double y1 = coord_y(ring, 1, ic, isr, osr);
1227  double x2 = coord_x(ring, 2, ic, isr, osr);
1228  double y2 = coord_y(ring, 3, ic, isr, osr);
1229  for (int32_t i = 4; i < ring_num_coords; i += 2) {
1230  double x3 = coord_x(ring, i, ic, isr, osr);
1231  double y3 = coord_y(ring, i + 1, ic, isr, osr);
1232  area += area_triangle(x1, y1, x2, y2, x3, y3);
1233  x2 = x3;
1234  y2 = y3;
1235  }
1236  return area;
1237 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 1203 of file ExtensionFunctionsGeo.hpp.

Referenced by area_ring().

1208  {
1209  return (x1 * y2 - x2 * y1 + x3 * y1 - x1 * y3 + x2 * y3 - x3 * y2) / 2.0;
1210 }

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

References box_contains_point().

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

829  {
830  // TODO: mixed spatial references
831  return (
833  bounds1, bounds1_size, bounds2[0], bounds2[1]) && // box1 <- box2: xmin, ymin
835  bounds1, bounds1_size, bounds2[2], bounds2[3])); // box1 <- box2: xmax, ymax
836 }
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 838 of file ExtensionFunctionsGeo.hpp.

References box_contains_point().

841  {
842  // TODO: mixed spatial references
843  return (
845  bounds1, bounds1_size, bounds2[0], bounds2[1]) || // box1 <- box2: xmin, ymin
847  bounds1, bounds1_size, bounds2[2], bounds2[3]) || // box1 <- box2: xmax, ymax
849  bounds1, bounds1_size, bounds2[0], bounds2[3]) || // box1 <- box2: xmin, ymax
851  bounds1, bounds1_size, bounds2[2], bounds2[1])); // box1 <- box2: xmax, ymin
852 }
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 809 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().

812  {
813  // TODO: mixed spatial references
814  return (tol_ge(px, bounds[0]) && tol_ge(py, bounds[1]) && tol_le(px, bounds[2]) &&
815  tol_le(py, bounds[3]));
816 }
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 898 of file ExtensionFunctionsGeo.hpp.

References transform_coord_x(), and transform_coord_y().

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().

905  {
906  // TODO: tolerance
907 
908  // Bounds come in corresponding input spatial references.
909  // For example, here the first bounding box may come in 4326, second in 900913:
910  // ST_DWithin(ST_Transform(linestring4326, 900913), linestring900913, 10)
911  // Distance is given in osr spatial reference units, in this case 10 meters.
912  // Bounds should be converted to osr before calculations, if isr != osr.
913 
914  // TODO: revise all other functions that process bounds
915 
916  if (
917  // box1 is left of box2: box1.xmax + distance < box2.xmin
918  transform_coord_x(bounds1[2], isr1, osr) + distance <
919  transform_coord_x(bounds2[0], isr2, osr) ||
920  // box1 is right of box2: box1.xmin - distance > box2.xmax
921  transform_coord_x(bounds1[0], isr1, osr) - distance >
922  transform_coord_x(bounds2[2], isr2, osr) ||
923  // box1 is below box2: box1.ymax + distance < box2.ymin
924  transform_coord_y(bounds1[3], isr1, osr) + distance <
925  transform_coord_y(bounds2[1], isr2, osr) ||
926  // box1 is above box2: box1.ymin - distance > box1.ymax
927  transform_coord_y(bounds1[1], isr1, osr) - distance >
928  transform_coord_y(bounds2[3], isr2, osr)) {
929  return false;
930  }
931  return true;
932 }
DEVICE ALWAYS_INLINE double transform_coord_y(const double coord, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double transform_coord_x(const double coord, 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 box_overlaps_box ( double *  bounds1,
int64_t  bounds1_size,
double *  bounds2,
int64_t  bounds2_size 
)

Definition at line 854 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().

857  {
858  // TODO: tolerance
859  // TODO: mixed spatial references
860  if (bounds1[2] < bounds2[0] || // box1 is left of box2: box1.xmax < box2.xmin
861  bounds1[0] > bounds2[2] || // box1 is right of box2: box1.xmin > box2.xmax
862  bounds1[3] < bounds2[1] || // box1 is below box2: box1.ymax < box2.ymin
863  bounds1[1] > bounds2[3]) { // box1 is above box2: box1.ymin > box1.ymax
864  return false;
865  }
866  return true;
867 }

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

References centroid_add_segment(), compression_unit_size(), coord_x(), coord_y(), and i.

Referenced by centroid_add_ring(), and ST_Centroid_LineString().

1373  {
1374  auto l_num_coords = lsize / compression_unit_size(ic);
1375  double length = 0.0;
1376  double l0x = coord_x(l, 0, ic, isr, osr);
1377  double l0y = coord_y(l, 1, ic, isr, osr);
1378  double l2x = l0x;
1379  double l2y = l0y;
1380  for (int32_t i = 2; i < l_num_coords; i += 2) {
1381  double l1x = l2x;
1382  double l1y = l2y;
1383  l2x = coord_x(l, i, ic, isr, osr);
1384  l2y = coord_y(l, i + 1, ic, isr, osr);
1385  centroid_add_segment(l1x, l1y, l2x, l2y, &length, linestring_centroid_sum);
1386  }
1387  if (l_num_coords > 4 && closed) {
1388  // Also add the closing segment between the last and the first points
1389  centroid_add_segment(l2x, l2y, l0x, l0y, &length, linestring_centroid_sum);
1390  }
1391  *total_length += length;
1392  if (length == 0.0 && l_num_coords > 0) {
1393  *num_points += 1;
1394  point_centroid_sum[0] += l0x;
1395  point_centroid_sum[1] += l0y;
1396  }
1397  return true;
1398 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 1491 of file ExtensionFunctionsGeo.hpp.

References centroid_add_ring(), and compression_unit_size().

Referenced by ST_Centroid_MultiPolygon(), and ST_Centroid_Polygon().

1503  {
1504  if (poly_num_rings <= 0) {
1505  return false;
1506  }
1507 
1508  auto ring_coords = poly_coords;
1509 
1510  for (auto r = 0; r < poly_num_rings; r++) {
1511  auto ring_coords_size = poly_ring_sizes[r] * 2 * compression_unit_size(ic);
1512  // Shape - positive area, holes - negative areas
1513  double sign = (r == 0) ? 1.0 : -1.0;
1514  centroid_add_ring(ring_coords,
1515  ring_coords_size,
1516  ic,
1517  isr,
1518  osr,
1519  sign,
1520  total_area2,
1521  cg3,
1522  total_length,
1523  linestring_centroid_sum,
1524  num_points,
1525  point_centroid_sum);
1526  // Advance to the next ring.
1527  ring_coords += ring_coords_size;
1528  }
1529  return true;
1530 }
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 1448 of file ExtensionFunctionsGeo.hpp.

References centroid_add_linestring(), centroid_add_triangle(), compression_unit_size(), coord_x(), coord_y(), and i.

Referenced by centroid_add_polygon().

1459  {
1460  auto ring_num_coords = ringsize / compression_unit_size(ic);
1461 
1462  if (ring_num_coords < 6) {
1463  return false;
1464  }
1465 
1466  double x1 = coord_x(ring, 0, ic, isr, osr);
1467  double y1 = coord_y(ring, 1, ic, isr, osr);
1468  double x2 = coord_x(ring, 2, ic, isr, osr);
1469  double y2 = coord_y(ring, 3, ic, isr, osr);
1470  for (int32_t i = 4; i < ring_num_coords; i += 2) {
1471  double x3 = coord_x(ring, i, ic, isr, osr);
1472  double y3 = coord_y(ring, i + 1, ic, isr, osr);
1473  centroid_add_triangle(x1, y1, x2, y2, x3, y3, sign, total_area2, cg3);
1474  x2 = x3;
1475  y2 = y3;
1476  }
1477 
1479  ringsize,
1480  ic,
1481  isr,
1482  osr,
1483  true, // closed
1484  total_length,
1485  linestring_centroid_sum,
1486  num_points,
1487  point_centroid_sum);
1488  return true;
1489 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 1349 of file ExtensionFunctionsGeo.hpp.

References distance_point_point().

Referenced by centroid_add_linestring().

1354  {
1355  double ldist = distance_point_point(x1, y1, x2, y2);
1356  *length += ldist;
1357  double segment_midpoint_x = (x1 + x2) / 2.0;
1358  double segment_midpoint_y = (y1 + y2) / 2.0;
1359  linestring_centroid_sum[0] += ldist * segment_midpoint_x;
1360  linestring_centroid_sum[1] += ldist * segment_midpoint_y;
1361  return true;
1362 }
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 1430 of file ExtensionFunctionsGeo.hpp.

Referenced by centroid_add_ring().

1438  {
1439  double cx = x1 + x2 + x3;
1440  double cy = y1 + y2 + y3;
1441  double area2 = x1 * y2 - x2 * y1 + x3 * y1 - x1 * y3 + x2 * y3 - x3 * y2;
1442  cg3[0] += sign * area2 * cx;
1443  cg3[1] += sign * area2 * cy;
1444  *total_area2 += sign * area2;
1445  return true;
1446 }

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

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

144  {
145  const auto compressed_coords = reinterpret_cast<const int32_t*>(data);
146  return compressed_coords[index];
147 }

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

References box_contains_point(), compression_unit_size(), coord_x(), and coord_y().

3411  {
3412  if (mpoly_num_polys <= 0) {
3413  return false;
3414  }
3415 
3416  // TODO: mpoly_bounds could contain individual bounding boxes too:
3417  // first two points - box for the entire multipolygon, then a pair for each polygon
3418  if (mpoly_bounds) {
3419  if (!box_contains_point(mpoly_bounds,
3420  mpoly_bounds_size,
3421  coord_x(p, 0, ic2, isr2, osr),
3422  coord_y(p, 1, ic2, isr2, osr))) {
3423  return false;
3424  }
3425  }
3426 
3427  // Set specific poly pointers as we move through the coords/ringsizes/polyrings
3428  // arrays.
3429  auto next_poly_coords = mpoly_coords;
3430  auto next_poly_ring_sizes = mpoly_ring_sizes;
3431 
3432  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
3433  const auto poly_coords = next_poly_coords;
3434  const auto poly_ring_sizes = next_poly_ring_sizes;
3435  const auto poly_num_rings = mpoly_poly_sizes[poly];
3436  // Count number of coords in all of poly's rings, advance ring size pointer.
3437  int32_t poly_num_coords = 0;
3438  for (auto ring = 0; ring < poly_num_rings; ring++) {
3439  poly_num_coords += 2 * *next_poly_ring_sizes++;
3440  }
3441  const auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
3442  next_poly_coords += poly_coords_size;
3443  // TODO: pass individual bounding boxes for each polygon
3444  if (Contains_Polygon_Point_Impl<T, TEdgeBehavior>(poly_coords,
3445  poly_coords_size,
3446  poly_ring_sizes,
3447  poly_num_rings,
3448  nullptr,
3449  0,
3450  p,
3451  psize,
3452  ic1,
3453  isr1,
3454  ic2,
3455  isr2,
3456  osr)) {
3457  return true;
3458  }
3459  }
3460 
3461  return false;
3462 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 3181 of file ExtensionFunctionsGeo.hpp.

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

3193  {
3194  if (poly_bounds) {
3195  // TODO: codegen
3196  if (!box_contains_point(poly_bounds,
3197  poly_bounds_size,
3198  coord_x(p, 0, ic2, isr2, osr),
3199  coord_y(p, 1, ic2, isr2, osr))) {
3200  DEBUG_STMT(printf("Bounding box does not contain point, exiting.\n"));
3201  return false;
3202  }
3203  }
3204 
3205  auto get_x_coord = [=]() -> T {
3206  if constexpr (std::is_floating_point<T>::value) {
3207  return coord_x(p, 0, ic2, isr2, osr);
3208  } else {
3209  return compressed_coord(p, 0);
3210  }
3211  return T{}; // https://stackoverflow.com/a/64561686/2700898
3212  };
3213 
3214  auto get_y_coord = [=]() -> T {
3215  if constexpr (std::is_floating_point<T>::value) {
3216  return coord_y(p, 1, ic2, isr2, osr);
3217  } else {
3218  return compressed_coord(p, 1);
3219  }
3220  return T{}; // https://stackoverflow.com/a/64561686/2700898
3221  };
3222 
3223  const T px = get_x_coord();
3224  const T py = get_y_coord();
3225  DEBUG_STMT(printf("pt: %f, %f\n", (double)px, (double)py));
3226 
3227  const auto poly_num_coords = poly_coords_size / compression_unit_size(ic1);
3228  auto exterior_ring_num_coords =
3229  poly_num_rings > 0 ? poly_ring_sizes[0] * 2 : poly_num_coords;
3230 
3231  auto poly = poly_coords;
3232  if (point_in_polygon_winding_number<T, TEdgeBehavior>(
3233  poly, exterior_ring_num_coords, px, py, ic1, isr1, osr)) {
3234  // Inside exterior ring
3235  poly += exterior_ring_num_coords * compression_unit_size(ic1);
3236  // Check that none of the polygon's holes contain that point
3237  for (auto r = 1; r < poly_num_rings; r++) {
3238  const int64_t interior_ring_num_coords = poly_ring_sizes[r] * 2;
3239  if (point_in_polygon_winding_number<T, TEdgeBehavior>(
3240  poly, interior_ring_num_coords, px, py, ic1, isr1, osr)) {
3241  return false;
3242  }
3243  poly += interior_ring_num_coords * compression_unit_size(ic1);
3244  }
3245  return true;
3246  }
3247  return false;
3248 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)

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

References decompress_coord(), and transform_coord().

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

4211  {
4212  const double const1 = 0.017453292519943295769236907684886;
4213  const double const2 = 6372797.560856;
4214  const auto lat = decompress_coord(p, 1, ic, false);
4215  const double latdiff = meters / (const1 * const2);
4216  const double newlat =
4217  (lat < 0) ? lat + latdiff : lat - latdiff; // assumes a lat range of [-90, 90]
4218  double t1 = transform_coord(lat, isr, osr, false);
4219  double t2 = transform_coord(newlat, isr, osr, false);
4220  const double min_domain_y = transform_coord(min_lat, isr, osr, false);
4221  const double max_domain_y = transform_coord(max_lat, isr, osr, false);
4222  const double domain_diff = max_domain_y - min_domain_y;
4223  t1 = ((t1 - min_domain_y) / domain_diff) * static_cast<double>(img_height);
4224  t2 = ((t2 - min_domain_y) / domain_diff) * static_cast<double>(img_height);
4225 
4226  // TODO(croot): need to account for edge cases, such as getting close to the poles.
4227  const double sz = fabs(t1 - t2);
4228  return (sz < min_height ? min_height : sz);
4229 }
DEVICE ALWAYS_INLINE double transform_coord(const double coord, const int32_t isr, const int32_t osr, const bool x)
DEVICE ALWAYS_INLINE double decompress_coord(const int8_t *data, const int32_t index, const int32_t ic, const bool x)

+ Here is the call graph for this function:

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

References decompress_coord(), and transform_coord().

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

4180  {
4181  const double const1 = 0.017453292519943295769236907684886;
4182  const double const2 = 6372797.560856;
4183  const auto lon = decompress_coord(p, 0, ic, true);
4184  const auto lat = decompress_coord(p, 1, ic, false);
4185  double t1 = sinf(meters / (2.0 * const2));
4186  double t2 = cosf(const1 * lat);
4187  const double newlon = lon - (2.0 * asinf(t1 / t2)) / const1;
4188  t1 = transform_coord(lon, isr, osr, true);
4189  t2 = transform_coord(newlon, isr, osr, true);
4190  const double min_domain_x = transform_coord(min_lon, isr, osr, true);
4191  const double max_domain_x = transform_coord(max_lon, isr, osr, true);
4192  const double domain_diff = max_domain_x - min_domain_x;
4193  t1 = ((t1 - min_domain_x) / domain_diff) * static_cast<double>(img_width);
4194  t2 = ((t2 - min_domain_x) / domain_diff) * static_cast<double>(img_width);
4195 
4196  // TODO(croot): need to account for edge cases, such as getting close to the poles.
4197  const double sz = fabs(t1 - t2);
4198  return (sz < min_width ? min_width : sz);
4199 }
DEVICE ALWAYS_INLINE double transform_coord(const double coord, const int32_t isr, const int32_t osr, const bool x)
DEVICE ALWAYS_INLINE double decompress_coord(const int8_t *data, const int32_t index, const int32_t ic, const bool x)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE double coord_x ( const int8_t *  data,
const int32_t  index,
const int32_t  ic,
const int32_t  isr,
const int32_t  osr 
)

Definition at line 120 of file ExtensionFunctionsGeo.hpp.

References decompress_coord(), and transform_coord().

Referenced by area_ring(), centroid_add_linestring(), centroid_add_ring(), Contains_MultiPolygon_Point_Impl(), Contains_Polygon_Point_Impl(), distance_point_linestring(), distance_ring_linestring(), distance_ring_ring(), length_linestring(), linestring_intersects_line(), linestring_intersects_linestring(), max_distance_point_linestring(), point_dwithin_box(), point_in_polygon_winding_number(), polygon_contains_linestring(), polygon_contains_point(), ring_intersects_line(), ST_Centroid_MultiPolygon(), ST_Centroid_Point(), ST_Centroid_Polygon(), ST_Contains_Point_LineString(), ST_Contains_Point_Point(), ST_Distance_LineString_LineString(), ST_Distance_Point_LineString_Geodesic(), ST_Distance_Point_Point(), ST_Distance_Point_Point_Geodesic(), ST_Distance_Point_Point_Squared(), ST_Distance_Point_Polygon(), ST_Intersects_Point_LineString(), ST_X_Point(), ST_XMax(), and ST_XMin().

124  {
125  auto decompressed_coord_x = decompress_coord(data, index, ic, true);
126  auto decompressed_transformed_coord_x =
127  transform_coord(decompressed_coord_x, isr, osr, true);
128  return decompressed_transformed_coord_x;
129 }
DEVICE ALWAYS_INLINE double transform_coord(const double coord, const int32_t isr, const int32_t osr, const bool x)
DEVICE ALWAYS_INLINE double decompress_coord(const int8_t *data, const int32_t index, const int32_t ic, const bool x)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE double coord_y ( const int8_t *  data,
const int32_t  index,
const int32_t  ic,
const int32_t  isr,
const int32_t  osr 
)

Definition at line 132 of file ExtensionFunctionsGeo.hpp.

References decompress_coord(), and transform_coord().

Referenced by area_ring(), centroid_add_linestring(), centroid_add_ring(), Contains_MultiPolygon_Point_Impl(), Contains_Polygon_Point_Impl(), distance_point_linestring(), distance_ring_linestring(), distance_ring_ring(), length_linestring(), linestring_intersects_line(), linestring_intersects_linestring(), max_distance_point_linestring(), point_dwithin_box(), point_in_polygon_winding_number(), polygon_contains_linestring(), polygon_contains_point(), ring_intersects_line(), ST_Centroid_MultiPolygon(), ST_Centroid_Point(), ST_Centroid_Polygon(), ST_Contains_Point_LineString(), ST_Contains_Point_Point(), ST_Distance_LineString_LineString(), ST_Distance_Point_LineString_Geodesic(), ST_Distance_Point_Point(), ST_Distance_Point_Point_Geodesic(), ST_Distance_Point_Point_Squared(), ST_Distance_Point_Polygon(), ST_Intersects_Point_LineString(), ST_Y_Point(), ST_YMax(), and ST_YMin().

136  {
137  auto decompressed_coord_y = decompress_coord(data, index, ic, false);
138  auto decompressed_transformed_coord_y =
139  transform_coord(decompressed_coord_y, isr, osr, false);
140  return decompressed_transformed_coord_y;
141 }
DEVICE ALWAYS_INLINE double transform_coord(const double coord, const int32_t isr, const int32_t osr, const bool x)
DEVICE ALWAYS_INLINE double decompress_coord(const int8_t *data, const int32_t index, const int32_t ic, const bool x)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE ALWAYS_INLINE double decompress_coord ( const int8_t *  data,
const int32_t  index,
const int32_t  ic,
const bool  x 
)

Definition at line 54 of file ExtensionFunctionsGeo.hpp.

References compressed_coord(), COMPRESSION_GEOINT32, Geospatial::decompress_lattitude_coord_geoint32(), and Geospatial::decompress_longitude_coord_geoint32().

Referenced by convert_meters_to_pixel_height(), convert_meters_to_pixel_width(), coord_x(), coord_y(), is_point_in_view(), and is_point_size_in_view().

57  {
58  if (ic == COMPRESSION_GEOINT32) {
59  auto compressed_coords = reinterpret_cast<const int32_t*>(data);
60  auto compressed_coord = compressed_coords[index];
61  if (x) {
63  } else {
65  }
66  }
67  auto double_coords = reinterpret_cast<const double*>(data);
68  return double_coords[index];
69 }
DEVICE ALWAYS_INLINE int32_t compressed_coord(const int8_t *data, const int32_t index)
DEVICE double decompress_lattitude_coord_geoint32(const int32_t compressed)
DEVICE double decompress_longitude_coord_geoint32(const int32_t compressed)
#define COMPRESSION_GEOINT32

+ Here is the call graph for this function:

+ Here is the caller 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 367 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().

374  {
375  if (line_intersects_line(l11x, l11y, l12x, l12y, l21x, l21y, l22x, l22y)) {
376  return 0.0;
377  }
378  double dist12 = fmin(distance_point_line(l11x, l11y, l21x, l21y, l22x, l22y),
379  distance_point_line(l12x, l12y, l21x, l21y, l22x, l22y));
380  double dist21 = fmin(distance_point_line(l21x, l21y, l11x, l11y, l12x, l12y),
381  distance_point_line(l22x, l22y, l11x, l11y, l12x, l12y));
382  return fmin(dist12, dist21);
383 }
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 387 of file ExtensionFunctionsGeo.hpp.

References distance_point_line_squared(), and line_intersects_line().

394  {
395  if (line_intersects_line(l11x, l11y, l12x, l12y, l21x, l21y, l22x, l22y)) {
396  return 0.0;
397  }
398  double dist12 = fmin(distance_point_line_squared(l11x, l11y, l21x, l21y, l22x, l22y),
399  distance_point_line_squared(l12x, l12y, l21x, l21y, l22x, l22y));
400  double dist21 = fmin(distance_point_line_squared(l21x, l21y, l11x, l11y, l12x, l12y),
401  distance_point_line_squared(l22x, l22y, l11x, l11y, l12x, l12y));
402  return fmin(dist12, dist21);
403 }
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 176 of file ExtensionFunctionsGeo.hpp.

References distance_point_point(), and tol_zero().

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

181  {
182  double length = distance_point_point(l1x, l1y, l2x, l2y);
183  if (tol_zero(length)) {
184  return distance_point_point(px, py, l1x, l1y);
185  }
186 
187  // Find projection of point P onto the line segment AB:
188  // Line containing that segment: A + k * (B - A)
189  // Projection of point P onto the line touches it at
190  // k = dot(P-A,B-A) / length^2
191  // AB segment is represented by k = [0,1]
192  // Clamping k to [0,1] will give the shortest distance from P to AB segment
193  double dotprod = (px - l1x) * (l2x - l1x) + (py - l1y) * (l2y - l1y);
194  double k = dotprod / (length * length);
195  k = fmax(0.0, fmin(1.0, k));
196  double projx = l1x + k * (l2x - l1x);
197  double projy = l1y + k * (l2y - l1y);
198  return distance_point_point(px, py, projx, projy);
199 }
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 203 of file ExtensionFunctionsGeo.hpp.

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

Referenced by distance_line_line_squared().

208  {
209  double length = distance_point_point_squared(l1x, l1y, l2x, l2y);
210  if (tol_zero(length, TOLERANCE_DEFAULT_SQUARED)) {
211  return distance_point_point_squared(px, py, l1x, l1y);
212  }
213 
214  // Find projection of point P onto the line segment AB:
215  // Line containing that segment: A + k * (B - A)
216  // Projection of point P onto the line touches it at
217  // k = dot(P-A,B-A) / length^2
218  // AB segment is represented by k = [0,1]
219  // Clamping k to [0,1] will give the shortest distance from P to AB segment
220  double dotprod = (px - l1x) * (l2x - l1x) + (py - l1y) * (l2y - l1y);
221  double k = dotprod / (length * length);
222  k = fmax(0.0, fmin(1.0, k));
223  double projx = l1x + k * (l2x - l1x);
224  double projy = l1y + k * (l2y - l1y);
225  return distance_point_point_squared(px, py, projx, projy);
226 }
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 1742 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), coord_x(), coord_y(), distance_point_line(), and i.

Referenced by ST_Distance_Point_ClosedLineString(), and ST_Distance_Point_LineString().

1752  {
1753  double px = coord_x(p, 0, ic1, isr1, osr);
1754  double py = coord_y(p, 1, ic1, isr1, osr);
1755 
1756  auto l_num_coords = lsize / compression_unit_size(ic2);
1757 
1758  double l1x = coord_x(l, 0, ic2, isr2, osr);
1759  double l1y = coord_y(l, 1, ic2, isr2, osr);
1760  double l2x = coord_x(l, 2, ic2, isr2, osr);
1761  double l2y = coord_y(l, 3, ic2, isr2, osr);
1762 
1763  double dist = distance_point_line(px, py, l1x, l1y, l2x, l2y);
1764  for (int32_t i = 4; i < l_num_coords; i += 2) {
1765  l1x = l2x; // advance one point
1766  l1y = l2y;
1767  l2x = coord_x(l, i, ic2, isr2, osr);
1768  l2y = coord_y(l, i + 1, ic2, isr2, osr);
1769  double ldist = distance_point_line(px, py, l1x, l1y, l2x, l2y);
1770  if (dist > ldist) {
1771  dist = ldist;
1772  }
1773  if (dist <= threshold) {
1774  return dist;
1775  }
1776  }
1777  if (l_num_coords > 4 && check_closed) {
1778  // Also check distance to the closing edge between the first and the last points
1779  l1x = coord_x(l, 0, ic2, isr2, osr);
1780  l1y = coord_y(l, 1, ic2, isr2, osr);
1781  double ldist = distance_point_line(px, py, l1x, l1y, l2x, l2y);
1782  if (dist > ldist) {
1783  dist = ldist;
1784  }
1785  }
1786  return dist;
1787 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 166 of file ExtensionFunctionsGeo.hpp.

References distance_point_point_squared().

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

169  {
170  auto d2 = distance_point_point_squared(p1x, p1y, p2x, p2y);
171  return sqrt(d2);
172 }
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 150 of file ExtensionFunctionsGeo.hpp.

References tol_zero(), and TOLERANCE_DEFAULT_SQUARED.

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

153  {
154  auto x = p1x - p2x;
155  auto y = p1y - p2y;
156  auto x2 = x * x;
157  auto y2 = y * y;
158  auto d2 = x2 + y2;
160  return 0.0;
161  }
162  return d2;
163 }
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
#define TOLERANCE_DEFAULT_SQUARED

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 406 of file ExtensionFunctionsGeo.hpp.

References coord_x(), coord_y(), distance_line_line(), i, and tol_zero().

Referenced by ST_Distance_LineString_Polygon().

415  {
416  double min_distance = 0.0;
417 
418  double re1x = coord_x(ring, ring_num_coords - 2, ic1, isr1, osr);
419  double re1y = coord_y(ring, ring_num_coords - 1, ic1, isr1, osr);
420  for (auto i = 0; i < ring_num_coords; i += 2) {
421  double re2x = coord_x(ring, i, ic1, isr1, osr);
422  double re2y = coord_y(ring, i + 1, ic1, isr1, osr);
423 
424  double le1x = coord_x(l, 0, ic2, isr2, osr);
425  double le1y = coord_y(l, 1, ic2, isr2, osr);
426  for (auto j = 2; j < lnum_coords; j += 2) {
427  double le2x = coord_x(l, j, ic2, isr2, osr);
428  double le2y = coord_y(l, j + 1, ic2, isr2, osr);
429 
430  auto distance = distance_line_line(re1x, re1y, re2x, re2y, le1x, le1y, le2x, le2y);
431  if ((i == 0 && j == 2) || min_distance > distance) {
432  min_distance = distance;
433  if (tol_zero(min_distance)) {
434  return 0.0;
435  }
436  if (min_distance <= threshold) {
437  return min_distance;
438  }
439  }
440  le1x = le2x;
441  le1y = le2y;
442  }
443  re1x = re2x;
444  re1y = re2y;
445  }
446 
447  return min_distance;
448 }
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t 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)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 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 451 of file ExtensionFunctionsGeo.hpp.

References coord_x(), coord_y(), distance_line_line(), i, and tol_zero().

Referenced by ST_Distance_Polygon_Polygon().

460  {
461  double min_distance = 0.0;
462 
463  double e11x = coord_x(ring1, ring1_num_coords - 2, ic1, isr1, osr);
464  double e11y = coord_y(ring1, ring1_num_coords - 1, ic1, isr1, osr);
465  for (auto i = 0; i < ring1_num_coords; i += 2) {
466  double e12x = coord_x(ring1, i, ic1, isr1, osr);
467  double e12y = coord_y(ring1, i + 1, ic1, isr1, osr);
468 
469  double e21x = coord_x(ring2, ring2_num_coords - 2, ic2, isr2, osr);
470  double e21y = coord_y(ring2, ring2_num_coords - 1, ic2, isr2, osr);
471  for (auto j = 0; j < ring2_num_coords; j += 2) {
472  double e22x = coord_x(ring2, j, ic2, isr2, osr);
473  double e22y = coord_y(ring2, j + 1, ic2, isr2, osr);
474 
475  auto distance = distance_line_line(e11x, e11y, e12x, e12y, e21x, e21y, e22x, e22y);
476  if ((i == 0 && j == 0) || min_distance > distance) {
477  min_distance = distance;
478  if (tol_zero(min_distance)) {
479  return 0.0;
480  }
481  if (min_distance <= threshold) {
482  return min_distance;
483  }
484  }
485  e21x = e22x;
486  e21y = e22y;
487  }
488  e11x = e12x;
489  e11y = e12y;
490  }
491 
492  return min_distance;
493 }
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t 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)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 >
DEVICE ALWAYS_INLINE T is_left ( const lx0,
const ly0,
const lx1,
const ly1,
const px,
const py 
)

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

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

Definition at line 501 of file ExtensionFunctionsGeo.hpp.

Referenced by point_in_polygon_winding_number().

501  {
502  return ((lx1 - lx0) * (py - ly0) - (px - lx0) * (ly1 - ly0));
503 }

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

References decompress_coord().

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

4237  {
4238  const auto lon = decompress_coord(p, 0, ic, true);
4239  const auto lat = decompress_coord(p, 1, ic, false);
4240  return !(lon < min_lon || lon > max_lon || lat < min_lat || lat > max_lat);
4241 }
DEVICE ALWAYS_INLINE double decompress_coord(const int8_t *data, const int32_t index, const int32_t ic, const bool x)

+ Here is the call graph for this function:

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

References decompress_coord().

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

4250  {
4251  const double const1 = 0.017453292519943295769236907684886;
4252  const double const2 = 6372797.560856;
4253  const auto lon = decompress_coord(p, 0, ic, true);
4254  const auto lat = decompress_coord(p, 1, ic, false);
4255  const double latdiff = meters / (const1 * const2);
4256  const double t1 = sinf(meters / (2.0 * const2));
4257  const double t2 = cosf(const1 * lat);
4258  const double londiff = (2.0 * asinf(t1 / t2)) / const1;
4259  return !(lon + londiff < min_lon || lon - londiff > max_lon ||
4260  lat + latdiff < min_lat || lat - latdiff > max_lat);
4261 }
DEVICE ALWAYS_INLINE double decompress_coord(const int8_t *data, const int32_t index, const int32_t ic, const bool x)

+ Here is the call graph for this function:

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

References compression_unit_size(), coord_x(), coord_y(), distance_in_meters(), distance_point_point(), and i.

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

1026  {
1027  auto l_num_coords = lsize / compression_unit_size(ic);
1028 
1029  double length = 0.0;
1030 
1031  double l0x = coord_x(l, 0, ic, isr, osr);
1032  double l0y = coord_y(l, 1, ic, isr, osr);
1033  double l2x = l0x;
1034  double l2y = l0y;
1035  for (int32_t i = 2; i < l_num_coords; i += 2) {
1036  double l1x = l2x;
1037  double l1y = l2y;
1038  l2x = coord_x(l, i, ic, isr, osr);
1039  l2y = coord_y(l, i + 1, ic, isr, osr);
1040  double ldist = geodesic ? distance_in_meters(l1x, l1y, l2x, l2y)
1041  : distance_point_point(l1x, l1y, l2x, l2y);
1042  length += ldist;
1043  }
1044  if (check_closed) {
1045  double ldist = geodesic ? distance_in_meters(l2x, l2y, l0x, l0y)
1046  : distance_point_point(l2x, l2y, l0x, l0y);
1047  length += ldist;
1048  }
1049  return length;
1050 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 254 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().

261  {
262  auto o1 = orientation(l11x, l11y, l12x, l12y, l21x, l21y);
263  auto o2 = orientation(l11x, l11y, l12x, l12y, l22x, l22y);
264  auto o3 = orientation(l21x, l21y, l22x, l22y, l11x, l11y);
265  auto o4 = orientation(l21x, l21y, l22x, l22y, l12x, l12y);
266 
267  // General case
268  if (o1 != o2 && o3 != o4) {
269  return true;
270  }
271 
272  // Special Cases
273  // l11, l12 and l21 are colinear and l21 lies on segment l11-l12
274  if (o1 == 0 && on_segment(l11x, l11y, l21x, l21y, l12x, l12y)) {
275  return true;
276  }
277 
278  // l11, l12 and l21 are colinear and l22 lies on segment l11-l12
279  if (o2 == 0 && on_segment(l11x, l11y, l22x, l22y, l12x, l12y)) {
280  return true;
281  }
282 
283  // l21, l22 and l11 are colinear and l11 lies on segment l21-l22
284  if (o3 == 0 && on_segment(l21x, l21y, l11x, l11y, l22x, l22y)) {
285  return true;
286  }
287 
288  // l21, l22 and l12 are colinear and l12 lies on segment l21-l22
289  if (o4 == 0 && on_segment(l21x, l21y, l12x, l12y, l22x, l22y)) {
290  return true;
291  }
292 
293  return false;
294 }
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 297 of file ExtensionFunctionsGeo.hpp.

References coord_x(), coord_y(), i, and line_intersects_line().

Referenced by ring_intersects_line().

305  {
306  double e1x = coord_x(l, 0, ic1, isr1, osr);
307  double e1y = coord_y(l, 1, ic1, isr1, osr);
308  for (int64_t i = 2; i < lnum_coords; i += 2) {
309  double e2x = coord_x(l, i, ic1, isr1, osr);
310  double e2y = coord_y(l, i + 1, ic1, isr1, osr);
311  if (line_intersects_line(e1x, e1y, e2x, e2y, l1x, l1y, l2x, l2y)) {
312  return true;
313  }
314  e1x = e2x;
315  e1y = e2y;
316  }
317  return false;
318 }
DEVICE bool line_intersects_line(double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 342 of file ExtensionFunctionsGeo.hpp.

References coord_x(), coord_y(), i, and line_intersects_line().

350  {
351  double e1x = coord_x(l, 0, ic1, isr1, osr);
352  double e1y = coord_y(l, 1, ic1, isr1, osr);
353  for (int64_t i = 2; i < lnum_coords; i += 2) {
354  double e2x = coord_x(l, i, ic1, isr1, osr);
355  double e2y = coord_y(l, i + 1, ic1, isr1, osr);
356  if (line_intersects_line(e1x, e1y, e2x, e2y, l1x, l1y, l2x, l2y)) {
357  return true;
358  }
359  e1x = e2x;
360  e1y = e2y;
361  }
362  return false;
363 }
DEVICE bool line_intersects_line(double l11x, double l11y, double l12x, double l12y, double l21x, double l21y, double l22x, double l22y)
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

EXTENSION_INLINE int64_t MapD_GeoPolyBoundsPtr ( double *  bounds,
int64_t  size 
)

Definition at line 4161 of file ExtensionFunctionsGeo.hpp.

References OmniSci_Geo_PolyBoundsPtr().

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

4161  {
4162  return OmniSci_Geo_PolyBoundsPtr(bounds, size);
4163 }
EXTENSION_INLINE int64_t OmniSci_Geo_PolyBoundsPtr(double *bounds, int64_t size)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE int32_t MapD_GeoPolyRenderGroup ( int32_t  render_group)

Definition at line 4166 of file ExtensionFunctionsGeo.hpp.

References OmniSci_Geo_PolyRenderGroup().

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

4166  {
4167  return OmniSci_Geo_PolyRenderGroup(render_group);
4168 }
EXTENSION_INLINE int32_t OmniSci_Geo_PolyRenderGroup(int32_t render_group)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2966 of file ExtensionFunctionsGeo.hpp.

References distance_point_point().

Referenced by max_distance_point_linestring().

2971  {
2972  // TODO: switch to squared distances
2973  double length1 = distance_point_point(px, py, l1x, l1y);
2974  double length2 = distance_point_point(px, py, l2x, l2y);
2975  if (length1 > length2) {
2976  return length1;
2977  }
2978  return length2;
2979 }
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 2981 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), coord_x(), coord_y(), i, and max_distance_point_line().

Referenced by ST_MaxDistance_LineString_Point(), and ST_MaxDistance_Point_LineString().

2990  {
2991  // TODO: switch to squared distances
2992  double px = coord_x(p, 0, ic1, isr1, osr);
2993  double py = coord_y(p, 1, ic1, isr1, osr);
2994 
2995  auto l_num_coords = lsize / compression_unit_size(ic2);
2996 
2997  double l1x = coord_x(l, 0, ic2, isr2, osr);
2998  double l1y = coord_y(l, 1, ic2, isr2, osr);
2999  double l2x = coord_x(l, 2, ic2, isr2, osr);
3000  double l2y = coord_y(l, 3, ic2, isr2, osr);
3001 
3002  double max_dist = max_distance_point_line(px, py, l1x, l1y, l2x, l2y);
3003  for (int32_t i = 4; i < l_num_coords; i += 2) {
3004  l1x = l2x; // advance one point
3005  l1y = l2y;
3006  l2x = coord_x(l, i, ic2, isr2, osr);
3007  l2y = coord_y(l, i + 1, ic2, isr2, osr);
3008  double ldist = max_distance_point_line(px, py, l1x, l1y, l2x, l2y);
3009  if (max_dist < ldist) {
3010  max_dist = ldist;
3011  }
3012  }
3013  if (l_num_coords > 4 && check_closed) {
3014  // Also check distance to the closing edge between the first and the last points
3015  l1x = coord_x(l, 0, ic2, isr2, osr);
3016  l1y = coord_y(l, 1, ic2, isr2, osr);
3017  double ldist = max_distance_point_line(px, py, l1x, l1y, l2x, l2y);
3018  if (max_dist < ldist) {
3019  max_dist = ldist;
3020  }
3021  }
3022  return max_dist;
3023 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE int64_t OmniSci_Geo_PolyBoundsPtr ( double *  bounds,
int64_t  size 
)

Definition at line 4151 of file ExtensionFunctionsGeo.hpp.

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

4151  {
4152  return reinterpret_cast<int64_t>(bounds);
4153 }

+ Here is the caller graph for this function:

EXTENSION_INLINE int32_t OmniSci_Geo_PolyRenderGroup ( int32_t  render_group)

Definition at line 4156 of file ExtensionFunctionsGeo.hpp.

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

4156  {
4157  return render_group;
4158 }

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

References tol_ge(), and tol_le().

Referenced by line_intersects_line().

235  {
236  return (tol_le(qx, fmax(px, rx)) && tol_ge(qx, fmin(px, rx)) &&
237  tol_le(qy, fmax(py, ry)) && tol_ge(qy, fmin(py, ry)));
238 }
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 241 of file ExtensionFunctionsGeo.hpp.

References tol_zero().

Referenced by line_intersects_line().

241  {
242  auto val = ((qy - py) * (rx - qx) - (qx - px) * (ry - qy));
243  if (tol_zero(val)) {
244  return 0; // Points p, q and r are colinear
245  }
246  if (val > 0.0) {
247  return 1; // Clockwise point orientation
248  }
249  return 2; // Counterclockwise point orientation
250 }
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 1111 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and length_linestring().

Referenced by ST_Perimeter_MultiPolygon(), and ST_Perimeter_MultiPolygon_Geodesic().

1120  {
1121  if (mpoly_num_polys <= 0 || mpoly_num_rings <= 0) {
1122  return 0.0;
1123  }
1124 
1125  double perimeter = 0.0;
1126 
1127  auto mpoly_ring_sizes = reinterpret_cast<int32_t*>(mpoly_ring_sizes_in);
1128 
1129  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1130  auto next_poly_coords = mpoly_coords;
1131  auto next_poly_ring_sizes = mpoly_ring_sizes;
1132 
1133  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1134  auto poly_coords = next_poly_coords;
1135  auto poly_ring_sizes = next_poly_ring_sizes;
1136  auto poly_num_rings = reinterpret_cast<int32_t*>(mpoly_poly_sizes)[poly];
1137  // Count number of coords in all of poly's rings, advance ring size pointer.
1138  int32_t poly_num_coords = 0;
1139  for (auto ring = 0; ring < poly_num_rings; ring++) {
1140  poly_num_coords += 2 * *next_poly_ring_sizes++;
1141  }
1142  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1143  next_poly_coords += poly_coords_size;
1144 
1145  auto exterior_ring_num_coords = poly_ring_sizes[0] * 2;
1146  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic);
1147 
1148  perimeter += length_linestring(
1149  poly_coords, exterior_ring_coords_size, ic, isr, osr, geodesic, true);
1150  }
1151 
1152  return perimeter;
1153 }
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 869 of file ExtensionFunctionsGeo.hpp.

References coord_x(), coord_y(), transform_coord_x(), and transform_coord_y().

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

877  {
878  // TODO: tolerance
879 
880  // Point has to be uncompressed and transformed to output SR.
881  // Bounding box has to be transformed to output SR.
882  auto px = coord_x(p1, 0, ic1, isr1, osr);
883  auto py = coord_y(p1, 1, ic1, isr1, osr);
884  if (
885  // point is left of box2: px < box2.xmin - distance
886  px < transform_coord_x(bounds2[0], isr2, osr) - distance ||
887  // point is right of box2: px > box2.xmax + distance
888  px > transform_coord_x(bounds2[2], isr2, osr) + distance ||
889  // point is below box2: py < box2.ymin - distance
890  py < transform_coord_y(bounds2[1], isr2, osr) - distance ||
891  // point is above box2: py > box2.ymax + distance
892  py > transform_coord_y(bounds2[3], isr2, osr) + distance) {
893  return false;
894  }
895  return true;
896 }
DEVICE ALWAYS_INLINE double transform_coord_y(const double coord, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double transform_coord_x(const double coord, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

Definition at line 530 of file ExtensionFunctionsGeo.hpp.

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

536  {
537  int32_t wn = 0;
538 
539  constexpr bool include_point_on_edge =
540  TEdgeBehavior == EdgeBehavior::kIncludePointOnEdge;
541 
542  auto get_x_coord = [=](const auto data, const auto index) -> T {
543  if constexpr (std::is_floating_point<T>::value) {
544  return coord_x(data, index, ic1, isr1, osr);
545  } else {
546  return compressed_coord(data, index);
547  }
548  return T{}; // https://stackoverflow.com/a/64561686/2700898
549  };
550 
551  auto get_y_coord = [=](const auto data, const auto index) -> T {
552  if constexpr (std::is_floating_point<T>::value) {
553  return coord_y(data, index, ic1, isr1, osr);
554  } else {
555  return compressed_coord(data, index);
556  }
557  return T{}; // https://stackoverflow.com/a/64561686/2700898
558  };
559 
560  DEBUG_STMT(printf("Poly num coords: %d\n", poly_num_coords));
561  const int64_t num_edges = poly_num_coords / 2;
562 
563  int64_t e0_index = 0;
564  T e0x = get_x_coord(poly, e0_index * 2);
565  T e0y = get_y_coord(poly, (e0_index * 2) + 1);
566 
567  int64_t e1_index;
568  T e1x, e1y;
569 
570  for (int64_t edge = 1; edge <= num_edges; edge++) {
571  DEBUG_STMT(printf("Edge %ld\n", edge));
572  // build the edge
573  e1_index = edge % num_edges;
574  e1x = get_x_coord(poly, e1_index * 2);
575  e1y = get_y_coord(poly, (e1_index * 2) + 1);
576 
577  DEBUG_STMT(printf("edge 0: %ld : %f, %f\n", e0_index, (double)e0x, (double)e0y));
578  DEBUG_STMT(printf("edge 1: %ld : %f, %f\n", e1_index, (double)e1x, (double)e1y));
579 
580  auto get_epsilon = [=]() -> T {
581  if constexpr (std::is_floating_point<T>::value) {
582  const T edge_vec_magnitude =
583  (e1x - e0x) * (e1x - e0x) + (e1y - e0y) * (e1y - e0y);
584  return 0.003 * edge_vec_magnitude;
585  } else {
586  return T(0);
587  }
588  return T{}; // https://stackoverflow.com/a/64561686/2700898
589  };
590 
591  const T epsilon = get_epsilon();
592  DEBUG_STMT(printf("using epsilon value %e\n", (double)epsilon));
593 
594  if constexpr (include_point_on_edge) {
595  const T xp = (px - e1x) * (e0y - e1y) - (py - e1y) * (e0x - e1x);
596  const T pt_vec_magnitude = (px - e0x) * (px - e0x) + (py - e0y) * (py - e0y);
597  const T edge_vec_magnitude = (e1x - e0x) * (e1x - e0x) + (e1y - e0y) * (e1y - e0y);
598  if (tol_zero_template(xp, epsilon) && (pt_vec_magnitude <= edge_vec_magnitude)) {
599  DEBUG_STMT(printf("point is on edge: %e && %e <= %e\n",
600  (double)xp,
601  (double)pt_vec_magnitude,
602  (double)edge_vec_magnitude));
603  return include_point_on_edge;
604  }
605  }
606 
607  if (e0y <= py) {
608  if (e1y > py) {
609  // upward crossing
610  DEBUG_STMT(printf("upward crossing\n"));
611  const auto is_left_val = is_left(e0x, e0y, e1x, e1y, px, py);
612  DEBUG_STMT(printf("Left val %f and tol zero left val %d\n",
613  (double)is_left_val,
614  tol_zero_template(is_left_val, epsilon)));
615  if (UNLIKELY(tol_zero_template(is_left_val, epsilon))) {
616  // p is on the edge
617  return include_point_on_edge;
618  } else if (is_left_val > T(0)) { // p left of edge
619  // valid up intersection
620  DEBUG_STMT(printf("++wn\n"));
621  ++wn;
622  }
623  }
624  } else if (e1y <= py) {
625  // downward crossing
626  DEBUG_STMT(printf("downward crossing\n"));
627  const auto is_left_val = is_left(e0x, e0y, e1x, e1y, px, py);
628  DEBUG_STMT(printf("Left val %f and tol zero left val %d\n",
629  (double)is_left_val,
630  tol_zero_template(is_left_val, epsilon)));
631  if (UNLIKELY(tol_zero_template(is_left_val, epsilon))) {
632  // p is on the edge
633  return include_point_on_edge;
634  } else if (is_left_val < T(0)) { // p right of edge
635  // valid down intersection
636  DEBUG_STMT(printf("--wn\n"));
637  --wn;
638  }
639  }
640 
641  e0_index = e1_index;
642  e0x = e1x;
643  e0y = e1y;
644  }
645  DEBUG_STMT(printf("wn: %d\n", wn));
646  // wn == 0 --> P is outside the polygon
647  return !(wn == 0);
648 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 818 of file ExtensionFunctionsGeo.hpp.

References box_contains_point().

821  {
822  // TODO: mixed spatial references
823  return box_contains_point(bounds, bounds_size, px, py);
824 }
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 779 of file ExtensionFunctionsGeo.hpp.

References coord_x(), coord_y(), i, polygon_contains_point(), and ring_intersects_line().

Referenced by ST_Contains_Polygon_LineString().

787  {
788  // Check that the first point is in the polygon
789  double l1x = coord_x(l, 0, ic2, isr2, osr);
790  double l1y = coord_y(l, 1, ic2, isr2, osr);
791  if (!polygon_contains_point(poly, poly_num_coords, l1x, l1y, ic1, isr1, osr)) {
792  return false;
793  }
794 
795  // Go through line segments and check if there are no intersections with poly edges,
796  // i.e. linestring doesn't escape
797  for (int32_t i = 2; i < lnum_coords; i += 2) {
798  double l2x = coord_x(l, i, ic2, isr2, osr);
799  double l2y = coord_y(l, i + 1, ic2, isr2, osr);
800  if (ring_intersects_line(poly, poly_num_coords, l1x, l1y, l2x, l2y, ic1, isr1, osr)) {
801  return false;
802  }
803  l1x = l2x;
804  l1y = l2y;
805  }
806  return true;
807 }
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 double coord_y(const int8_t *data, const int32_t 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)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 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 664 of file ExtensionFunctionsGeo.hpp.

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

Referenced by polygon_contains_linestring(), and ST_Distance_Point_Polygon().

670  {
671  bool result = false;
672  int xray_touch = 0;
673  bool horizontal_edge = false;
674  bool yray_intersects = false;
675 
676  double e1x = coord_x(poly, poly_num_coords - 2, ic1, isr1, osr);
677  double e1y = coord_y(poly, poly_num_coords - 1, ic1, isr1, osr);
678  for (int64_t i = 0; i < poly_num_coords; i += 2) {
679  double e2x = coord_x(poly, i, ic1, isr1, osr);
680  double e2y = coord_y(poly, i + 1, ic1, isr1, osr);
681 
682  // Check if point sits on an edge.
683  if (tol_zero(distance_point_line(px, py, e1x, e1y, e2x, e2y))) {
684  return true;
685  }
686 
687  // Before flipping the switch, check if xray hit a horizontal edge
688  // - If an edge lays on the xray, one of the previous edges touched it
689  // so while moving horizontally we're in 'xray_touch' state
690  // - Last edge that touched xray at (e2x,e2y) didn't register intersection
691  // - Next edge that diverges from xray at (e1,e1y) will register intersection
692  // - Can have several horizontal edges, one after the other, keep moving though
693  // in 'xray_touch' state without flipping the switch
694  horizontal_edge = (xray_touch != 0) && tol_eq(py, e1y) && tol_eq(py, e2y);
695 
696  // Main probe: xray
697  // Overshoot the xray to detect an intersection if there is one.
698  double xray = fmax(e2x, e1x) + 1.0;
699  if (px <= xray && // Only check for intersection if the edge is on the right
700  !horizontal_edge && // Keep moving through horizontal edges
701  line_intersects_line(px, // xray shooting from point p to the right
702  py,
703  xray,
704  py,
705  e1x, // polygon edge
706  e1y,
707  e2x,
708  e2y)) {
709  // Register intersection
710  result = !result;
711 
712  // Adjust for special cases
713  if (xray_touch == 0) {
714  if (tol_zero(distance_point_line(e2x, e2y, px, py, xray + 1.0, py))) {
715  // Xray goes through the edge's second vertex, unregister intersection -
716  // that vertex will be crossed again when we look at the following edge(s)
717  result = !result;
718  // Enter the xray-touch state:
719  // (1) - xray was touched by the edge from above, (-1) from below
720  xray_touch = (e1y > py) ? 1 : -1;
721  }
722  } else {
723  // Previous edge touched the xray, intersection hasn't been registered,
724  // it has to be registered now if this edge continues across the xray.
725  if (xray_touch > 0) {
726  // Previous edge touched the xray from above
727  if (e2y <= py) {
728  // Current edge crosses under xray: intersection is already registered
729  } else {
730  // Current edge just touched the xray and pulled up: unregister intersection
731  result = !result;
732  }
733  } else {
734  // Previous edge touched the xray from below
735  if (e2y > py) {
736  // Current edge crosses over xray: intersection is already registered
737  } else {
738  // Current edge just touched the xray and pulled down: unregister intersection
739  result = !result;
740  }
741  }
742  // Exit the xray-touch state
743  xray_touch = 0;
744  }
745  }
746 
747  // Redundancy: vertical yray down
748  // Main probe xray may hit multiple complex fragments which increases a chance of
749  // error. Perform a simple secondary check for edge intersections to see if point is
750  // outside.
751  if (!yray_intersects) { // Continue checking on yray until intersection is found
752  double yray = fmin(e2y, e1y) - 1.0;
753  if (yray <= py) { // Only check for yray intersection if point P is above the edge
754  yray_intersects = line_intersects_line(px, // yray shooting from point P down
755  py,
756  px,
757  yray,
758  e1x, // polygon edge
759  e1y,
760  e2x,
761  e2y);
762  }
763  }
764 
765  // Advance to the next vertex
766  e1x = e2x;
767  e1y = e2y;
768  }
769  if (!yray_intersects) {
770  // yray has zero intersections - point is outside the polygon
771  return false;
772  }
773  // Otherwise rely on the main probe
774  return result;
775 }
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 double coord_y(const int8_t *data, const int32_t 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)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 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 321 of file ExtensionFunctionsGeo.hpp.

References coord_x(), coord_y(), line_intersects_line(), and linestring_intersects_line().

Referenced by polygon_contains_linestring().

329  {
330  double e1x = coord_x(ring, ring_num_coords - 2, ic1, isr1, osr);
331  double e1y = coord_y(ring, ring_num_coords - 1, ic1, isr1, osr);
332  double e2x = coord_x(ring, 0, ic1, isr1, osr);
333  double e2y = coord_y(ring, 1, ic1, isr1, osr);
334  if (line_intersects_line(e1x, e1y, e2x, e2y, l1x, l1y, l2x, l2y)) {
335  return true;
336  }
338  ring, ring_num_coords, l1x, l1y, l2x, l2y, ic1, isr1, osr);
339 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 1279 of file ExtensionFunctionsGeo.hpp.

References area_polygon(), and compression_unit_size().

1287  {
1288  if (mpoly_num_rings <= 0 || mpoly_num_polys <= 0) {
1289  return 0.0;
1290  }
1291 
1292  double area = 0.0;
1293 
1294  auto mpoly_poly_sizes = reinterpret_cast<int32_t*>(mpoly_poly_sizes_in);
1295 
1296  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1297  auto next_poly_coords = mpoly_coords;
1298  auto next_poly_ring_sizes = reinterpret_cast<int32_t*>(mpoly_ring_sizes);
1299 
1300  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1301  auto poly_coords = next_poly_coords;
1302  auto poly_ring_sizes = next_poly_ring_sizes;
1303  auto poly_num_rings = mpoly_poly_sizes[poly];
1304  // Count number of coords in all of poly's rings, advance ring size pointer.
1305  int32_t poly_num_coords = 0;
1306  for (auto ring = 0; ring < poly_num_rings; ring++) {
1307  poly_num_coords += 2 * *next_poly_ring_sizes++;
1308  }
1309  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1310  next_poly_coords += poly_coords_size;
1311 
1312  area += area_polygon(poly_coords,
1313  poly_coords_size,
1314  reinterpret_cast<int8_t*>(poly_ring_sizes),
1315  poly_num_rings,
1316  ic,
1317  isr,
1318  osr);
1319  }
1320  return area;
1321 }
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 1267 of file ExtensionFunctionsGeo.hpp.

References area_polygon().

1273  {
1274  return area_polygon(
1275  poly_coords, poly_coords_size, poly_ring_sizes, poly_num_rings, ic, isr, osr);
1276 }
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 3498 of file ExtensionFunctionsGeo.hpp.

3512  {
3513  return Contains_MultiPolygon_Point_Impl<int64_t, EdgeBehavior::kExcludePointOnEdge>(
3514  mpoly_coords,
3515  mpoly_coords_size,
3516  mpoly_ring_sizes,
3517  mpoly_num_rings,
3518  mpoly_poly_sizes,
3519  mpoly_num_polys,
3520  mpoly_bounds,
3521  mpoly_bounds_size,
3522  p,
3523  psize,
3524  ic1,
3525  isr1,
3526  ic2,
3527  isr2,
3528  osr);
3529 }
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 3279 of file ExtensionFunctionsGeo.hpp.

3291  {
3292  return Contains_Polygon_Point_Impl<int64_t, EdgeBehavior::kExcludePointOnEdge>(
3293  poly_coords,
3294  poly_coords_size,
3295  poly_ring_sizes,
3296  poly_num_rings,
3297  poly_bounds,
3298  poly_bounds_size,
3299  p,
3300  psize,
3301  ic1,
3302  isr1,
3303  ic2,
3304  isr2,
3305  osr);
3306 }
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 1401 of file ExtensionFunctionsGeo.hpp.

References centroid_add_linestring().

1406  {
1407  double length = 0.0;
1408  double linestring_centroid_sum[2] = {0.0, 0.0};
1409  int64_t num_points = 0;
1410  double point_centroid_sum[2] = {0.0, 0.0};
1411  centroid_add_linestring(coords,
1412  coords_sz,
1413  ic,
1414  isr,
1415  osr,
1416  false, // not closed
1417  &length,
1418  &linestring_centroid_sum[0],
1419  &num_points,
1420  &point_centroid_sum[0]);
1421  if (length > 0) {
1422  linestring_centroid[0] = linestring_centroid_sum[0] / length;
1423  linestring_centroid[1] = linestring_centroid_sum[1] / length;
1424  } else if (num_points > 0) {
1425  linestring_centroid[0] = point_centroid_sum[0] / num_points;
1426  linestring_centroid[1] = point_centroid_sum[1] / num_points;
1427  }
1428 }
DEVICE ALWAYS_INLINE bool centroid_add_linestring(int8_t *l, int64_t lsize, int32_t ic, int32_t isr, int32_t osr, bool closed, double *total_length, double *linestring_centroid_sum, int64_t *num_points, double *point_centroid_sum)

+ Here is the call graph for this function:

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

Definition at line 1583 of file ExtensionFunctionsGeo.hpp.

References centroid_add_polygon(), compression_unit_size(), coord_x(), and coord_y().

1592  {
1593  if (mpoly_num_rings <= 0 || mpoly_num_polys <= 0) {
1594  mpoly_centroid[0] = 0.0;
1595  mpoly_centroid[1] = 0.0;
1596  }
1597 
1598  double total_area2 = 0.0;
1599  double cg3[2] = {0.0, 0.0};
1600  double total_length = 0.0;
1601  double linestring_centroid_sum[2] = {0.0, 0.0};
1602  int64_t num_points = 0;
1603  double point_centroid_sum[2] = {0.0, 0.0};
1604 
1605  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1606  auto next_poly_coords = mpoly_coords;
1607  auto next_poly_ring_sizes = mpoly_ring_sizes;
1608 
1609  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1610  auto poly_coords = next_poly_coords;
1611  auto poly_ring_sizes = next_poly_ring_sizes;
1612  auto poly_num_rings = mpoly_poly_sizes[poly];
1613  // Count number of coords in all of poly's rings, advance ring size pointer.
1614  int32_t poly_num_coords = 0;
1615  for (auto ring = 0; ring < poly_num_rings; ring++) {
1616  poly_num_coords += 2 * *next_poly_ring_sizes++;
1617  }
1618  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1619  next_poly_coords += poly_coords_size;
1620 
1621  centroid_add_polygon(poly_coords,
1622  poly_coords_size,
1623  poly_ring_sizes,
1624  poly_num_rings,
1625  ic,
1626  isr,
1627  osr,
1628  &total_area2,
1629  &cg3[0],
1630  &total_length,
1631  &linestring_centroid_sum[0],
1632  &num_points,
1633  &point_centroid_sum[0]);
1634  }
1635 
1636  if (total_area2 != 0.0) {
1637  mpoly_centroid[0] = cg3[0] / 3 / total_area2;
1638  mpoly_centroid[1] = cg3[1] / 3 / total_area2;
1639  } else if (total_length > 0.0) {
1640  // zero-area multipolygon, fall back to linear centroid
1641  mpoly_centroid[0] = linestring_centroid_sum[0] / total_length;
1642  mpoly_centroid[1] = linestring_centroid_sum[1] / total_length;
1643  } else if (num_points > 0) {
1644  // zero-area zero-length multipolygon, fall further back to point centroid
1645  mpoly_centroid[0] = point_centroid_sum[0] / num_points;
1646  mpoly_centroid[1] = point_centroid_sum[1] / num_points;
1647  } else {
1648  mpoly_centroid[0] = coord_x(mpoly_coords, 0, ic, isr, osr);
1649  mpoly_centroid[1] = coord_y(mpoly_coords, 1, ic, isr, osr);
1650  }
1651 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 1339 of file ExtensionFunctionsGeo.hpp.

References coord_x(), and coord_y().

1344  {
1345  point_centroid[0] = coord_y(p, 0, ic, isr, osr);
1346  point_centroid[1] = coord_x(p, 1, ic, isr, osr);
1347 }
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 1533 of file ExtensionFunctionsGeo.hpp.

References centroid_add_polygon(), coord_x(), and coord_y().

1540  {
1541  if (poly_num_rings <= 0) {
1542  poly_centroid[0] = 0.0;
1543  poly_centroid[1] = 0.0;
1544  }
1545  double total_area2 = 0.0;
1546  double cg3[2] = {0.0, 0.0};
1547  double total_length = 0.0;
1548  double linestring_centroid_sum[2] = {0.0, 0.0};
1549  int64_t num_points = 0;
1550  double point_centroid_sum[2] = {0.0, 0.0};
1551  centroid_add_polygon(poly_coords,
1552  poly_coords_size,
1553  poly_ring_sizes,
1554  poly_num_rings,
1555  ic,
1556  isr,
1557  osr,
1558  &total_area2,
1559  &cg3[0],
1560  &total_length,
1561  &linestring_centroid_sum[0],
1562  &num_points,
1563  &point_centroid_sum[0]);
1564 
1565  if (total_area2 != 0.0) {
1566  poly_centroid[0] = cg3[0] / 3 / total_area2;
1567  poly_centroid[1] = cg3[1] / 3 / total_area2;
1568  } else if (total_length > 0.0) {
1569  // zero-area polygon, fall back to linear centroid
1570  poly_centroid[0] = linestring_centroid_sum[0] / total_length;
1571  poly_centroid[1] = linestring_centroid_sum[1] / total_length;
1572  } else if (num_points > 0) {
1573  // zero-area zero-length polygon, fall further back to point centroid
1574  poly_centroid[0] = point_centroid_sum[0] / num_points;
1575  poly_centroid[1] = point_centroid_sum[1] / num_points;
1576  } else {
1577  poly_centroid[0] = coord_x(poly_coords, 0, ic, isr, osr);
1578  poly_centroid[1] = coord_y(poly_coords, 1, ic, isr, osr);
1579  }
1580 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

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

Definition at line 3145 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString(), and tol_zero().

3155  {
3156  return tol_zero(
3157  ST_Distance_Point_LineString(p, psize, l, lsize, ic2, isr2, ic1, isr1, osr, 0.0));
3158 }
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 3161 of file ExtensionFunctionsGeo.hpp.

3175  {
3176  // TODO
3177  return false;
3178 }
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 3532 of file ExtensionFunctionsGeo.hpp.

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

3548  {
3549  if (mpoly_num_polys <= 0) {
3550  return false;
3551  }
3552 
3553  if (mpoly_bounds && lbounds) {
3554  if (!box_contains_box(mpoly_bounds, mpoly_bounds_size, lbounds, lbounds_size)) {
3555  return false;
3556  }
3557  }
3558 
3559  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
3560  auto next_poly_coords = mpoly_coords;
3561  auto next_poly_ring_sizes = mpoly_ring_sizes;
3562 
3563  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
3564  auto poly_coords = next_poly_coords;
3565  auto poly_ring_sizes = next_poly_ring_sizes;
3566  auto poly_num_rings = mpoly_poly_sizes[poly];
3567  // Count number of coords in all of poly's rings, advance ring size pointer.
3568  int32_t poly_num_coords = 0;
3569  for (auto ring = 0; ring < poly_num_rings; ring++) {
3570  poly_num_coords += 2 * *next_poly_ring_sizes++;
3571  }
3572  auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
3573  next_poly_coords += poly_coords_size;
3574 
3575  if (ST_Contains_Polygon_LineString(poly_coords,
3576  poly_coords_size,
3577  poly_ring_sizes,
3578  poly_num_rings,
3579  nullptr,
3580  0,
3581  l,
3582  lsize,
3583  nullptr,
3584  0,
3585  ic1,
3586  isr1,
3587  ic2,
3588  isr2,
3589  osr)) {
3590  return true;
3591  }
3592  }
3593 
3594  return false;
3595 }
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 3465 of file ExtensionFunctionsGeo.hpp.

Referenced by ST_Intersects_Point_MultiPolygon().

3479  {
3480  return Contains_MultiPolygon_Point_Impl<double, EdgeBehavior::kExcludePointOnEdge>(
3481  mpoly_coords,
3482  mpoly_coords_size,
3483  mpoly_ring_sizes,
3484  mpoly_num_rings,
3485  mpoly_poly_sizes,
3486  mpoly_num_polys,
3487  mpoly_bounds,
3488  mpoly_bounds_size,
3489  p,
3490  psize,
3491  ic1,
3492  isr1,
3493  ic2,
3494  isr2,
3495  osr);
3496 }

+ Here is the caller graph for this function:

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

Definition at line 3078 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), coord_x(), coord_y(), i, and tol_eq().

Referenced by ST_Contains_Point_Polygon().

3088  {
3089  double px = coord_x(p, 0, ic1, isr1, osr);
3090  double py = coord_y(p, 1, ic1, isr1, osr);
3091 
3092  if (lbounds) {
3093  if (tol_eq(px, lbounds[0]) && tol_eq(py, lbounds[1]) && tol_eq(px, lbounds[2]) &&
3094  tol_eq(py, lbounds[3])) {
3095  return true;
3096  }
3097  }
3098 
3099  auto l_num_coords = lsize / compression_unit_size(ic2);
3100  for (int i = 0; i < l_num_coords; i += 2) {
3101  double lx = coord_x(l, i, ic2, isr2, osr);
3102  double ly = coord_y(l, i + 1, ic2, isr2, osr);
3103  if (tol_eq(px, lx) && tol_eq(py, ly)) {
3104  continue;
3105  }
3106  return false;
3107  }
3108  return true;
3109 }
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t 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)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 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 3060 of file ExtensionFunctionsGeo.hpp.

References coord_x(), coord_y(), tol(), and tol_eq().

3068  {
3069  double p1x = coord_x(p1, 0, ic1, isr1, osr);
3070  double p1y = coord_y(p1, 1, ic1, isr1, osr);
3071  double p2x = coord_x(p2, 0, ic2, isr2, osr);
3072  double p2y = coord_y(p2, 1, ic2, isr2, osr);
3073  double tolerance = tol(ic1, ic2);
3074  return tol_eq(p1x, p2x, tolerance) && tol_eq(p1y, p2y, tolerance);
3075 }
DEVICE ALWAYS_INLINE double tol(int32_t ic)
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t 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)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)

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

References compression_unit_size(), and ST_Contains_Point_LineString().

3124  {
3125  auto exterior_ring_num_coords = poly_coords_size / compression_unit_size(ic2);
3126  if (poly_num_rings > 0) {
3127  exterior_ring_num_coords = poly_ring_sizes[0] * 2;
3128  }
3129  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic2);
3130 
3132  psize,
3133  poly_coords,
3134  exterior_ring_coords_size,
3135  poly_bounds,
3136  poly_bounds_size,
3137  ic1,
3138  isr1,
3139  ic2,
3140  isr2,
3141  osr);
3142 }
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 3309 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().

3323  {
3324  if (poly_num_rings > 1) {
3325  return false; // TODO: support polygons with interior rings
3326  }
3327 
3328  // Bail out if poly bounding box doesn't contain linestring bounding box
3329  if (poly_bounds && lbounds) {
3330  if (!box_contains_box(poly_bounds, poly_bounds_size, lbounds, lbounds_size)) {
3331  return false;
3332  }
3333  }
3334 
3335  const auto poly_num_coords = poly_coords_size / compression_unit_size(ic1);
3336  const auto lnum_coords = lsize / compression_unit_size(ic2);
3337 
3339  poly_coords, poly_num_coords, l, lnum_coords, ic1, isr1, ic2, isr2, osr);
3340 }
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 3250 of file ExtensionFunctionsGeo.hpp.

3262  {
3263  return Contains_Polygon_Point_Impl<double, EdgeBehavior::kExcludePointOnEdge>(
3264  poly_coords,
3265  poly_coords_size,
3266  poly_ring_sizes,
3267  poly_num_rings,
3268  poly_bounds,
3269  poly_bounds_size,
3270  p,
3271  psize,
3272  ic1,
3273  isr1,
3274  ic2,
3275  isr2,
3276  osr);
3277 }
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 3343 of file ExtensionFunctionsGeo.hpp.

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

3359  {
3360  // TODO: needs to be extended, cover more cases
3361  // Right now only checking if simple poly1 (no holes) contains poly2's exterior shape
3362  if (poly1_num_rings > 1) {
3363  return false; // TODO: support polygons with interior rings
3364  }
3365 
3366  if (poly1_bounds && poly2_bounds) {
3367  if (!box_contains_box(
3368  poly1_bounds, poly1_bounds_size, poly2_bounds, poly2_bounds_size)) {
3369  return false;
3370  }
3371  }
3372 
3373  int64_t poly2_exterior_ring_coords_size = poly2_coords_size;
3374  if (poly2_num_rings > 0) {
3375  poly2_exterior_ring_coords_size =
3376  2 * poly2_ring_sizes[0] * compression_unit_size(ic2);
3377  }
3378  return ST_Contains_Polygon_LineString(poly1_coords,
3379  poly1_coords_size,
3380  poly1_ring_sizes,
3381  poly1_num_rings,
3382  poly1_bounds,
3383  poly1_bounds_size,
3384  poly2_coords,
3385  poly2_exterior_ring_coords_size,
3386  poly2_bounds,
3387  poly2_bounds_size,
3388  ic1,
3389  isr1,
3390  ic2,
3391  isr2,
3392  osr);
3393 }
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 1949 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), coord_x(), coord_y(), distance_line_line(), tol_zero(), and TOLERANCE_DEFAULT_SQUARED.

Referenced by ST_DWithin_LineString_LineString(), and ST_Intersects_LineString_Linestring().

1958  {
1959  auto l1_num_coords = l1size / compression_unit_size(ic1);
1960  auto l2_num_coords = l2size / compression_unit_size(ic2);
1961 
1962  double threshold_squared = threshold * threshold;
1963  double dist_squared = 0.0;
1964  double l11x = coord_x(l1, 0, ic1, isr1, osr);
1965  double l11y = coord_y(l1, 1, ic1, isr1, osr);
1966  for (int32_t i1 = 2; i1 < l1_num_coords; i1 += 2) {
1967  double l12x = coord_x(l1, i1, ic1, isr1, osr);
1968  double l12y = coord_y(l1, i1 + 1, ic1, isr1, osr);
1969 
1970  double l21x = coord_x(l2, 0, ic2, isr2, osr);
1971  double l21y = coord_y(l2, 1, ic2, isr2, osr);
1972  for (int32_t i2 = 2; i2 < l2_num_coords; i2 += 2) {
1973  double l22x = coord_x(l2, i2, ic2, isr2, osr);
1974  double l22y = coord_y(l2, i2 + 1, ic2, isr2, osr);
1975 
1976  // double ldist_squared =
1977  // distance_line_line_squared(l11x, l11y, l12x, l12y, l21x, l21y, l22x, l22y);
1978  // TODO: fix distance_line_line_squared
1979  double ldist = distance_line_line(l11x, l11y, l12x, l12y, l21x, l21y, l22x, l22y);
1980  double ldist_squared = ldist * ldist;
1981 
1982  if (i1 == 2 && i2 == 2) {
1983  dist_squared = ldist_squared; // initialize dist with distance between the first
1984  // two segments
1985  } else if (dist_squared > ldist_squared) {
1986  dist_squared = ldist_squared;
1987  }
1988  if (tol_zero(dist_squared, TOLERANCE_DEFAULT_SQUARED)) {
1989  return 0.0; // Segments touch, short-circuit
1990  }
1991  if (dist_squared <= threshold_squared) {
1992  // If threashold_squared is defined and the calculated dist_squared dips under it,
1993  // short-circuit and return it
1994  return sqrt(dist_squared);
1995  }
1996 
1997  l21x = l22x; // advance to the next point on l2
1998  l21y = l22y;
1999  }
2000 
2001  l11x = l12x; // advance to the next point on l1
2002  l11y = l12y;
2003  }
2004  return sqrt(dist_squared);
2005 }
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)
#define TOLERANCE_DEFAULT_SQUARED
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t 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)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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_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 2077 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().

2090  {
2091  // TODO: revisit implementation, cover all cases
2092  double min_distance = 0.0;
2093 
2094  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
2095  auto next_poly_coords = mpoly_coords;
2096  auto next_poly_ring_sizes = mpoly_ring_sizes;
2097 
2098  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
2099  auto poly_coords = next_poly_coords;
2100  auto poly_ring_sizes = next_poly_ring_sizes;
2101  auto poly_num_rings = mpoly_poly_sizes[poly];
2102  // Count number of coords in all of poly's rings, advance ring size pointer.
2103  int32_t poly_num_coords = 0;
2104  for (auto ring = 0; ring < poly_num_rings; ring++) {
2105  poly_num_coords += 2 * *next_poly_ring_sizes++;
2106  }
2107  auto poly_coords_size = poly_num_coords * compression_unit_size(ic2);
2108  next_poly_coords += poly_coords_size;
2109  double distance = ST_Distance_LineString_Polygon(l,
2110  lsize,
2111  poly_coords,
2112  poly_coords_size,
2113  poly_ring_sizes,
2114  poly_num_rings,
2115  ic1,
2116  isr1,
2117  ic2,
2118  isr2,
2119  osr,
2120  threshold);
2121  if (poly == 0 || min_distance > distance) {
2122  min_distance = distance;
2123  if (tol_zero(min_distance)) {
2124  min_distance = 0.0;
2125  break;
2126  }
2127  if (min_distance <= threshold) {
2128  return min_distance;
2129  }
2130  }
2131  }
2132 
2133  return min_distance;
2134 }
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 1934 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString().

1943  {
1945  p, psize, l, lsize, ic2, isr2, ic1, isr1, osr, threshold);
1946 }
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 1728 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString_Geodesic().

1736  {
1737  // Currently only statically indexed LineString is supported
1739  p, psize, l, lsize, ic2, isr2, ic1, isr1, osr);
1740 }
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 2008 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().

2019  {
2020  auto lnum_coords = lsize / compression_unit_size(ic1);
2021  auto psize = 2 * compression_unit_size(ic1);
2022  auto min_distance =
2023  ST_Distance_Point_Polygon(l, // pointer to start of linestring for first point
2024  psize,
2025  poly_coords,
2026  poly_coords_size,
2027  poly_ring_sizes,
2028  poly_num_rings,
2029  ic1,
2030  isr1,
2031  ic2,
2032  isr2,
2033  osr,
2034  threshold);
2035  if (tol_zero(min_distance)) {
2036  // Linestring's first point is inside the poly
2037  return 0.0;
2038  }
2039  if (min_distance <= threshold) {
2040  return min_distance;
2041  }
2042 
2043  // Otherwise, linestring's first point is outside the external ring or inside
2044  // an internal ring. Measure minimum distance between linestring segments and
2045  // poly rings. Crossing a ring zeroes the distance and causes an early return.
2046  auto poly_ring_coords = poly_coords;
2047  for (auto r = 0; r < poly_num_rings; r++) {
2048  int64_t poly_ring_num_coords = poly_ring_sizes[r] * 2;
2049 
2050  auto distance = distance_ring_linestring(poly_ring_coords,
2051  poly_ring_num_coords,
2052  l,
2053  lnum_coords,
2054  ic2,
2055  isr2,
2056  ic1,
2057  isr1,
2058  osr,
2059  threshold);
2060  if (min_distance > distance) {
2061  min_distance = distance;
2062  if (tol_zero(min_distance)) {
2063  return 0.0;
2064  }
2065  if (min_distance <= threshold) {
2066  return min_distance;
2067  }
2068  }
2069 
2070  poly_ring_coords += poly_ring_num_coords * compression_unit_size(ic2);
2071  }
2072 
2073  return min_distance;
2074 }
EXTENSION_NOINLINE double ST_Distance_Point_Polygon(int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE double distance_ring_linestring(int8_t *ring, int32_t ring_num_coords, int8_t *l, int32_t lnum_coords, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2370 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_LineString_MultiPolygon().

2383  {
2385  lsize,
2386  mpoly_coords,
2387  mpoly_coords_size,
2388  mpoly_ring_sizes,
2389  mpoly_num_rings,
2390  mpoly_poly_sizes,
2391  mpoly_num_polys,
2392  ic2,
2393  isr2,
2394  ic1,
2395  isr1,
2396  osr,
2397  threshold);
2398 }
EXTENSION_NOINLINE double ST_Distance_LineString_MultiPolygon(int8_t *l, int64_t lsize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

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

Definition at line 2436 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().

2453  {
2454  double min_distance = 0.0;
2455 
2456  // Set specific poly pointers as we move through mpoly1's coords/ringsizes/polyrings
2457  // arrays.
2458  auto next_poly_coords = mpoly1_coords;
2459  auto next_poly_ring_sizes = mpoly1_ring_sizes;
2460 
2461  for (auto poly = 0; poly < mpoly1_num_polys; poly++) {
2462  auto poly_coords = next_poly_coords;
2463  auto poly_ring_sizes = next_poly_ring_sizes;
2464  auto poly_num_rings = mpoly1_poly_sizes[poly];
2465  // Count number of coords in all of poly's rings, advance ring size pointer.
2466  int32_t poly_num_coords = 0;
2467  for (auto ring = 0; ring < poly_num_rings; ring++) {
2468  poly_num_coords += 2 * *next_poly_ring_sizes++;
2469  }
2470  auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
2471  next_poly_coords += poly_coords_size;
2472  double distance = ST_Distance_Polygon_MultiPolygon(poly_coords,
2473  poly_coords_size,
2474  poly_ring_sizes,
2475  poly_num_rings,
2476  mpoly2_coords,
2477  mpoly2_coords_size,
2478  mpoly2_ring_sizes,
2479  mpoly2_num_rings,
2480  mpoly2_poly_sizes,
2481  mpoly2_num_polys,
2482  ic1,
2483  isr1,
2484  ic2,
2485  isr2,
2486  osr,
2487  threshold);
2488  if (poly == 0 || min_distance > distance) {
2489  min_distance = distance;
2490  if (tol_zero(min_distance)) {
2491  min_distance = 0.0;
2492  break;
2493  }
2494  if (min_distance <= threshold) {
2495  break;
2496  }
2497  }
2498  }
2499 
2500  return min_distance;
2501 }
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 2339 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_MultiPolygon().

2352  {
2354  psize,
2355  mpoly_coords,
2356  mpoly_coords_size,
2357  mpoly_ring_sizes,
2358  mpoly_num_rings,
2359  mpoly_poly_sizes,
2360  mpoly_num_polys,
2361  ic2,
2362  isr2,
2363  ic1,
2364  isr1,
2365  osr,
2366  threshold);
2367 }
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 2401 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Polygon_MultiPolygon().

2416  {
2417  return ST_Distance_Polygon_MultiPolygon(poly1_coords,
2418  poly1_coords_size,
2419  poly1_ring_sizes,
2420  poly1_num_rings,
2421  mpoly_coords,
2422  mpoly_coords_size,
2423  mpoly_ring_sizes,
2424  mpoly_num_rings,
2425  mpoly_poly_sizes,
2426  mpoly_num_polys,
2427  ic2,
2428  isr2,
2429  ic1,
2430  isr1,
2431  osr,
2432  threshold);
2433 }
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 1790 of file ExtensionFunctionsGeo.hpp.

References distance_point_linestring().

Referenced by ST_Distance_Point_Polygon().

1799  {
1801  p, psize, l, lsize, ic1, isr1, ic2, isr2, osr, true, threshold);
1802 }
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 1805 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().

1814  {
1816  p, psize, l, lsize, ic1, isr1, ic2, isr2, osr, false, threshold);
1817 }
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 1709 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), coord_x(), coord_y(), and distance_in_meters().

Referenced by ST_Distance_LineString_Point_Geodesic().

1717  {
1718  // Currently only statically indexed LineString is supported
1719  double px = coord_x(p, 0, ic1, 4326, 4326);
1720  double py = coord_y(p, 1, ic1, 4326, 4326);
1721  const auto lpoints = lsize / (2 * compression_unit_size(ic2));
1722  double lx = coord_x(l, 2 * (lpoints - 1), ic2, 4326, 4326);
1723  double ly = coord_y(l, 2 * (lpoints - 1) + 1, ic2, 4326, 4326);
1724  return distance_in_meters(px, py, lx, ly);
1725 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 1872 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Distance_MultiPolygon_Point(), and ST_DWithin_Point_MultiPolygon().

1885  {
1886  if (mpoly_num_polys <= 0) {
1887  return 0.0;
1888  }
1889  double min_distance = 0.0;
1890 
1891  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1892  auto next_poly_coords = mpoly_coords;
1893  auto next_poly_ring_sizes = mpoly_ring_sizes;
1894 
1895  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1896  auto poly_coords = next_poly_coords;
1897  auto poly_ring_sizes = next_poly_ring_sizes;
1898  auto poly_num_rings = mpoly_poly_sizes[poly];
1899  // Count number of coords in all of poly's rings, advance ring size pointer.
1900  int32_t poly_num_coords = 0;
1901  for (auto ring = 0; ring < poly_num_rings; ring++) {
1902  poly_num_coords += 2 * *next_poly_ring_sizes++;
1903  }
1904  auto poly_coords_size = poly_num_coords * compression_unit_size(ic2);
1905  next_poly_coords += poly_coords_size;
1906  double distance = ST_Distance_Point_Polygon(p,
1907  psize,
1908  poly_coords,
1909  poly_coords_size,
1910  poly_ring_sizes,
1911  poly_num_rings,
1912  ic1,
1913  isr1,
1914  ic2,
1915  isr2,
1916  osr,
1917  threshold);
1918  if (poly == 0 || min_distance > distance) {
1919  min_distance = distance;
1920  if (tol_zero(min_distance)) {
1921  min_distance = 0.0;
1922  break;
1923  }
1924  if (min_distance <= threshold) {
1925  break;
1926  }
1927  }
1928  }
1929 
1930  return min_distance;
1931 }
EXTENSION_NOINLINE double ST_Distance_Point_Polygon(int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1658 of file ExtensionFunctionsGeo.hpp.

References coord_x(), coord_y(), and distance_point_point().

Referenced by ST_Intersects_Point_Point().

1666  {
1667  double p1x = coord_x(p1, 0, ic1, isr1, osr);
1668  double p1y = coord_y(p1, 1, ic1, isr1, osr);
1669  double p2x = coord_x(p2, 0, ic2, isr2, osr);
1670  double p2y = coord_y(p2, 1, ic2, isr2, osr);
1671  return distance_point_point(p1x, p1y, p2x, p2y);
1672 }
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 1692 of file ExtensionFunctionsGeo.hpp.

References coord_x(), coord_y(), and distance_in_meters().

Referenced by ST_DWithin_Point_Point_Geodesic().

1700  {
1701  double p1x = coord_x(p1, 0, ic1, 4326, 4326);
1702  double p1y = coord_y(p1, 1, ic1, 4326, 4326);
1703  double p2x = coord_x(p2, 0, ic2, 4326, 4326);
1704  double p2y = coord_y(p2, 1, ic2, 4326, 4326);
1705  return distance_in_meters(p1x, p1y, p2x, p2y);
1706 }
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 double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 1675 of file ExtensionFunctionsGeo.hpp.

References coord_x(), coord_y(), and distance_point_point_squared().

Referenced by ST_DWithin_Point_Point().

1683  {
1684  double p1x = coord_x(p1, 0, ic1, isr1, osr);
1685  double p1y = coord_y(p1, 1, ic1, isr1, osr);
1686  double p2x = coord_x(p2, 0, ic2, isr2, osr);
1687  double p2y = coord_y(p2, 1, ic2, isr2, osr);
1688  return distance_point_point_squared(p1x, p1y, p2x, p2y);
1689 }
DEVICE ALWAYS_INLINE double distance_point_point_squared(double p1x, double p1y, double p2x, double p2y)
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t 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 1820 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), coord_x(), coord_y(), polygon_contains_point(), and ST_Distance_Point_ClosedLineString().

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

1831  {
1832  auto exterior_ring_num_coords = polysize / compression_unit_size(ic2);
1833  if (poly_num_rings > 0) {
1834  exterior_ring_num_coords = poly_ring_sizes[0] * 2;
1835  }
1836  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic2);
1837 
1838  double px = coord_x(p, 0, ic1, isr1, osr);
1839  double py = coord_y(p, 1, ic1, isr1, osr);
1840  if (!polygon_contains_point(poly, exterior_ring_num_coords, px, py, ic2, isr2, osr)) {
1841  // Outside the exterior ring
1843  p, psize, poly, exterior_ring_coords_size, ic1, isr1, ic2, isr2, osr, threshold);
1844  }
1845  // Inside exterior ring
1846  // Advance to first interior ring
1847  poly += exterior_ring_coords_size;
1848  // Check if one of the polygon's holes contains that point
1849  for (auto r = 1; r < poly_num_rings; r++) {
1850  auto interior_ring_num_coords = poly_ring_sizes[r] * 2;
1851  auto interior_ring_coords_size =
1852  interior_ring_num_coords * compression_unit_size(ic2);
1853  if (polygon_contains_point(poly, interior_ring_num_coords, px, py, ic2, isr2, osr)) {
1854  // Inside an interior ring
1856  psize,
1857  poly,
1858  interior_ring_coords_size,
1859  ic1,
1860  isr1,
1861  ic2,
1862  isr2,
1863  osr,
1864  threshold);
1865  }
1866  poly += interior_ring_coords_size;
1867  }
1868  return 0.0;
1869 }
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)
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)
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE ALWAYS_INLINE double coord_x(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References ST_Distance_LineString_Polygon().

2175  {
2177  lsize,
2178  poly_coords,
2179  poly_coords_size,
2180  poly_ring_sizes,
2181  poly_num_rings,
2182  ic2,
2183  isr2,
2184  ic1,
2185  isr2,
2186  osr,
2187  threshold);
2188 }
EXTENSION_NOINLINE double ST_Distance_LineString_Polygon(int8_t *l, int64_t lsize, int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

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

Definition at line 2276 of file ExtensionFunctionsGeo.hpp.

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

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

2291  {
2292  double min_distance = 0.0;
2293 
2294  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
2295  auto next_poly_coords = mpoly_coords;
2296  auto next_poly_ring_sizes = mpoly_ring_sizes;
2297 
2298  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
2299  auto poly_coords = next_poly_coords;
2300  auto poly_ring_sizes = next_poly_ring_sizes;
2301  auto poly_num_rings = mpoly_poly_sizes[poly];
2302  // Count number of coords in all of poly's rings, advance ring size pointer.
2303  int32_t poly_num_coords = 0;
2304  for (auto ring = 0; ring < poly_num_rings; ring++) {
2305  poly_num_coords += 2 * *next_poly_ring_sizes++;
2306  }
2307  auto poly_coords_size = poly_num_coords * compression_unit_size(ic2);
2308  next_poly_coords += poly_coords_size;
2309  double distance = ST_Distance_Polygon_Polygon(poly1_coords,
2310  poly1_coords_size,
2311  poly1_ring_sizes,
2312  poly1_num_rings,
2313  poly_coords,
2314  poly_coords_size,
2315  poly_ring_sizes,
2316  poly_num_rings,
2317  ic1,
2318  isr1,
2319  ic2,
2320  isr2,
2321  osr,
2322  threshold);
2323  if (poly == 0 || min_distance > distance) {
2324  min_distance = distance;
2325  if (tol_zero(min_distance)) {
2326  min_distance = 0.0;
2327  break;
2328  }
2329  if (min_distance <= threshold) {
2330  break;
2331  }
2332  }
2333  }
2334 
2335  return min_distance;
2336 }
EXTENSION_NOINLINE double ST_Distance_Polygon_Polygon(int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int8_t *poly2_coords, int64_t poly2_coords_size, int32_t *poly2_ring_sizes, int64_t poly2_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2137 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_Polygon().

Referenced by ST_Distance_Polygon_Polygon().

2148  {
2149  return ST_Distance_Point_Polygon(p,
2150  psize,
2151  poly_coords,
2152  poly_coords_size,
2153  poly_ring_sizes,
2154  poly_num_rings,
2155  ic2,
2156  isr2,
2157  ic1,
2158  isr1,
2159  osr,
2160  threshold);
2161 }
EXTENSION_NOINLINE double ST_Distance_Point_Polygon(int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2191 of file ExtensionFunctionsGeo.hpp.

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

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

2204  {
2205  // Check if poly1 contains the first point of poly2's shape, i.e. the external ring
2206  auto poly2_first_point_coords = poly2_coords;
2207  auto poly2_first_point_coords_size = compression_unit_size(ic2) * 2;
2208  auto min_distance = ST_Distance_Polygon_Point(poly1_coords,
2209  poly1_coords_size,
2210  poly1_ring_sizes,
2211  poly1_num_rings,
2212  poly2_first_point_coords,
2213  poly2_first_point_coords_size,
2214  ic1,
2215  isr1,
2216  ic2,
2217  isr2,
2218  osr,
2219  threshold);
2220  if (tol_zero(min_distance)) {
2221  // Polygons overlap
2222  return 0.0;
2223  }
2224  if (min_distance <= threshold) {
2225  return min_distance;
2226  }
2227 
2228  // Poly2's first point is either outside poly1's external ring or inside one of the
2229  // internal rings. Measure the smallest distance between a poly1 ring (external or
2230  // internal) and a poly2 ring (external or internal). If poly2 is completely outside
2231  // poly1, then the min distance would be between poly1's and poly2's external rings. If
2232  // poly2 is completely inside one of poly1 internal rings then the min distance would be
2233  // between that poly1 internal ring and poly2's external ring. If poly1 is completely
2234  // inside one of poly2 internal rings, min distance is between that internal ring and
2235  // poly1's external ring. In each case other rings don't get in the way. Any ring
2236  // intersection means zero distance - short-circuit and return.
2237 
2238  auto poly1_ring_coords = poly1_coords;
2239  for (auto r1 = 0; r1 < poly1_num_rings; r1++) {
2240  int64_t poly1_ring_num_coords = poly1_ring_sizes[r1] * 2;
2241 
2242  auto poly2_ring_coords = poly2_coords;
2243  for (auto r2 = 0; r2 < poly2_num_rings; r2++) {
2244  int64_t poly2_ring_num_coords = poly2_ring_sizes[r2] * 2;
2245 
2246  auto distance = distance_ring_ring(poly1_ring_coords,
2247  poly1_ring_num_coords,
2248  poly2_ring_coords,
2249  poly2_ring_num_coords,
2250  ic1,
2251  isr1,
2252  ic2,
2253  isr2,
2254  osr,
2255  threshold);
2256  if (min_distance > distance) {
2257  min_distance = distance;
2258  if (tol_zero(min_distance)) {
2259  return 0.0;
2260  }
2261  if (min_distance <= threshold) {
2262  return min_distance;
2263  }
2264  }
2265 
2266  poly2_ring_coords += poly2_ring_num_coords * compression_unit_size(ic2);
2267  }
2268 
2269  poly1_ring_coords += poly1_ring_num_coords * compression_unit_size(ic1);
2270  }
2271 
2272  return min_distance;
2273 }
DEVICE double distance_ring_ring(int8_t *ring1, int32_t ring1_num_coords, int8_t *ring2, int32_t ring2_num_coords, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
EXTENSION_INLINE double ST_Distance_Polygon_Point(int8_t *poly_coords, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2662 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), and ST_Distance_LineString_LineString().

2675  {
2676  if (l1bounds && l2bounds) {
2677  // Bounding boxes need to be transformed to output SR before proximity check
2678  if (!box_dwithin_box(l1bounds,
2679  l1bounds_size,
2680  isr1,
2681  l2bounds,
2682  l2bounds_size,
2683  isr2,
2684  osr,
2685  distance_within)) {
2686  return false;
2687  }
2688  }
2689 
2690  // May need to adjust the threshold by TOLERANCE_DEFAULT
2691  const double threshold = distance_within;
2693  l1, l1size, l2, l2size, ic1, isr1, ic2, isr2, osr, threshold) <=
2694  distance_within;
2695 }
EXTENSION_NOINLINE double ST_Distance_LineString_LineString(int8_t *l1, int64_t l1size, int8_t *l2, int64_t l2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool box_dwithin_box(double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)

+ Here is the call graph for this function:

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

Definition at line 2745 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), and ST_Distance_LineString_MultiPolygon().

2762  {
2763  if (l1bounds && mpoly_bounds) {
2764  // Bounding boxes need to be transformed to output SR before proximity check
2765  if (!box_dwithin_box(l1bounds,
2766  l1bounds_size,
2767  isr1,
2768  mpoly_bounds,
2769  mpoly_bounds_size,
2770  isr2,
2771  osr,
2772  distance_within)) {
2773  return false;
2774  }
2775  }
2776 
2777  // May need to adjust the threshold by TOLERANCE_DEFAULT
2778  const double threshold = distance_within;
2780  l1size,
2781  mpoly_coords,
2782  mpoly_coords_size,
2783  mpoly_ring_sizes,
2784  mpoly_num_rings,
2785  mpoly_poly_sizes,
2786  mpoly_num_polys,
2787  ic1,
2788  isr1,
2789  ic2,
2790  isr2,
2791  osr,
2792  threshold) <= distance_within;
2793 }
DEVICE ALWAYS_INLINE bool box_dwithin_box(double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
EXTENSION_NOINLINE double ST_Distance_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 bool ST_DWithin_LineString_Polygon ( int8_t *  l1,
int64_t  l1size,
double *  l1bounds,
int64_t  l1bounds_size,
int8_t *  poly_coords,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
double *  poly_bounds,
int64_t  poly_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2698 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), and ST_Distance_LineString_Polygon().

2713  {
2714  if (l1bounds && poly_bounds) {
2715  // Bounding boxes need to be transformed to output SR before proximity check
2716  if (!box_dwithin_box(l1bounds,
2717  l1bounds_size,
2718  isr1,
2719  poly_bounds,
2720  poly_bounds_size,
2721  isr2,
2722  osr,
2723  distance_within)) {
2724  return false;
2725  }
2726  }
2727 
2728  // May need to adjust the threshold by TOLERANCE_DEFAULT
2729  const double threshold = distance_within;
2731  l1size,
2732  poly_coords,
2733  poly_coords_size,
2734  poly_ring_sizes,
2735  poly_num_rings,
2736  ic1,
2737  isr1,
2738  ic2,
2739  isr2,
2740  osr,
2741  threshold) <= distance_within;
2742 }
DEVICE ALWAYS_INLINE bool box_dwithin_box(double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
EXTENSION_NOINLINE double ST_Distance_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 bool ST_DWithin_MultiPolygon_MultiPolygon ( int8_t *  mpoly1_coords,
int64_t  mpoly1_coords_size,
int32_t *  mpoly1_ring_sizes,
int64_t  mpoly1_num_rings,
int32_t *  mpoly1_poly_sizes,
int64_t  mpoly1_num_polys,
double *  mpoly1_bounds,
int64_t  mpoly1_bounds_size,
int8_t *  mpoly2_coords,
int64_t  mpoly2_coords_size,
int32_t *  mpoly2_ring_sizes,
int64_t  mpoly2_num_rings,
int32_t *  mpoly2_poly_sizes,
int64_t  mpoly2_num_polys,
double *  mpoly2_bounds,
int64_t  mpoly2_bounds_size,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2902 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), and ST_Distance_MultiPolygon_MultiPolygon().

2923  {
2924  if (mpoly1_bounds && mpoly2_bounds) {
2925  // Bounding boxes need to be transformed to output SR before proximity check
2926  if (!box_dwithin_box(mpoly1_bounds,
2927  mpoly1_bounds_size,
2928  isr1,
2929  mpoly2_bounds,
2930  mpoly2_bounds_size,
2931  isr2,
2932  osr,
2933  distance_within)) {
2934  return false;
2935  }
2936  }
2937 
2938  // May need to adjust the threshold by TOLERANCE_DEFAULT
2939  const double threshold = distance_within;
2940  return ST_Distance_MultiPolygon_MultiPolygon(mpoly1_coords,
2941  mpoly1_coords_size,
2942  mpoly1_ring_sizes,
2943  mpoly1_num_rings,
2944  mpoly1_poly_sizes,
2945  mpoly1_num_polys,
2946  mpoly2_coords,
2947  mpoly2_coords_size,
2948  mpoly2_ring_sizes,
2949  mpoly2_num_rings,
2950  mpoly2_poly_sizes,
2951  mpoly2_num_polys,
2952  ic1,
2953  isr1,
2954  ic2,
2955  isr2,
2956  osr,
2957  threshold) <= distance_within;
2958 }
DEVICE ALWAYS_INLINE bool box_dwithin_box(double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
EXTENSION_NOINLINE double ST_Distance_MultiPolygon_MultiPolygon(int8_t *mpoly1_coords, int64_t mpoly1_coords_size, int32_t *mpoly1_ring_sizes, int64_t mpoly1_num_rings, int32_t *mpoly1_poly_sizes, int64_t mpoly1_num_polys, int8_t *mpoly2_coords, int64_t mpoly2_coords_size, int32_t *mpoly2_ring_sizes, int64_t mpoly2_num_rings, int32_t *mpoly2_poly_sizes, int64_t mpoly2_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

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

Definition at line 2540 of file ExtensionFunctionsGeo.hpp.

References point_dwithin_box(), and ST_Distance_Point_LineString().

2551  {
2552  if (l2bounds) {
2553  // Bounding boxes need to be transformed to output SR before proximity check
2554  if (!point_dwithin_box(
2555  p1, p1size, ic1, isr1, l2bounds, l2bounds_size, isr2, osr, distance_within)) {
2556  return false;
2557  }
2558  }
2559 
2560  // May need to adjust the threshold by TOLERANCE_DEFAULT
2561  const double threshold = distance_within;
2563  p1, p1size, l2, l2size, ic1, isr1, ic2, isr2, osr, threshold) <=
2564  distance_within;
2565 }
EXTENSION_NOINLINE double ST_Distance_Point_LineString(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool point_dwithin_box(int8_t *p1, int64_t p1size, int32_t ic1, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)

+ Here is the call graph for this function:

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

Definition at line 2613 of file ExtensionFunctionsGeo.hpp.

References point_dwithin_box(), and ST_Distance_Point_MultiPolygon().

2628  {
2629  if (mpoly_bounds) {
2630  if (!point_dwithin_box(p,
2631  psize,
2632  ic1,
2633  isr1,
2634  mpoly_bounds,
2635  mpoly_bounds_size,
2636  isr2,
2637  osr,
2638  distance_within)) {
2639  return false;
2640  }
2641  }
2642 
2643  // May need to adjust the threshold by TOLERANCE_DEFAULT
2644  const double threshold = distance_within;
2646  psize,
2647  mpoly_coords,
2648  mpoly_coords_size,
2649  mpoly_ring_sizes,
2650  mpoly_num_rings,
2651  mpoly_poly_sizes,
2652  mpoly_num_polys,
2653  ic1,
2654  isr1,
2655  ic2,
2656  isr2,
2657  osr,
2658  threshold) <= distance_within;
2659 }
EXTENSION_NOINLINE double ST_Distance_Point_MultiPolygon(int8_t *p, int64_t psize, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool point_dwithin_box(int8_t *p1, int64_t p1size, int32_t ic1, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)

+ Here is the call graph for this function:

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

Definition at line 2508 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_Point_Squared().

2517  {
2519  p1, p1size, p2, p2size, ic1, isr1, ic2, isr2, osr) <=
2520  distance_within * distance_within;
2521 }
EXTENSION_NOINLINE double ST_Distance_Point_Point_Squared(int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)

+ Here is the call graph for this function:

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

Definition at line 2524 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_Point_Geodesic().

2533  {
2534  auto dist_meters =
2535  ST_Distance_Point_Point_Geodesic(p1, p1size, p2, p2size, ic1, isr1, ic2, isr2, osr);
2536  return (dist_meters <= distance_within);
2537 }
EXTENSION_NOINLINE double ST_Distance_Point_Point_Geodesic(int8_t *p1, int64_t p1size, int8_t *p2, int64_t p2size, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)

+ Here is the call graph for this function:

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

Definition at line 2568 of file ExtensionFunctionsGeo.hpp.

References point_dwithin_box(), and ST_Distance_Point_Polygon().

2581  {
2582  if (poly_bounds) {
2583  if (!point_dwithin_box(p,
2584  psize,
2585  ic1,
2586  isr1,
2587  poly_bounds,
2588  poly_bounds_size,
2589  isr2,
2590  osr,
2591  distance_within)) {
2592  return false;
2593  }
2594  }
2595 
2596  // May need to adjust the threshold by TOLERANCE_DEFAULT
2597  const double threshold = distance_within;
2598  return ST_Distance_Point_Polygon(p,
2599  psize,
2600  poly_coords,
2601  poly_coords_size,
2602  poly_ring_sizes,
2603  poly_num_rings,
2604  ic1,
2605  isr1,
2606  ic2,
2607  isr2,
2608  osr,
2609  threshold) <= distance_within;
2610 }
EXTENSION_NOINLINE double ST_Distance_Point_Polygon(int8_t *p, int64_t psize, int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
DEVICE ALWAYS_INLINE bool point_dwithin_box(int8_t *p1, int64_t p1size, int32_t ic1, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)

+ Here is the call graph for this function:

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

Definition at line 2847 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), and ST_Distance_Polygon_MultiPolygon().

2866  {
2867  if (poly_bounds && mpoly_bounds) {
2868  // Bounding boxes need to be transformed to output SR before proximity check
2869  if (!box_dwithin_box(poly_bounds,
2870  poly_bounds_size,
2871  isr1,
2872  mpoly_bounds,
2873  mpoly_bounds_size,
2874  isr2,
2875  osr,
2876  distance_within)) {
2877  return false;
2878  }
2879  }
2880 
2881  // May need to adjust the threshold by TOLERANCE_DEFAULT
2882  const double threshold = distance_within;
2883  return ST_Distance_Polygon_MultiPolygon(poly_coords,
2884  poly_coords_size,
2885  poly_ring_sizes,
2886  poly_num_rings,
2887  mpoly_coords,
2888  mpoly_coords_size,
2889  mpoly_ring_sizes,
2890  mpoly_num_rings,
2891  mpoly_poly_sizes,
2892  mpoly_num_polys,
2893  ic1,
2894  isr1,
2895  ic2,
2896  isr2,
2897  osr,
2898  threshold) <= distance_within;
2899 }
DEVICE ALWAYS_INLINE bool box_dwithin_box(double *bounds1, int64_t bounds1_size, int32_t isr1, double *bounds2, int64_t bounds2_size, int32_t isr2, int32_t osr, double distance)
EXTENSION_NOINLINE double ST_Distance_Polygon_MultiPolygon(int8_t *poly1_coords, int64_t poly1_coords_size, int32_t *poly1_ring_sizes, int64_t poly1_num_rings, int8_t *mpoly_coords, int64_t mpoly_coords_size, int32_t *mpoly_ring_sizes, int64_t mpoly_num_rings, int32_t *mpoly_poly_sizes, int64_t mpoly_num_polys, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)

+ Here is the call graph for this function:

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

Definition at line 2796 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), and ST_Distance_Polygon_Polygon().