[postgis-users] correcting polygons
Obe, Regina
robe.dnd at cityofboston.gov
Mon Jun 4 04:46:35 PDT 2007
The error means that you are trying to insert geometries with a
different SRID than the SRID that you specified for your new table.
Note your new table has an SRID = -1
My guess is that your original deparea table has an SRID different from
-1.
To check try
SELECT distinct(srid(the_geom)) as the_srid
FROM deparea
You should only get 1 record unless you have a mixed bag of SRIDs. Now
whatever that srid is, your add geometry should use that instead of the
-1 you have in place. So the line
SELECT AddGeometryColumn('public','deparea2', 'poli', '<WHATEVER SRID
YOU GOT ABOVE GOES HERE>',
'POLYGON',2);
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: Monday, June 04, 2007 1:54 AM
To: PostGIS Users Discussion
Subject: RE: [postgis-users] correcting polygons
Thanks Regina,
If you, or someone else, got the time I would be pleased if you can
explain this error code for me. I've tried to do some random changes :)
since I'm not very good at SQL.
ERROR (appears on the last SQL row):
org.postgresql.util.PSQLException: ERROR: new row for relation
"depare_area2" violates check constraint "enforce_srid_poli"
This is what I do:
SELECT geometryN(the_geom, generate_series(1, numgeometries(the_geom)))
AS poli FROM deparea;
CREATE TABLE deparea2 (gid serial, CONSTRAINT pk_deparea2 PRIMARY
KEY(gid));
SELECT AddGeometryColumn('public','deparea2', 'poli', '-1',
'POLYGON',2);
INSERT INTO deparea2(poli) SELECT geometryn(the_geom, generate_series(1,
numgeometries(the_geom))) As poli FROM deparea;
CREATE INDEX idx_deparea2_poli ON deparea2 USING gist (poli);
UPDATE deparea2 SET poli = multi(buffer(poli, 0.0)) WHERE isvalid(poli)
= false AND isvalid(buffer(poli, 0.0)) = true;
Kind regards,
Paul
-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Obe,
Regina
Sent: den 1 juni 2007 17:05
To: PostGIS Users Discussion
Subject: RE: [postgis-users] correcting polygons
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
_______________________________________________
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
More information about the postgis-users
mailing list