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

J.Alejandro Martinez Linares islanis at infomed.sld.cu
Mon Dec 16 08:01:29 PST 2013


El 16/12/13 12:33, Nicolas Ribot escribió:
> Hi,
>
> If you have a lot of data in your tables, it could be much faster to 
> to a CREATE TABLE as SELECT... than doing an update on an existing table.
what do you mean, i don't understand, please

>
> Nicolas
>
>
> On 15 December 2013 23:48, J.Alejandro Martinez Linares 
> <islanis at infomed.sld.cu <mailto:islanis at infomed.sld.cu>> wrote:
>
>     Hey all, i follow your answer Remi, but do this because your code
>     come to me late:
>
>     --part 1
>     DROP TABLE IF EXISTS all_lines;
>     CREATE TABLE all_lines AS
>     SELECT ST_ExteriorRing((ST_Dump(z.the_geom)).geom) AS the_geom
>     FROM public.rad_solar_global z
>     UNION ALL
>     SELECT ST_ExteriorRing((ST_Dump(r.the_geom)).geom) AS the_geom
>     FROM public.rad_solar_plano_inclinado r;
>     UPDATE all_lines SET the_geom=ST_SetSRID(the_geom,4326);
>     SELECT Populate_Geometry_Columns('public.all_lines'::regclass);
>     ALTER TABLE all_lines ADD column gid serial;
>     ALTER TABLE all_lines ADD PRIMARY KEY (gid);
>
>
>     --part 2
>     DROP TABLE IF EXISTS all_lines_MERGED;
>     CREATE TABLE all_lines_MERGED AS
>     (SELECT ST_LineMerge(k.the_geom) AS the_geom
>     FROM public.all_lines k);
>     UPDATE all_lines_MERGED SET the_geom=ST_SetSRID(the_geom,4326);
>     SELECT Populate_Geometry_Columns('public.all_lines_MERGED'::regclass);
>     ALTER TABLE all_lines_MERGED ADD column gid serial;
>     ALTER TABLE all_lines_MERGED ADD PRIMARY KEY (gid);
>
>     --part 3
>     DROP TABLE IF EXISTS rad_solar_directa_SPLITED;
>     CREATE TABLE rad_solar_directa_SPLITED AS
>     (SELECT ST_Split(b.the_geom,k.the_geom) AS the_geom
>     FROM public.rad_solar_directa b,public.all_lines_MERGED k);
>     UPDATE rad_solar_directa_SPLITED SET
>     the_geom=ST_SetSRID(the_geom,4326);
>     SELECT
>     Populate_Geometry_Columns('public.rad_solar_directa_SPLITED'::regclass);
>     ALTER TABLE rad_solar_directa_SPLITED ADD column gid serial;
>     ALTER TABLE rad_solar_directa_SPLITED ADD PRIMARY KEY (gid);
>
>
>     --i just have made part 1,2  and am still in part 3, am there
>     since 2 days ago, is there a way to know if this is working fine
>     or if it fall in an  unfinish error. am still in part 3, is that
>     posible? help please.
>
>     Cheers,
>     Ale
>
>     El 14/12/13 17:19, Rémi Cura escribió:
>>     OK,
>>     with luck you won't have precision issues.
>>
>>     (please note that the only good way to do this is to use
>>     postgis_topology and faces.)
>>
>>     So here is one idea to do it :
>>     table1 : first image, very big shape
>>     table 2 : second image, smal rectangular shape
>>     table 3 third image , mdium irregular shape
>>
>>     1.) convert poly from table 1 and table 3 to linestring. (i
>>     called these lines dumped_lines for the following)
>>     You can do it manually or use the function I wrote (beta)
>>     https://github.com/Remi-C/PPPP_utilities/blob/master/postgis/rc_DumpLines.sql
>>
>>
>>     2.) split poly from table 2 by the dumped_lines from table 1
>>     (http://postgis.net/docs/ST_Split.html) . The result are polygons
>>
>>     3.) Split the result from 2. by dumpl_lines from table 3. The
>>     result are polygons.
>>
>>     3. is what you want geometrically. I'll call it splited_polygons
>>     for the following
>>
>>     Now you want to get, for each splitted_polygons, the id of
>>     polygons of table 1, and 3 which overlaps. You already have id
>>     from table 2 because you can keep it during computing of  2. and 3.
>>
>>     you can do it sequentially :
>>
>>     SELECT DISTINCT ON (sp.geom) sp.geom, aray_agg(id) AS id_table1
>>     FROM splited_polygons AS sp, table_1
>>     WHERE ST_Overlaps(sp.geom, table_1.geom)=TRUE
>>
>>     , then the same type of query on result, with table 3
>>
>>     Cheers,
>>     Rémi-C
>>
>>
>>
>>
>>
>>     2013/12/12 <islanis at infomed.sld.cu <mailto:islanis at infomed.sld.cu>>
>>
>>         I want to create little pieces of multipolygons from these 3
>>         shapes (A,B and C)=result , result with all the sections
>>         formed with the intersection from the 3 shapes together, come
>>         on tell me , do you understand now what i want
>>         thanks
>>
>>             no never mind am not offended, am trying that you
>>             understand Ok, here   are png of my 3 multipolygon
>>             shapes, what else do you need
>>
>>             "Rémi Cura" <remi.cura at gmail.com
>>             <mailto:remi.cura at gmail.com>> escribió:
>>
>>                 Sorry I'm  not trying to offend you.
>>
>>                 For example in this thread
>>                 https://groups.google.com/forum/#!topic/postgis-users/9pozIoUAZuI
>>                 <https://groups.google.com/forum/#%21topic/postgis-users/9pozIoUAZuI>
>>                 The asker posted an image to explain better.
>>
>>                 Cheers,
>>                 Rémi-C
>>
>>
>>                 2013/12/12 <islanis at infomed.sld.cu
>>                 <mailto:islanis at infomed.sld.cu>>
>>
>>                     no is not dificult to understand, what ever you
>>                     want i'll give , just ask
>>                     what do you want to a better understanding.
>>                     please i need it
>>
>>                     "Rémi Cura" <remi.cura at gmail.com
>>                     <mailto:remi.cura at gmail.com>> escribió:
>>
>>
>>                     I'm very sorry it is difficult to understand what
>>                     you mean.
>>
>>                         Maybe with a real drawing and link here to
>>                         it, or to some screenshots?
>>                         ;-)
>>
>>                         Cheers,
>>
>>                         Rémi-C
>>
>>                         2013/12/12 <islanis at infomed.sld.cu
>>                         <mailto:islanis at infomed.sld.cu>>
>>
>>                         thanks for the quick answer Rémi, but, thats
>>                         right thats one of answers,
>>
>>                             but my idea was not complete,because
>>                             there is a
>>                             3rd shape, your answer works fine for the
>>                             1st and 2dn shapes, but not
>>                             with
>>                             the 3rd, because the 3rd has not suares
>>                             inside,
>>                             the 3rd shape have big triangles
>>                             inside,the idea is that i need some
>>                             routine that merge or blend the spatial
>>                             data and with it the attributes
>>                             of respective data, i need some ideas for
>>                             do that, and am working on it,
>>                             but not sucess, please i need help,
>>                             thanks for all.
>>
>>
>>                             1-the first shapefile
>>                             __________________
>>                             |                 |
>>                             |                 |
>>                             |         1       |     shp=A
>>                             |                 |
>>                             |                 |
>>                             |_________________|
>>                             num of poligons=1
>>
>>
>>                             The one big country, this is a
>>                             multipolygon shape
>>
>>                             DATA=>dni01 numeric,dni02 numeric,dni03
>>                             numeric,
>>                                  dni04 numeric,dni05 numeric,dni06
>>                             numeric,
>>                                  dni07 numeric,dni08 numeric,dni09
>>                             numeric,
>>                                  dni10 numeric,dni11 numeric,dni12
>>                             numeric,
>>                                  dniann numeric,the_geom geometry
>>
>>                             2-and the second shapefile
>>                             __________________
>>                             |     2  |  2     |
>>                             |________|________|
>>                             |     2  |  2     |     shp=B
>>                             |________|________|
>>                             |     2  |  2     |
>>                             |________|________|
>>                             num of poligons = 6
>>
>>                             The same country, but this time in little
>>                             pieces, the states, this is a
>>                             multipolygon shape too
>>
>>                             DATA=>dni01 numeric,dni02 numeric,dni03
>>                             numeric,
>>                                  dni04 numeric,dni05 numeric,dni06
>>                             numeric,
>>                                  dni07 numeric,dni08 numeric,dni09
>>                             numeric,
>>                                  dni10 numeric,dni11 numeric,dni12
>>                             numeric,
>>                                  dniann numeric,the_geom geometry
>>
>>
>>                             3-and the second shapefile
>>                             __________________
>>                             |          /      |
>>                             |         /       |
>>                             |   3    /        |     shp=C
>>                             |       /         |
>>                             |      /     4    |
>>                             |_____/___________|
>>                             num of poligons = 2
>>
>>                             The same country, but this time in little
>>                             pieces, the states, this is a
>>                             multipolygon shape too
>>
>>                             DATA=>dni01 numeric,dni02 numeric,dni03
>>                             numeric,
>>                                  dni04 numeric,dni05 numeric,dni06
>>                             numeric,
>>                                  dni07 numeric,dni08 numeric,dni09
>>                             numeric,
>>                                  dni10 numeric,dni11 numeric,dni12
>>                             numeric,
>>                                  dniann numeric,the_geom geometry
>>
>>
>>
>>                             and i want join the 2 shapes in only one
>>                             shapefile getting something
>>                             like
>>                             this
>>
>>                             ______________________________
>>                             |              |        /     |
>>                             |              |1,2,3  /      |
>>                             |    1,2,3     |      /1,2,4  |
>>                             |              |     /        |
>>                             |______________|____/_________|
>>                             |              |1,2/          |     shp=A
>>                             and B
>>                             |              |,3/           |
>>                             |    1,2,3     | /     1,2,4  |
>>                             |              |/             |
>>                             |______________/______________|
>>                             |             /|              |
>>                             |            / |              |
>>                             |    1,2,3  /1,|       1,2,4  |
>>                             |          /2,4|              |
>>                             |_________/____|______________|
>>                             num of poligons = 9
>>
>>
>>                             DATA=>dni01A numeric,dni02A
>>                             numeric,dni03A numeric,dni04A numeric,
>>                                 dni05A numeric,dni06A numeric,dni07A
>>                             numeric,dni08A numeric,
>>                                 dni09A numeric,dni10A numeric,dni11A
>>                             numeric,dni12A numeric,
>>                                 dniannA numeric,dni01B numeric,dni02B
>>                             numeric,dni03B numeric,
>>                                 dni04B numeric,dni05B numeric,dni06B
>>                             numeric,dni07B numeric,
>>                                 dni08B numeric,dni09B numeric,dni10B
>>                             numeric,dni11B numeric,
>>                                 dni12B numeric,dniannB numeric,dni01C
>>                             numeric,dni02C numeric,
>>                                 dni03C numeric,dni04C numeric,dni05C
>>                             numeric,dni06C numeric,
>>                                 dni07C numeric,dni08C numeric,dni09C
>>                             numeric,dni10C numeric,
>>                                 dni11C numeric,dni12C numeric,dniannC
>>                             numeric,the_geom geometry
>>
>>                             "Rémi Cura" <remi.cura at gmail.com
>>                             <mailto:remi.cura at gmail.com>> escribió:
>>
>>
>>                             Seems like If you want :
>>
>>                                 for each little square, get the id of
>>                                 big square overlaping.
>>                                 If this is simply this, you don't
>>                                 need the "intersection" function,
>>                                 but only the "intersects" function :
>>
>>                                 You could do something like this
>>
>>                                 SELECT ss.id <http://ss.id>, bs.id
>>                                 <http://bs.id> , ss.geom
>>                                 FROM smal_square_table AS ss,
>>                                 big_square_table AS bs
>>                                 WHERE ST_Intersects(ss.geom,bs.geom)=TRUE
>>
>>                                 Cheers,
>>                                 Rémi-C
>>
>>
>>
>>
>>                                 2013/12/12 <islanis at infomed.sld.cu
>>                                 <mailto:islanis at infomed.sld.cu>>
>>
>>                                 Hi,
>>
>>
>>
>>                                         Try pg 21 of this:
>>                                         http://presentations.opengeo.
>>                                         org/2011_FOSS4G/postgis-power.pdf
>>
>>                                         That will give you the metacode.
>>
>>                                         Overlays. (he sighs.)  Be
>>                                         glad you only have 2 layers... .
>>
>>                                         Best,
>>                                         Steve
>>
>>                                         Hey steve thanks for the book
>>                                         is really good as a resume,
>>                                         but the
>>                                         only
>>
>>                                     apart that it have to do with my
>>                                     problem is the intersection of 2
>>                                     shapes
>>                                     "SELECT
>>                                     a.*, b.*,
>>                                     ST_Intersection(a.geom, b.geom)
>>                                     FROM
>>                                     a, b
>>                                     WHERE
>>                                     ST_Intersects(a.geom, b.geom);"
>>
>>                                     but my problem  is different, i
>>                                     got as a mention 2 shapes with
>>                                     the same
>>                                     projection and place,
>>                                     and are the same but one is from
>>                                     one study, and the other is from
>>                                     other
>>                                     stufy, but are the same
>>                                     place and each one have data, the
>>                                     only things that they got different
>>                                     are
>>                                     the size of the squares,the data
>>                                     they got and the
>>                                     name of the columns are the same,
>>                                     but the values are different cause
>>                                     the
>>                                     type of the study
>>                                     ,there is one that have the
>>                                     squares more smaller that the
>>                                     other, but i
>>                                     dont want lose any data, i need
>>                                     that in the map it has seen like
>>                                     the figure "A and B" but in the
>>                                     data each row got the values of A and
>>                                     the
>>                                     values of B
>>
>>                                     1-the first shapefile
>>                                     __________________
>>                                     |                 |
>>                                     |                 |
>>                                     |         1       | shp=A
>>                                     |                 |
>>                                     |                 |
>>                                     |_________________|
>>
>>                                     The one big country, this is a
>>                                     multipolygon shape
>>
>>                                     DATA=>dni01 numeric,dni02
>>                                     numeric,dni03 numeric,
>>                                          dni04 numeric,dni05
>>                                     numeric,dni06 numeric,
>>                                          dni07 numeric,dni08
>>                                     numeric,dni09 numeric,
>>                                          dni10 numeric,dni11
>>                                     numeric,dni12 numeric,
>>                                          dniann numeric,the_geom geometry
>>
>>
>>                                     2-and the second shapefile
>>                                     __________________
>>                                     |     2  |  2     |
>>                                     |________|________|
>>                                     |     2  |  2     | shp=B
>>                                     |________|________|
>>                                     |     2  |  2     |
>>                                     |________|________|
>>                                     The same country, but this time
>>                                     in little pieces, the states, this is
>>                                     a
>>                                     multipolygon shape too
>>
>>                                     DATA=>dni01 numeric,dni02
>>                                     numeric,dni03 numeric,
>>                                          dni04 numeric,dni05
>>                                     numeric,dni06 numeric,
>>                                          dni07 numeric,dni08
>>                                     numeric,dni09 numeric,
>>                                          dni10 numeric,dni11
>>                                     numeric,dni12 numeric,
>>                                          dniann numeric,the_geom geometry
>>
>>
>>                                     and i want join the 2 shapes in
>>                                     only one shapefile getting something
>>                                     like
>>                                     this
>>
>>                                     __________________
>>                                     |    1,2 |   1,2  |
>>                                     |________|________|
>>                                     |    1,2 |   1,2  | shp=A and B
>>                                     |________|________|
>>                                     |    1,2 |   1,2  |
>>                                     |________|________|
>>
>>                                     DATA=>dni01A numeric,dni02A
>>                                     numeric,dni03A numeric,dni04A
>>                                     numeric,
>>                                         dni05A numeric,dni06A
>>                                     numeric,dni07A numeric,dni08A
>>                                     numeric,
>>                                         dni09A numeric,dni10A
>>                                     numeric,dni11A numeric,dni12A
>>                                     numeric,
>>                                         dniannA numeric,dni01B
>>                                     numeric,dni02B numeric,dni03B
>>                                     numeric,
>>                                         dni04B numeric,dni05B
>>                                     numeric,dni06B numeric,dni07B
>>                                     numeric,
>>                                         dni08B numeric,dni09B
>>                                     numeric,dni10B numeric,dni11B
>>                                     numeric,
>>                                         dni12B numeric,dniannB
>>                                     numeric,the_geom geometry
>>
>>                                     i think that this is posible to
>>                                     do with postgis, but i dont know why,
>>                                     am
>>                                     looking in quantumGIS but i lose
>>                                     data cause the big suare overlap the
>>                                     little
>>                                     ones and i lose data cause there
>>                                     is some places that i get NULL.
>>
>>                                     please help
>>                                     thanks for all
>>
>>
>>
>>
>>
>>
>>
>>                                         On Mon, Dec 9, 2013 at 11:03
>>                                         AM, J.Alejandro Martinez
>>                                         Linares <
>>
>>                                         islanis at infomed.sld.cu
>>                                         <mailto:islanis at infomed.sld.cu>>
>>                                         wrote:
>>
>>
>>                                              Hi People, i need your
>>                                             help, let say that i have
>>                                             2 shapefiles
>>
>>                                              1-the first shapefile
>>                                              __________________
>>                                              |                 |
>>                                              |                 |
>>                                              |         1       | shp=B
>>                                              |                 |
>>                                              |                 |
>>                                              |_________________|
>>
>>                                              One big country, this is
>>                                             a multipolygon shape
>>
>>                                              2-and the second shapefile
>>                                              __________________
>>                                              |     2  |  2     |
>>                                              |________|________|
>>                                              |     2  |  2     | shp=B
>>                                              |________|________|
>>                                              |     2  |  2     |
>>                                              |________|________|
>>                                              The same country, but
>>                                             this time in little
>>                                             pieces, the states, this
>>                                             is
>>                                             a multipolygon shape too
>>
>>                                              and i want join the 2
>>                                             shapes in only one
>>                                             shapefile getting
>>                                             something
>>                                             like this
>>
>>                                              __________________
>>                                              |    1,2 |   1,2  |
>>                                              |________|________|
>>                                              |    1,2 |   1,2  |
>>                                             shp=A and B
>>                                              |________|________|
>>                                              |    1,2 |   1,2  |
>>                                              |________|________|
>>
>>                                              i think that this is
>>                                             posible, please help me
>>                                             to get somthing like
>>                                             this i need it.
>>
>>
>>
>>                                              --
>>
>>                                              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/
>>
>>                                              _______________________________________________
>>                                              postgis-users mailing list
>>                                             postgis-users at lists.osgeo.org
>>                                             <mailto:postgis-users at lists.osgeo.org>
>>                                             http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>>
>>
>>
>>
>>
>>
>>                                     ----------------------------------------------------------------
>>                                     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/
>>
>>                                     _______________________________________________
>>                                     postgis-users mailing list
>>                                     postgis-users at lists.osgeo.org
>>                                     <mailto:postgis-users at lists.osgeo.org>
>>                                     http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>>
>>
>>
>>
>>
>>                             ----------------------------------------------------------------
>>                             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/
>>
>>
>>
>>
>>
>>
>>                     ----------------------------------------------------------------
>>                     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/
>>
>>
>>
>>
>>
>>             ----------------------------------------------------------------
>>             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/
>>
>>
>>
>>
>>
>>
>>         ----------------------------------------------------------------
>>         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/
>>
>>
>>
>>         _______________________________________________
>>         postgis-users mailing list
>>         postgis-users at lists.osgeo.org
>>         <mailto:postgis-users at lists.osgeo.org>
>>         http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>>
>>
>
>
>     _______________________________________________
>     postgis-users mailing list
>     postgis-users at lists.osgeo.org <mailto:postgis-users at lists.osgeo.org>
>     http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
>
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users



--

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/20131216/26c7b60e/attachment.html>


More information about the postgis-users mailing list