788 GBOX gbox, gbox1, gbox2;
793 double xwidth, ywidth;
796 Datum d1 = PG_GETARG_DATUM(0);
797 Datum d2 = PG_GETARG_DATUM(1);
807 elog(ERROR,
"Error in geography_bestsrid calling gserialized_get_gbox_p(g1, &gbox1)");
809 POSTGIS_DEBUGF(4,
"calculated gbox = %s",
gbox_to_string(&gbox1));
818 elog(ERROR,
"Error in geography_bestsrid calling gserialized_get_gbox_p(g2, &gbox2)");
826 gbox = gbox2 = gbox1;
830 if ( empty1 && empty2 )
847 POSTGIS_DEBUGF(2,
"xwidth %g", xwidth);
848 POSTGIS_DEBUGF(2,
"ywidth %g", ywidth);
849 POSTGIS_DEBUGF(2,
"center POINT(%g %g)", center.
x, center.
y);
852 if ( center.
y > 70.0 && ywidth < 45.0 )
854 PG_RETURN_INT32(SRID_NORTH_LAMBERT);
858 if ( center.
y < -70.0 && ywidth < 45.0 )
860 PG_RETURN_INT32(SRID_SOUTH_LAMBERT);
871 int zone = floor((center.
x + 180.0) / 6.0);
873 if ( zone > 59 ) zone = 59;
876 if ( center.
y < 0.0 )
878 PG_RETURN_INT32( SRID_SOUTH_UTM_START + zone );
883 PG_RETURN_INT32( SRID_NORTH_UTM_START + zone );
896 int yzone = 3 + floor(center.
y / 30.0);
899 if ( (yzone == 2 || yzone == 3) && xwidth < 30.0 )
901 xzone = 6 + floor(center.
x / 30.0);
904 else if ( (yzone == 1 || yzone == 4) && xwidth < 45.0 )
906 xzone = 4 + floor(center.
x / 45.0);
909 else if ( (yzone == 0 || yzone == 5) && xwidth < 90.0 )
911 xzone = 2 + floor(center.
x / 90.0);
917 PG_RETURN_INT32(SRID_LAEA_START + 20 * yzone + xzone);
925 PG_RETURN_INT32(SRID_WORLD_MERCATOR);
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.
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
int gbox_centroid(const GBOX *gbox, POINT2D *out)
Computes the average(ish) center of the box and returns success.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout)
Update the output GBOX to be large enough to include both inputs.
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.