Issues with NetTopologySuite Port to Silverlight

Nov 3, 2009 at 3:57 PM

First, excellent work porting the NetTopologySuite to Silverlight as this will be very useful for GIS Silverlight apps.

I ran into a few issues with the NetTopologySuite Port to Silverlight that I wanted to share becuase they are causing Runtime exceptions.  The issues are mainly around the porting of SortedList to Dictionary.  For instance, in EdgeIntersectionList.cs:

private Dictionary<EdgeIntersection, EdgeIntersection> nodeMap = new Dictionary<EdgeIntersection, EdgeIntersection>();
...
public IEnumerator GetEnumerator() 
{
    nodeMap.OrderBy(x => x);
    return nodeMap.Values.GetEnumerator(); 
}
Although it appears that the expection of doing an OrderBy(x => x) is to sort the Dictionary in place, this isn't working as expecting.  Changing the return to nodeMap.Values.OrderBy(x => x).GetEnumerator() appears to fix this issue in most of the places where this occurs.
 
Also, checking to see if a key exists in a dictionary by using [] is causing other Runtime Exceptions.  For instance, in EdgeIntersectionList.cs:
EdgeIntersection eiNew = new EdgeIntersection(intPt, segmentIndex, dist);
EdgeIntersection ei = (EdgeIntersection) nodeMap[eiNew];
if (ei != null) 
    return ei;            
nodeMap.Add(eiNew, eiNew);
return eiNew;
 
Checking nodeMap[eiNew] will throw an exception if it does not exist rather than return null as is expected.  Accessing the IsValid property of a square polygon cause some of these exceptions to occur.
 
Coordinator
Nov 5, 2009 at 9:53 AM

Thanks for spotting this, I was getting this error also but wasn't sure if it was an issue with the orginal. I will fix this tomorrow as per your work request.

I also noticed that it looks like the nettopologysuite is going to get a major update in the comming weeks. Are you involved with that project? I'd love for them to maintain a Silverlight version.

Coordinator
Nov 11, 2009 at 6:03 AM

Can you double check my logic?

 

        public EdgeIntersection Add(ICoordinate intPt, int segmentIndex, double dist)
        {
            var eiNew = new EdgeIntersection(intPt, segmentIndex, dist);
            if (nodeMap.ContainsKey(eiNew))
            {
                return nodeMap[eiNew];
            }
            nodeMap.Add(eiNew, eiNew);
            return eiNew;
        }

and

        public ICollection Dissolved
        {
            get
            {
		return ocaMap.OrderBy(x => x).ToList();
            }
        }