CoordinateList.cs :  » GIS » DeepEarth » GisSharpBlog » NetTopologySuite » Geometries » 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 » Geometries » CoordinateList.cs
using System;
using System.Collections.Generic;
using GeoAPI.Geometries;

namespace GisSharpBlog.NetTopologySuite.Geometries{       
    /// <summary>
    /// A list of Coordinates, which may
    /// be set to prevent repeated coordinates from occuring in the list.
    /// </summary>
    public class CoordinateList : List<ICoordinate>, ICloneable
    {
        /// <summary>
        /// Constructs a new list without any coordinates
        /// </summary>
        public CoordinateList() : base() {}

        /// <summary>
        /// The basic constructor for a CoordinateArray allows repeated points
        /// (i.e produces a CoordinateList with exactly the same set of points).
        /// </summary>
        /// <param name="coord">Initial coordinates</param>
        public CoordinateList(ICoordinate[] coord)
        {
            Add(coord, true);
        }

        /// <summary>
        /// Constructs a new list from a collection of Coordinates,
        /// allows repeated points.
        /// </summary>
        /// <param name="coordList">Collection of coordinates to load into the list.</param>
        public CoordinateList(List<ICoordinate> coordList)
        {
            AddAll(coordList, true);
        }

        /// <summary>
        /// Constructs a new list from a collection of Coordinates,
        /// allowing caller to specify if repeated points are to be removed.
        /// </summary>
        /// <param name="coordList">Collection of coordinates to load into the list.</param>
        /// <param name="allowRepeated">If <c>false</c>, repeated points are removed.</param>
        public CoordinateList(List<ICoordinate> coordList, bool allowRepeated)
        {
            AddAll(coordList, allowRepeated);
        }

        /// <summary>
        /// Constructs a new list from an array of Coordinates,
        /// allowing caller to specify if repeated points are to be removed.
        /// </summary>
        /// <param name="coord">Array of coordinates to load into the list.</param>
        /// <param name="allowRepeated">If <c>false</c>, repeated points are removed.</param>
        public CoordinateList(ICoordinate[] coord, bool allowRepeated)
        {
            Add(coord, allowRepeated);
        }        

        /// <summary>
        /// Returns the coordinate at specified index.
        /// </summary>
        /// <param name="i">Coordinate index.</param>
        /// <return>Coordinate specified.</return>
        public ICoordinate GetCoordinate(int i)
        {
            return base[i];
        }        

        /// <summary>
        /// Add an array of coordinates.
        /// </summary>
        /// <param name="coord">Coordinates to be inserted.</param>
        /// <param name="allowRepeated">If set to false, repeated coordinates are collapsed.</param>
        /// <param name="direction">If false, the array is added in reverse order.</param>
        /// <returns>Return true.</returns>
        public bool Add(ICoordinate[] coord, bool allowRepeated, bool direction)
        {
            if (direction)
                for (int i = 0; i < coord.Length; i++)
                    Add(coord[i], allowRepeated);
            else
                for (int i = coord.Length - 1; i >= 0; i--)
                    Add(coord[i], allowRepeated);
            return true;
        }

        /// <summary>
        /// Add an array of coordinates.
        /// </summary>
        /// <param name="coord">Coordinates to be inserted.</param>
        /// <param name="allowRepeated">If set to false, repeated coordinates are collapsed.</param>
        /// <returns>Return true.</returns>
        public bool Add(ICoordinate[] coord, bool allowRepeated)
        {
            return Add(coord, allowRepeated, true);
        }

        /// <summary>
        /// Add a coordinate.
        /// </summary>
        /// <param name="obj">Coordinate to be inserted, as object.</param>
        /// <param name="allowRepeated">If set to false, repeated coordinates are collapsed.</param>
        /// <returns>Return true.</returns>
        public bool Add(object obj, bool allowRepeated)
        {
            return Add((ICoordinate) obj, allowRepeated);
        }

        /// <summary>
        /// Add a coordinate.
        /// </summary>
        /// <param name="coord">Coordinate to be inserted.</param>
        /// <param name="allowRepeated">If set to false, repeated coordinates are collapsed.</param>
        /// <returns>Return true if all ok.</returns>
        public bool Add(ICoordinate coord, bool allowRepeated)
        {
            // don't add duplicate coordinates
            if (!allowRepeated)
            {
                if (Count >= 1)
                {
                    ICoordinate last = this[Count - 1];
                    if (last.Equals2D(coord)) 
                        return false;
                }
            }
            Add(coord);
            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="i"></param>
        /// <param name="coord"></param>
        /// <param name="allowRepeated"></param>
        public void Add(int i, ICoordinate coord, bool allowRepeated)
        {
            // don't add duplicate coordinates
            if (!allowRepeated)
            {
                int size = Count;
                if (size > 0)
                {
                    if (i > 0)
                    {
                        ICoordinate prev = this[i - 1];
                        if (prev.Equals2D(coord)) return;
                    }
                    if (i < size)
                    {
                        ICoordinate next = this[i];
                        if (next.Equals2D(coord)) return;
                    }
                }
            }
            Insert(i, coord);
        }

        /// <summary>
        /// Add an array of coordinates.
        /// </summary>
        /// <param name="coll">Coordinates collection to be inserted.</param>
        /// <param name="allowRepeated">If set to false, repeated coordinates are collapsed.</param>
        /// <returns>Return true if at least one element has added (IList not empty).</returns>
        public bool AddAll(List<ICoordinate> coll, bool allowRepeated)
        {
            bool isChanged = false;
            foreach (ICoordinate c in coll)
            {
                Add(c, allowRepeated);
                isChanged = true;
            }
            return isChanged;
        }

        /// <summary>
        /// Ensure this coordList is a ring, by adding the start point if necessary.
        /// </summary>
        public void CloseRing()
        {
            if (Count > 0)
                Add(this[0], false);
        }

        /// <summary>
        /// Returns the Coordinates in this collection.
        /// </summary>
        /// <returns>Coordinater as <c>Coordinate[]</c> array.</returns>
        public ICoordinate[] ToCoordinateArray()
        {
            return ToArray();
        }

        /// <summary>
        /// Returns a deep copy of this collection.
        /// </summary>
        /// <returns>The copied object.</returns>
        public object Clone()
        {         
            CoordinateList copy = new CoordinateList();
            foreach (ICoordinate c in this)
                copy.Add((ICoordinate) c.Clone());
            return copy;
        }        
    } 
} 
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.