Quantcast

Simplification on an invalid polygon, expected behavior?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Simplification on an invalid polygon, expected behavior?

Jeff Adams-4
I have some code that creates "circle" polygons given a center, radius, and number of points.  The circle gets passed to some other code that happens to simplify the polygon (using DouglasPeucker).

I accidentally wound up calling this code with a radius of zero.  This produced a 46-point polygon where all the points were identical.  What was surprising to me is that the simplifier didn't seem to change it at all.  I would have expected it to return a single point, or throw an exception, or something.  Is this (doing nothing) the expected behavior?

Thanks,
Jeff

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

Re: Simplification on an invalid polygon, expected behavior?

Martin Davis
What was your simplification tolerance?  If it was 0 as well, then
nothing would be changed.

If not, this might be a bug - although this is a bit outside what would
be considered as reasonable input to a simplification routine.

Jeff Adams wrote:

> I have some code that creates "circle" polygons given a center,
> radius, and number of points.  The circle gets passed to some other
> code that happens to simplify the polygon (using DouglasPeucker).
>
> I accidentally wound up calling this code with a radius of zero.  This
> produced a 46-point polygon where all the points were identical.  What
> was surprising to me is that the simplifier didn't seem to change it
> at all.  I would have expected it to return a single point, or throw
> an exception, or something.  Is this (doing nothing) the expected
> behavior?
>
> Thanks,
> Jeff
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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
|  
Report Content as Inappropriate

Re: Simplification on an invalid polygon, expected behavior?

Jeff Adams-4
It shouldn't have been zero, although I don't actually know what it was (It was due to a bug in my code, that has since been fixed). 

However I just tried to reproduce it with a test case and simplify seems to return an empty geometrycollection (which seems like resonable behavior, although better behavior might be to produce a single point at the center).  So perhaps I was mistaken about exactly what was going on...  It makes me wonder if my code that calls simplify is not correct ;-).  I'll let you know if I am able to reproduce this again.

Here is my simple test case if you want to mess around with it:

        [Test]
        public void TestSimplifyBadPoly()
        {
            Polygon p = new Polygon(new LinearRing(new ICoordinate[] {
                new Coordinate(1, 1), new Coordinate(1, 1),
                new Coordinate(1, 1), new Coordinate(1, 1),
                new Coordinate(1, 1)}));
            Console.Out.WriteLine("Bad polygon: " + p);
            IGeometry simpleP = DouglasPeuckerSimplifier.Simplify(p, 0.1);
            Console.Out.WriteLine("Simple bad polygon: " + simpleP);
            Assert.AreNotEqual(p, simpleP, "Simplify didn't do anything to this invalid polygon.");
        }


On Tue, Mar 3, 2009 at 11:39 AM, Martin Davis <[hidden email]> wrote:
What was your simplification tolerance?  If it was 0 as well, then nothing would be changed.

If not, this might be a bug - although this is a bit outside what would be considered as reasonable input to a simplification routine.

Jeff Adams wrote:
- Show quoted text -
I have some code that creates "circle" polygons given a center, radius, and number of points.  The circle gets passed to some other code that happens to simplify the polygon (using DouglasPeucker).

I accidentally wound up calling this code with a radius of zero.  This produced a 46-point polygon where all the points were identical.  What was surprising to me is that the simplifier didn't seem to change it at all.  I would have expected it to return a single point, or throw an exception, or something.  Is this (doing nothing) the expected behavior?

Thanks,
Jeff
------------------------------------------------------------------------

_______________________________________________
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
|  
Report Content as Inappropriate

Re: Simplification on an invalid polygon, expected behavior?

Martin Davis
I notice you're using NTS (right?)...  The behaviour in JTS is slightly
different - it returns a POLYGON EMPTY.

Simplification always returns a geometry of the same type as the input
geometry, and by default it attempts to ensure valid topology (by
applying  a buffer(0) - which is a bit of a hack, I admit). This is why
it returns an empty polygon.

You can prevent the validity enforcement by using
DouglasPeuckerSimplifier.setEnsureValid(false)

AFAIK there's no clear standard on how to handle degenerate cases like
this - different use cases might require different kinds of output.  You
should check for degenerate input first and convert it according to your
precise need.

Jeff Adams wrote:

