Quantcast

Can you call LineMerger.getMergedLineStrings more than once?

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

Can you call LineMerger.getMergedLineStrings more than once?

Jeff Adams-4
I am trying to join successive LineStrings until I find a gap.  So the way I am doing it is something like this:

while (merger.getMergedLineStrings().count() == 1)
    merger.add(...);
}

The problem is, getMergedLineStrings only calculates the merged line once.  After that, no matter how many more I add, it seems to always returns the same value.

What I don't know is if that is correct behavior or not.  I am actually using NTS, so there are a couple possibilities:
1) It's correct
2) It's a bug in the NTS port.
3) It's a JTS bug that has been faithfully ported to NTS.

Here is a C# test case, which you should be able to port to Java by changing capitalization on the methods and changing the Assert.IsBlah()s to assertIsBlah()s.  I apologize but I do not have a java development environment here so I cannot port it myself.

        [Test] public void TestLineMerger()
        {
            Coordinate coord1 = new Coordinate(0, 0);
            Coordinate coord2 = new Coordinate(0, 100);
            Coordinate coord3 = new Coordinate(0, 200);
            Coordinate coord4 = new Coordinate(0, 300);
            LineString line1 = new LineString(new ICoordinate[] { coord1, coord2 });
            LineString line2 = new LineString(new ICoordinate[] { coord2, coord3 });
            LineString line3 = new LineString(new ICoordinate[] { coord3, coord4 });

            LineMerger merger = new LineMerger();
            merger.Add(line1);
            IList mergedLines = merger.GetMergedLineStrings();
            Assert.IsNotNull(mergedLines, "Shouldn't get null when merging 1 line.");
            Assert.AreEqual(1, mergedLines.Count, "Should get 1 merged line from 1 input.");
            ILineString mergedLine = (ILineString)mergedLines[0];
            Assert.Greater(mergedLine.Length, 99.9, "Merged line was too short.");
            Assert.Less(mergedLine.Length, 100.1, "Merged line was too long.");

            merger.Add(line2);
            mergedLines = merger.GetMergedLineStrings();
            Assert.IsNotNull(mergedLines, "Shouldn't get null when merging 2 line.");
            Assert.AreEqual(1, mergedLines.Count, "Should get 1 merged line from 2 inputs.");
            mergedLine = (ILineString)mergedLines[0];
            // Fails here because the "merged" linestring is exactly the same as the first time
            // we called it.
            Assert.Greater(mergedLine.Length, 199.9, "Merged line was too short.");
            Assert.Less(mergedLine.Length, 200.1, "Merged line was too long.");
           
            merger.Add(line3);
            mergedLines = merger.GetMergedLineStrings();
            Assert.IsNotNull(mergedLines, "Shouldn't get null when merging 3 line.");
            Assert.AreEqual(1, mergedLines.Count, "Should get 1 merged line from 3 inputs.");
            mergedLine = (ILineString)mergedLines[0];
            Assert.Greater(mergedLine.Length, 299.9, "Merged line was too short.");
            Assert.Less(mergedLine.Length, 300.1, "Merged line was too long.");
        }

_______________________________________________
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: Can you call LineMerger.getMergedLineStrings more than once?

Martin Davis
You can only call getMergedLineStrings once.  If you need to merge
repeatedly, you will have to create a new LineMerger each time.

I'll add this caveat to the javadoc.

Jeff Adams wrote:

