Geometry#isValid

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Geometry#isValid

John Cartwright
Hello All,

I notice that if I create a invalid geometry using a WKT string like
"POINT(1,2)", the resulting Geometry still returns true on a call to
it's isValid() method.  point.getCoordinate.y in this case shows NaN.
Is the isValid procedure supposed to do this?  Is there another way to
determine whether a Geometry does not contain NaN or a better way to
protect against invalid WKT strings?

Thanks!

--john





_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|

Re: Geometry#isValid

Martin Davis
What version of JTS are you using?

"POINT(1,2)" should not parse as correct WKT.  And for several versions
now isValid() has checked for Coordinates with NaN ordinate values.

John Cartwright wrote:

> Hello All,
>
> I notice that if I create a invalid geometry using a WKT string like
> "POINT(1,2)", the resulting Geometry still returns true on a call to
> it's isValid() method.  point.getCoordinate.y in this case shows NaN.
> Is the isValid procedure supposed to do this?  Is there another way to
> determine whether a Geometry does not contain NaN or a better way to
> protect against invalid WKT strings?
>
> Thanks!
>
> --john
>
>
>
>
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|

Re: Geometry#isValid

John Cartwright
Thanks for the prompt reply and sorry I omitted the version - 1.10.

--john


Martin Davis wrote:

> What version of JTS are you using?
>
> "POINT(1,2)" should not parse as correct WKT.  And for several
> versions now isValid() has checked for Coordinates with NaN ordinate
> values.
>
> John Cartwright wrote:
>> Hello All,
>>
>> I notice that if I create a invalid geometry using a WKT string like
>> "POINT(1,2)", the resulting Geometry still returns true on a call to
>> it's isValid() method.  point.getCoordinate.y in this case shows NaN.
>> Is the isValid procedure supposed to do this?  Is there another way to
>> determine whether a Geometry does not contain NaN or a better way to
>> protect against invalid WKT strings?
>>
>> Thanks!
>>
>> --john
>>
>>
>>
>>
>>
>> _______________________________________________
>> jts-devel mailing list
>> [hidden email]
>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>
>>  
>
_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|

Re: Geometry#isValid

Martin Davis
If you're using 1.10 then I'm puzzled by what you're seeing.

Can you post code that exhibits the problem?

John Cartwright wrote:

> Thanks for the prompt reply and sorry I omitted the version - 1.10.
>
> --john
>
>
> Martin Davis wrote:
>  
>> What version of JTS are you using?
>>
>> "POINT(1,2)" should not parse as correct WKT.  And for several
>> versions now isValid() has checked for Coordinates with NaN ordinate
>> values.
>>
>> John Cartwright wrote:
>>    
>>> Hello All,
>>>
>>> I notice that if I create a invalid geometry using a WKT string like
>>> "POINT(1,2)", the resulting Geometry still returns true on a call to
>>> it's isValid() method.  point.getCoordinate.y in this case shows NaN.
>>> Is the isValid procedure supposed to do this?  Is there another way to
>>> determine whether a Geometry does not contain NaN or a better way to
>>> protect against invalid WKT strings?
>>>
>>> Thanks!
>>>
>>> --john
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> jts-devel mailing list
>>> [hidden email]
>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>
>>>  
>>>      
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|

Re: Geometry#isValid

John Cartwright
In reply to this post by John Cartwright
Hi Martin,

a little further investigation showed that the comma was being stripped
out before WKTReader got to the String, but it still looks like NaN is
being treated as valid - is this correct?

Thanks for your help!

--john


public void testWktParse() throws ParseException{
        String wkt = null;
        Geometry geometry = null;
               
        wkt = "POINT (10 10)";
        geometry = wktReader.read(wkt);
        assertNotNull(geometry);
        assertTrue(geometry.isValid());
           
        wkt = "POINT (10, 10)";
        try {
      geometry = wktReader.read(wkt);
      fail("should have seen ParseException");
      } catch (ParseException e) {
     
      }
           
        wkt = "POINT (10 NaN)";
        geometry = wktReader.read(wkt);
           assertNotNull(geometry);
           assertFalse("NaN coordinate",geometry.isValid());
        }


----- Original Message -----
From: Martin Davis <[hidden email]>
Date: Monday, September 21, 2009 6:14 pm
Subject: Re: [jts-devel] Geometry#isValid

