Skip to content

Commit

Permalink
Optimize temporalseq_minus_timestampset
Browse files Browse the repository at this point in the history
  • Loading branch information
Esteban Zimanyi committed Mar 25, 2020
1 parent 5ab7432 commit 6d043de
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions point/src/tpoint_spatialfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,27 +409,6 @@ geompoint_trajectory_lwline(Datum value1, Datum value2)

/* Compute a trajectory from a set of points. The result is either a line or a
* multipoint depending on whether the interpolation is step or linear */
static Datum
pointarr_make_trajectory(Datum *points, int count, bool linear)
{
LWGEOM **lwpoints = palloc(sizeof(LWGEOM *) * count);
for (int i = 0; i < count; i++)
{
GSERIALIZED *gs = (GSERIALIZED *) DatumGetPointer(points[i]);
lwpoints[i] = lwgeom_from_gserialized(gs);
}
LWGEOM *geom;
if (linear)
geom = (LWGEOM *) lwline_from_lwgeom_array(lwpoints[0]->srid, (uint32_t) count, lwpoints);
else
geom = (LWGEOM *) lwcollection_construct(MULTIPOINTTYPE, lwpoints[0]->srid,
NULL, (uint32_t) count, lwpoints);
Datum result = PointerGetDatum(geometry_serialize(geom));
for (int i = 0; i < count; i++)
lwgeom_free(lwpoints[i]);
pfree(lwpoints); pfree(geom);
return result;
}

static Datum
lwpointarr_make_trajectory(LWGEOM **lwpoints, int count, bool linear)
Expand All @@ -444,6 +423,22 @@ lwpointarr_make_trajectory(LWGEOM **lwpoints, int count, bool linear)
return result;
}

static Datum
pointarr_make_trajectory(Datum *points, int count, bool linear)
{
LWGEOM **lwpoints = palloc(sizeof(LWGEOM *) * count);
for (int i = 0; i < count; i++)
{
GSERIALIZED *gs = (GSERIALIZED *) DatumGetPointer(points[i]);
lwpoints[i] = lwgeom_from_gserialized(gs);
}
Datum result = lwpointarr_make_trajectory(lwpoints, count, linear);
for (int i = 0; i < count; i++)
lwgeom_free(lwpoints[i]);
pfree(lwpoints);
return result;
}

/* Compute the trajectory of an array of instants.
* This function is called by the constructor of a temporal sequence and
* returns a single Datum which is a geometry */
Expand Down

0 comments on commit 6d043de

Please sign in to comment.