OmniSciDB  8fa3bf436f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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_X_LineString (int8_t *l, int64_t lsize, int32_t lindex, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Y_LineString (int8_t *l, int64_t lsize, int32_t lindex, 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, int64_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, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Perimeter_Polygon_Geodesic (int8_t *poly, int64_t polysize, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
 
DEVICE ALWAYS_INLINE double perimeter_multipolygon (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 ic, int32_t isr, int32_t osr, bool geodesic)
 
EXTENSION_NOINLINE double ST_Perimeter_MultiPolygon (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 ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Perimeter_MultiPolygon_Geodesic (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 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, int64_t poly_coords_size, int32_t *poly_ring_sizes, int64_t poly_num_rings, int32_t ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Area_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)
 
EXTENSION_INLINE double ST_Area_Polygon_Geodesic (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)
 
EXTENSION_NOINLINE double ST_Area_MultiPolygon (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 ic, int32_t isr, int32_t osr)
 
EXTENSION_INLINE double ST_Area_MultiPolygon_Geodesic (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 ic, int32_t isr, int32_t osr)
 
EXTENSION_NOINLINE double ST_Centroid_Point (int8_t *p, int64_t psize, int32_t ic, int32_t isr, int32_t osr, bool ycoord)
 
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 double ST_Centroid_LineString (int8_t *coords, int64_t coords_sz, int32_t ic, int32_t isr, int32_t osr, bool ycoord)
 
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 double ST_Centroid_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, bool ycoord)
 
EXTENSION_NOINLINE double ST_Centroid_MultiPolygon (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 ic, int32_t isr, int32_t osr, bool ycoord)
 
EXTENSION_INLINE int32_t ST_NPoints (int8_t *coords, int64_t coords_sz, int32_t ic)
 
EXTENSION_INLINE int32_t ST_NRings (int32_t *poly_ring_sizes, int64_t poly_num_rings)
 
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 lindex, 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, int32_t lindex, int8_t *p, int64_t psize, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr)
 
EXTENSION_NOINLINE double ST_Distance_LineString_LineString_Geodesic (int8_t *l1, int64_t l1size, int32_t l1index, int8_t *l2, int64_t l2size, int32_t l2index, 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 lindex, 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 lindex, 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 lindex, 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, int32_t lindex, 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, int32_t l1index, int8_t *l2, int64_t l2size, int32_t l2index, 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, int32_t lindex, 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, int32_t lindex, 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 li, 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 lindex, 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_LineString (int8_t *p1, int64_t p1size, int8_t *l2, int64_t l2size, double *l2bounds, int64_t l2bounds_size, int32_t l2index, 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, int32_t l1index, int8_t *l2, int64_t l2size, double *l2bounds, int64_t l2bounds_size, int32_t l2index, 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, int32_t l1index, 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, int32_t l1index, 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 lindex, 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 lindex, 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, int32_t lindex, 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 li, 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, int32_t li, 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_LineString (int8_t *l1, int64_t l1size, double *l1bounds, int64_t l1bounds_size, int32_t l1i, int8_t *l2, int64_t l2size, double *l2bounds, int64_t l2bounds_size, int32_t l2i, 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, int32_t li, 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 li, 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 li, 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 li, 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, int32_t li, 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, int32_t l1i, int8_t *l2, int64_t l2size, double *l2bounds, int64_t l2bounds_size, int32_t l2i, 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, int32_t li, 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, int32_t li, 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 li, 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 li, 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,
int64_t  poly_coords_size,
int32_t *  poly_ring_sizes,
int64_t  poly_num_rings,
int32_t  ic,
int32_t  isr,
int32_t  osr 
)

Definition at line 1264 of file ExtensionFunctionsGeo.hpp.

References area_ring(), compression_unit_size(), and test_fsi::r.

Referenced by ST_Area_MultiPolygon(), and ST_Area_Polygon().

1270  {
1271  if (poly_num_rings <= 0) {
1272  return 0.0;
1273  }
1274 
1275  double area = 0.0;
1276  auto ring_coords = poly_coords;
1277 
1278  // Add up the areas of all rings.
1279  // External ring is CCW, open - positive area.
1280  // Internal rings (holes) are CW, open - negative areas.
1281  for (auto r = 0; r < poly_num_rings; r++) {
1282  auto ring_coords_size = poly_ring_sizes[r] * 2 * compression_unit_size(ic);
1283  area += area_ring(ring_coords, ring_coords_size, ic, isr, osr);
1284  // Advance to the next ring.
1285  ring_coords += ring_coords_size;
1286  }
1287  return area;
1288 }
tuple r
Definition: test_fsi.py:16
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 1237 of file ExtensionFunctionsGeo.hpp.

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

Referenced by area_polygon().

1241  {
1242  auto ring_num_coords = ringsize / compression_unit_size(ic);
1243 
1244  if (ring_num_coords < 6) {
1245  return 0.0;
1246  }
1247 
1248  double area = 0.0;
1249 
1250  double x1 = coord_x(ring, 0, ic, isr, osr);
1251  double y1 = coord_y(ring, 1, ic, isr, osr);
1252  double x2 = coord_x(ring, 2, ic, isr, osr);
1253  double y2 = coord_y(ring, 3, ic, isr, osr);
1254  for (int32_t i = 4; i < ring_num_coords; i += 2) {
1255  double x3 = coord_x(ring, i, ic, isr, osr);
1256  double y3 = coord_y(ring, i + 1, ic, isr, osr);
1257  area += area_triangle(x1, y1, x2, y2, x3, y3);
1258  x2 = x3;
1259  y2 = y3;
1260  }
1261  return area;
1262 }
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 1228 of file ExtensionFunctionsGeo.hpp.

Referenced by area_ring().

1233  {
1234  return (x1 * y2 - x2 * y1 + x3 * y1 - x1 * y3 + x2 * y3 - x3 * y2) / 2.0;
1235 }

+ 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(), ST_Contains_MultiPolygon_LineString(), ST_Contains_Polygon_LineString(), 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 1416 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().

1425  {
1426  auto l_num_coords = lsize / compression_unit_size(ic);
1427  double length = 0.0;
1428  double l0x = coord_x(l, 0, ic, isr, osr);
1429  double l0y = coord_y(l, 1, ic, isr, osr);
1430  double l2x = l0x;
1431  double l2y = l0y;
1432  for (int32_t i = 2; i < l_num_coords; i += 2) {
1433  double l1x = l2x;
1434  double l1y = l2y;
1435  l2x = coord_x(l, i, ic, isr, osr);
1436  l2y = coord_y(l, i + 1, ic, isr, osr);
1437  centroid_add_segment(l1x, l1y, l2x, l2y, &length, linestring_centroid_sum);
1438  }
1439  if (l_num_coords > 4 && closed) {
1440  // Also add the closing segment between the last and the first points
1441  centroid_add_segment(l2x, l2y, l0x, l0y, &length, linestring_centroid_sum);
1442  }
1443  *total_length += length;
1444  if (length == 0.0 && l_num_coords > 0) {
1445  *num_points += 1;
1446  point_centroid_sum[0] += l0x;
1447  point_centroid_sum[1] += l0y;
1448  }
1449  return true;
1450 }
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 1548 of file ExtensionFunctionsGeo.hpp.

References centroid_add_ring(), compression_unit_size(), and test_fsi::r.

Referenced by ST_Centroid_MultiPolygon(), and ST_Centroid_Polygon().

1560  {
1561  if (poly_num_rings <= 0) {
1562  return false;
1563  }
1564 
1565  auto ring_coords = poly_coords;
1566 
1567  for (auto r = 0; r < poly_num_rings; r++) {
1568  auto ring_coords_size = poly_ring_sizes[r] * 2 * compression_unit_size(ic);
1569  // Shape - positive area, holes - negative areas
1570  double sign = (r == 0) ? 1.0 : -1.0;
1571  centroid_add_ring(ring_coords,
1572  ring_coords_size,
1573  ic,
1574  isr,
1575  osr,
1576  sign,
1577  total_area2,
1578  cg3,
1579  total_length,
1580  linestring_centroid_sum,
1581  num_points,
1582  point_centroid_sum);
1583  // Advance to the next ring.
1584  ring_coords += ring_coords_size;
1585  }
1586  return true;
1587 }
tuple r
Definition: test_fsi.py:16
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 1505 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().

1516  {
1517  auto ring_num_coords = ringsize / compression_unit_size(ic);
1518 
1519  if (ring_num_coords < 6) {
1520  return false;
1521  }
1522 
1523  double x1 = coord_x(ring, 0, ic, isr, osr);
1524  double y1 = coord_y(ring, 1, ic, isr, osr);
1525  double x2 = coord_x(ring, 2, ic, isr, osr);
1526  double y2 = coord_y(ring, 3, ic, isr, osr);
1527  for (int32_t i = 4; i < ring_num_coords; i += 2) {
1528  double x3 = coord_x(ring, i, ic, isr, osr);
1529  double y3 = coord_y(ring, i + 1, ic, isr, osr);
1530  centroid_add_triangle(x1, y1, x2, y2, x3, y3, sign, total_area2, cg3);
1531  x2 = x3;
1532  y2 = y3;
1533  }
1534 
1536  ringsize,
1537  ic,
1538  isr,
1539  osr,
1540  true, // closed
1541  total_length,
1542  linestring_centroid_sum,
1543  num_points,
1544  point_centroid_sum);
1545  return true;
1546 }
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 1401 of file ExtensionFunctionsGeo.hpp.

References distance_point_point().

Referenced by centroid_add_linestring().

1406  {
1407  double ldist = distance_point_point(x1, y1, x2, y2);
1408  *length += ldist;
1409  double segment_midpoint_x = (x1 + x2) / 2.0;
1410  double segment_midpoint_y = (y1 + y2) / 2.0;
1411  linestring_centroid_sum[0] += ldist * segment_midpoint_x;
1412  linestring_centroid_sum[1] += ldist * segment_midpoint_y;
1413  return true;
1414 }
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 1487 of file ExtensionFunctionsGeo.hpp.

Referenced by centroid_add_ring().

1495  {
1496  double cx = x1 + x2 + x3;
1497  double cy = y1 + y2 + y3;
1498  double area2 = x1 * y2 - x2 * y1 + x3 * y1 - x1 * y3 + x2 * y3 - x3 * y2;
1499  cg3[0] += sign * area2 * cx;
1500  cg3[1] += sign * area2 * cy;
1501  *total_area2 += sign * area2;
1502  return true;
1503 }

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

DEVICE ALWAYS_INLINE int32_t compression_unit_size ( const int32_t  ic)

Definition at line 71 of file ExtensionFunctionsGeo.hpp.

References COMPRESSION_GEOINT32.

Referenced by area_polygon(), area_ring(), centroid_add_linestring(), centroid_add_polygon(), centroid_add_ring(), Contains_MultiPolygon_Point_Impl(), Contains_Polygon_Point_Impl(), distance_point_linestring(), length_linestring(), max_distance_point_linestring(), perimeter_multipolygon(), ST_Area_MultiPolygon(), ST_Centroid_MultiPolygon(), ST_Contains_MultiPolygon_LineString(), ST_Contains_Point_LineString(), ST_Contains_Point_Polygon(), ST_Contains_Polygon_LineString(), ST_Contains_Polygon_Polygon(), ST_Distance_LineString_LineString(), ST_Distance_LineString_LineString_Geodesic(), ST_Distance_LineString_MultiPolygon(), ST_Distance_LineString_Polygon(), ST_Distance_MultiPolygon_MultiPolygon(), ST_Distance_Point_LineString(), ST_Distance_Point_LineString_Geodesic(), ST_Distance_Point_MultiPolygon(), ST_Distance_Point_Polygon(), ST_Distance_Polygon_MultiPolygon(), ST_Distance_Polygon_Polygon(), ST_Intersects_LineString_Linestring(), ST_Intersects_LineString_MultiPolygon(), ST_Intersects_LineString_Polygon(), ST_Intersects_Point_LineString(), ST_NPoints(), ST_Perimeter_Polygon(), ST_Perimeter_Polygon_Geodesic(), ST_X_LineString(), ST_XMax(), ST_XMin(), ST_Y_LineString(), ST_YMax(), and ST_YMin().

71  {
72  if (ic == COMPRESSION_GEOINT32) {
73  return 4;
74  }
75  return 8;
76 }
#define COMPRESSION_GEOINT32

+ Here is the caller graph for this function:

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

Definition at line 3672 of file ExtensionFunctionsGeo.hpp.

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

3687  {
3688  if (mpoly_num_polys <= 0) {
3689  return false;
3690  }
3691 
3692  // TODO: mpoly_bounds could contain individual bounding boxes too:
3693  // first two points - box for the entire multipolygon, then a pair for each polygon
3694  if (mpoly_bounds) {
3695  if (!box_contains_point(mpoly_bounds,
3696  mpoly_bounds_size,
3697  coord_x(p, 0, ic2, isr2, osr),
3698  coord_y(p, 1, ic2, isr2, osr))) {
3699  return false;
3700  }
3701  }
3702 
3703  // Set specific poly pointers as we move through the coords/ringsizes/polyrings
3704  // arrays.
3705  auto next_poly_coords = mpoly_coords;
3706  auto next_poly_ring_sizes = mpoly_ring_sizes;
3707 
3708  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
3709  const auto poly_coords = next_poly_coords;
3710  const auto poly_ring_sizes = next_poly_ring_sizes;
3711  const auto poly_num_rings = mpoly_poly_sizes[poly];
3712  // Count number of coords in all of poly's rings, advance ring size pointer.
3713  int32_t poly_num_coords = 0;
3714  for (auto ring = 0; ring < poly_num_rings; ring++) {
3715  poly_num_coords += 2 * *next_poly_ring_sizes++;
3716  }
3717  const auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
3718  next_poly_coords += poly_coords_size;
3719  // TODO: pass individual bounding boxes for each polygon
3720  if (Contains_Polygon_Point_Impl<T, TEdgeBehavior>(poly_coords,
3721  poly_coords_size,
3722  poly_ring_sizes,
3723  poly_num_rings,
3724  nullptr,
3725  0,
3726  p,
3727  psize,
3728  ic1,
3729  isr1,
3730  ic2,
3731  isr2,
3732  osr)) {
3733  return true;
3734  }
3735  }
3736 
3737  return false;
3738 }
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 3437 of file ExtensionFunctionsGeo.hpp.

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

3449  {
3450  if (poly_bounds) {
3451  // TODO: codegen
3452  if (!box_contains_point(poly_bounds,
3453  poly_bounds_size,
3454  coord_x(p, 0, ic2, isr2, osr),
3455  coord_y(p, 1, ic2, isr2, osr))) {
3456  DEBUG_STMT(printf("Bounding box does not contain point, exiting.\n"));
3457  return false;
3458  }
3459  }
3460 
3461  auto get_x_coord = [=]() -> T {
3462  if constexpr (std::is_floating_point<T>::value) {
3463  return coord_x(p, 0, ic2, isr2, osr);
3464  } else {
3465  return compressed_coord(p, 0);
3466  }
3467  return T{}; // https://stackoverflow.com/a/64561686/2700898
3468  };
3469 
3470  auto get_y_coord = [=]() -> T {
3471  if constexpr (std::is_floating_point<T>::value) {
3472  return coord_y(p, 1, ic2, isr2, osr);
3473  } else {
3474  return compressed_coord(p, 1);
3475  }
3476  return T{}; // https://stackoverflow.com/a/64561686/2700898
3477  };
3478 
3479  const T px = get_x_coord();
3480  const T py = get_y_coord();
3481  DEBUG_STMT(printf("pt: %f, %f\n", (double)px, (double)py));
3482 
3483  const auto poly_num_coords = poly_coords_size / compression_unit_size(ic1);
3484  auto exterior_ring_num_coords =
3485  poly_num_rings > 0 ? poly_ring_sizes[0] * 2 : poly_num_coords;
3486 
3487  auto poly = poly_coords;
3488  if (point_in_polygon_winding_number<T, TEdgeBehavior>(
3489  poly, exterior_ring_num_coords, px, py, ic1, isr1, osr)) {
3490  // Inside exterior ring
3491  poly += exterior_ring_num_coords * compression_unit_size(ic1);
3492  // Check that none of the polygon's holes contain that point
3493  for (auto r = 1; r < poly_num_rings; r++) {
3494  const int64_t interior_ring_num_coords = poly_ring_sizes[r] * 2;
3495  if (point_in_polygon_winding_number<T, TEdgeBehavior>(
3496  poly, interior_ring_num_coords, px, py, ic1, isr1, osr)) {
3497  return false;
3498  }
3499  poly += interior_ring_num_coords * compression_unit_size(ic1);
3500  }
3501  return true;
3502  }
3503  return false;
3504 }
DEVICE ALWAYS_INLINE int32_t compressed_coord(const int8_t *data, const int32_t index)
tuple r
Definition: test_fsi.py:16
#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 4615 of file ExtensionFunctionsGeo.hpp.

References decompress_coord(), and transform_coord().

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

4624  {
4625  const double const1 = 0.017453292519943295769236907684886;
4626  const double const2 = 6372797.560856;
4627  const auto lat = decompress_coord(p, 1, ic, false);
4628  const double latdiff = meters / (const1 * const2);
4629  const double newlat =
4630  (lat < 0) ? lat + latdiff : lat - latdiff; // assumes a lat range of [-90, 90]
4631  double t1 = transform_coord(lat, isr, osr, false);
4632  double t2 = transform_coord(newlat, isr, osr, false);
4633  const double min_domain_y = transform_coord(min_lat, isr, osr, false);
4634  const double max_domain_y = transform_coord(max_lat, isr, osr, false);
4635  const double domain_diff = max_domain_y - min_domain_y;
4636  t1 = ((t1 - min_domain_y) / domain_diff) * static_cast<double>(img_height);
4637  t2 = ((t2 - min_domain_y) / domain_diff) * static_cast<double>(img_height);
4638 
4639  // TODO(croot): need to account for edge cases, such as getting close to the poles.
4640  const double sz = fabs(t1 - t2);
4641  return (sz < min_height ? min_height : sz);
4642 }
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 4584 of file ExtensionFunctionsGeo.hpp.

References decompress_coord(), and transform_coord().

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

4593  {
4594  const double const1 = 0.017453292519943295769236907684886;
4595  const double const2 = 6372797.560856;
4596  const auto lon = decompress_coord(p, 0, ic, true);
4597  const auto lat = decompress_coord(p, 1, ic, false);
4598  double t1 = sinf(meters / (2.0 * const2));
4599  double t2 = cosf(const1 * lat);
4600  const double newlon = lon - (2.0 * asinf(t1 / t2)) / const1;
4601  t1 = transform_coord(lon, isr, osr, true);
4602  t2 = transform_coord(newlon, isr, osr, true);
4603  const double min_domain_x = transform_coord(min_lon, isr, osr, true);
4604  const double max_domain_x = transform_coord(max_lon, isr, osr, true);
4605  const double domain_diff = max_domain_x - min_domain_x;
4606  t1 = ((t1 - min_domain_x) / domain_diff) * static_cast<double>(img_width);
4607  t2 = ((t2 - min_domain_x) / domain_diff) * static_cast<double>(img_width);
4608 
4609  // TODO(croot): need to account for edge cases, such as getting close to the poles.
4610  const double sz = fabs(t1 - t2);
4611  return (sz < min_width ? min_width : sz);
4612 }
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_MultiPolygon_LineString(), ST_Contains_Point_LineString(), ST_Contains_Point_Point(), ST_Contains_Polygon_LineString(), ST_Distance_LineString_LineString(), ST_Distance_LineString_LineString_Geodesic(), ST_Distance_Point_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_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_MultiPolygon_LineString(), ST_Contains_Point_LineString(), ST_Contains_Point_Point(), ST_Contains_Polygon_LineString(), ST_Distance_LineString_LineString(), ST_Distance_LineString_LineString_Geodesic(), ST_Distance_Point_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_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(), generate_TableFunctionsFactory_init::k, 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(), generate_TableFunctionsFactory_init::k, 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  lindex,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
bool  check_closed,
double  threshold 
)

Definition at line 1851 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Distance_Point_ClosedLineString(), and ST_Distance_Point_LineString().

1862  {
1863  double px = coord_x(p, 0, ic1, isr1, osr);
1864  double py = coord_y(p, 1, ic1, isr1, osr);
1865 
1866  auto l_num_coords = lsize / compression_unit_size(ic2);
1867  auto l_num_points = l_num_coords / 2;
1868  if (lindex != 0) { // Statically indexed linestring
1869  if (lindex < 0 || lindex > l_num_points) {
1870  lindex = l_num_points; // Endpoint
1871  }
1872  double lx = coord_x(l, 2 * (lindex - 1), ic2, isr2, osr);
1873  double ly = coord_y(l, 2 * (lindex - 1) + 1, ic2, isr2, osr);
1874  return distance_point_point(px, py, lx, ly);
1875  }
1876 
1877  double l1x = coord_x(l, 0, ic2, isr2, osr);
1878  double l1y = coord_y(l, 1, ic2, isr2, osr);
1879  double l2x = coord_x(l, 2, ic2, isr2, osr);
1880  double l2y = coord_y(l, 3, ic2, isr2, osr);
1881 
1882  double dist = distance_point_line(px, py, l1x, l1y, l2x, l2y);
1883  for (int32_t i = 4; i < l_num_coords; i += 2) {
1884  l1x = l2x; // advance one point
1885  l1y = l2y;
1886  l2x = coord_x(l, i, ic2, isr2, osr);
1887  l2y = coord_y(l, i + 1, ic2, isr2, osr);
1888  double ldist = distance_point_line(px, py, l1x, l1y, l2x, l2y);
1889  if (dist > ldist) {
1890  dist = ldist;
1891  }
1892  if (dist <= threshold) {
1893  return dist;
1894  }
1895  }
1896  if (l_num_coords > 4 && check_closed) {
1897  // Also check distance to the closing edge between the first and the last points
1898  l1x = coord_x(l, 0, ic2, isr2, osr);
1899  l1y = coord_y(l, 1, ic2, isr2, osr);
1900  double ldist = distance_point_line(px, py, l1x, l1y, l2x, l2y);
1901  if (dist > ldist) {
1902  dist = ldist;
1903  }
1904  }
1905  return dist;
1906 }
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)
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 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(), distance_point_linestring(), length_linestring(), max_distance_point_line(), max_distance_point_linestring(), ST_Distance_Point_LineString(), 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, generate_TableFunctionsFactory_init::j, 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, generate_TableFunctionsFactory_init::j, 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 4644 of file ExtensionFunctionsGeo.hpp.

