ThinkGeo.com    |     Documentation    |     Premium Support

NetTopologySuite IComparer Exception

We are using the Buffer method to create a new extent for the map display. This is the basic code we are using to take a PointShape defined by a lat/long, convert it to spherical mercator, center the map on that point and set the width of the map to the WidthInMeters value:



PointShape convPnt = new PointShape(-122.8,45.5);

Dim proj = new ManagedProj4Projection(ManagedProj4Projection.GetEpsgParameters(4326), ManagedProj4Projection.GetGoogleMapParameters())
proj.Open()

// Convert Point to Spherical Mercator Projection
convPnt = (PointShape) proj.ConvertToExternalProjection(convPnt)

Dim rect = convPnt.Buffer(WidthInMeters / 2, GeographyUnit.Meter, DistanceUnit.Meter).GetBoundingBox()

Me.CurrentExtent = rect

Me.Refresh()

When running this code against a map control that has an InMemoryFeatureLayer with multiple features of PointShapes on it, we get this exception:



System.ArgumentException: IComparer (or the IComparable methods it relies upon) did not return zero when Array.Sort called x. CompareTo(x). x: 'GisSharpBlog.NetTopologySuite.Index.Strtree.ItemBoundable'  x's type: 'ItemBoundable' The IComparer: 'GisSharpBlog.NetTopologySuite.Index.Strtree.STRtree+AnonymousXComparerImpl'.
   at System.Array.SorterObjectArray.QuickSort(Int32 left, Int32 right)
   at System.Array.Sort(Array keys, Array items, Int32 index, Int32 length, IComparer comparer)
   at System.Collections.ArrayList.Sort(Int32 index, Int32 count, IComparer comparer)
   at System.Collections.ArrayList.Sort(IComparer comparer)
   at GisSharpBlog.NetTopologySuite.Index.Strtree.STRtree.CreateParentBoundables(IList childBoundables, Int32 newLevel)
   at GisSharpBlog.NetTopologySuite.Index.Strtree.AbstractSTRtree.CreateHigherLevels(IList boundablesOfALevel, Int32 level)
   at GisSharpBlog.NetTopologySuite.Index.Strtree.AbstractSTRtree.Build()
   at GisSharpBlog.NetTopologySuite.Index.Strtree.AbstractSTRtree.Query(Object searchBounds)
   at GisSharpBlog.NetTopologySuite.Index.Strtree.STRtree.Query(IEnvelope searchEnv)
   at GisSharpBlog.NetTopologySuite.Noding.MCIndexNoder.IntersectChains()
   at GisSharpBlog.NetTopologySuite.Noding.MCIndexNoder.ComputeNodes(IList inputSegStrings)
   at GisSharpBlog.NetTopologySuite.Operation.Buffer.BufferBuilder.ComputeNodedEdges(IList bufferSegStrList, IPrecisionModel precisionModel)
   at GisSharpBlog.NetTopologySuite.Operation.Buffer.BufferBuilder.Buffer(IGeometry g, Double distance)
   at GisSharpBlog.NetTopologySuite.Operation.Buffer.BufferOp.BufferOriginalPrecision()
   at GisSharpBlog.NetTopologySuite.Operation.Buffer.BufferOp.ComputeGeometry()
   at GisSharpBlog.NetTopologySuite.Operation.Buffer.BufferOp.GetResultGeometry(Double distance)
   at GisSharpBlog.NetTopologySuite.Operation.Buffer.BufferOp.Buffer(IGeometry g, Double distance, Int32 quadrantSegments, BufferStyle endCapStyle)
   at GisSharpBlog.NetTopologySuite.Geometries.Geometry.Buffer(Double distance, Int32 quadrantSegments, BufferStyle endCapStyle)
   at ThinkGeo.MapSuite.Core.BaseShape.BufferCore(Double distance, Int32 quadrantSegments, BufferCapType bufferCapType, GeographyUnit shapeUnit, DistanceUnit distanceUnit)
   at ThinkGeo.MapSuite.Core.BaseShape.Buffer(Double distance, GeographyUnit shapeUnit, DistanceUnit distanceUnit)
   at MapControl.ThinkGeoMapControl.SetMapDisplay(LatLong CenterPoint, Double WidthInMeters) in D:\_dev\svn\FieldTest7\trunk\FieldTest\MapControl\ThinkGeoMapControl.vb:line 598

Any idea why we'd be getting this exception?



Paul, 
  
 Thanks for your post, 
  
 I cannot reproduce your problem exactly, I used the code what you attached above, the Buffer operation can work fine and I used the latest DesktopEdition to test, the DesktopEdition version is 4.5.90.0 and the version number of NTS is 1.7.3.31740.  
  
 According to your description, it seems when processing the Buffer operation, there is an exception occurred in the NTS component, but I cannot reproduce it, please get the latest version to try again, 
  
 Thanks, 
  
 Scott,