784 GBOX gbox, gbox1, gbox2;
789 double xwidth, ywidth;
792 Datum d1 = PG_GETARG_DATUM(0);
793 Datum d2 = PG_GETARG_DATUM(1);
803 elog(ERROR,
"Error in geography_bestsrid calling gserialized_get_gbox_p(g1, &gbox1)");
805 POSTGIS_DEBUGF(4,
"calculated gbox = %s",
gbox_to_string(&gbox1));
814 elog(ERROR,
"Error in geography_bestsrid calling gserialized_get_gbox_p(g2, &gbox2)");
822 gbox = gbox2 = gbox1;
826 if ( empty1 && empty2 )
843 POSTGIS_DEBUGF(2,
"xwidth %g", xwidth);
844 POSTGIS_DEBUGF(2,
"ywidth %g", ywidth);
845 POSTGIS_DEBUGF(2,
"center POINT(%g %g)", center.
x, center.
y);
848 if ( center.
y > 70.0 && ywidth < 45.0 )
850 PG_RETURN_INT32(SRID_NORTH_LAMBERT);
854 if ( center.
y < -70.0 && ywidth < 45.0 )
856 PG_RETURN_INT32(SRID_SOUTH_LAMBERT);
867 int zone = floor((center.
x + 180.0) / 6.0);
869 if ( zone > 59 ) zone = 59;
872 if ( center.
y < 0.0 )
874 PG_RETURN_INT32( SRID_SOUTH_UTM_START + zone );
879 PG_RETURN_INT32( SRID_NORTH_UTM_START + zone );
892 int yzone = 3 + floor(center.
y / 30.0);
895 if ( (yzone == 2 || yzone == 3) && xwidth < 30.0 )
897 xzone = 6 + floor(center.
x / 30.0);
900 else if ( (yzone == 1 || yzone == 4) && xwidth < 45.0 )
902 xzone = 4 + floor(center.
x / 45.0);
905 else if ( (yzone == 0 || yzone == 5) && xwidth < 90.0 )
907 xzone = 2 + floor(center.
x / 90.0);
913 PG_RETURN_INT32(SRID_LAEA_START + 20 * yzone + xzone);
921 PG_RETURN_INT32(SRID_WORLD_MERCATOR);
int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout)
Update the output GBOX to be large enough to include both inputs.
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
double gbox_angular_height(const GBOX *gbox)
GBOX utility functions to figure out coverage/location on the globe.
double gbox_angular_width(const GBOX *gbox)
Returns the angular width (longitudinal span) of the box in radians.
int gbox_centroid(const GBOX *gbox, POINT2D *out)
Computes the average(ish) center of the box and returns success.