LocationIndexOfLine.cs :  » GIS » DeepEarth » GisSharpBlog » NetTopologySuite » LinearReferencing » 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 » LinearReferencing » LocationIndexOfLine.cs
using GeoAPI.Geometries;
using GisSharpBlog.NetTopologySuite.Geometries;

namespace GisSharpBlog.NetTopologySuite.LinearReferencing{
    /// <summary>
    /// Determines the location of a subline along a linear <see cref="Geometry" />.
    /// The location is reported as a pair of <see cref="LinearLocation" />s.
    /// NOTE: Currently this algorithm is not guaranteed to
    /// return the correct substring in some situations where
    /// an endpoint of the test line occurs more than once in the input line.
    /// (However, the common case of a ring is always handled correctly).
    /// </summary>
    public class LocationIndexOfLine
    {      
        /// <summary>
        /// 
        /// </summary>
        /// <param name="linearGeom"></param>
        /// <param name="subLine"></param>
        /// <returns></returns>
        public static LinearLocation[] IndicesOf(IGeometry linearGeom, IGeometry subLine)
        {
            /*
             * MD - this algorithm has been extracted into a class
             * because it is intended to validate that the subline truly is a subline,
             * and also to use the internal vertex information to unambiguously locate the subline.
             */
            LocationIndexOfLine locater = new LocationIndexOfLine(linearGeom);
            return locater.IndicesOf(subLine);
        }

        private IGeometry linearGeom;

        /// <summary>
        /// Initializes a new instance of the <see cref="LocationIndexOfLine"/> class.
        /// </summary>
        /// <param name="linearGeom">The linear geom.</param>
        public LocationIndexOfLine(IGeometry linearGeom)
        {
            this.linearGeom = linearGeom;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="subLine"></param>
        /// <returns></returns>
        public virtual LinearLocation[] IndicesOf(IGeometry subLine)
        {
            ICoordinate startPt = ((ILineString) subLine.GetGeometryN(0)).GetCoordinateN(0);
            ILineString lastLine = (ILineString) subLine.GetGeometryN(subLine.NumGeometries - 1);
            ICoordinate endPt = lastLine.GetCoordinateN(lastLine.NumPoints - 1);

            LocationIndexOfPoint locPt = new LocationIndexOfPoint(linearGeom);
            LinearLocation[] subLineLoc = new LinearLocation[2];
            subLineLoc[0] = locPt.IndexOf(startPt);

            // check for case where subline is zero length
            if (subLine.Length == 0)
                 subLineLoc[1] = (LinearLocation) subLineLoc[0].Clone();            
            else subLineLoc[1] = locPt.IndexOfAfter(endPt, subLineLoc[0]);
            return subLineLoc;
        }
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.