[postgis-users] help with the Union of 2 shp

Rémi Cura remi.cura at gmail.com
Tue Dec 17 07:12:22 PST 2013


Most likely,
in your last step,
"cuadrados_parts" :
there is not guaranteed type to the_geom :
it could be multi, simple, line, point, etc etc.

So if you expect polygon, use ST_CollectionExtract(the_geom,3)
Then use (ST_Dump()).geom to break appart multi polygon if you want to
(thus making something like
(ST_Dump(ST_CollectionExtract(the_geom,3))).geom AS the_geom
)
(you will need to generate an unique ID, see
http://trac.osgeo.org/postgis/wiki/UsersWikiQGIS
 row_number() OVER() AS id_qgis
;-) )


2013/12/17 <islanis at infomed.sld.cu>

> "Rémi Cura" <remi.cura at gmail.com> escribió:
>
>
>  Juste use one or 2 polygon !
>> you can use limits on your first query,
>> or add a where condition with gid=XX, I guess you have a gid field
>> (primary
>> key).
>>
>
> ok i make this, and i get all suces but i can see what happening because i
> can see the answer in my quantumgis it say "detecting..." in the type of
> the table of my result, in this case in the "all_lines_cuadrado_merged"
> table, whats happening? please and thanks
>
> *drop table if exists cuadrado;
> CREATE TABLE cuadrado
> AS (select ST_GeomFromText('MULTIPOLYGON(((-77 56,-52 18,-88 -27,-10
> -13,-11 38,-77 56)))',4326)as the_geom );
> UPDATE cuadrado SET the_geom=ST_SetSRID(the_geom,4326);
> SELECT Populate_Geometry_Columns('public.cuadrado'::regclass);
> ALTER TABLE cuadrado ADD column gid serial;
> ALTER TABLE cuadrado ADD COLUMN dato character varying;
> ALTER TABLE cuadrado ADD PRIMARY KEY (gid);
> UPDATE cuadrado SET dato='cuadrado' WHERE gid=1;
>
> drop table if exists cuadrados;
> CREATE TABLE cuadrados
> AS (select ST_GeomFromText('MULTIPOLYGON(((-49 63,-32 24,-39 -7,-66
> -19,-72 -9,-74 31,-49 63)))',4326)as the_geom );
> UPDATE cuadrados SET the_geom=ST_SetSRID(the_geom,4326);
> SELECT Populate_Geometry_Columns('public.cuadrados'::regclass);
> ALTER TABLE cuadrados ADD column gid serial;
> ALTER TABLE cuadrados ADD COLUMN dato character varying;
> ALTER TABLE cuadrados ADD PRIMARY KEY (gid);
> UPDATE cuadrados SET dato='cuadrados' WHERE gid=1;
>
> DROP TABLE IF EXISTS all_lines_cuadrado_merged;
> CREATE TABLE all_lines_cuadrado_merged AS
> SELECT ST_LineMerge(ST_ExteriorRing((ST_Dump(z.the_geom)).geom)) AS
> the_geom
> FROM public.cuadrado z;
> UPDATE all_lines_cuadrado_merged SET the_geom=ST_SetSRID(the_geom,4326);
> SELECT Populate_Geometry_Columns('public.all_lines_cuadrado_
> merged'::regclass);
> ALTER TABLE all_lines_cuadrado_merged ADD column gid serial;
> ALTER TABLE all_lines_cuadrado_merged ADD COLUMN dato character varying;
> ALTER TABLE all_lines_cuadrado_merged ADD PRIMARY KEY (gid);
>
>
> DROP TABLE IF EXISTS cuadrados_parts;
> CREATE TABLE cuadrados_parts AS
> SELECT ST_Split(a.the_geom,z.the_geom) AS the_geom
> FROM public.cuadrados a, public.all_lines_cuadrado_merged z;
> UPDATE cuadrados_parts SET the_geom=ST_SetSRID(the_geom,4326);
> SELECT Populate_Geometry_Columns('public.cuadrados_parts'::regclass);
> ALTER TABLE cuadrados_parts ADD column gid serial;
> ALTER TABLE cuadrados_parts ADD COLUMN dato character varying;
> ALTER TABLE cuadrados_parts ADD PRIMARY KEY (gid);
>
>
>> Cheers,
>> Rémi-C
>>
>>
>> 2013/12/16 J.Alejandro Martinez Linares <islanis at infomed.sld.cu>
>>
>>
>>> El 16/12/13 14:38, Rémi Cura escribió:
>>>
>>> And of course it is *a very bad idea* to try something without knowing if
>>>
>>> it works on all your data !
>>>
>>>  You should try the complete solution on a small sample, then optimize
>>> your queries, then use it on all your data...
>>>
>>>  Cheers,
>>>
>>>  Rémi-C
>>>
>>> ok ok, but there are 6570 rows of multipolygons, ok what can i do?, at
>>> least i need to know if the entire process is working, i mean like a
>>> progress bar, is there enything like that??!!! please and thanks
>>>
>>>
>>
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
>
>
> --
>
> Este mensaje le ha llegado mediante el servicio de correo electronico que
> ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema
> Nacional de Salud. La persona que envia este correo asume el compromiso de
> usar el servicio a tales fines y cumplir con las regulaciones establecidas
>
> Infomed: http://www.sld.cu/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20131217/0b7df335/attachment.html>


More information about the postgis-users mailing list