> It shouldn't have been zero, although I don't actually know what it
> was (It was due to a bug in my code, that has since been fixed).
>
> However I just tried to reproduce it with a test case and simplify
> seems to return an empty geometrycollection (which seems like
> resonable behavior, although better behavior might be to produce a
> single point at the center).  So perhaps I was mistaken about exactly
> what was going on...  It makes me wonder if my code that calls
> simplify is not correct ;-).  I'll let you know if I am able to
> reproduce this again.
>
> Here is my simple test case if you want to mess around with it:
>
>         [Test]
>         public void TestSimplifyBadPoly()
>         {
>             Polygon p = new Polygon(new LinearRing(new ICoordinate[] {
>                 new Coordinate(1, 1), new Coordinate(1, 1),
>                 new Coordinate(1, 1), new Coordinate(1, 1),
>                 new Coordinate(1, 1)}));
>             Console.Out.WriteLine("Bad polygon: " + p);
>             IGeometry simpleP = DouglasPeuckerSimplifier.Simplify(p, 0.1);
>             Console.Out.WriteLine("Simple bad polygon: " + simpleP);
>             Assert.AreNotEqual(p, simpleP, "Simplify didn't do
> anything to this invalid polygon.");
>         }
>
>
> On Tue, Mar 3, 2009 at 11:39 AM, Martin Davis <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     What was your simplification tolerance?  If it was 0 as well, then
>     nothing would be changed.
>
>     If not, this might be a bug - although this is a bit outside what
>     would be considered as reasonable input to a simplification routine.
>
>     Jeff Adams wrote:
>
>         - Show quoted text -
>         I have some code that creates "circle" polygons given a
>         center, radius, and number of points.  The circle gets passed
>         to some other code that happens to simplify the polygon (using
>         DouglasPeucker).
>
>         I accidentally wound up calling this code with a radius of
>         zero.  This produced a 46-point polygon where all the points
>         were identical.  What was surprising to me is that the
>         simplifier didn't seem to change it at all.  I would have
>         expected it to return a single point, or throw an exception,
>         or something.  Is this (doing nothing) the expected behavior?
>
>         Thanks,
>         Jeff
>         ------------------------------------------------------------------------
>
>         _______________________________________________
>         jts-devel mailing list
>         [hidden email]
>         <mailto:[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]
>     <mailto:[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
|  
Report Content as Inappropriate

Re: Simplification on an invalid polygon, expected behavior?

Jeff Adams-4
That makes sense, thanks for the explaination.  And yep, I'm using NTS.

On Wed, Mar 4, 2009 at 11:41 AM, Martin Davis <[hidden email]> wrote:
I notice you're using NTS (right?)...  The behaviour in JTS is slightly different - it returns a POLYGON EMPTY.

Simplification always returns a geometry of the same type as the input geometry, and by default it attempts to ensure valid topology (by applying  a buffer(0) - which is a bit of a hack, I admit). This is why it returns an empty polygon.

You can prevent the validity enforcement by using DouglasPeuckerSimplifier.setEnsureValid(false)

AFAIK there's no clear standard on how to handle degenerate cases like this - different use cases might require different kinds of output.  You should check for degenerate input first and convert it according to your precise need.

Jeff Adams wrote:
It shouldn't have been zero, although I don't actually know what it was (It was due to a bug in my code, that has since been fixed).
However I just tried to reproduce it with a test case and simplify seems to return an empty geometrycollection (which seems like resonable behavior, although better behavior might be to produce a single point at the center).  So perhaps I was mistaken about exactly what was going on...  It makes me wonder if my code that calls simplify is not correct ;-).  I'll let you know if I am able to reproduce this again.

Here is my simple test case if you want to mess around with it:

       [Test]
       public void TestSimplifyBadPoly()
       {
           Polygon p = new Polygon(new LinearRing(new ICoordinate[] {
               new Coordinate(1, 1), new Coordinate(1, 1),
               new Coordinate(1, 1), new Coordinate(1, 1),
               new Coordinate(1, 1)}));
           Console.Out.WriteLine("Bad polygon: " + p);
           IGeometry simpleP = DouglasPeuckerSimplifier.Simplify(p, 0.1);
           Console.Out.WriteLine("Simple bad polygon: " + simpleP);
           Assert.AreNotEqual(p, simpleP, "Simplify didn't do anything to this invalid polygon.");
       }


On Tue, Mar 3, 2009 at 11:39 AM, Martin Davis <[hidden email] <mailto:[hidden email]>> wrote:

   What was your simplification tolerance?  If it was 0 as well, then
   nothing would be changed.

   If not, this might be a bug - although this is a bit outside what
   would be considered as reasonable input to a simplification routine.

   Jeff Adams wrote:

       - Show quoted text -
       I have some code that creates "circle" polygons given a
       center, radius, and number of points.  The circle gets passed
       to some other code that happens to simplify the polygon (using
       DouglasPeucker).

       I accidentally wound up calling this code with a radius of
       zero.  This produced a 46-point polygon where all the points
       were identical.  What was surprising to me is that the
       simplifier didn't seem to change it at all.  I would have
       expected it to return a single point, or throw an exception,
       or something.  Is this (doing nothing) the expected behavior?

       Thanks,
       Jeff
       ------------------------------------------------------------------------

       _______________________________________________
       jts-devel mailing list
       [hidden email]
       <mailto:[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]
   <mailto:[hidden email]>

   http://lists.refractions.net/mailman/listinfo/jts-devel


------------------------------------------------------------------------

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

--
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
|  
Report Content as Inappropriate

Re: Simplification on an invalid polygon, expected behavior?

D_Guidi
> That makes sense, thanks for the explaination.  And yep, I'm using NTS.
Please try to open an isse in NTS so I could try to fix the behavior.
And, well, thanks to JTS authors and JTS mailing list for your
invaluable support, your amazing work makes also .NET GIS world a
better place to live :)
_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Simplification on an invalid polygon, expected behavior?

Jeff Adams-4
>And, well, thanks to JTS authors and JTS mailing list for your
>invaluable support, your amazing work makes also .NET GIS world a
>better place to live :)

Understatement of the year!  If it weren't for NTS I'd be stuck using ArcObjects...

On Wed, Mar 4, 2009 at 2:01 PM, Diego Guidi <[hidden email]> wrote:
> That makes sense, thanks for the explaination.  And yep, I'm using NTS.
Please try to open an isse in NTS so I could try to fix the behavior.
And, well, thanks to JTS authors and JTS mailing list for your
invaluable support, your amazing work makes also .NET GIS world a
better place to live :)
- Show quoted text -
_______________________________________________
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
Loading...