[postgis-users] error in isvalid function

ksa-nil5 ksa-nil5 at yandex.ru
Fri Nov 5 01:41:58 PST 2004


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?

>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