Commit 39adc44a authored by Raúl Marín's avatar Raúl Marín

Optimize geometry_to_point

References #4676
parent 83c62dbf
Pipeline #141801333 passed with stage
in 29 minutes and 23 seconds
......@@ -15,6 +15,7 @@ Only tickets not included in 3.1.0alpha1
- #4490, Tweak function costs (Raúl Marín)
- #4672, Cache getSRSbySRID and getSRIDbySRS (Raúl Marín)
- #4676, Avoid decompressing toasted geometries to read only the header (Raúl Marín)
Optimize cast to Postgresql point type (Raúl Marín)
* Bug fixes *
- #4652, Fix several memory related bugs in ST_GeomFromGML (Raúl Marín)
......
......@@ -72,33 +72,22 @@ PG_FUNCTION_INFO_V1(geometry_to_point);
Datum geometry_to_point(PG_FUNCTION_ARGS)
{
Point *point;
LWGEOM *lwgeom;
LWPOINT *lwpoint;
POINT4D pt;
GSERIALIZED *geom;
POSTGIS_DEBUG(2, "geometry_to_point called");
if ( PG_ARGISNULL(0) )
if (PG_ARGISNULL(0))
PG_RETURN_NULL();
geom = PG_GETARG_GSERIALIZED_P(0);
if ( gserialized_get_type(geom) != POINTTYPE )
if (gserialized_get_type(geom) != POINTTYPE)
elog(ERROR, "geometry_to_point only accepts Points");
lwgeom = lwgeom_from_gserialized(geom);
if ( lwgeom_is_empty(lwgeom) )
if (gserialized_peek_first_point(geom, &pt) == LW_FAILURE)
PG_RETURN_NULL();
lwpoint = lwgeom_as_lwpoint(lwgeom);
point = (Point*)palloc(sizeof(Point));
point->x = lwpoint_get_x(lwpoint);
point->y = lwpoint_get_y(lwpoint);
lwpoint_free(lwpoint);
PG_FREE_IF_COPY(geom,0);
point = (Point *)palloc(sizeof(Point));
point->x = pt.x;
point->y = pt.y;
PG_RETURN_POINT_P(point);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment