[postgis-users] correcting polygons

Obe, Regina robe.dnd at cityofboston.gov
Fri Jun 1 08:05:15 PDT 2007


Forgot to mention before updating the field, its probably best to only
if you really need to and if updating will help so something like

UPDATE sometable 
SET the_geom = multi(buffer(the_geom, 0.0))
WHERE isvalid(the_geom) = false and isvalid(buffer(the_geom,0.0)) = true
 

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Obe,
Regina
Sent: Friday, June 01, 2007 8:28 AM
To: PostGIS Users Discussion
Subject: RE: [postgis-users] correcting polygons

Paul,

Not sure if this quite answers your question, but you would use an
UPDATE statement to update a geometry

So for example

UPDATE sometable SET the_geom = multi(buffer(the_geom, 0.0))

or 
UPDATE sometable SET the_geom = buffer(the_geom, 0.0)


Now generate_series explodes a row so in an update statement - doesn't
really make sense to use unless you want to do something with each
individual geometry and then collapse it back using something like
collect or geomunion.  As I recall from using buffer before, I think it
acts on each individual geometry in a multi set e..g in a multipolygon.
So doing a generate series is really not necessary to use buffer - it
sort of implicitly does that whole thing for you.  Someone correct me if
I am wrong on that assumption :)

The only thing to be careful of is that if you have a constraint on your
table that requires the_geom to be say a multipolygon,  when you apply a
buffer operation to it and there is only one geometry within the
multigeometry, buffer will convert that multipolygon to a polygon.  To
prevent that from happening, you would then apply the multi function.
multi function in essence wraps your single polygon into a multipolygon
encasement.

Hope that helps,
Regina 

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Malm
Paul
Sent: Friday, June 01, 2007 4:50 AM
To: PostGIS Users Discussion
Subject: RE: [postgis-users] correcting polygons

Thanks, Paul!

I'm not to good in SQL and have looked at old userGroup qestions and
found this (Regina Obe):
(converting multi polygons to polygons by creating a new tabel)
/////////////////////////////////////////
String table = "depare_area";
String qq;
myStat = con.createStatement();

qq= "SELECT geometryN(the_geom, generate_series(1,
numgeometries(the_geom))) AS poli FROM " + table;
Statement myStat2 = con.createStatement();
ResultSet myResult2 = myStat2.executeQuery(qq);

qq = "CREATE TABLE " + table + "2 " + "(gid serial, CONSTRAINT " + "pk_"
+ table + "2 " + " PRIMARY KEY(gid))";
myStat.execute(qq);

qq = "SELECT AddGeometryColumn('public','" + table + "2', 'poli', '-1',
'POLYGON',2)";
myStat.execute(qq);

qq = "INSERT INTO " + table + "2(poli) SELECT geometryn(the_geom,
generate_series(1, numgeometries(the_geom))) As poli FROM " + table;
myStat.execute(qq);
			
qq = "CREATE INDEX idx_" + table + "2_poli  ON " + table + "2  USING
gist (poli)";
myStat.execute(qq);
//////////////////////////////////////////////

Du you know how I at the same time can use your suggestion to use
buffer(xxxx, 0.0) to correct the polygons?

I have not found anything of how to update objects, only how to create
new objects.

Kind regards,
Paul
  

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Paul
Ramsey
Sent: den 30 maj 2007 20:01
To: PostGIS Users Discussion
Subject: Re: [postgis-users] correcting polygons

buffer(polygon,0.0) should re-build it with correct structure

On 30-May-07, at 7:29 AM, Malm Paul wrote:

> Hi list,
> Is there a simple way to correct a polygon that has a hole and where 
> one of the coordinates of that hole is exactly the same as one 
> coordinate in the external ring?
>
> Kind regards,
> Paul
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
-----------------------------------------
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.
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



More information about the postgis-users mailing list