References decompress_coord().

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

4650  {
4651  const auto lon = decompress_coord(p, 0, ic, true);
4652  const auto lat = decompress_coord(p, 1, ic, false);
4653  return !(lon < min_lon || lon > max_lon || lat < min_lat || lat > max_lat);
4654 }
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 4656 of file ExtensionFunctionsGeo.hpp.

References decompress_coord().

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

4663  {
4664  const double const1 = 0.017453292519943295769236907684886;
4665  const double const2 = 6372797.560856;
4666  const auto lon = decompress_coord(p, 0, ic, true);
4667  const auto lat = decompress_coord(p, 1, ic, false);
4668  const double latdiff = meters / (const1 * const2);
4669  const double t1 = sinf(meters / (2.0 * const2));
4670  const double t2 = cosf(const1 * lat);
4671  const double londiff = (2.0 * asinf(t1 / t2)) / const1;
4672  return !(lon + londiff < min_lon || lon - londiff > max_lon ||
4673  lat + latdiff < min_lat || lat - latdiff > max_lat);
4674 }
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,
int64_t  lsize,
int32_t  ic,
int32_t  isr,
int32_t  osr,
bool  geodesic,
bool  check_closed 
)

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

1054  {
1055  auto l_num_coords = lsize / compression_unit_size(ic);
1056 
1057  double length = 0.0;
1058 
1059  double l0x = coord_x(l, 0, ic, isr, osr);
1060  double l0y = coord_y(l, 1, ic, isr, osr);
1061  double l2x = l0x;
1062  double l2y = l0y;
1063  for (int32_t i = 2; i < l_num_coords; i += 2) {
1064  double l1x = l2x;
1065  double l1y = l2y;
1066  l2x = coord_x(l, i, ic, isr, osr);
1067  l2y = coord_y(l, i + 1, ic, isr, osr);
1068  double ldist = geodesic ? distance_in_meters(l1x, l1y, l2x, l2y)
1069  : distance_point_point(l1x, l1y, l2x, l2y);
1070  length += ldist;
1071  }
1072  if (check_closed) {
1073  double ldist = geodesic ? distance_in_meters(l2x, l2y, l0x, l0y)
1074  : distance_point_point(l2x, l2y, l0x, l0y);
1075  length += ldist;
1076  }
1077  return length;
1078 }
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 4574 of file ExtensionFunctionsGeo.hpp.

