<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>
Thanks for the help...I'm using an if statement comparing the first and last coords as suggested earlier, and then a next if they are not equal. So far it works, but if I run into issues, I'll attempt the try catch block. <br>Shad<br><br><br><blockquote><hr>From: lr@pcorp.us<br>To: postgis-users@postgis.refractions.net<br>Subject: RE: [postgis-users] only insert valid/closed ring geometries<br>Date: Thu, 10 Apr 2008 12:24:01 -0400<br><br>
<meta http-equiv="Content-Type" content="text/html; charset=unicode">
<meta name="Generator" content="Microsoft SafeHTML">
<style>
.ExternalClass .EC_hmmessage P
{padding-right:0px;padding-left:0px;padding-bottom:0px;padding-top:0px;}
.ExternalClass BODY.EC_hmmessage
{font-size:10pt;font-family:Tahoma;}
</style>
<div dir="ltr" align="left"><span class="EC_257202216-10042008"><font color="#0000ff" face="Arial">For this kind of situation I usually use a Try Catch block and
then in the Catch either discard the error and move on or log
it.</font></span></div>
<div dir="ltr" align="left"><span class="EC_257202216-10042008"><font color="#0000ff" face="Arial"></font></span> </div>
<div dir="ltr" align="left"><span class="EC_257202216-10042008"><font color="#0000ff" face="Arial">I haven't used perl much, but from this, it looks like it supports
Try Catch</font></span></div>
<div dir="ltr" align="left"><span class="EC_257202216-10042008"><font color="#0000ff" face="Arial"><a href="http://snippets.dzone.com/posts/show/928" target="_blank">http://snippets.dzone.com/posts/show/928</a></font></span></div>
<div dir="ltr" align="left"><span class="EC_257202216-10042008"><font color="#0000ff" face="Arial"></font></span> </div>
<div dir="ltr" align="left"><span class="EC_257202216-10042008"><font color="#0000ff" face="Arial">Hope that helps,</font></span></div>
<div dir="ltr" align="left"><span class="EC_257202216-10042008"><font color="#0000ff" face="Arial">Leo</font></span></div><font color="#0000ff" face="Arial"></font><br>
<div class="EC_OutlookMessageHeader" dir="ltr" align="left" lang="en-us">
<hr>
<font face="Tahoma"><b>From:</b> postgis-users-bounces@postgis.refractions.net
[mailto:postgis-users-bounces@postgis.refractions.net] <b>On Behalf Of </b>Shad
Keene<br><b>Sent:</b> Thursday, April 10, 2008 9:36 AM<br><b>To:</b>
postgis-users@postgis.refractions.net<br><b>Subject:</b> [postgis-users] only
insert valid/closed ring geometries<br></font><br></div>
<div></div><br><br><br> I started
using postgis recently because of the spatial capabilities, but I'm stuck
now.<br>
<blockquote>
<style>
.ExternalClass EC_UNKNOWN
{;}
.ExternalClass EC_UNKNOWN
{;}
</style>
I have a list of user-entered geometries that I'm inserting into a table via
perl. I'm using the following code to insert the geometries into the
table: (ISOL basically refers to a point
geometry.)<br><br><br> <br><br>if ($cwa_entries[4] eq "AREA")
{<br><br>$sth = $dbh->prepare("INSERT into cwa
values(GeomFromText('POLYGON(($cwa_entries[3]))', 4326), '$cwa_entries[6]',
'$cwa_entries[5]', nextval('cwa_id_seq'), '$cwa_entries[0]',
'$cwa_entries[1]', '$cwa_entries[4]')") or die "could not execute:
$DBI::errstr";<br><br>}<br><br>elsif ($cwa_entries[4] eq "LINE") {<br><br>$sth
= $dbh->prepare("INSERT into cwa
values(GeomFromText('LINESTRING($cwa_entries[3])', 4326), '$cwa_entries[6]',
'$cwa_entries[5]', nextval('cwa_id_seq'), '$cwa_entries[0]',
'$cwa_entries[1]', '$cwa_entries[4]')") or die "could not execute:
$DBI::errstr";<br><br>}<br><br>elsif ($cwa_entries[4] eq "ISOL") {<br><br>$sth
= $dbh->prepare("INSERT into cwa
values(GeomFromText('POINT($cwa_entries[3])', 4326), '$cwa_entries[6]',
'$cwa_entries[5]', nextval('cwa_id_seq'), '$cwa_entries[0]',
'$cwa_entries[1]', '$cwa_entries[4]')") or die "could not execute:
$DBI::errstr";<br><br>}<br><br> <br><br>$sth->execute() or die "Could
not execute: $DBI::errstr";<br><br> <br><br>Sometimes there are values
that are entered that do not represent valid geometries. For instance, I
might get a set of coordinates that is designated a polygon, but the last
coordinates don't equal the first coordinates(i.e. non-closed ring). I
don't have any control over the data that reaches me(i.e. it's already
designated as AREA or LINE or ISOLD(for point). So how can I skip the
non-closed-ring geometries and only enter the valid geometries so that my
script doesn't quit on me and produce an error before it enters all the
data. Right now, I get an error on the execute statement, and it pretty
much prevents the rest of the data from being inserted into the
database. This may be a more perl-centered question, but I thought there
might be a postgresql command that has the effect of "insert only if
GeomFromText()...is valid", else move on to the next insert. I did see
the <span class="EC_term">ST_IsClosed(geometry) and the ST_IsValid(geometry)
statements, but I don't know how to implement them prior to the insert.
Thanks for any help.</span><br><br>Shad</blockquote><br><br>
<div><font style="color: rgb(0, 0, 255);" size="1"><span style="font-style: italic; font-family: Lucida Handwriting,Cursive;"></span></font><em><font color="#0000ff" face="Lucida Handwriting" size="1"><br></font></em></div><br>
<hr>
Get in touch in an instant. <a href="http://www.windowslive.com/messenger/overview.html?ocid=TXT_TAGLM_WL_Refresh_getintouch_042008" target="_blank">Get Windows Live Messenger now.</a>
</blockquote><br /><hr />Going green? <a href='http://green.msn.com/galleries/photos/photos.aspx?gid=164&ocid=T003MSN51N1653A' target='_new'>See the top 12 foods to eat organic.</a></body>
</html>