<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>RE: [postgis-users] Intersection - No GID</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16481" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008>Marcus,</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008>Just to add to some things that Robert 
said.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008>1) You can also add the serial after the fact with a 
</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008>ALTER TABLE new_fields ADD COLUMN gid 
serial;</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008></SPAN></FONT><FONT face=Arial color=#0000ff 
size=2><SPAN class=835422719-03062008>ALTER TABLE new_fields  ADD 
CONSTRAINT pk_new_fields PRIMARY KEY(gid);</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008>3) ST_Intersects is different from Intersects although 
ST_Intersection is the same as Intersection.  It includes the && 
operator so you can leave out the && in it</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT size=2><SPAN class=835422719-03062008>CREATE TABLE 
new_fields AS<BR> SELECT<BR>   ST_Intersection(f.the_geom, 
c.the_geom) AS the_geom,<BR>   f.attr1,<BR>   
f.attr2,<BR>   c.clu_name<BR> FROM<BR>   fields 
f,<BR>   clu c<BR> WHERE<BR>    
ST_Intersects(f.the_geom, c.the_geom)</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008>Hope that hleps,</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=835422719-03062008>Regina</SPAN></FONT></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>Burgholzer,Robert<BR><B>Sent:</B> Tuesday, June 03, 2008 3:07 
PM<BR><B>To:</B> marcuscengland@gmail.com; PostGIS Users Discussion; PostGIS 
Users Discussion<BR><B>Subject:</B> RE: [postgis-users] Intersection - No 
GID<BR></FONT><BR></DIV>
<DIV></DIV><!-- Converted from text/plain format -->
<P><FONT size=2>Marcus,<BR>1) You could create your table prior to populating 
it, and include a column that is type "SERIAL", this will create an 
autogenerated integer identifier that you could name "gid" if you so 
desired.<BR><BR>2) select area2d(Intersection(f.the_geom, c.the_geom)) 
...<BR>NOTE: You will have to convert this area2d result from the units of your 
map projection into acres<BR><BR>3) ST_intersection and intersection are the 
same, the new (ST_*) naming convention was recently added, for reasons that I do 
not know but assume that they were good 
ones.<BR><BR>HTH,<BR>Robert<BR><BR>-----Original 
Message-----<BR>From:   postgis-users-bounces@postgis.refractions.net 
on behalf of Marcus C. England<BR>Sent:   Tue 6/3/2008 2:57 
PM<BR>To:     PostGIS Users 
Discussion<BR>Cc:    <BR>Subject:        
[postgis-users] Intersection - No GID<BR><BR>Hi all,<BR><BR>I figured out how to 
use Intersection and get a resulting table with<BR>apparently correct results 
using the example from the PostGIS website:<BR><BR>CREATE TABLE new_fields 
AS<BR> SELECT<BR>   Intersection(f.the_geom, c.the_geom) AS 
the_geom,<BR>   f.attr1,<BR>   f.attr2,<BR>   
c.clu_name<BR> FROM<BR>   fields f,<BR>   clu 
c<BR> WHERE<BR>   f.the_geom && 
c.the_geom<BR> AND<BR>   Intersects(f.the_geom, 
c.the_geom)<BR><BR>However, this example does not create a gid column and I 
therefore can<BR>not view the results in a GIS program. Is there a way to create 
a gid<BR>column after-the-fact?<BR><BR>Optional questions for those feeling 
super-helpful:<BR><BR>(1) How should the above SQL be rewritten to include gid 
in the<BR>resulting table?<BR><BR>(2) I know that eliminating the first line 
will simply give me a table<BR>spit onto the SQL results in pgAdmin. How do I 
alter the SQL above to<BR>give me the acreages rather then a list of the 
geometries? I can get the<BR>acreages from the table resulting from the above, 
but I can't figure out<BR>how to skip the step of creating a table.<BR><BR>(3) 
What is the syntax using ST_Intersection rather than 
Intersection?<BR><BR>thanks,<BR><BR>Marcus<BR>_______________________________________________<BR>postgis-users 
mailing list<BR>postgis-users@postgis.refractions.net<BR><A 
href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</A><BR><BR><BR></FONT></P></BODY></HTML>

<HTML><BODY><P><hr size=1></P>
<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></BODY></HTML>

<P><hr size=1></P>
<P><STRONG><font size="2" color="339900"> Help make the earth a greener place. If at all possible resist printing this email and join us in saving paper. </p> <p> </font></STRONG></P>