References OmniSci_Geo_PolyBoundsPtr().

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

4574  {
4575  return OmniSci_Geo_PolyBoundsPtr(bounds, size);
4576 }
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 4579 of file ExtensionFunctionsGeo.hpp.

References OmniSci_Geo_PolyRenderGroup().

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

4579  {
4580  return OmniSci_Geo_PolyRenderGroup(render_group);
4581 }
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 3177 of file ExtensionFunctionsGeo.hpp.

References distance_point_point().

Referenced by max_distance_point_linestring().

3182  {
3183  // TODO: switch to squared distances
3184  double length1 = distance_point_point(px, py, l1x, l1y);
3185  double length2 = distance_point_point(px, py, l2x, l2y);
3186  if (length1 > length2) {
3187  return length1;
3188  }
3189  return length2;
3190 }
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  lindex,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
bool  check_closed 
)

Definition at line 3192 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_MaxDistance_LineString_Point(), and ST_MaxDistance_Point_LineString().

3202  {
3203  // TODO: switch to squared distances
3204  double px = coord_x(p, 0, ic1, isr1, osr);
3205  double py = coord_y(p, 1, ic1, isr1, osr);
3206 
3207  auto l_num_coords = lsize / compression_unit_size(ic2);
3208  auto l_num_points = l_num_coords / 2;
3209  if (lindex != 0) { // Statically indexed linestring
3210  if (lindex < 0 || lindex > l_num_points) {
3211  lindex = l_num_points; // Endpoint
3212  }
3213  double lx = coord_x(l, 2 * (lindex - 1), ic2, isr2, osr);
3214  double ly = coord_y(l, 2 * (lindex - 1) + 1, ic2, isr2, osr);
3215  return distance_point_point(px, py, lx, ly);
3216  }
3217 
3218  double l1x = coord_x(l, 0, ic2, isr2, osr);
3219  double l1y = coord_y(l, 1, ic2, isr2, osr);
3220  double l2x = coord_x(l, 2, ic2, isr2, osr);
3221  double l2y = coord_y(l, 3, ic2, isr2, osr);
3222 
3223  double max_dist = max_distance_point_line(px, py, l1x, l1y, l2x, l2y);
3224  for (int32_t i = 4; i < l_num_coords; i += 2) {
3225  l1x = l2x; // advance one point
3226  l1y = l2y;
3227  l2x = coord_x(l, i, ic2, isr2, osr);
3228  l2y = coord_y(l, i + 1, ic2, isr2, osr);
3229  double ldist = max_distance_point_line(px, py, l1x, l1y, l2x, l2y);
3230  if (max_dist < ldist) {
3231  max_dist = ldist;
3232  }
3233  }
3234  if (l_num_coords > 4 && check_closed) {
3235  // Also check distance to the closing edge between the first and the last points
3236  l1x = coord_x(l, 0, ic2, isr2, osr);
3237  l1y = coord_y(l, 1, ic2, isr2, osr);
3238  double ldist = max_distance_point_line(px, py, l1x, l1y, l2x, l2y);
3239  if (max_dist < ldist) {
3240  max_dist = ldist;
3241  }
3242  }
3243  return max_dist;
3244 }
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)
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_INLINE int64_t OmniSci_Geo_PolyBoundsPtr ( double *  bounds,
int64_t  size 
)

Definition at line 4564 of file ExtensionFunctionsGeo.hpp.

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

4564  {
4565  return reinterpret_cast<int64_t>(bounds);
4566 }

+ Here is the caller graph for this function:

EXTENSION_INLINE int32_t OmniSci_Geo_PolyRenderGroup ( int32_t  render_group)

Definition at line 4569 of file ExtensionFunctionsGeo.hpp.

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

4569  {
4570  return render_group;
4571 }

+ 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,
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  ic,
int32_t  isr,
int32_t  osr,
bool  geodesic 
)

Definition at line 1138 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and length_linestring().

Referenced by ST_Perimeter_MultiPolygon(), and ST_Perimeter_MultiPolygon_Geodesic().

1147  {
1148  if (mpoly_num_polys <= 0 || mpoly_num_rings <= 0) {
1149  return 0.0;
1150  }
1151 
1152  double perimeter = 0.0;
1153 
1154  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1155  auto next_poly_coords = mpoly_coords;
1156  auto next_poly_ring_sizes = mpoly_ring_sizes;
1157 
1158  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1159  auto poly_coords = next_poly_coords;
1160  auto poly_ring_sizes = next_poly_ring_sizes;
1161  auto poly_num_rings = mpoly_poly_sizes[poly];
1162  // Count number of coords in all of poly's rings, advance ring size pointer.
1163  int32_t poly_num_coords = 0;
1164  for (auto ring = 0; ring < poly_num_rings; ring++) {
1165  poly_num_coords += 2 * *next_poly_ring_sizes++;
1166  }
1167  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1168  next_poly_coords += poly_coords_size;
1169 
1170  auto exterior_ring_num_coords = poly_ring_sizes[0] * 2;
1171  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic);
1172 
1173  perimeter += length_linestring(
1174  poly_coords, exterior_ring_coords_size, ic, isr, osr, geodesic, true);
1175  }
1176 
1177  return perimeter;
1178 }
DEVICE ALWAYS_INLINE double length_linestring(int8_t *l, int64_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,
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  ic,
int32_t  isr,
int32_t  osr 
)

Definition at line 1315 of file ExtensionFunctionsGeo.hpp.

References area_polygon(), and compression_unit_size().

Referenced by ST_Area_MultiPolygon_Geodesic().

