[postgis-users] Join variation

Obe, Regina robe.dnd at cityofboston.gov
Thu Sep 13 05:54:27 PDT 2007


First I would call your field something other than geometry since that
is confusing and could get you into trouble since its a psuedo keyword
 
So would be something like
 
DROP TABLE  abc
CREATE TABLE abc(code smallint, info smallint, the_geom geometry) with
oids
 
(you might want to use addgeomtrycolumn to create the_geom field so
geometry_columns table is updated, but I'm not sure what you are
expecting for a geometry so not sure what parameters to feed you but
would be something like this.
 
CREATE TABLE abc(code smallint, info smallint) with oids;
SELECT AddGeometryColumn('public', 'abc', 'the_geom', 4326,
'MULTIPOLYGON', 2);
 
--The insert
 
INSERT INTO abc(code, info, the_geom)
SELECT newtb.code,  newtb.info, geomunion(newtb.cgeom) as thenewgeom
FROM 
(  SELECT a.code, b.info, geomunion(a.geometry, b.geometry) as cgeom
    FROM a
        INNER JOIN b ON a.geometry && b.geometry AND
intersects(a.geometry, b.geometry)
    UNION ALL
    SELECT a.code, null As info, a.geometry as cgeom 
    FROM a 
        LEFT JOIN b ON a.geometry && b.geometry AND
intersects(a.geometry, b.geometry)
        WHERE b.geometry IS NULL
    UNION ALL
    SELECT null as code, b.info, b.geometry as cgeom
            FROM b LEFT JOIN a ON a.geometry && b.geometry AND
intersects(a.geometry, b.geometry)
           WHERE a.geometry IS NULL
)  AS newtb
GROUP BY newtb.code, newtb.info

________________________________

From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of RAVI
KUMAR
Sent: Thursday, September 13, 2007 8:17 AM
To: postgis
Subject: [postgis-users] Join variation


Hi Andreas and Regina,
I have used the following to get a result which will have polygons that
do not overlap.
But failed. 
Pl help me and correct the following query.
All I want is that after UNION of two layers, the polygons must split
and have both the attributes of source layers. (NO PLace for overlapping
polygons)

drop table abc;
create table abc (code smallint, info smallint, geometry geometry) with
oids;

insert into abc (select a.code, b.info,(geomunion(a.geometry,
 b.geometry)) AS abc FROM b inner JOIN a ON (a.geometry && b.geometry
AND  intersects(a.geometry, b.geometry)));

I can actually send two small shape files 'a' and 'b' If U want to
private mail Ids..
Along with the result I wish to get..

Cheers
Ravi Kumar


________________________________

Got a little couch potato? 
Check out fun summer activities for kids.
<http://us.rd.yahoo.com/evt=48248/*http://search.yahoo.com/search?fr=oni
_on_mail&p=summer+activities+for+kids&cs=bz> 



-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070913/b3d20b92/attachment.html>


More information about the postgis-users mailing list