> I am trying to join successive LineStrings until I find a gap.  So the
> way I am doing it is something like this:
>
> while (merger.getMergedLineStrings().count() == 1)
>     merger.add(...);
> }
>
> The problem is, getMergedLineStrings only calculates the merged line
> once.  After that, no matter how many more I add, it seems to always
> returns the same value.
>
> What I don't know is if that is correct behavior or not.  I am
> actually using NTS, so there are a couple possibilities:
> 1) It's correct
> 2) It's a bug in the NTS port.
> 3) It's a JTS bug that has been faithfully ported to NTS.
>
> Here is a C# test case, which you should be able to port to Java by
> changing capitalization on the methods and changing the
> Assert.IsBlah()s to assertIsBlah()s.  I apologize but I do not have a
> java development environment here so I cannot port it myself.
>
>         [Test] public void TestLineMerger()
>         {
>             Coordinate coord1 = new Coordinate(0, 0);
>             Coordinate coord2 = new Coordinate(0, 100);
>             Coordinate coord3 = new Coordinate(0, 200);
>             Coordinate coord4 = new Coordinate(0, 300);
>             LineString line1 = new LineString(new ICoordinate[] {
> coord1, coord2 });
>             LineString line2 = new LineString(new ICoordinate[] {
> coord2, coord3 });
>             LineString line3 = new LineString(new ICoordinate[] {
> coord3, coord4 });
>
>             LineMerger merger = new LineMerger();
>             merger.Add(line1);
>             IList mergedLines = merger.GetMergedLineStrings();
>             Assert.IsNotNull(mergedLines, "Shouldn't get null when
> merging 1 line.");
>             Assert.AreEqual(1, mergedLines.Count, "Should get 1 merged
> line from 1 input.");
>             ILineString mergedLine = (ILineString)mergedLines[0];
>             Assert.Greater(mergedLine.Length, 99.9, "Merged line was
> too short.");
>             Assert.Less(mergedLine.Length, 100.1, "Merged line was too
> long.");
>
>             merger.Add(line2);
>             mergedLines = merger.GetMergedLineStrings();
>             Assert.IsNotNull(mergedLines, "Shouldn't get null when
> merging 2 line.");
>             Assert.AreEqual(1, mergedLines.Count, "Should get 1 merged
> line from 2 inputs.");
>             mergedLine = (ILineString)mergedLines[0];
>             // Fails here because the "merged" linestring is exactly
> the same as the first time
>             // we called it.
>             Assert.Greater(mergedLine.Length, 199.9, "Merged line was
> too short.");
>             Assert.Less(mergedLine.Length, 200.1, "Merged line was too
> long.");
>            
>             merger.Add(line3);
>             mergedLines = merger.GetMergedLineStrings();
>             Assert.IsNotNull(mergedLines, "Shouldn't get null when
> merging 3 line.");
>             Assert.AreEqual(1, mergedLines.Count, "Should get 1 merged
> line from 3 inputs.");
>             mergedLine = (ILineString)mergedLines[0];
>             Assert.Greater(mergedLine.Length, 299.9, "Merged line was
> too short.");
>             Assert.Less(mergedLine.Length, 300.1, "Merged line was too
> long.");
>         }
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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: Can you call LineMerger.getMergedLineStrings more than once?

Martin Davis
Even better - I've modified the code to be able to be called incrementally.

Martin Davis wrote:

> You can only call getMergedLineStrings once.  If you need to merge
> repeatedly, you will have to create a new LineMerger each time.
>
> I'll add this caveat to the javadoc.
>
> Jeff Adams wrote:
>> I am trying to join successive LineStrings until I find a gap.  So
>> the way I am doing it is something like this:
>>
>> while (merger.getMergedLineStrings().count() == 1)
>>     merger.add(...);
>> }
>>
>> The problem is, getMergedLineStrings only calculates the merged line
>> once.  After that, no matter how many more I add, it seems to always
>> returns the same value.
>>
>> What I don't know is if that is correct behavior or not.  I am
>> actually using NTS, so there are a couple possibilities:
>> 1) It's correct
>> 2) It's a bug in the NTS port.
>> 3) It's a JTS bug that has been faithfully ported to NTS.
>>
>> Here is a C# test case, which you should be able to port to Java by
>> changing capitalization on the methods and changing the
>> Assert.IsBlah()s to assertIsBlah()s.  I apologize but I do not have a
>> java development environment here so I cannot port it myself.
>>
>>         [Test] public void TestLineMerger()
>>         {
>>             Coordinate coord1 = new Coordinate(0, 0);
>>             Coordinate coord2 = new Coordinate(0, 100);
>>             Coordinate coord3 = new Coordinate(0, 200);
>>             Coordinate coord4 = new Coordinate(0, 300);
>>             LineString line1 = new LineString(new ICoordinate[] {
>> coord1, coord2 });
>>             LineString line2 = new LineString(new ICoordinate[] {
>> coord2, coord3 });
>>             LineString line3 = new LineString(new ICoordinate[] {
>> coord3, coord4 });
>>
>>             LineMerger merger = new LineMerger();
>>             merger.Add(line1);
>>             IList mergedLines = merger.GetMergedLineStrings();
>>             Assert.IsNotNull(mergedLines, "Shouldn't get null when
>> merging 1 line.");
>>             Assert.AreEqual(1, mergedLines.Count, "Should get 1
>> merged line from 1 input.");
>>             ILineString mergedLine = (ILineString)mergedLines[0];
>>             Assert.Greater(mergedLine.Length, 99.9, "Merged line was
>> too short.");
>>             Assert.Less(mergedLine.Length, 100.1, "Merged line was
>> too long.");
>>
>>             merger.Add(line2);
>>             mergedLines = merger.GetMergedLineStrings();
>>             Assert.IsNotNull(mergedLines, "Shouldn't get null when
>> merging 2 line.");
>>             Assert.AreEqual(1, mergedLines.Count, "Should get 1
>> merged line from 2 inputs.");
>>             mergedLine = (ILineString)mergedLines[0];
>>             // Fails here because the "merged" linestring is exactly
>> the same as the first time
>>             // we called it.
>>             Assert.Greater(mergedLine.Length, 199.9, "Merged line was
>> too short.");
>>             Assert.Less(mergedLine.Length, 200.1, "Merged line was
>> too long.");
>>                        merger.Add(line3);
>>             mergedLines = merger.GetMergedLineStrings();
>>             Assert.IsNotNull(mergedLines, "Shouldn't get null when
>> merging 3 line.");
>>             Assert.AreEqual(1, mergedLines.Count, "Should get 1
>> merged line from 3 inputs.");
>>             mergedLine = (ILineString)mergedLines[0];
>>             Assert.Greater(mergedLine.Length, 299.9, "Merged line was
>> too short.");
>>             Assert.Less(mergedLine.Length, 300.1, "Merged line was
>> too long.");
>>         }
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> 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: Can you call LineMerger.getMergedLineStrings more than once?

Jeff Adams-4
Heh, ok thanks.  Now I just have to wait for a new release, and then NTS to update to that new release... ;-).  I'll create a new LineMerger in the meanwhile.

Thanks for the quick response!
Jeff

On Tue, Oct 14, 2008 at 12:03 PM, Martin Davis <[hidden email]> wrote:
Even better - I've modified the code to be able to be called incrementally.


Martin Davis wrote:
You can only call getMergedLineStrings once.  If you need to merge repeatedly, you will have to create a new LineMerger each time.

I'll add this caveat to the javadoc.

Jeff Adams wrote:
I am trying to join successive LineStrings until I find a gap.  So the way I am doing it is something like this:

while (merger.getMergedLineStrings().count() == 1)
   merger.add(...);
}

The problem is, getMergedLineStrings only calculates the merged line once.  After that, no matter how many more I add, it seems to always returns the same value.

What I don't know is if that is correct behavior or not.  I am actually using NTS, so there are a couple possibilities:
1) It's correct
2) It's a bug in the NTS port.
3) It's a JTS bug that has been faithfully ported to NTS.

Here is a C# test case, which you should be able to port to Java by changing capitalization on the methods and changing the Assert.IsBlah()s to assertIsBlah()s.  I apologize but I do not have a java development environment here so I cannot port it myself.

       [Test] public void TestLineMerger()
       {
           Coordinate coord1 = new Coordinate(0, 0);
           Coordinate coord2 = new Coordinate(0, 100);
           Coordinate coord3 = new Coordinate(0, 200);
           Coordinate coord4 = new Coordinate(0, 300);
           LineString line1 = new LineString(new ICoordinate[] { coord1, coord2 });
           LineString line2 = new LineString(new ICoordinate[] { coord2, coord3 });
           LineString line3 = new LineString(new ICoordinate[] { coord3, coord4 });

           LineMerger merger = new LineMerger();
           merger.Add(line1);
           IList mergedLines = merger.GetMergedLineStrings();
           Assert.IsNotNull(mergedLines, "Shouldn't get null when merging 1 line.");
           Assert.AreEqual(1, mergedLines.Count, "Should get 1 merged line from 1 input.");
           ILineString mergedLine = (ILineString)mergedLines[0];
           Assert.Greater(mergedLine.Length, 99.9, "Merged line was too short.");
           Assert.Less(mergedLine.Length, 100.1, "Merged line was too long.");

           merger.Add(line2);
           mergedLines = merger.GetMergedLineStrings();
           Assert.IsNotNull(mergedLines, "Shouldn't get null when merging 2 line.");
           Assert.AreEqual(1, mergedLines.Count, "Should get 1 merged line from 2 inputs.");
           mergedLine = (ILineString)mergedLines[0];
           // Fails here because the "merged" linestring is exactly the same as the first time
           // we called it.
           Assert.Greater(mergedLine.Length, 199.9, "Merged line was too short.");
           Assert.Less(mergedLine.Length, 200.1, "Merged line was too long.");
                      merger.Add(line3);
           mergedLines = merger.GetMergedLineStrings();
           Assert.IsNotNull(mergedLines, "Shouldn't get null when merging 3 line.");
           Assert.AreEqual(1, mergedLines.Count, "Should get 1 merged line from 3 inputs.");
           mergedLine = (ILineString)mergedLines[0];
           Assert.Greater(mergedLine.Length, 299.9, "Merged line was too short.");
           Assert.Less(mergedLine.Length, 300.1, "Merged line was too long.");
       }
------------------------------------------------------------------------

_______________________________________________
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
Loading...