1323  {
1324  if (mpoly_num_rings <= 0 || mpoly_num_polys <= 0) {
1325  return 0.0;
1326  }
1327 
1328  double area = 0.0;
1329 
1330  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1331  auto next_poly_coords = mpoly_coords;
1332  auto next_poly_ring_sizes = mpoly_ring_sizes;
1333 
1334  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1335  auto poly_coords = next_poly_coords;
1336  auto poly_ring_sizes = next_poly_ring_sizes;
1337  auto poly_num_rings = mpoly_poly_sizes[poly];
1338  // Count number of coords in all of poly's rings, advance ring size pointer.
1339  int32_t poly_num_coords = 0;
1340  for (auto ring = 0; ring < poly_num_rings; ring++) {
1341  poly_num_coords += 2 * *next_poly_ring_sizes++;
1342  }
1343  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1344  next_poly_coords += poly_coords_size;
1345 
1346  area += area_polygon(
1347  poly_coords, poly_coords_size, poly_ring_sizes, poly_num_rings, ic, isr, osr);
1348  }
1349  return area;
1350 }
DEVICE ALWAYS_INLINE double area_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)
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_Area_MultiPolygon_Geodesic ( 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  ic,
int32_t  isr,
int32_t  osr 
)

Definition at line 1353 of file ExtensionFunctionsGeo.hpp.

References ST_Area_MultiPolygon().

1361  {
1362  return ST_Area_MultiPolygon(mpoly_coords,
1363  mpoly_coords_size,
1364  mpoly_ring_sizes,
1365  mpoly_num_rings,
1366  mpoly_poly_sizes,
1367  mpoly_num_polys,
1368  ic,
1369  isr,
1370  osr);
1371 }
EXTENSION_NOINLINE double ST_Area_MultiPolygon(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 ic, int32_t isr, int32_t osr)

+ Here is the call graph for this function:

EXTENSION_NOINLINE double ST_Area_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 
)

Definition at line 1291 of file ExtensionFunctionsGeo.hpp.

References area_polygon().

Referenced by ST_Area_Polygon_Geodesic().

1297  {
1298  return area_polygon(
1299  poly_coords, poly_coords_size, poly_ring_sizes, poly_num_rings, ic, isr, osr);
1300 }
DEVICE ALWAYS_INLINE double area_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)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXTENSION_INLINE double ST_Area_Polygon_Geodesic ( 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 
)

Definition at line 1303 of file ExtensionFunctionsGeo.hpp.

References ST_Area_Polygon().

1309  {
1310  return ST_Area_Polygon(
1311  poly_coords, poly_coords_size, poly_ring_sizes, poly_num_rings, ic, isr, osr);
1312 }
EXTENSION_NOINLINE double ST_Area_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)

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

3788  {
3789  return Contains_MultiPolygon_Point_Impl<int64_t, EdgeBehavior::kExcludePointOnEdge>(
3790  mpoly_coords,
3791  mpoly_coords_size,
3792  mpoly_ring_sizes,
3793  mpoly_num_rings,
3794  mpoly_poly_sizes,
3795  mpoly_num_polys,
3796  mpoly_bounds,
3797  mpoly_bounds_size,
3798  p,
3799  psize,
3800  ic1,
3801  isr1,
3802  ic2,
3803  isr2,
3804  osr);
3805 }
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 3535 of file ExtensionFunctionsGeo.hpp.

3547  {
3548  return Contains_Polygon_Point_Impl<int64_t, EdgeBehavior::kExcludePointOnEdge>(
3549  poly_coords,
3550  poly_coords_size,
3551  poly_ring_sizes,
3552  poly_num_rings,
3553  poly_bounds,
3554  poly_bounds_size,
3555  p,
3556  psize,
3557  ic1,
3558  isr1,
3559  ic2,
3560  isr2,
3561  osr);
3562 }
EXTENSION_NOINLINE double ST_Centroid_LineString ( int8_t *  coords,
int64_t  coords_sz,
int32_t  ic,
int32_t  isr,
int32_t  osr,
bool  ycoord 
)

Definition at line 1453 of file ExtensionFunctionsGeo.hpp.

References centroid_add_linestring().

1458  {
1459  double length = 0.0;
1460  double linestring_centroid_sum[2] = {0.0, 0.0};
1461  int64_t num_points = 0;
1462  double point_centroid_sum[2] = {0.0, 0.0};
1463  centroid_add_linestring(coords,
1464  coords_sz,
1465  ic,
1466  isr,
1467  osr,
1468  false, // not closed
1469  &length,
1470  &linestring_centroid_sum[0],
1471  &num_points,
1472  &point_centroid_sum[0]);
1473  double linestring_centroid[2] = {0.0, 0.0};
1474  if (length > 0) {
1475  linestring_centroid[0] = linestring_centroid_sum[0] / length;
1476  linestring_centroid[1] = linestring_centroid_sum[1] / length;
1477  } else if (num_points > 0) {
1478  linestring_centroid[0] = point_centroid_sum[0] / num_points;
1479  linestring_centroid[1] = point_centroid_sum[1] / num_points;
1480  }
1481  if (ycoord) {
1482  return linestring_centroid[1];
1483  }
1484  return linestring_centroid[0];
1485 }
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 double ST_Centroid_MultiPolygon ( 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  ic,
int32_t  isr,
int32_t  osr,
bool  ycoord 
)

Definition at line 1644 of file ExtensionFunctionsGeo.hpp.

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

1653  {
1654  if (mpoly_num_rings <= 0 || mpoly_num_polys <= 0) {
1655  return 0.0;
1656  }
1657 
1658  double total_area2 = 0.0;
1659  double cg3[2] = {0.0, 0.0};
1660  double total_length = 0.0;
1661  double linestring_centroid_sum[2] = {0.0, 0.0};
1662  int64_t num_points = 0;
1663  double point_centroid_sum[2] = {0.0, 0.0};
1664 
1665  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
1666  auto next_poly_coords = mpoly_coords;
1667  auto next_poly_ring_sizes = mpoly_ring_sizes;
1668 
1669  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
1670  auto poly_coords = next_poly_coords;
1671  auto poly_ring_sizes = next_poly_ring_sizes;
1672  auto poly_num_rings = mpoly_poly_sizes[poly];
1673  // Count number of coords in all of poly's rings, advance ring size pointer.
1674  int32_t poly_num_coords = 0;
1675  for (auto ring = 0; ring < poly_num_rings; ring++) {
1676  poly_num_coords += 2 * *next_poly_ring_sizes++;
1677  }
1678  auto poly_coords_size = poly_num_coords * compression_unit_size(ic);
1679  next_poly_coords += poly_coords_size;
1680 
1681  centroid_add_polygon(poly_coords,
1682  poly_coords_size,
1683  poly_ring_sizes,
1684  poly_num_rings,
1685  ic,
1686  isr,
1687  osr,
1688  &total_area2,
1689  &cg3[0],
1690  &total_length,
1691  &linestring_centroid_sum[0],
1692  &num_points,
1693  &point_centroid_sum[0]);
1694  }
1695 
1696  double x1 = coord_x(mpoly_coords, 0, ic, isr, osr);
1697  double y1 = coord_y(mpoly_coords, 1, ic, isr, osr);
1698  double mpoly_centroid[2] = {x1, y1};
1699  if (total_area2 != 0.0) {
1700  mpoly_centroid[0] = cg3[0] / 3 / total_area2;
1701  mpoly_centroid[1] = cg3[1] / 3 / total_area2;
1702  } else if (total_length > 0.0) {
1703  // zero-area multipolygon, fall back to linear centroid
1704  mpoly_centroid[0] = linestring_centroid_sum[0] / total_length;
1705  mpoly_centroid[1] = linestring_centroid_sum[1] / total_length;
1706  } else if (num_points > 0) {
1707  // zero-area zero-length multipolygon, fall further back to point centroid
1708  mpoly_centroid[0] = point_centroid_sum[0] / num_points;
1709  mpoly_centroid[1] = point_centroid_sum[1] / num_points;
1710  }
1711 
1712  if (ycoord) {
1713  return mpoly_centroid[1];
1714  }
1715  return mpoly_centroid[0];
1716 }
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 double ST_Centroid_Point ( int8_t *  p,
int64_t  psize,
int32_t  ic,
int32_t  isr,
int32_t  osr,
bool  ycoord 
)

Definition at line 1389 of file ExtensionFunctionsGeo.hpp.

References coord_x(), and coord_y().

1394  {
1395  if (ycoord) {
1396  return coord_y(p, 1, ic, isr, osr);
1397  }
1398  return coord_x(p, 0, ic, isr, osr);
1399 }
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 ST_Centroid_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,
bool  ycoord 
)

Definition at line 1590 of file ExtensionFunctionsGeo.hpp.

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

