[postgis-users] Collect() and MemCollect() problem

ksa-nil5 ksa-nil5 at yandex.ru
Mon Mar 28 00:48:08 PST 2005


Hi, strk.

I have some problem with collect() and memcollect() functions in postgis 1.0.0rc4.

I have a layer with MULTILINESTRINGs each of that consists of one LINESTRING:
test_export=# \d t_table_1
                                Table "public.t_table_1"
     Column      |   Type   |                         Modifiers
-----------------+----------+------------------------------------------------------------
 gid             | integer  | not null default nextval('public.t_table_1_gid_seq'::text)
 geom_order      | integer  | not null default 0
 geom            | geometry |
Indexes:
    "pk_t_table_1" PRIMARY KEY, btree (gid)
    "i_t_table_1_gist" gist (geom)
Check constraints:
    "enforce_srid_geom" CHECK (srid(geom) = 300001)
    "enforce_dims_geom" CHECK (ndims(geom) = 2)
    "enforce_geotype_geom" CHECK (geometrytype(geom) = 'MULTILINESTRING'::text OR geom IS NULL)

The layer contains 1999 MULTILINESTRINGs:
test_export=# select count(*) from t_table_1;
 count
-------
  1999
(1 row)

As you can see, all geometries have same SRID. (srid = 300001). So, all geometries are stored in same projection. 
Now, I want to get boundary box of that layer, so I execute collection of all geometries in layer and then execute function envelope().

(Because output of collect() function with all of that geometries would be very big, I use else srid() function)

test_export=# select srid(collect(geom)) from t_table_1;
  srid
--------
 300001
(1 row)

test_export=# select envelope(collect(geom)) from t_table_1;
                                                                                              envelope
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 0103000020E19304000100000005000000000000C097815441000000E065835741000000C097815441000000A0299A584100000040CCC75541000000A0299A584100000040CCC75541000000E065835741000000C097815441000000E065835741
(1 row)

So, all works fine! :) But if I use MemCollect() function I receive an error....

test_export=# select memcollect(geom) from t_table_1;
ERROR:  Operation on two GEOMETRIES with different SRIDs

Why?

I have found some interesting:
test_export=# select srid(memcollect(geom)) from t_table_1 where gid<2;
  srid
--------
 300001
(1 row)

test_export=# select srid(memcollect(geom)) from t_table_1 where gid<3;
 srid
------
   -1
(1 row)

So, srid is lost... why?
That is first two geometries:
test_export=# select geom from t_table_1 where gid < 3;
                                                                                                                                                     geom
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 0105000020E193040001000000010200000004000000AC1C5A0CC58B54412FDD242EECF85741713D0A6F0E8C5441D34D62983DF957413333337B458C5441D122DB81B0F95741D34D62F84F8C5441000000E8DAF95741
 0105000020E193040001000000010200000008000000CDCCCC8C518B5441D578E926BAF857411D5A645B678B5441A4703D229FF857417F6ABC3C8B8B544108AC1C7A67F85741AAF1D2ADBB8B5441EC51B8D629F85741EC51B886F18B5441BC7493D8E1F757418195436B168C54415A643B3FC4F75741CBA14586608C5441DBF97E62DCF757415839B410B58C5441621058F9F0F75741
(2 rows)

test_export=# select astext(geom) from t_table_1 where gid < 3;
                                                                                                      astext
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 MULTILINESTRING((5386004.193 6284208.721,5386297.735 6284534.381,5386517.925 6284994.029,5386559.881 6285163.625))
 MULTILINESTRING((5385542.2 6284008.608,5385629.428 6283900.535,5385772.949 6283677.908,5385966.716 6283431.355,5386182.105 6283143.384,5386329.676 6283024.988,5386626.098 6283121.539,5386964.261 6283203.896))
(2 rows)



Sergey Karin

PS. Up to last time I have used postgis 0.9.0. When I install postgis 1.0.0rc4 I have some problems in work my program. Maybe there is some instructions where described difference in work of functions? And what I shall do to port my program from 0.9.0 to 1.0.0

thanks in anvance



More information about the postgis-users mailing list