> If you're using 1.10 then I'm puzzled by what you're seeing.
>
> Can you post code that exhibits the problem?
>
> John Cartwright wrote:
> > Thanks for the prompt reply and sorry I omitted the version - 1.10.
> >
> > --john
> >
> >
> > Martin Davis wrote:
> >  
> >> What version of JTS are you using?
> >>
> >> "POINT(1,2)" should not parse as correct WKT.  And for several
> >> versions now isValid() has checked for Coordinates with NaN
> ordinate>> values.
> >>
> >> John Cartwright wrote:
> >>    
> >>> Hello All,
> >>>
> >>> I notice that if I create a invalid geometry using a WKT string
> like>>> "POINT(1,2)", the resulting Geometry still returns true on
> a call to
> >>> it's isValid() method.  point.getCoordinate.y in this case
> shows NaN.
> >>> Is the isValid procedure supposed to do this?  Is there another
> way to
> >>> determine whether a Geometry does not contain NaN or a better
> way to
> >>> protect against invalid WKT strings?
> >>>
> >>> Thanks!
> >>>
> >>> --john
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> _______________________________________________
> >>> jts-devel mailing list
> >>> [hidden email]
> >>> http://lists.refractions.net/mailman/listinfo/jts-devel
> >>>
> >>>  
> >>>      
> > _______________________________________________
> > jts-devel mailing list
> > [hidden email]
> > http://lists.refractions.net/mailman/listinfo/jts-devel
> >
> >  
>
> --
> Martin Davis
> Senior Technical Architect
> Refractions Research, Inc.
> (250) 383-3022
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|

Re: Geometry#isValid

Martin Davis
Ok, John, I see what's going on now.  You've found a sneaky little bug
in JTS.  The Point#isValid method was not checking for ordinate values
of NaN.

Lineal and Polygonal geometries are not affected by this bug.

I've fixed this in CVS, and it will appear in JTS 1.11

Martin

[hidden email] wrote:

> Hi Martin,
>
> a little further investigation showed that the comma was being stripped
> out before WKTReader got to the String, but it still looks like NaN is
> being treated as valid - is this correct?
>
> Thanks for your help!
>
> --john
>
>
> public void testWktParse() throws ParseException{
> String wkt = null;
> Geometry geometry = null;
>
> wkt = "POINT (10 10)";
>         geometry = wktReader.read(wkt);
> assertNotNull(geometry);
> assertTrue(geometry.isValid());
>  
> wkt = "POINT (10, 10)";
>         try {
>       geometry = wktReader.read(wkt);
>       fail("should have seen ParseException");
>       } catch (ParseException e) {
>      
>       }
>  
> wkt = "POINT (10 NaN)";
>         geometry = wktReader.read(wkt);
>   assertNotNull(geometry);
>   assertFalse("NaN coordinate",geometry.isValid());
> }
>
>
> ----- Original Message -----
> From: Martin Davis <[hidden email]>
> Date: Monday, September 21, 2009 6:14 pm
> Subject: Re: [jts-devel] Geometry#isValid
>
>  
>> If you're using 1.10 then I'm puzzled by what you're seeing.
>>
>> Can you post code that exhibits the problem?
>>
>> John Cartwright wrote:
>>    
>>> Thanks for the prompt reply and sorry I omitted the version - 1.10.
>>>
>>> --john
>>>
>>>
>>> Martin Davis wrote:
>>>  
>>>      
>>>> What version of JTS are you using?
>>>>
>>>> "POINT(1,2)" should not parse as correct WKT.  And for several
>>>> versions now isValid() has checked for Coordinates with NaN
>>>>        
>> ordinate>> values.
>>    
>>>> John Cartwright wrote:
>>>>    
>>>>        
>>>>> Hello All,
>>>>>
>>>>> I notice that if I create a invalid geometry using a WKT string
>>>>>          
>> like>>> "POINT(1,2)", the resulting Geometry still returns true on
>> a call to
>>    
>>>>> it's isValid() method.  point.getCoordinate.y in this case
>>>>>          
>> shows NaN.
>>    
>>>>> Is the isValid procedure supposed to do this?  Is there another
>>>>>          
>> way to
>>    
>>>>> determine whether a Geometry does not contain NaN or a better
>>>>>          
>> way to
>>    
>>>>> protect against invalid WKT strings?
>>>>>
>>>>> Thanks!
>>>>>
>>>>> --john
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> jts-devel mailing list
>>>>> [hidden email]
>>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>>
>>>>>  
>>>>>      
>>>>>          
>>> _______________________________________________
>>> jts-devel mailing list
>>> [hidden email]
>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>
>>>  
>>>      
>> --
>> Martin Davis
>> Senior Technical Architect
>> Refractions Research, Inc.
>> (250) 383-3022
>>
>> _______________________________________________
>> jts-devel mailing list
>> [hidden email]
>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>
>>    
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel