ST_Distance_Spheroid is kinda broken (#677)

git-svn-id: http://svn.osgeo.org/postgis/trunk@6516 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
Paul Ramsey 2010-12-28 00:24:58 +00:00
parent 1e2f558d94
commit d96fda6248
3 changed files with 21 additions and 6 deletions

View file

@ -174,9 +174,9 @@ int gbox_overlaps(const GBOX *g1, const GBOX *g2)
{
/* Make sure our boxes have the same dimensionality */
if ( ! (FLAGS_GET_Z(g1->flags) == FLAGS_GET_Z(g2->flags) &&
FLAGS_GET_M(g1->flags) == FLAGS_GET_M(g2->flags) &&
FLAGS_GET_GEODETIC(g1->flags) == FLAGS_GET_GEODETIC(g2->flags) ) )
if ( (FLAGS_GET_Z(g1->flags) != FLAGS_GET_Z(g2->flags)) ||
(FLAGS_GET_M(g1->flags) != FLAGS_GET_M(g2->flags)) ||
(FLAGS_GET_GEODETIC(g1->flags) != FLAGS_GET_GEODETIC(g2->flags)) )
{
lwerror("gbox_overlaps: geometries have mismatched dimensionality");
}
@ -593,6 +593,10 @@ static int lwcollection_calculate_gbox_cartesian(LWCOLLECTION *coll, GBOX *gbox)
{
if ( lwgeom_calculate_gbox_cartesian((LWGEOM*)(coll->geoms[i]), &subbox) == LW_SUCCESS )
{
/* Keep a copy of the sub-bounding box for later */
if ( coll->geoms[i]->bbox )
lwfree(coll->geoms[i]->bbox);
coll->geoms[i]->bbox = gbox_copy(&subbox);
if ( first )
{
gbox_duplicate(&subbox, gbox);
@ -611,8 +615,7 @@ static int lwcollection_calculate_gbox_cartesian(LWCOLLECTION *coll, GBOX *gbox)
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
{
if ( ! lwgeom ) return LW_FAILURE;
LWDEBUGF(4, "lwgeom_calculate_gbox got type (%d) - %s",
lwgeom->type, lwtype_name(lwgeom->type));
LWDEBUGF(4, "lwgeom_calculate_gbox got type (%d) - %s", lwgeom->type, lwtype_name(lwgeom->type));
switch (lwgeom->type)
{

View file

@ -1791,8 +1791,10 @@ double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, co
int type1, type2;
int check_intersection = LW_FALSE;
GBOX gbox1, gbox2;
gbox1.flags = gbox2.flags = 0;
gbox_init(&gbox1);
gbox_init(&gbox2);
assert(lwgeom1);
assert(lwgeom2);
@ -2306,6 +2308,10 @@ static int lwcollection_calculate_gbox_geodetic(const LWCOLLECTION *coll, GBOX *
{
if ( lwgeom_calculate_gbox_geodetic((LWGEOM*)(coll->geoms[i]), &subbox) == LW_SUCCESS )
{
/* Keep a copy of the sub-bounding box for later */
if ( coll->geoms[i]->bbox )
lwfree(coll->geoms[i]->bbox);
coll->geoms[i]->bbox = gbox_copy(&subbox);
if ( first )
{
gbox_duplicate(&subbox, gbox);
@ -2326,6 +2332,7 @@ int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
int result = LW_FAILURE;
LWDEBUGF(4, "got type %d", geom->type);
/* Add a geodetic flag to the incoming gbox */
gbox->flags = gflags(FLAGS_GET_Z(geom->flags),FLAGS_GET_M(geom->flags),1);
switch (geom->type)

View file

@ -507,8 +507,13 @@ Datum geometry_distance_spheroid(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
}
/* Get #LWGEOM structures */
lwgeom1 = pglwgeom_deserialize(geom1);
lwgeom2 = pglwgeom_deserialize(geom2);
/* We are going to be calculating geodetic distances */
lwgeom_set_geodetic(lwgeom1, LW_TRUE);
lwgeom_set_geodetic(lwgeom2, LW_TRUE);
distance = lwgeom_distance_spheroid(lwgeom1, lwgeom2, sphere, 0.0);