NodeMap.cs :  » GIS » DeepEarth » GisSharpBlog » NetTopologySuite » GeometriesGraph » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GIS » DeepEarth 
DeepEarth » GisSharpBlog » NetTopologySuite » GeometriesGraph » NodeMap.cs
using System.Collections;
using System.IO;
using System.Linq;
using GeoAPI.Geometries;
using System.Collections.Generic;

namespace GisSharpBlog.NetTopologySuite.GeometriesGraph{
    /// <summary> 
    /// A map of nodes, indexed by the coordinate of the node.
    /// </summary>
    public class NodeMap
    {
    private Dictionary<ICoordinate, Node> nodeMap = new Dictionary<ICoordinate, Node>();
        private NodeFactory nodeFact;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="nodeFact"></param>
        public NodeMap(NodeFactory nodeFact)
        {
            this.nodeFact = nodeFact;
        }

        /// <summary> 
        /// This method expects that a node has a coordinate value.
        /// </summary>
        /// <param name="coord"></param>
        public Node AddNode(ICoordinate coord)
        {
            Node node = nodeMap.ContainsKey(coord) ? (Node) nodeMap[coord] : null;
            if (node == null) 
            {
                node = nodeFact.CreateNode(coord);
                nodeMap.Add(coord, node);
            }
            return node;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public Node AddNode(Node n)
        {
      Node node = nodeMap.ContainsKey(n.Coordinate) ? (Node)nodeMap[n.Coordinate] : null;
            if (node == null) 
            {
                nodeMap.Add(n.Coordinate, n);
                return n;
            }
            node.MergeLabel(n);
            return node;
        }

        /// <summary> 
        /// Adds a node for the start point of this EdgeEnd
        /// (if one does not already exist in this map).
        /// Adds the EdgeEnd to the (possibly new) node.
        /// </summary>
        /// <param name="e"></param>
        public void Add(EdgeEnd e)
        {
            ICoordinate p = e.Coordinate;
            Node n = AddNode(p);
            n.Add(e);
        }

        /// <returns> 
        /// The node if found; null otherwise.
        /// </returns>
        /// <param name="coord"></param>
        public Node Find(ICoordinate coord)  
        {
            return (Node) nodeMap[coord];
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IEnumerator GetEnumerator()
        {
      return nodeMap.OrderBy(x => x).GetEnumerator();
        }

        /// <summary>
        /// 
        /// </summary>
        public IList Values
        {
            get
            {
                var list = new List<object>();
        foreach (var obj in nodeMap.Values)
        {
          list.Add(obj);
        }
        return list;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="geomIndex"></param>
        /// <returns></returns>
        public IList GetBoundaryNodes(int geomIndex)
        {
            IList bdyNodes = new List<Node>();
            for (IEnumerator i = GetEnumerator(); i.MoveNext(); ) 
            {
                Node node = (Node) i.Current;
                if (node.Label.GetLocation(geomIndex) == Locations.Boundary)
                    bdyNodes.Add(node);
            }
            return bdyNodes;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="outstream"></param>
        public void Write(StreamWriter outstream)
        {
            for (IEnumerator i = GetEnumerator(); i.MoveNext(); ) 
            {
                Node n = (Node)i.Current;
                n.Write(outstream);
            }
        }
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.