Datum LWGEOM_translate(PG_FUNCTION_ARGS)
{
PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
+ PG_LWGEOM *oldgeom;
+ char *srl = SERIALIZED_FORM(geom);
+
double xoff = PG_GETARG_FLOAT8(1);
double yoff = PG_GETARG_FLOAT8(2);
double zoff = PG_GETARG_FLOAT8(3);
- lwgeom_translate_recursive(SERIALIZED_FORM(geom), xoff, yoff, zoff);
+ lwgeom_translate_recursive(srl, xoff, yoff, zoff);
+
+ if ( TYPE_HASBBOX(geom->type) )
+ {
+ if ( ! compute_serialized_bbox_p(srl, getbox2d_internal(srl)) )
+ {
+ oldgeom = geom;
+ geom = PG_LWGEOM_construct(srl, lwgeom_getSRID(geom), 0);
+ lwfree(oldgeom);
+ }
+ }
PG_RETURN_POINTER(geom);
}
PG_FUNCTION_INFO_V1(transform_geom);
Datum transform_geom(PG_FUNCTION_ARGS)
{
- PG_LWGEOM *geom;
+ PG_LWGEOM *geom, *oldgeom;
PG_LWGEOM *result=NULL;
PJ *input_pj,*output_pj;
char *input_proj4, *output_proj4;
text *input_proj4_text;
text *output_proj4_text;
int32 result_srid ;
+ char *srl;
result_srid = PG_GETARG_INT32(3);
if (result_srid == -1)
pj_free(output_pj);
pfree(input_proj4); pfree(output_proj4);
+ // Compute bbox if input had one
+ if ( TYPE_HASBBOX(result->type) )
+ {
+ srl = SERIALIZED_FORM(result);
+ if ( ! compute_serialized_bbox_p(srl, getbox2d_internal(srl)) )
+ {
+ oldgeom = result;
+ result = PG_LWGEOM_construct(srl, lwgeom_getSRID(result), 0);
+ lwfree(oldgeom);
+ }
+ }
+
PG_RETURN_POINTER(result); // new geometry
}