2
votes

My database has a table with tons of geometry(PointZ,4326) I am doing a lot of my processing on the database side and I've noticed that when I use the ST_MakeLine I seem to be hitting a cap on the number of points it will make a line from. My table and function/query is below.

It works as long as the number of track_points returned from the sub query is less than 97. I know this because the insert puts data in the table for all columns when there are 96 points or fewer. For all records where there are 97 or more points all it inserts is the track_id, start_time and end_time.

I'm wondering if this is a bug in the ST_makeLine function of postgis or is it a setting in postgres that I need to modify.

CREATE TABLE track_line_strings( 
    track_id bigint NOT NULL, 
    linestring geometry(LINESTRINGZ,4326), 
    start_time bigint NOT NULL, 
    end_time bigint NOT NULL, 
    CONSTRAINT track_line_strings_pk PRIMARY KEY (track_id) 
);



CREATE OR REPLACE FUNCTION create_track_line_string() RETURNS trigger 
LANGUAGE plpgsql 
AS $$ 
    DECLARE 
            TRACKITEMID bigint := new.track_item_id; 
            TRACKID bigint := track_id from track_item ti where ti.id = TRACKITEMID; 
            STARTTIME bigint := MIN(ti.item_time) from track_item ti where ti.track_id = TRACKID; 
            ENDTIME bigint := MAX(ti.item_time) from track_item ti where ti.track_id = TRACKID; 
    BEGIN 
    IF EXISTS (SELECT track_id from track_line_strings where track_id = TRACKID) 
    THEN 
            UPDATE track_line_strings 
            SET start_time = STARTTIME, end_time = ENDTIME, linestring = ( 
                    SELECT ST_Makeline(e.trackPosition) FROM 
                            ( 
                                    Select track_id, tp.track_position AS trackPosition 
                                    FROM track_point tp JOIN track_item ti ON tp.track_item_id = ti.id 
                                    where ti.track_id = TRACKID ORDER BY ti.item_time ASC   
                            ) E ) 
                    WHERE track_id = TRACKID; 
    ELSE 
            INSERT INTO track_line_strings(track_id, linestring, start_time, end_time) 
                    SELECT  TRACKID, ST_Makeline(e.trackPosition), STARTTIME, ENDTIME FROM 
                    ( 
                            Select track_id, tp.track_position AS trackPosition 
                            FROM track_point tp JOIN track_item ti ON tp.track_item_id = ti.id 
                            where ti.track_id = TRACKID ORDER BY ti.item_time ASC     
                    )E; 
    END IF; 
    RETURN new; 
    END; 
$$; 
2

2 Answers

2
votes

The database limits are pretty high, 1 GB data worth of geometry data in a field. It depends on what kind of point geometry, but it will be on the order of tens of millions of point geometries that can be used to construct a LineString.

You will see a proper error message with something about "exceeded size" if it is a limitation.


Apparent empty or missing data with pgAdminIII is a common question, but not related to database limitations:

1
votes

There doesnt appear to be a limit. I was viewing results in pgAdminIII and there must be a limit on the number of characters the data output can handle for each column. I only realized this by copy pasting the results into a text file to see that it did infact return a value for the lines that have more than 96 points.