1597  {
1598  if (poly_num_rings <= 0) {
1599  return 0.0;
1600  }
1601  double total_area2 = 0.0;
1602  double cg3[2] = {0.0, 0.0};
1603  double total_length = 0.0;
1604  double linestring_centroid_sum[2] = {0.0, 0.0};
1605  int64_t num_points = 0;
1606  double point_centroid_sum[2] = {0.0, 0.0};
1607  centroid_add_polygon(poly_coords,
1608  poly_coords_size,
1609  poly_ring_sizes,
1610  poly_num_rings,
1611  ic,
1612  isr,
1613  osr,
1614  &total_area2,
1615  &cg3[0],
1616  &total_length,
1617  &linestring_centroid_sum[0],
1618  &num_points,
1619  &point_centroid_sum[0]);
1620 
1621  double x1 = coord_x(poly_coords, 0, ic, isr, osr);
1622  double y1 = coord_y(poly_coords, 1, ic, isr, osr);
1623  double poly_centroid[2] = {x1, y1};
1624  if (total_area2 != 0.0) {
1625  poly_centroid[0] = cg3[0] / 3 / total_area2;
1626  poly_centroid[1] = cg3[1] / 3 / total_area2;
1627  } else if (total_length > 0.0) {
1628  // zero-area polygon, fall back to linear centroid
1629  poly_centroid[0] = linestring_centroid_sum[0] / total_length;
1630  poly_centroid[1] = linestring_centroid_sum[1] / total_length;
1631  } else if (num_points > 0) {
1632  // zero-area zero-length polygon, fall further back to point centroid
1633  poly_centroid[0] = point_centroid_sum[0] / num_points;
1634  poly_centroid[1] = point_centroid_sum[1] / num_points;
1635  }
1636 
1637  if (ycoord) {
1638  return poly_centroid[1];
1639  }
1640  return poly_centroid[0];
1641 }
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_NOINLINE bool ST_Contains_LineString_LineString ( int8_t *  l1,
int64_t  l1size,
double *  l1bounds,
int64_t  l1bounds_size,
int32_t  l1i,
int8_t *  l2,
int64_t  l2size,
double *  l2bounds,
int64_t  l2bounds_size,
int32_t  l2i,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3387 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_LineString_LineString(), and tol_zero().

3401  {
3402  if (l1i != 0 || l2i != 0) {
3403  // At least one linestring is indexed, can rely on distance
3405  l1, l1size, l1i, l2, l2size, l2i, ic1, isr1, ic2, isr2, osr, 0.0));
3406  }
3407 
3408  // TODO: sublinestring
3409  // For each line segment in l2 check if there is a segment in l1
3410  // that it's colinear with and both l2 vertices are on l1 segment.
3411  // Bail if any line segment deviates from the path.
3412  return false;
3413 }
EXTENSION_NOINLINE double ST_Distance_LineString_LineString(int8_t *l1, int64_t l1size, int32_t l1index, int8_t *l2, int64_t l2size, int32_t l2index, 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_INLINE bool ST_Contains_LineString_Point ( int8_t *  l,
int64_t  lsize,
double *  lbounds,
int64_t  lbounds_size,
int32_t  li,
int8_t *  p,
int64_t  psize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3370 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString(), and tol_zero().

3381  {
3383  p, psize, l, lsize, li, ic2, isr2, ic1, isr1, osr, 0.0));
3384 }
EXTENSION_NOINLINE double ST_Distance_Point_LineString(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t lindex, 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,
int32_t  li,
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 3416 of file ExtensionFunctionsGeo.hpp.

3431  {
3432  // TODO
3433  return false;
3434 }
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  li,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3808 of file ExtensionFunctionsGeo.hpp.

References box_contains_box(), box_contains_point(), compression_unit_size(), coord_x(), coord_y(), ST_Contains_MultiPolygon_Point(), and ST_Contains_Polygon_LineString().

3825  {
3826  if (mpoly_num_polys <= 0) {
3827  return false;
3828  }
3829 
3830  auto lnum_coords = lsize / compression_unit_size(ic2);
3831  auto lnum_points = lnum_coords / 2;
3832  if (li != 0) {
3833  // Statically indexed linestring
3834  if (li < 0 || li > lnum_points) {
3835  li = lnum_points;
3836  }
3837  double lx = coord_x(l, 2 * (li - 1), ic2, isr2, osr);
3838  double ly = coord_y(l, 2 * (li - 1) + 1, ic2, isr2, osr);
3839 
3840  if (mpoly_bounds) {
3841  if (!box_contains_point(mpoly_bounds, mpoly_bounds_size, lx, ly)) {
3842  return false;
3843  }
3844  }
3845  auto p = l + li * compression_unit_size(ic2);
3846  auto psize = 2 * compression_unit_size(ic2);
3847  return ST_Contains_MultiPolygon_Point(mpoly_coords,
3848  mpoly_coords_size,
3849  mpoly_ring_sizes,
3850  mpoly_num_rings,
3851  mpoly_poly_sizes,
3852  mpoly_num_polys,
3853  mpoly_bounds,
3854  mpoly_bounds_size,
3855  p,
3856  psize,
3857  ic1,
3858  isr1,
3859  ic2,
3860  isr2,
3861  osr);
3862  }
3863 
3864  if (mpoly_bounds && lbounds) {
3865  if (!box_contains_box(mpoly_bounds, mpoly_bounds_size, lbounds, lbounds_size)) {
3866  return false;
3867  }
3868  }
3869 
3870  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
3871  auto next_poly_coords = mpoly_coords;
3872  auto next_poly_ring_sizes = mpoly_ring_sizes;
3873 
3874  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
3875  auto poly_coords = next_poly_coords;
3876  auto poly_ring_sizes = next_poly_ring_sizes;
3877  auto poly_num_rings = mpoly_poly_sizes[poly];
3878  // Count number of coords in all of poly's rings, advance ring size pointer.
3879  int32_t poly_num_coords = 0;
3880  for (auto ring = 0; ring < poly_num_rings; ring++) {
3881  poly_num_coords += 2 * *next_poly_ring_sizes++;
3882  }
3883  auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
3884  next_poly_coords += poly_coords_size;
3885 
3886  if (ST_Contains_Polygon_LineString(poly_coords,
3887  poly_coords_size,
3888  poly_ring_sizes,
3889  poly_num_rings,
3890  nullptr,
3891  0,
3892  l,
3893  lsize,
3894  nullptr,
3895  0,
3896  li,
3897  ic1,
3898  isr1,
3899  ic2,
3900  isr2,
3901  osr)) {
3902  return true;
3903  }
3904  }
3905 
3906  return false;
3907 }
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 li, 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)
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)
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)
DEVICE ALWAYS_INLINE bool box_contains_box(double *bounds1, int64_t bounds1_size, double *bounds2, int64_t bounds2_size)
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_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 3741 of file ExtensionFunctionsGeo.hpp.

Referenced by ST_Contains_MultiPolygon_LineString(), ST_Intersects_LineString_MultiPolygon(), and ST_Intersects_Point_MultiPolygon().

3755  {
3756  return Contains_MultiPolygon_Point_Impl<double, EdgeBehavior::kExcludePointOnEdge>(
3757  mpoly_coords,
3758  mpoly_coords_size,
3759  mpoly_ring_sizes,
3760  mpoly_num_rings,
3761  mpoly_poly_sizes,
3762  mpoly_num_polys,
3763  mpoly_bounds,
3764  mpoly_bounds_size,
3765  p,
3766  psize,
3767  ic1,
3768  isr1,
3769  ic2,
3770  isr2,
3771  osr);
3772 }

+ 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  li,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3301 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Contains_Point_Polygon().

3312  {
3313  double px = coord_x(p, 0, ic1, isr1, osr);
3314  double py = coord_y(p, 1, ic1, isr1, osr);
3315 
3316  if (lbounds) {
3317  if (tol_eq(px, lbounds[0]) && tol_eq(py, lbounds[1]) && tol_eq(px, lbounds[2]) &&
3318  tol_eq(py, lbounds[3])) {
3319  return true;
3320  }
3321  }
3322 
3323  auto l_num_coords = lsize / compression_unit_size(ic2);
3324  for (int i = 0; i < l_num_coords; i += 2) {
3325  double lx = coord_x(l, i, ic2, isr2, osr);
3326  double ly = coord_y(l, i + 1, ic2, isr2, osr);
3327  if (tol_eq(px, lx) && tol_eq(py, ly)) {
3328  continue;
3329  }
3330  return false;
3331  }
3332  return true;
3333 }
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 3283 of file ExtensionFunctionsGeo.hpp.

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

3291  {
3292  double p1x = coord_x(p1, 0, ic1, isr1, osr);
3293  double p1y = coord_y(p1, 1, ic1, isr1, osr);
3294  double p2x = coord_x(p2, 0, ic2, isr2, osr);
3295  double p2y = coord_y(p2, 1, ic2, isr2, osr);
3296  double tolerance = tol(ic1, ic2);
3297  return tol_eq(p1x, p2x, tolerance) && tol_eq(p1y, p2y, tolerance);
3298 }
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 3336 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), and ST_Contains_Point_LineString().

3348  {
3349  auto exterior_ring_num_coords = poly_coords_size / compression_unit_size(ic2);
3350  if (poly_num_rings > 0) {
3351  exterior_ring_num_coords = poly_ring_sizes[0] * 2;
3352  }
3353  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic2);
3354 
3356  psize,
3357  poly_coords,
3358  exterior_ring_coords_size,
3359  poly_bounds,
3360  poly_bounds_size,
3361  0,
3362  ic1,
3363  isr1,
3364  ic2,
3365  isr2,
3366  osr);
3367 }
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 li, 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  li,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 3565 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Contains_MultiPolygon_LineString(), and ST_Contains_Polygon_Polygon().

3580  {
3581  if (poly_num_rings > 1) {
3582  return false; // TODO: support polygons with interior rings
3583  }
3584 
3585  auto poly_num_coords = poly_coords_size / compression_unit_size(ic1);
3586  auto lnum_coords = lsize / compression_unit_size(ic2);
3587  auto lnum_points = lnum_coords / 2;
3588  if (li != 0) {
3589  // Statically indexed linestring
3590  if (li < 0 || li > lnum_points) {
3591  li = lnum_points;
3592  }
3593  double lx = coord_x(l, 2 * (li - 1), ic2, isr2, osr);
3594  double ly = coord_y(l, 2 * (li - 1) + 1, ic2, isr2, osr);
3595 
3596  if (poly_bounds) {
3597  if (!box_contains_point(poly_bounds, poly_bounds_size, lx, ly)) {
3598  return false;
3599  }
3600  }
3601  // TODO: should be exclude
3602  return point_in_polygon_winding_number<double, EdgeBehavior::kIncludePointOnEdge>(
3603  poly_coords, poly_num_coords, lx, ly, ic1, isr1, osr);
3604  }
3605 
3606  // Bail out if poly bounding box doesn't contain linestring bounding box
3607  if (poly_bounds && lbounds) {
3608  if (!box_contains_box(poly_bounds, poly_bounds_size, lbounds, lbounds_size)) {
3609  return false;
3610  }
3611  }
3612 
3614  poly_coords, poly_num_coords, l, lnum_coords, ic1, isr1, ic2, isr2, osr);
3615 }
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 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)
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_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 3506 of file ExtensionFunctionsGeo.hpp.

3518  {
3519  return Contains_Polygon_Point_Impl<double, EdgeBehavior::kExcludePointOnEdge>(
3520  poly_coords,
3521  poly_coords_size,
3522  poly_ring_sizes,
3523  poly_num_rings,
3524  poly_bounds,
3525  poly_bounds_size,
3526  p,
3527  psize,
3528  ic1,
3529  isr1,
3530  ic2,
3531  isr2,
3532  osr);
3533 }
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 3618 of file ExtensionFunctionsGeo.hpp.

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

3634  {
3635  // TODO: needs to be extended, cover more cases
3636  // Right now only checking if simple poly1 (no holes) contains poly2's exterior shape
3637  if (poly1_num_rings > 1) {
3638  return false; // TODO: support polygons with interior rings
3639  }
3640 
3641  if (poly1_bounds && poly2_bounds) {
3642  if (!box_contains_box(
3643  poly1_bounds, poly1_bounds_size, poly2_bounds, poly2_bounds_size)) {
3644  return false;
3645  }
3646  }
3647 
3648  int64_t poly2_exterior_ring_coords_size = poly2_coords_size;
3649  if (poly2_num_rings > 0) {
3650  poly2_exterior_ring_coords_size =
3651  2 * poly2_ring_sizes[0] * compression_unit_size(ic2);
3652  }
3653  return ST_Contains_Polygon_LineString(poly1_coords,
3654  poly1_coords_size,
3655  poly1_ring_sizes,
3656  poly1_num_rings,
3657  poly1_bounds,
3658  poly1_bounds_size,
3659  poly2_coords,
3660  poly2_exterior_ring_coords_size,
3661  poly2_bounds,
3662  poly2_bounds_size,
3663  0,
3664  ic1,
3665  isr1,
3666  ic2,
3667  isr2,
3668  osr);
3669 }
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 li, 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,
int32_t  l1index,
int8_t *  l2,
int64_t  l2size,
int32_t  l2index,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2094 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Contains_LineString_LineString(), ST_DWithin_LineString_LineString(), and ST_Intersects_LineString_Linestring().

2105  {
2106  auto l1_num_coords = l1size / compression_unit_size(ic1);
2107  if (l1index != 0) {
2108  // l1 is a statically indexed linestring
2109  auto l1_num_points = l1_num_coords / 2;
2110  if (l1index < 0 || l1index > l1_num_points) {
2111  l1index = l1_num_points;
2112  }
2113  int8_t* p = l1 + 2 * (l1index - 1) * compression_unit_size(ic1);
2114  int64_t psize = 2 * compression_unit_size(ic1);
2116  p, psize, l2, l2size, l2index, ic1, isr1, ic2, isr2, osr, threshold);
2117  }
2118 
2119  auto l2_num_coords = l2size / compression_unit_size(ic2);
2120  if (l2index != 0) {
2121  // l2 is a statically indexed linestring
2122  auto l2_num_points = l2_num_coords / 2;
2123  if (l2index < 0 || l2index > l2_num_points) {
2124  l2index = l2_num_points;
2125  }
2126  int8_t* p = l2 + 2 * (l2index - 1) * compression_unit_size(ic2);
2127  int64_t psize = 2 * compression_unit_size(ic2);
2129  p, psize, l1, l1size, l1index, ic2, isr2, ic1, isr1, osr, threshold);
2130  }
2131 
2132  double threshold_squared = threshold * threshold;
2133  double dist_squared = 0.0;
2134  double l11x = coord_x(l1, 0, ic1, isr1, osr);
2135  double l11y = coord_y(l1, 1, ic1, isr1, osr);
2136  for (int32_t i1 = 2; i1 < l1_num_coords; i1 += 2) {
2137  double l12x = coord_x(l1, i1, ic1, isr1, osr);
2138  double l12y = coord_y(l1, i1 + 1, ic1, isr1, osr);
2139 
2140  double l21x = coord_x(l2, 0, ic2, isr2, osr);
2141  double l21y = coord_y(l2, 1, ic2, isr2, osr);
2142  for (int32_t i2 = 2; i2 < l2_num_coords; i2 += 2) {
2143  double l22x = coord_x(l2, i2, ic2, isr2, osr);
2144  double l22y = coord_y(l2, i2 + 1, ic2, isr2, osr);
2145 
2146  // double ldist_squared =
2147  // distance_line_line_squared(l11x, l11y, l12x, l12y, l21x, l21y, l22x, l22y);
2148  // TODO: fix distance_line_line_squared
2149  double ldist = distance_line_line(l11x, l11y, l12x, l12y, l21x, l21y, l22x, l22y);
2150  double ldist_squared = ldist * ldist;
2151 
2152  if (i1 == 2 && i2 == 2) {
2153  dist_squared = ldist_squared; // initialize dist with distance between the first
2154  // two segments
2155  } else if (dist_squared > ldist_squared) {
2156  dist_squared = ldist_squared;
2157  }
2158  if (tol_zero(dist_squared, TOLERANCE_DEFAULT_SQUARED)) {
2159  return 0.0; // Segments touch, short-circuit
2160  }
2161  if (dist_squared <= threshold_squared) {
2162  // If threashold_squared is defined and the calculated dist_squared dips under it,
2163  // short-circuit and return it
2164  return sqrt(dist_squared);
2165  }
2166 
2167  l21x = l22x; // advance to the next point on l2
2168  l21y = l22y;
2169  }
2170 
2171  l11x = l12x; // advance to the next point on l1
2172  l11y = l12y;
2173  }
2174  return sqrt(dist_squared);
2175 }
EXTENSION_NOINLINE double ST_Distance_Point_LineString(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t lindex, 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)
#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_LineString_Geodesic ( int8_t *  l1,
int64_t  l1size,
int32_t  l1index,
int8_t *  l2,
int64_t  l2size,
int32_t  l2index,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 1824 of file ExtensionFunctionsGeo.hpp.

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

1834  {
1835  // Currently only statically indexed LineStrings are supported
1836  auto l1points = l1size / (2 * compression_unit_size(ic1));
1837  if (l1index < 0 || l1index > l1points) {
1838  l1index = l1points; // Endpoint
1839  }
1840  double l1x = coord_x(l1, 2 * (l1index - 1), ic1, 4326, 4326);
1841  double l1y = coord_y(l1, 2 * (l1index - 1) + 1, ic1, 4326, 4326);
1842  auto l2points = l2size / (2 * compression_unit_size(ic2));
1843  if (l2index < 0 || l2index > l2points) {
1844  l2index = l2points; // Endpoint
1845  }
1846  double l2x = coord_x(l2, 2 * (l2index - 1), ic2, 4326, 4326);
1847  double l2y = coord_y(l2, 2 * (l2index - 1) + 1, ic2, 4326, 4326);
1848  return distance_in_meters(l1x, l1y, l2x, l2y);
1849 }
EXTENSION_NOINLINE double distance_in_meters(const double fromlon, const double fromlat, const double tolon, const double tolat)
Computes the distance, in meters, between two WGS-84 positions.
DEVICE ALWAYS_INLINE 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 ST_Distance_LineString_MultiPolygon ( int8_t *  l,
int64_t  lsize,
int32_t  lindex,
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 2256 of file ExtensionFunctionsGeo.hpp.

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

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

2270  {
2271  // TODO: revisit implementation, cover all cases
2272 
2273  auto lnum_coords = lsize / compression_unit_size(ic1);
2274  auto lnum_points = lnum_coords / 2;
2275  if (lindex != 0) {
2276  // Statically indexed linestring
2277  if (lindex < 0 || lindex > lnum_points) {
2278  lindex = lnum_points;
2279  }
2280  auto p = l + lindex * compression_unit_size(ic1);
2281  auto psize = 2 * compression_unit_size(ic1);
2283  psize,
2284  mpoly_coords,
2285  mpoly_coords_size,
2286  mpoly_ring_sizes,
2287  mpoly_num_rings,
2288  mpoly_poly_sizes,
2289  mpoly_num_polys,
2290  ic1,
2291  isr1,
2292  ic2,
2293  isr2,
2294  osr,
2295  threshold);
2296  }
2297 
2298  double min_distance = 0.0;
2299 
2300  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
2301  auto next_poly_coords = mpoly_coords;
2302  auto next_poly_ring_sizes = mpoly_ring_sizes;
2303 
2304  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
2305  auto poly_coords = next_poly_coords;
2306  auto poly_ring_sizes = next_poly_ring_sizes;
2307  auto poly_num_rings = mpoly_poly_sizes[poly];
2308  // Count number of coords in all of poly's rings, advance ring size pointer.
2309  int32_t poly_num_coords = 0;
2310  for (auto ring = 0; ring < poly_num_rings; ring++) {
2311  poly_num_coords += 2 * *next_poly_ring_sizes++;
2312  }
2313  auto poly_coords_size = poly_num_coords * compression_unit_size(ic2);
2314  next_poly_coords += poly_coords_size;
2315  double distance = ST_Distance_LineString_Polygon(l,
2316  lsize,
2317  lindex,
2318  poly_coords,
2319  poly_coords_size,
2320  poly_ring_sizes,
2321  poly_num_rings,
2322  ic1,
2323  isr1,
2324  ic2,
2325  isr2,
2326  osr,
2327  threshold);
2328  if (poly == 0 || min_distance > distance) {
2329  min_distance = distance;
2330  if (tol_zero(min_distance)) {
2331  min_distance = 0.0;
2332  break;
2333  }
2334  if (min_distance <= threshold) {
2335  return min_distance;
2336  }
2337  }
2338  }
2339 
2340  return min_distance;
2341 }
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 tol_zero(const double x, const double tolerance=TOLERANCE_DEFAULT)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
EXTENSION_NOINLINE double ST_Distance_LineString_Polygon(int8_t *l, int64_t lsize, int32_t lindex, 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:

+ Here is the caller graph for this function:

EXTENSION_INLINE double ST_Distance_LineString_Point ( int8_t *  l,
int64_t  lsize,
int32_t  lindex,
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 2078 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString().

2088  {
2090  p, psize, l, lsize, lindex, ic2, isr2, ic1, isr1, osr, threshold);
2091 }
EXTENSION_NOINLINE double ST_Distance_Point_LineString(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t lindex, 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,
int32_t  lindex,
int8_t *  p,
int64_t  psize,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 1808 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_LineString_Geodesic().

1817  {
1818  // Currently only statically indexed LineString is supported
1820  p, psize, l, lsize, lindex, ic2, isr2, ic1, isr1, osr);
1821 }
EXTENSION_NOINLINE double ST_Distance_Point_LineString_Geodesic(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t lindex, 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,
int32_t  lindex,
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 2178 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), distance_ring_linestring(), test_fsi::r, 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().

2190  {
2191  auto lnum_coords = lsize / compression_unit_size(ic1);
2192  auto lnum_points = lnum_coords / 2;
2193  if (lindex < 0 || lindex > lnum_points) {
2194  lindex = lnum_points;
2195  }
2196  auto p = l + lindex * compression_unit_size(ic1);
2197  auto psize = 2 * compression_unit_size(ic1);
2198  auto min_distance = ST_Distance_Point_Polygon(p,
2199  psize,
2200  poly_coords,
2201  poly_coords_size,
2202  poly_ring_sizes,
2203  poly_num_rings,
2204  ic1,
2205  isr1,
2206  ic2,
2207  isr2,
2208  osr,
2209  threshold);
2210  if (lindex != 0) {
2211  // Statically indexed linestring: return distance from the indexed point to poly
2212  return min_distance;
2213  }
2214  if (tol_zero(min_distance)) {
2215  // Linestring's first point is inside the poly
2216  return 0.0;
2217  }
2218  if (min_distance <= threshold) {
2219  return min_distance;
2220  }
2221 
2222  // Otherwise, linestring's first point is outside the external ring or inside
2223  // an internal ring. Measure minimum distance between linestring segments and
2224  // poly rings. Crossing a ring zeroes the distance and causes an early return.
2225  auto poly_ring_coords = poly_coords;
2226  for (auto r = 0; r < poly_num_rings; r++) {
2227  int64_t poly_ring_num_coords = poly_ring_sizes[r] * 2;
2228 
2229  auto distance = distance_ring_linestring(poly_ring_coords,
2230  poly_ring_num_coords,
2231  l,
2232  lnum_coords,
2233  ic2,
2234  isr2,
2235  ic1,
2236  isr1,
2237  osr,
2238  threshold);
2239  if (min_distance > distance) {
2240  min_distance = distance;
2241  if (tol_zero(min_distance)) {
2242  return 0.0;
2243  }
2244  if (min_distance <= threshold) {
2245  return min_distance;
2246  }
2247  }
2248 
2249  poly_ring_coords += poly_ring_num_coords * compression_unit_size(ic2);
2250  }
2251 
2252  return min_distance;
2253 }
tuple r
Definition: test_fsi.py:16
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  lindex,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2579 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_LineString_MultiPolygon().

2593  {
2595  lsize,
2596  lindex,
2597  mpoly_coords,
2598  mpoly_coords_size,
2599  mpoly_ring_sizes,
2600  mpoly_num_rings,
2601  mpoly_poly_sizes,
2602  mpoly_num_polys,
2603  ic2,
2604  isr2,
2605  ic1,
2606  isr1,
2607  osr,
2608  threshold);
2609 }
EXTENSION_NOINLINE double ST_Distance_LineString_MultiPolygon(int8_t *l, int64_t lsize, int32_t lindex, 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 2647 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().

2664  {
2665  double min_distance = 0.0;
2666 
2667  // Set specific poly pointers as we move through mpoly1's coords/ringsizes/polyrings
2668  // arrays.
2669  auto next_poly_coords = mpoly1_coords;
2670  auto next_poly_ring_sizes = mpoly1_ring_sizes;
2671 
2672  for (auto poly = 0; poly < mpoly1_num_polys; poly++) {
2673  auto poly_coords = next_poly_coords;
2674  auto poly_ring_sizes = next_poly_ring_sizes;
2675  auto poly_num_rings = mpoly1_poly_sizes[poly];
2676  // Count number of coords in all of poly's rings, advance ring size pointer.
2677  int32_t poly_num_coords = 0;
2678  for (auto ring = 0; ring < poly_num_rings; ring++) {
2679  poly_num_coords += 2 * *next_poly_ring_sizes++;
2680  }
2681  auto poly_coords_size = poly_num_coords * compression_unit_size(ic1);
2682  next_poly_coords += poly_coords_size;
2683  double distance = ST_Distance_Polygon_MultiPolygon(poly_coords,
2684  poly_coords_size,
2685  poly_ring_sizes,
2686  poly_num_rings,
2687  mpoly2_coords,
2688  mpoly2_coords_size,
2689  mpoly2_ring_sizes,
2690  mpoly2_num_rings,
2691  mpoly2_poly_sizes,
2692  mpoly2_num_polys,
2693  ic1,
2694  isr1,
2695  ic2,
2696  isr2,
2697  osr,
2698  threshold);
2699  if (poly == 0 || min_distance > distance) {
2700  min_distance = distance;
2701  if (tol_zero(min_distance)) {
2702  min_distance = 0.0;
2703  break;
2704  }
2705  if (min_distance <= threshold) {
2706  break;
2707  }
2708  }
2709  }
2710 
2711  return min_distance;
2712 }
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 2548 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_MultiPolygon().

2561  {
2563  psize,
2564  mpoly_coords,
2565  mpoly_coords_size,
2566  mpoly_ring_sizes,
2567  mpoly_num_rings,
2568  mpoly_poly_sizes,
2569  mpoly_num_polys,
2570  ic2,
2571  isr2,
2572  ic1,
2573  isr1,
2574  osr,
2575  threshold);
2576 }
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 2612 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Polygon_MultiPolygon().

2627  {
2628  return ST_Distance_Polygon_MultiPolygon(poly1_coords,
2629  poly1_coords_size,
2630  poly1_ring_sizes,
2631  poly1_num_rings,
2632  mpoly_coords,
2633  mpoly_coords_size,
2634  mpoly_ring_sizes,
2635  mpoly_num_rings,
2636  mpoly_poly_sizes,
2637  mpoly_num_polys,
2638  ic2,
2639  isr2,
2640  ic1,
2641  isr1,
2642  osr,
2643  threshold);
2644 }
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  lindex,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 1909 of file ExtensionFunctionsGeo.hpp.

References distance_point_linestring().

Referenced by ST_Distance_Point_Polygon().

1919  {
1921  p, psize, l, lsize, lindex, ic1, isr1, ic2, isr2, osr, true, threshold);
1922 }
DEVICE ALWAYS_INLINE double distance_point_linestring(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t lindex, 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  lindex,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 1925 of file ExtensionFunctionsGeo.hpp.

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

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

1935  {
1936  if (lindex != 0) { // Statically indexed linestring
1937  auto l_num_coords = lsize / compression_unit_size(ic2);
1938  auto l_num_points = l_num_coords / 2;
1939  if (lindex < 0 || lindex > l_num_points) {
1940  lindex = l_num_points; // Endpoint
1941  }
1942  double px = coord_x(p, 0, ic1, isr1, osr);
1943  double py = coord_y(p, 1, ic1, isr1, osr);
1944  double lx = coord_x(l, 2 * (lindex - 1), ic2, isr2, osr);
1945  double ly = coord_y(l, 2 * (lindex - 1) + 1, ic2, isr2, osr);
1946  return distance_point_point(px, py, lx, ly);
1947  }
1948 
1950  p, psize, l, lsize, lindex, ic1, isr1, ic2, isr2, osr, false, threshold);
1951 }
DEVICE ALWAYS_INLINE double distance_point_linestring(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t lindex, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, bool check_closed, double threshold)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
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_LineString_Geodesic ( int8_t *  p,
int64_t  psize,
int8_t *  l,
int64_t  lsize,
int32_t  lindex,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr 
)

Definition at line 1785 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Distance_LineString_Point_Geodesic().

1794  {
1795  // Currently only statically indexed LineString is supported
1796  double px = coord_x(p, 0, ic1, 4326, 4326);
1797  double py = coord_y(p, 1, ic1, 4326, 4326);
1798  auto lpoints = lsize / (2 * compression_unit_size(ic2));
1799  if (lindex < 0 || lindex > lpoints) {
1800  lindex = lpoints; // Endpoint
1801  }
1802  double lx = coord_x(l, 2 * (lindex - 1), ic2, 4326, 4326);
1803  double ly = coord_y(l, 2 * (lindex - 1) + 1, ic2, 4326, 4326);
1804  return distance_in_meters(px, py, lx, ly);
1805 }
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 2016 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Distance_LineString_MultiPolygon(), ST_Distance_MultiPolygon_Point(), and ST_DWithin_Point_MultiPolygon().

2029  {
2030  if (mpoly_num_polys <= 0) {
2031  return 0.0;
2032  }
2033  double min_distance = 0.0;
2034 
2035  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
2036  auto next_poly_coords = mpoly_coords;
2037  auto next_poly_ring_sizes = mpoly_ring_sizes;
2038 
2039  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
2040  auto poly_coords = next_poly_coords;
2041  auto poly_ring_sizes = next_poly_ring_sizes;
2042  auto poly_num_rings = mpoly_poly_sizes[poly];
2043  // Count number of coords in all of poly's rings, advance ring size pointer.
2044  int32_t poly_num_coords = 0;
2045  for (auto ring = 0; ring < poly_num_rings; ring++) {
2046  poly_num_coords += 2 * *next_poly_ring_sizes++;
2047  }
2048  auto poly_coords_size = poly_num_coords * compression_unit_size(ic2);
2049  next_poly_coords += poly_coords_size;
2050  double distance = ST_Distance_Point_Polygon(p,
2051  psize,
2052  poly_coords,
2053  poly_coords_size,
2054  poly_ring_sizes,
2055  poly_num_rings,
2056  ic1,
2057  isr1,
2058  ic2,
2059  isr2,
2060  osr,
2061  threshold);
2062  if (poly == 0 || min_distance > distance) {
2063  min_distance = distance;
2064  if (tol_zero(min_distance)) {
2065  min_distance = 0.0;
2066  break;
2067  }
2068  if (min_distance <= threshold) {
2069  break;
2070  }
2071  }
2072  }
2073 
2074  return min_distance;
2075 }
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 1734 of file ExtensionFunctionsGeo.hpp.

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

Referenced by ST_Intersects_Point_LineString(), and ST_Intersects_Point_Point().

1742  {
1743  double p1x = coord_x(p1, 0, ic1, isr1, osr);
1744  double p1y = coord_y(p1, 1, ic1, isr1, osr);
1745  double p2x = coord_x(p2, 0, ic2, isr2, osr);
1746  double p2y = coord_y(p2, 1, ic2, isr2, osr);
1747  return distance_point_point(p1x, p1y, p2x, p2y);
1748 }
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 1768 of file ExtensionFunctionsGeo.hpp.

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

1776  {
1777  double p1x = coord_x(p1, 0, ic1, 4326, 4326);
1778  double p1y = coord_y(p1, 1, ic1, 4326, 4326);
1779  double p2x = coord_x(p2, 0, ic2, 4326, 4326);
1780  double p2y = coord_y(p2, 1, ic2, 4326, 4326);
1781  return distance_in_meters(p1x, p1y, p2x, p2y);
1782 }
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:

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

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

