mirror of
https://git.osgeo.org/gitea/postgis/postgis
synced 2024-10-23 00:22:38 +00:00
Use lwvarlena_t for encoded polyline
This commit is contained in:
parent
b342086449
commit
80e13b74b5
|
@ -22,19 +22,13 @@
|
|||
static void
|
||||
do_encoded_polyline_test(char* in, int precision, char* out)
|
||||
{
|
||||
LWGEOM* g;
|
||||
char* h;
|
||||
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
|
||||
lwvarlena_t *v = lwgeom_to_encoded_polyline(g, precision);
|
||||
|
||||
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
|
||||
h = lwgeom_to_encoded_polyline(g, precision);
|
||||
|
||||
if (strcmp(h, out))
|
||||
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
|
||||
|
||||
CU_ASSERT_STRING_EQUAL(h, out);
|
||||
ASSERT_VARLENA_EQUAL(v, out);
|
||||
|
||||
lwgeom_free(g);
|
||||
lwfree(h);
|
||||
lwfree(v);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -1702,7 +1702,7 @@ extern lwvarlena_t* lwgeom_to_kml2(const LWGEOM *geom, int precision, const char
|
|||
extern lwvarlena_t* lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox);
|
||||
extern lwvarlena_t* lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid);
|
||||
extern lwvarlena_t* lwgeom_to_svg(const LWGEOM *geom, int precision, int relative);
|
||||
extern char* lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision);
|
||||
extern lwvarlena_t* lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision);
|
||||
|
||||
/**
|
||||
* Create an LWGEOM object from a GeoJSON representation
|
||||
|
|
|
@ -26,13 +26,13 @@
|
|||
#include "stringbuffer.h"
|
||||
#include "liblwgeom_internal.h"
|
||||
|
||||
static char* lwline_to_encoded_polyline(const LWLINE*, int precision);
|
||||
static char* lwmmpoint_to_encoded_polyline(const LWMPOINT*, int precision);
|
||||
static char* pointarray_to_encoded_polyline(const POINTARRAY*, int precision);
|
||||
static lwvarlena_t *lwline_to_encoded_polyline(const LWLINE *, int precision);
|
||||
static lwvarlena_t *lwmmpoint_to_encoded_polyline(const LWMPOINT *, int precision);
|
||||
static lwvarlena_t *pointarray_to_encoded_polyline(const POINTARRAY *, int precision);
|
||||
|
||||
/* takes a GEOMETRY and returns an Encoded Polyline representation */
|
||||
extern char*
|
||||
lwgeom_to_encoded_polyline(const LWGEOM* geom, int precision)
|
||||
extern lwvarlena_t *
|
||||
lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision)
|
||||
{
|
||||
int type = geom->type;
|
||||
switch (type)
|
||||
|
@ -48,37 +48,37 @@ lwgeom_to_encoded_polyline(const LWGEOM* geom, int precision)
|
|||
}
|
||||
}
|
||||
|
||||
static char*
|
||||
lwline_to_encoded_polyline(const LWLINE* line, int precision)
|
||||
static lwvarlena_t *
|
||||
lwline_to_encoded_polyline(const LWLINE *line, int precision)
|
||||
{
|
||||
return pointarray_to_encoded_polyline(line->points, precision);
|
||||
}
|
||||
|
||||
static char*
|
||||
lwmmpoint_to_encoded_polyline(const LWMPOINT* mpoint, int precision)
|
||||
static lwvarlena_t *
|
||||
lwmmpoint_to_encoded_polyline(const LWMPOINT *mpoint, int precision)
|
||||
{
|
||||
LWLINE* line = lwline_from_lwmpoint(mpoint->srid, mpoint);
|
||||
char* encoded_polyline = lwline_to_encoded_polyline(line, precision);
|
||||
lwvarlena_t *encoded_polyline = lwline_to_encoded_polyline(line, precision);
|
||||
|
||||
lwline_free(line);
|
||||
return encoded_polyline;
|
||||
}
|
||||
|
||||
static char*
|
||||
pointarray_to_encoded_polyline(const POINTARRAY* pa, int precision)
|
||||
static lwvarlena_t *
|
||||
pointarray_to_encoded_polyline(const POINTARRAY *pa, int precision)
|
||||
{
|
||||
uint32_t i;
|
||||
const POINT2D* prevPoint;
|
||||
int* delta;
|
||||
char* encoded_polyline = NULL;
|
||||
stringbuffer_t* sb;
|
||||
double scale = pow(10, precision);
|
||||
|
||||
/* Empty input is empty string */
|
||||
if (pa->npoints == 0) {
|
||||
encoded_polyline = lwalloc(1 * sizeof(char));
|
||||
encoded_polyline[0] = 0;
|
||||
return encoded_polyline;
|
||||
if (pa->npoints == 0)
|
||||
{
|
||||
lwvarlena_t *v = lwalloc(LWVARHDRSZ);
|
||||
LWSIZE_SET(v->size, LWVARHDRSZ);
|
||||
return v;
|
||||
}
|
||||
|
||||
delta = lwalloc(2 * sizeof(int) * pa->npoints);
|
||||
|
@ -132,8 +132,8 @@ pointarray_to_encoded_polyline(const POINTARRAY* pa, int precision)
|
|||
}
|
||||
|
||||
lwfree(delta);
|
||||
encoded_polyline = stringbuffer_getstringcopy(sb);
|
||||
lwvarlena_t *v = stringbuffer_getvarlenacopy(sb);
|
||||
stringbuffer_destroy(sb);
|
||||
|
||||
return encoded_polyline;
|
||||
return v;
|
||||
}
|
||||
|
|
|
@ -556,9 +556,7 @@ Datum LWGEOM_asEncodedPolyline(PG_FUNCTION_ARGS)
|
|||
{
|
||||
GSERIALIZED *geom;
|
||||
LWGEOM *lwgeom;
|
||||
char *encodedpolyline;
|
||||
int precision = 5;
|
||||
text *result;
|
||||
|
||||
if ( PG_ARGISNULL(0) ) PG_RETURN_NULL();
|
||||
|
||||
|
@ -576,12 +574,5 @@ Datum LWGEOM_asEncodedPolyline(PG_FUNCTION_ARGS)
|
|||
if ( precision < 0 ) precision = 5;
|
||||
}
|
||||
|
||||
encodedpolyline = lwgeom_to_encoded_polyline(lwgeom, precision);
|
||||
lwgeom_free(lwgeom);
|
||||
PG_FREE_IF_COPY(geom, 0);
|
||||
|
||||
result = cstring_to_text(encodedpolyline);
|
||||
lwfree(encodedpolyline);
|
||||
|
||||
PG_RETURN_TEXT_P(result);
|
||||
PG_RETURN_TEXT_P(lwgeom_to_encoded_polyline(lwgeom, precision));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue