From: Regina Obe Date: Mon, 30 Nov 2015 16:24:57 +0000 (+0000) Subject: gserialized_from_lwgeom get rid of is_geodetic ignored arg , X-Git-Tag: 2.3.0beta1~352 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27266edf40cd1228069d80b9fa05ef2a3c45709c;p=postgis gserialized_from_lwgeom get rid of is_geodetic ignored arg , force geography_serialize to always return a geography closes pull request #72 closes ticket #3361 git-svn-id: http://svn.osgeo.org/postgis/trunk@14453 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_geodetic.c b/liblwgeom/cunit/cu_geodetic.c index 51d383dac..fa0436f62 100644 --- a/liblwgeom/cunit/cu_geodetic.c +++ b/liblwgeom/cunit/cu_geodetic.c @@ -345,7 +345,7 @@ static LWGEOM* lwgeom_over_gserialized(char *wkt) GSERIALIZED *g; lwg = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE); - g = gserialized_from_lwgeom(lwg, 1, 0); + g = gserialized_from_lwgeom(lwg, 0); lwgeom_free(lwg); return lwgeom_from_gserialized(g); } @@ -799,7 +799,7 @@ static LWGEOM* lwgeom_over_gserialized(char *wkt, GSERIALIZED **g) lwg = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE); FLAGS_SET_GEODETIC(lwg->flags, 1); - *g = gserialized_from_lwgeom(lwg, 1, 0); + *g = gserialized_from_lwgeom(lwg, 0); lwgeom_free(lwg); return lwgeom_from_gserialized(*g); } @@ -901,7 +901,7 @@ static void test_gserialized_from_lwgeom(void) geom = lwgeom_from_wkt("POINT(0 0.2)", LW_PARSER_CHECK_NONE); FLAGS_SET_GEODETIC(geom->flags, 1); - g = gserialized_from_lwgeom(geom, 1, 0); + g = gserialized_from_lwgeom(geom, 0); type = gserialized_get_type(g); CU_ASSERT_EQUAL( type, POINTTYPE ); inspect = (double*)g; @@ -911,7 +911,7 @@ static void test_gserialized_from_lwgeom(void) geom = lwgeom_from_wkt("POLYGON((-1 -1, -1 2.5, 2 2, 2 -1, -1 -1), (0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE); FLAGS_SET_GEODETIC(geom->flags, 1); - g = gserialized_from_lwgeom(geom, 1, 0); + g = gserialized_from_lwgeom(geom, 0); type = gserialized_get_type(g); CU_ASSERT_EQUAL( type, POLYGONTYPE ); inspect = (double*)g; @@ -921,7 +921,7 @@ static void test_gserialized_from_lwgeom(void) geom = lwgeom_from_wkt("MULTILINESTRING((0 0, 1 1),(0 0.1, 1 1))", LW_PARSER_CHECK_NONE); FLAGS_SET_GEODETIC(geom->flags, 1); - g = gserialized_from_lwgeom(geom, 1, 0); + g = gserialized_from_lwgeom(geom, 0); type = gserialized_get_type(g); CU_ASSERT_EQUAL( type, MULTILINETYPE ); inspect = (double*)g; diff --git a/liblwgeom/cunit/cu_libgeom.c b/liblwgeom/cunit/cu_libgeom.c index 6fb3187d1..accf7d2a7 100644 --- a/liblwgeom/cunit/cu_libgeom.c +++ b/liblwgeom/cunit/cu_libgeom.c @@ -283,7 +283,7 @@ static void test_lwgeom_from_gserialized(void) geom = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE); lwgeom_add_bbox(geom); if ( geom->bbox ) gbox_float_round(geom->bbox); - g = gserialized_from_lwgeom(geom, 0, 0); + g = gserialized_from_lwgeom(geom, 0); geom2 = lwgeom_from_gserialized(g); out_ewkt = lwgeom_to_ewkt(geom2); @@ -337,7 +337,7 @@ static void test_gserialized_is_empty(void) { // i = 11; LWGEOM *lw = lwgeom_from_wkt(cases[i].wkt, LW_PARSER_CHECK_NONE); - GSERIALIZED *g = gserialized_from_lwgeom(lw, 0, 0); + GSERIALIZED *g = gserialized_from_lwgeom(lw, 0); int ie = gserialized_is_empty(g); // printf("%s: we say %d, they say %d\n", cases[i].wkt, cases[i].isempty, ie); CU_ASSERT_EQUAL(ie, cases[i].isempty); @@ -420,7 +420,7 @@ static void test_on_gser_lwgeom_count_vertices(void) lwgeom = lwgeom_from_wkt("MULTIPOINT(-1 -1,-1 2.5,2 2,2 -1,1 1,2 2,4 5)", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(lwgeom_count_vertices(lwgeom),7); - g_ser1 = gserialized_from_lwgeom(lwgeom, 1, &ret_size); + g_ser1 = gserialized_from_lwgeom(lwgeom, &ret_size); lwgeom_free(lwgeom); lwgeom = lwgeom_from_gserialized(g_ser1); @@ -1055,7 +1055,7 @@ void test_gbox_same_2d(void) /* Serializing a GBOX with precise coordinates renders the boxes not strictly equal, * but still equal according to gbox_same_2d_float. */ - GSERIALIZED* s3 = gserialized_from_lwgeom(g3, LW_FALSE, NULL); + GSERIALIZED* s3 = gserialized_from_lwgeom(g3, NULL); GBOX s3box; gserialized_read_gbox_p(s3, &s3box); diff --git a/liblwgeom/cunit/cu_surface.c b/liblwgeom/cunit/cu_surface.c index bf3c27138..4adaa7f48 100644 --- a/liblwgeom/cunit/cu_surface.c +++ b/liblwgeom/cunit/cu_surface.c @@ -99,7 +99,7 @@ void triangle_parse(void) /* geography support */ geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2))", LW_PARSER_CHECK_NONE); - g = gserialized_from_lwgeom(geom, 1, 0); + g = gserialized_from_lwgeom(geom, 0); CU_ASSERT_EQUAL(gserialized_get_type(g), TRIANGLETYPE); lwgeom_free(geom); lwfree(g); @@ -225,7 +225,7 @@ void tin_parse(void) /* geography support */ geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE); - g = gserialized_from_lwgeom(geom, 1, 0); + g = gserialized_from_lwgeom(geom, 0); CU_ASSERT_EQUAL(gserialized_get_type(g), TINTYPE); lwgeom_free(geom); lwfree(g); @@ -362,7 +362,7 @@ void polyhedralsurface_parse(void) /* geography support */ geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE); - g = gserialized_from_lwgeom(geom, 1, 0); + g = gserialized_from_lwgeom(geom, 0); CU_ASSERT_EQUAL(gserialized_get_type(g), POLYHEDRALSURFACETYPE); lwgeom_free(geom); lwfree(g); diff --git a/liblwgeom/g_serialized.c b/liblwgeom/g_serialized.c index ced4177b2..a5aa99961 100644 --- a/liblwgeom/g_serialized.c +++ b/liblwgeom/g_serialized.c @@ -903,7 +903,7 @@ static size_t gserialized_from_gbox(const GBOX *gbox, uint8_t *buf) /* Public function */ -GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, int is_geodetic, size_t *size) +GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, size_t *size) { size_t expected_size = 0; size_t return_size = 0; diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 84abc520b..46cf6ed79 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -1900,7 +1900,7 @@ extern size_t gserialized_from_lwgeom_size(const LWGEOM *geom); * will contain the size of the final output, which is useful for setting the PgSQL * VARSIZE information. */ -extern GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, int is_geodetic, size_t *size); +extern GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, size_t *size); /** * Allocate a new #LWGEOM from a #GSERIALIZED. The resulting #LWGEOM will have coordinates diff --git a/libpgcommon/lwgeom_pg.c b/libpgcommon/lwgeom_pg.c index b989c3d3c..14eac85d9 100644 --- a/libpgcommon/lwgeom_pg.c +++ b/libpgcommon/lwgeom_pg.c @@ -217,11 +217,12 @@ pg_install_lwgeom_handlers(void) */ GSERIALIZED* geography_serialize(LWGEOM *lwgeom) { - static int is_geodetic = 1; size_t ret_size = 0; GSERIALIZED *g = NULL; + /** force to geodetic in case it's not **/ + lwgeom_set_geodetic(lwgeom, true); - g = gserialized_from_lwgeom(lwgeom, is_geodetic, &ret_size); + g = gserialized_from_lwgeom(lwgeom, &ret_size); if ( ! g ) lwpgerror("Unable to serialize lwgeom."); SET_VARSIZE(g, ret_size); return g; @@ -234,11 +235,10 @@ GSERIALIZED* geography_serialize(LWGEOM *lwgeom) */ GSERIALIZED* geometry_serialize(LWGEOM *lwgeom) { - static int is_geodetic = 0; size_t ret_size = 0; GSERIALIZED *g = NULL; - g = gserialized_from_lwgeom(lwgeom, is_geodetic, &ret_size); + g = gserialized_from_lwgeom(lwgeom, &ret_size); if ( ! g ) lwpgerror("Unable to serialize lwgeom."); SET_VARSIZE(g, ret_size); return g; diff --git a/postgis/geography_measurement.c b/postgis/geography_measurement.c index d5d4804d3..45ce96b16 100644 --- a/postgis/geography_measurement.c +++ b/postgis/geography_measurement.c @@ -673,7 +673,7 @@ Datum geography_point_outside(PG_FUNCTION_ARGS) GSERIALIZED *g = NULL; GSERIALIZED *g_out = NULL; size_t g_out_size; - LWPOINT *lwpoint = NULL; + LWGEOM *lwpoint = NULL; POINT2D pt; /* Get our geometry object loaded into memory. */ @@ -691,9 +691,12 @@ Datum geography_point_outside(PG_FUNCTION_ARGS) /* Get an exterior point, based on this gbox */ gbox_pt_outside(&gbox, &pt); - lwpoint = lwpoint_make2d(4326, pt.x, pt.y); - - g_out = gserialized_from_lwgeom((LWGEOM*)lwpoint, 1, &g_out_size); + lwpoint = (LWGEOM*) lwpoint_make2d(4326, pt.x, pt.y); + /* TODO: Investigate where this is used, this was probably not + * returning a geography object before. How did this miss checking + */ + lwgeom_set_geodetic(lwpoint, true); + g_out = gserialized_from_lwgeom(lwpoint, &g_out_size); SET_VARSIZE(g_out, g_out_size); PG_FREE_IF_COPY(g, 0); diff --git a/postgis/lwgeom_dumppoints.c b/postgis/lwgeom_dumppoints.c index 7c2757834..d9d984b54 100644 --- a/postgis/lwgeom_dumppoints.c +++ b/postgis/lwgeom_dumppoints.c @@ -233,7 +233,7 @@ Datum LWGEOM_dumppoints(PG_FUNCTION_ARGS) { pathpt[0] = PointerGetDatum(construct_array(state->path, state->pathlen+1, INT4OID, state->typlen, state->byval, state->align)); - pathpt[1] = PointerGetDatum(gserialized_from_lwgeom((LWGEOM*)lwpoint,0,0)); + pathpt[1] = PointerGetDatum(gserialized_from_lwgeom((LWGEOM*)lwpoint,0)); tuple = heap_form_tuple(funcctx->tuple_desc, pathpt, isnull); result = HeapTupleGetDatum(tuple); diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c index 9efc12538..b22f1c707 100644 --- a/postgis/lwgeom_geos.c +++ b/postgis/lwgeom_geos.c @@ -1375,7 +1375,7 @@ Datum ST_OffsetCurve(PG_FUNCTION_ARGS) if (lwgeom_result == NULL) lwpgerror("ST_OffsetCurve: lwgeom_offsetcurve returned NULL"); - gser_result = gserialized_from_lwgeom(lwgeom_result, 0, 0); + gser_result = gserialized_from_lwgeom(lwgeom_result, 0); lwgeom_free(lwgeom_input); lwgeom_free(lwgeom_result); PG_RETURN_POINTER(gser_result); @@ -3566,7 +3566,7 @@ Datum cluster_within_distance_garray(PG_FUNCTION_ARGS) result_array_data = palloc(nclusters * sizeof(Datum)); for (i=0; i