[postgis-users] error in isvalid function
strk at refractions.net
strk at refractions.net
Fri Nov 5 01:48:46 PST 2004
On Fri, Nov 05, 2004 at 12:41:58PM +0300, ksa-nil5 wrote:
> function is valid define as follows:
>
> PG_FUNCTION_INFO_V1(isvalid);
> Datum isvalid(PG_FUNCTION_ARGS)
> {
> GEOMETRY *geom1 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
> bool result;
> Geometry *g1;
>
> initGEOS(MAXIMUM_ALIGNOF);
>
> g1 = POSTGIS2GEOS(geom1 );
>
> result = GEOSisvalid(g1);
> GEOSdeleteGeometry(g1);
> if (result == 2)
> {
> elog(ERROR,"GEOS isvalid() threw an error!");
> PG_RETURN_NULL(); //never get here
> }
>
>
> PG_RETURN_BOOL(result);
> }
>
> So, if GEOSisvalid() returns 2 then isvalid() returns PG_RETURN_NULL(). Why? It may be better if in that case isvalid() will return PG_RETURN_BOOL(false). Do you think so?
As a quick and dirty solution, yes.
But the GEOSisvalid function could handle it itself....
In our case (I went through it more deeply) it is not the GEOS
convertion as I thought, but the IsValidOp itself which is failing
to catch an exception thrown by the GeometryGraph.
My point is that an exception is an exception, like something preventing
the IsValidOp to do it's work. I don't feel comfortable in threating
all of them as Invalidity responses, as they might not be.
--strk;
>
> >On Fri, Nov 05, 2004 at 11:42:46AM +0300, ksa wrote:
> >> okay, hole is really invalid. But how I can handle of this situation? If I
> >> *already* have polygones with similar holes. Which function I can use to
> >> determinate this without getting an exception?
> >
> >Problem is that the invalidity of that geometry prevents
> >POSTGIS->GEOS conversion.
> >GEOS refuses to build a polygon *that* invalid...
> >Maybe the postgis geos wrapped could consider that as an invalidity,
> >do people see any drawbacks in this ?
> >
> >--strk;
> >
> >>
> >> > I've verified your query.
> >> > The Polygon is actually invalid due to degenerate hole (as the
> >> > exception states).
> >> > When extracting the rings, these are handled as LINESTRINGS, for which
> >> > the degenerate case is not checked.
> >> > Which do you think would be a better handling of this situation ?
> >> >
> >> > --strk;
> >> >
> >> >
> >> >
> >> > On Fri, Nov 05, 2004 at 09:17:01AM +0300, ksa-nil5 wrote:
> >> > > >> Hi, all!
> >> > > >>
> >> > > >> I'm working with follow data (POLYGON):
> >> > > >>
> >> > > >> POLYGON((37.654639 55.726496,37.654056 55.726947,37.653801
> >> 55.727333,37.653801 55.727435,37.654468 55.727483,37.656654
> >> 55.727466,37.656572 55.727063,37.656654 55.726713,37.657052
> >> 55.726531,37.657571 55.726365,37.658071 55.725961,37.658321
> >> 55.725609,37.658303 55.725374,37.658321 55.725609,37.658906
> >> 55.725309,37.659488 55.72511,37.658135 55.724571,37.657386
> >> 55.724922,37.657135 55.724873,37.65647 55.725274,37.655635
> >> 55.725828,37.655195 55.7265,37.655635 55.725927,37.654639
> >> 55.726496),(37.658321 55.725609,37.658906 55.725309,37.659488
> >> 55.72511,37.658906 55.725309,37.658321 55.725609))
> >> > > >>
> >> > > >> search=# select isvalid(geometryFromText(the_geom));
> >> > > >> NOTICE: IllegalArgumentException: degenerate ring (does not contain
> >> 3 distinct points)
> >> > > >> ERROR: GEOS isvalid() threw an error!
> >> > > >>
> >> > > >> search=# select isvalid(exteriorring(geometryFromText(the_geom)));
> >> > > >> isvalid
> >> > > >> ---------
> >> > > >> t
> >> > > >> (1 row)
> >> > > >>
> >> > > >> search=# select isvalid(interiorringN(geometryFromText(the_geom),1));
> >> > > >> isvalid
> >> > > >> ---------
> >> > > >> t
> >> > > >> (1 row)
> >> > > >>
> >> > > >> Any suggestions?
> >> > > >>
> >> > > >> Thanks!
> >> > > >>
> >> > > >> Sergey Karin
> >> > > >
> >> > > >What GEOS / PostGIS version are you using ?
> >> > > >
> >> > > >SELECT postgis_full_version();
> >> > > >
> >> > > >--strk;
> >> > > >
> >> > >
> >> > > search=# select postgis_full_version();
> >> > > postgis_full_version
> >> >
> >> > --------------------------------------------------------------------------
> >> ---------------------------
> >> > > POSTGIS="0.9.0" GEOS="2.0.1" PROJ="Rel. 4.4.8, 3 May 2004" USE_STATS
> >> DBPROC="0.0.1" RELPROC="0.0.1"
> >> > > (1 row)
>
>
> --
> ñÎÄÅËÓ.éÇÒÕÛËÉ - ÑÒËÉÊ ÐÅÒÅÒÙ× × ÓÅÒÙÈ ÔÒÕÄÏ×ÙÈ ÂÕÄÎÑÈ. http://play.yandex.ru/
More information about the postgis-users
mailing list