<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16481" name=GENERATOR></HEAD>
<BODY
style="WORD-WRAP: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space">
<DIV dir=ltr align=left><SPAN class=581141314-12032008><FONT face=Arial
color=#0000ff size=2>Could be your export routine then. I don't think ' is
legal. Need to use double-quotes (or at least on windows) for the SQL. You
can also leave out the .shp although I guess its harmless.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=581141314-12032008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=581141314-12032008><FONT face=Arial
color=#0000ff size=2>Try</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=581141314-12032008><FONT face=Verdana
size=2>pgsql2shp -f ext conversion "select * from matable2"</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=581141314-12032008><FONT face=Verdana
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=581141314-12032008><FONT face=Verdana
size=2>Hope that helps,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=581141314-12032008><FONT face=Verdana
size=2>Regina</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B>
postgis-users-bounces@postgis.refractions.net
[mailto:postgis-users-bounces@postgis.refractions.net] <B>On Behalf Of
</B>Ghislain Geniaux<BR><B>Sent:</B> Wednesday, March 12, 2008 8:47
AM<BR><B>To:</B> PostGIS Users Discussion<BR><B>Subject:</B> Re: [postgis-users]
problem creating and exporting a polygon withholeusing
pgsql2shp<BR></FONT><BR></DIV>
<DIV></DIV><FONT class=Apple-style-span><FONT class=Apple-style-span
face=Monaco>Thanks for your answer Regina,</FONT></FONT>
<DIV><FONT class=Apple-style-span face=Monaco><BR
class=webkit-block-placeholder></FONT></DIV>
<DIV><FONT class=Apple-style-span><FONT class=Apple-style-span face=Monaco>but
ST_Difference does not solve the problem : </FONT></FONT>
<DIV><FONT class=Apple-style-span><FONT class=Apple-style-span
face=Monaco>ST_Difference and ST_Symdifference give the same polygon but
the export by pgsql2shp failled.</FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span><FONT class=Apple-style-span face=Monaco><BR
class=webkit-block-placeholder></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Arial color=#0000ff size=2><SPAN
class=Apple-style-span style="FONT-SIZE: 10px">
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">conversion=# create table temp
as </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">conversion-# select r.gid, <FONT
class=Apple-style-span color=#ff0219>ST_Difference</FONT>(r.the_geom,i.the_geom)
as the_geom from recouv as r, recouv as i where i.gid=2 and
r.gid=1;</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">SELECT</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">conversion=# ALTER TABLE temp ADD PRIMARY KEY
(gID);</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">NOTICE: ALTER TABLE / ADD PRIMARY KEY will create
implicit index "temp_pkey" for table "temp"</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">ALTER TABLE</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">conversion=# SELECT geometrytype(the_geom),
Nrings(the_geom), area2d(the_geom) from temp;</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px"> geometrytype | nrings | area2d
</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">--------------+--------+------------------</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px"> POLYGON |
2 | 2177713.02017212</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">(1 row)</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px"><BR
class=webkit-block-placeholder></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px"><BR
class=webkit-block-placeholder></SPAN></FONT></FONT></FONT></DIV>
<DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">conversion=# create table temp
as </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">conversion-# select r.gid, <FONT
class=Apple-style-span
color=#ff0219>ST_symDifference</FONT>(r.the_geom,i.the_geom) as the_geom from
recouv as r, recouv as i where i.gid=2 and
r.gid=1;</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">SELECT</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">conversion=# ALTER TABLE temp ADD PRIMARY KEY
(gID);</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">NOTICE: ALTER TABLE / ADD PRIMARY KEY will create
implicit index "temp_pkey" for table "temp"</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">ALTER TABLE</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">conversion=# SELECT geometrytype(the_geom),
Nrings(the_geom), area2d(the_geom) from temp;</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px"> geometrytype | nrings | area2d
</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">--------------+--------+------------------</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px"> POLYGON |
2 | 2177713.02017212</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT class=Apple-style-span color=#000000><FONT class=Apple-style-span
face=Monaco><FONT class=Apple-style-span size=3><SPAN class=Apple-style-span
style="FONT-SIZE: 12px">(1 row)</SPAN></FONT></FONT></FONT></DIV>
<DIV><BR class=webkit-block-placeholder></DIV>
<DIV><BR class=webkit-block-placeholder></DIV>
<DIV><FONT class=Apple-style-span face=Monaco color=#000000 size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px">The two polygons are goods and
well displayed in QGIS but exported shapefiles are empty or
corrupted.</SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Monaco color=#000000 size=3><SPAN
class=Apple-style-span style="FONT-SIZE: 12px"><BR
class=webkit-block-placeholder></SPAN></FONT></DIV></DIV></SPAN></FONT>
<DIV><FONT class=Apple-style-span face=Arial color=#0000ff size=2><SPAN
class=Apple-style-span style="FONT-SIZE: 10px"><BR
class=webkit-block-placeholder></SPAN></FONT></DIV>
<DIV><FONT class=Apple-style-span face=Arial color=#0000ff size=2><SPAN
class=Apple-style-span style="FONT-SIZE: 10px"><BR></SPAN></FONT>
<DIV>
<DIV>Le 12 mars 08 à 12:51, Obe, Regina a écrit :</DIV><BR
class=Apple-interchange-newline>
<BLOCKQUOTE type="cite">
<DIV dir=ltr align=left><SPAN class=829444111-12032008><FONT face=Arial
color=#0000ff size=2>I'm guessing your result may be a Geometrycollection
which ESRI shape has no clue what to do with.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=829444111-12032008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=829444111-12032008><FONT face=Arial
color=#0000ff size=2>If I understand you correctly, I think you really should
be using ST_Difference instead of ST_SymDifference.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=829444111-12032008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=829444111-12032008><FONT face=Arial
color=#0000ff size=2>So ST_Difference(polygon2, polygon1) - will give you that
portion of polygon2 which does not intersect with polygon1 which would give
you a polygon with polygon1 removed (a doughnut so to
speak).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=829444111-12032008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=829444111-12032008><FONT face=Arial
color=#0000ff size=2>The ST_Symdifference will give you that portion of
polygon2 not in polygon1 + polygon1 not in polygon2 = the holed polygon you
want + an empty geometry collection -> a geometry collection if taken
strictly. </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=829444111-12032008><FONT face=Arial
color=#0000ff size=2> I'm not sure if PostGIS will throw out the second
part (the empty collection) - and at anyrate is a waste of processing power to
even compute it.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=829444111-12032008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=829444111-12032008><FONT face=Arial
color=#0000ff size=2>Hope that helps,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=829444111-12032008><FONT face=Arial
color=#0000ff size=2>Regina</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B>
postgis-users-bounces@postgis.refractions.net [<A
href="mailto:postgis-users-bounces@postgis.refractions.net">mailto:postgis-users-bounces@postgis.refractions.net</A>]
<B>On Behalf Of </B>Ghislain Geniaux<BR><B>Sent:</B> Wednesday, March 12, 2008
6:29 AM<BR><B>To:</B> <A
href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</A><BR><B>Subject:</B>
[postgis-users] problem creating and exporting a polygon with holeusing
pgsql2shp<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Verdana" face=Verdana
size=4>Using a postgis table with Two polygons, in which polygon 1 entirely
contained in polygon 2, I've create a new polygon with a hole using
: </FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Verdana"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Verdana" face=Verdana
size=4>------ </FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Verdana" face=Verdana
size=4>create table matable2 as </FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Verdana" face=Verdana
size=4>select r.gid, area(symdifference(r.the_geom,i.the_geom)) as
area,(symdifference(r.the_geom,i.the_geom)) as the_geom from matable as r,
matable as i where i.gid=2 and r.gid=1; </FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Verdana"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Verdana" face=Verdana
size=4>ALTER TABLE matable2 ADD PRIMARY KEY (GID); </FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Verdana" face=Verdana
size=4>\q </FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Verdana" face=Verdana
size=4>pgsql2shp -f ext.shp conversion 'select * from
matable2' </FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Verdana" face=Verdana
size=4>----- </FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Verdana"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Verdana" face=Verdana
size=4>Area is correct, display of the polygon in QGIS is also correct, but
the export by pgsl2shp produce an empty shapefile. </FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Verdana"><BR></DIV>
<DIV style="MARGIN: 0px"><SPAN class=Apple-style-span
style="FONT-SIZE: 13px; FONT-FAMILY: Verdana">How to deal with this
problem?</SPAN></DIV>
<DIV style="MARGIN: 0px"><FONT class=Apple-style-span face=Verdana
size=3><SPAN class=Apple-style-span style="FONT-SIZE: 13px"><BR
class=webkit-block-placeholder></SPAN></FONT></DIV>
<DIV style="MARGIN: 0px">------------------------------------------</DIV>
<DIV><SPAN class=Apple-style-span
style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; border-spacing: 0px 0px; -khtml-text-decorations-in-effect: none; -apple-text-size-adjust: auto; orphans: 2; widows: 2"><SPAN
class=Apple-style-span
style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; border-spacing: 0px 0px; -khtml-text-decorations-in-effect: none; -apple-text-size-adjust: auto; orphans: 2; widows: 2"><SPAN
class=Apple-style-span
style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; border-spacing: 0px 0px; -khtml-text-decorations-in-effect: none; -apple-text-size-adjust: auto; orphans: 2; widows: 2">
<DIV style="MARGIN: 0px">Geniaux Ghislain</DIV>
<DIV style="MARGIN: 0px"><BR></DIV></SPAN></SPAN></SPAN></DIV><BR>
<DIV><BR class=khtml-block-placeholder></DIV>
<HR SIZE=1>
<DIV><BR class=khtml-block-placeholder></DIV>
<P><STRONG>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. </STRONG></P>
<DIV><BR class=khtml-block-placeholder></DIV>
<HR SIZE=1>
<DIV><BR class=khtml-block-placeholder></DIV>
<P><STRONG><FONT color=#339900 size=2>Help make the earth a greener place. If
at all possible resist printing this email and join us in saving paper.
</FONT></STRONG></P><STRONG><FONT color=#339900 size=2></FONT></STRONG>
<P><STRONG><FONT color=#339900 size=2></FONT></STRONG></P>
<DIV style="MARGIN: 0px">_______________________________________________</DIV>
<DIV style="MARGIN: 0px">postgis-users mailing list</DIV>
<DIV style="MARGIN: 0px"><A
href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</A></DIV>
<DIV style="MARGIN: 0px"><A
href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</A></DIV></BLOCKQUOTE></DIV><BR>
<DIV><SPAN class=Apple-style-span
style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; border-spacing: 0px 0px; -khtml-text-decorations-in-effect: none; -apple-text-size-adjust: auto; orphans: 2; widows: 2"><BR
class=Apple-interchange-newline><SPAN class=Apple-style-span
style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; border-spacing: 0px 0px; -khtml-text-decorations-in-effect: none; -apple-text-size-adjust: auto; orphans: 2; widows: 2"><SPAN
class=Apple-style-span
style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; border-spacing: 0px 0px; -khtml-text-decorations-in-effect: none; -apple-text-size-adjust: auto; orphans: 2; widows: 2">
<DIV style="MARGIN: 0px"><BR class=khtml-block-placeholder></DIV>
<DIV style="MARGIN: 0px">------------------------------------------</DIV>
<DIV style="MARGIN: 0px">Geniaux Ghislain</DIV>
<DIV style="MARGIN: 0px">INRA SAD Ecodéveloppement</DIV>
<DIV style="MARGIN: 0px">Site Agroparc</DIV>
<DIV style="MARGIN: 0px">Domaine St Paul</DIV>
<DIV style="MARGIN: 0px">84914 Avignon Cedex 9</DIV>
<DIV style="MIN-HEIGHT: 14px; MARGIN: 0px"><BR></DIV>
<DIV style="MARGIN: 0px">Tél : 04 32 72 25 64</DIV>
<DIV style="MARGIN: 0px">Fax : 04 32 72 25 62</DIV><BR
class=Apple-interchange-newline></SPAN></SPAN></SPAN></DIV><BR></DIV></DIV></DIV></BODY></HTML>