Referenced by ST_DWithin_Point_Point().

1759  {
1760  double p1x = coord_x(p1, 0, ic1, isr1, osr);
1761  double p1y = coord_y(p1, 1, ic1, isr1, osr);
1762  double p2x = coord_x(p2, 0, ic2, isr2, osr);
1763  double p2y = coord_y(p2, 1, ic2, isr2, osr);
1764  return distance_point_point_squared(p1x, p1y, p2x, p2y);
1765 }
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 1954 of file ExtensionFunctionsGeo.hpp.

References compression_unit_size(), coord_x(), coord_y(), polygon_contains_point(), test_fsi::r, and ST_Distance_Point_ClosedLineString().

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

1965  {
1966  auto exterior_ring_num_coords = polysize / compression_unit_size(ic2);
1967  if (poly_num_rings > 0) {
1968  exterior_ring_num_coords = poly_ring_sizes[0] * 2;
1969  }
1970  auto exterior_ring_coords_size = exterior_ring_num_coords * compression_unit_size(ic2);
1971 
1972  double px = coord_x(p, 0, ic1, isr1, osr);
1973  double py = coord_y(p, 1, ic1, isr1, osr);
1974  if (!polygon_contains_point(poly, exterior_ring_num_coords, px, py, ic2, isr2, osr)) {
1975  // Outside the exterior ring
1977  psize,
1978  poly,
1979  exterior_ring_coords_size,
1980  0,
1981  ic1,
1982  isr1,
1983  ic2,
1984  isr2,
1985  osr,
1986  threshold);
1987  }
1988  // Inside exterior ring
1989  // Advance to first interior ring
1990  poly += exterior_ring_coords_size;
1991  // Check if one of the polygon's holes contains that point
1992  for (auto r = 1; r < poly_num_rings; r++) {
1993  auto interior_ring_num_coords = poly_ring_sizes[r] * 2;
1994  auto interior_ring_coords_size =
1995  interior_ring_num_coords * compression_unit_size(ic2);
1996  if (polygon_contains_point(poly, interior_ring_num_coords, px, py, ic2, isr2, osr)) {
1997  // Inside an interior ring
1999  psize,
2000  poly,
2001  interior_ring_coords_size,
2002  0,
2003  ic1,
2004  isr1,
2005  ic2,
2006  isr2,
2007  osr,
2008  threshold);
2009  }
2010  poly += interior_ring_coords_size;
2011  }
2012  return 0.0;
2013 }
tuple r
Definition: test_fsi.py:16
DEVICE ALWAYS_INLINE bool polygon_contains_point(const int8_t *poly, const int32_t poly_num_coords, const double px, const double py, const int32_t ic1, const int32_t isr1, const int32_t osr)
DEVICE ALWAYS_INLINE int32_t compression_unit_size(const int32_t ic)
DEVICE ALWAYS_INLINE double coord_y(const int8_t *data, const int32_t index, const int32_t ic, const int32_t isr, const int32_t osr)
EXTENSION_NOINLINE double ST_Distance_Point_ClosedLineString(int8_t *p, int64_t psize, int8_t *l, int64_t lsize, int32_t lindex, int32_t ic1, int32_t isr1, int32_t ic2, int32_t isr2, int32_t osr, double threshold)
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  li,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  threshold 
)

Definition at line 2371 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_LineString_Polygon().

2383  {
2385  lsize,
2386  li,
2387  poly_coords,
2388  poly_coords_size,
2389  poly_ring_sizes,
2390  poly_num_rings,
2391  ic2,
2392  isr2,
2393  ic1,
2394  isr2,
2395  osr,
2396  threshold);
2397 }
EXTENSION_NOINLINE double ST_Distance_LineString_Polygon(int8_t *l, int64_t lsize, int32_t lindex, 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 2485 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().

2500  {
2501  double min_distance = 0.0;
2502 
2503  // Set specific poly pointers as we move through the coords/ringsizes/polyrings arrays.
2504  auto next_poly_coords = mpoly_coords;
2505  auto next_poly_ring_sizes = mpoly_ring_sizes;
2506 
2507  for (auto poly = 0; poly < mpoly_num_polys; poly++) {
2508  auto poly_coords = next_poly_coords;
2509  auto poly_ring_sizes = next_poly_ring_sizes;
2510  auto poly_num_rings = mpoly_poly_sizes[poly];
2511  // Count number of coords in all of poly's rings, advance ring size pointer.
2512  int32_t poly_num_coords = 0;
2513  for (auto ring = 0; ring < poly_num_rings; ring++) {
2514  poly_num_coords += 2 * *next_poly_ring_sizes++;
2515  }
2516  auto poly_coords_size = poly_num_coords * compression_unit_size(ic2);
2517  next_poly_coords += poly_coords_size;
2518  double distance = ST_Distance_Polygon_Polygon(poly1_coords,
2519  poly1_coords_size,
2520  poly1_ring_sizes,
2521  poly1_num_rings,
2522  poly_coords,
2523  poly_coords_size,
2524  poly_ring_sizes,
2525  poly_num_rings,
2526  ic1,
2527  isr1,
2528  ic2,
2529  isr2,
2530  osr,
2531  threshold);
2532  if (poly == 0 || min_distance > distance) {
2533  min_distance = distance;
2534  if (tol_zero(min_distance)) {
2535  min_distance = 0.0;
2536  break;
2537  }
2538  if (min_distance <= threshold) {
2539  break;
2540  }
2541  }
2542  }
2543 
2544  return min_distance;
2545 }
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 2344 of file ExtensionFunctionsGeo.hpp.

References ST_Distance_Point_Polygon().

Referenced by ST_Distance_Polygon_Polygon().

2355  {
2356  return ST_Distance_Point_Polygon(p,
2357  psize,
2358  poly_coords,
2359  poly_coords_size,
2360  poly_ring_sizes,
2361  poly_num_rings,
2362  ic2,
2363  isr2,
2364  ic1,
2365  isr1,
2366  osr,
2367  threshold);
2368 }
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 2400 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().

2413  {
2414  // Check if poly1 contains the first point of poly2's shape, i.e. the external ring
2415  auto poly2_first_point_coords = poly2_coords;
2416  auto poly2_first_point_coords_size = compression_unit_size(ic2) * 2;
2417  auto min_distance = ST_Distance_Polygon_Point(poly1_coords,
2418  poly1_coords_size,
2419  poly1_ring_sizes,
2420  poly1_num_rings,
2421  poly2_first_point_coords,
2422  poly2_first_point_coords_size,
2423  ic1,
2424  isr1,
2425  ic2,
2426  isr2,
2427  osr,
2428  threshold);
2429  if (tol_zero(min_distance)) {
2430  // Polygons overlap
2431  return 0.0;
2432  }
2433  if (min_distance <= threshold) {
2434  return min_distance;
2435  }
2436 
2437  // Poly2's first point is either outside poly1's external ring or inside one of the
2438  // internal rings. Measure the smallest distance between a poly1 ring (external or
2439  // internal) and a poly2 ring (external or internal). If poly2 is completely outside
2440  // poly1, then the min distance would be between poly1's and poly2's external rings. If
2441  // poly2 is completely inside one of poly1 internal rings then the min distance would be
2442  // between that poly1 internal ring and poly2's external ring. If poly1 is completely
2443  // inside one of poly2 internal rings, min distance is between that internal ring and
2444  // poly1's external ring. In each case other rings don't get in the way. Any ring
2445  // intersection means zero distance - short-circuit and return.
2446 
2447  auto poly1_ring_coords = poly1_coords;
2448  for (auto r1 = 0; r1 < poly1_num_rings; r1++) {
2449  int64_t poly1_ring_num_coords = poly1_ring_sizes[r1] * 2;
2450 
2451  auto poly2_ring_coords = poly2_coords;
2452  for (auto r2 = 0; r2 < poly2_num_rings; r2++) {
2453  int64_t poly2_ring_num_coords = poly2_ring_sizes[r2] * 2;
2454 
2455  auto distance = distance_ring_ring(poly1_ring_coords,
2456  poly1_ring_num_coords,
2457  poly2_ring_coords,
2458  poly2_ring_num_coords,
2459  ic1,
2460  isr1,
2461  ic2,
2462  isr2,
2463  osr,
2464  threshold);
2465  if (min_distance > distance) {
2466  min_distance = distance;
2467  if (tol_zero(min_distance)) {
2468  return 0.0;
2469  }
2470  if (min_distance <= threshold) {
2471  return min_distance;
2472  }
2473  }
2474 
2475  poly2_ring_coords += poly2_ring_num_coords * compression_unit_size(ic2);
2476  }
2477 
2478  poly1_ring_coords += poly1_ring_num_coords * compression_unit_size(ic1);
2479  }
2480 
2481  return min_distance;
2482 }
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,
int32_t  l1index,
int8_t *  l2,
int64_t  l2size,
double *  l2bounds,
int64_t  l2bounds_size,
int32_t  l2index,
int32_t  ic1,
int32_t  isr1,
int32_t  ic2,
int32_t  isr2,
int32_t  osr,
double  distance_within 
)

Definition at line 2858 of file ExtensionFunctionsGeo.hpp.

References box_dwithin_box(), and ST_Distance_LineString_LineString().

2873  {
2874  if (l1bounds && l2bounds) {
2875  // Bounding boxes need to be transformed to output SR before proximity check
2876  if (!box_dwithin_box(l1bounds,
2877  l1bounds_size,
2878  isr1,
2879  l2bounds,
2880  l2bounds_size,
2881  isr2,
2882  osr,
2883  distance_within)) {
2884  return false;
2885  }
2886  }
2887 
2888  // May need to adjust the threshold by TOLERANCE_DEFAULT
2889  const double threshold = distance_within;
2891  l1size,
2892  l1index,
2893  l2,
2894  l2size,
2895  l2index,
2896  ic1,
2897  isr1,
2898  ic2,
2899  isr2,
2900  osr,
2901  threshold) <= distance_within;
2902 }
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_LineString(int8_t *l1, int64_t l1size, int32_t l1index, int8_t *l2, int64_t l2size, int32_t l2index, 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_MultiPolygon ( int8_t *  l1,
int64_t  l1size,
double *  l1bounds,
int64_t  l1bounds_size,
int32_t  l1index,
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,