Source Code Cross Referenced for LinearIterator.java in  » GIS » jts » com » vividsolutions » jts » linearref » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » jts » com.vividsolutions.jts.linearref 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.vividsolutions.jts.linearref;
002:
003:        import com.vividsolutions.jts.geom.*;
004:
005:        /**
006:         * An iterator over the components and coordinates of a linear geometry
007:         * ({@link LineString}s and {@link MultiLineString}s.
008:         *
009:         * The standard usage pattern for a {@link LinearIterator} is:
010:         *
011:         * <pre>
012:         * for (LinearIterator it = new LinearIterator(...); it.hasNext(); it.next()) {
013:         *   ...
014:         *   int ci = it.getComponentIndex();   // for example
015:         *   int vi = it.getVertexIndex();      // for example
016:         *   ...
017:         * }
018:         * </pre>
019:         *
020:         * @version 1.7
021:         */
022:        public class LinearIterator {
023:            private static int segmentEndVertexIndex(LinearLocation loc) {
024:                if (loc.getSegmentFraction() > 0.0)
025:                    return loc.getSegmentIndex() + 1;
026:                return loc.getSegmentIndex();
027:            }
028:
029:            private Geometry linear;
030:            private final int numLines;
031:
032:            /**
033:             * Invariant: currentLine <> null if the iterator is pointing at a valid coordinate
034:             */
035:            private LineString currentLine;
036:            private int componentIndex = 0;
037:            private int vertexIndex = 0;
038:
039:            /**
040:             * Creates an iterator initialized to the start of a linear {@link Geometry}
041:             *
042:             * @param linear the linear geometry to iterate over
043:             */
044:            public LinearIterator(Geometry linear) {
045:                this (linear, 0, 0);
046:            }
047:
048:            /**
049:             * Creates an iterator starting at
050:             * a {@link LinearLocation} on a linear {@link Geometry}
051:             *
052:             * @param linear the linear geometry to iterate over
053:             * @param start the location to start at
054:             */
055:            public LinearIterator(Geometry linear, LinearLocation start) {
056:                this (linear, start.getComponentIndex(),
057:                        segmentEndVertexIndex(start));
058:            }
059:
060:            /**
061:             * Creates an iterator starting at
062:             * a component and vertex in a linear {@link Geometry}
063:             *
064:             * @param linear the linear geometry to iterate over
065:             * @param componentIndex the component to start at
066:             * @param vertexIndex the vertex to start at
067:             */
068:            public LinearIterator(Geometry linear, int componentIndex,
069:                    int vertexIndex) {
070:                this .linear = linear;
071:                numLines = linear.getNumGeometries();
072:                this .componentIndex = componentIndex;
073:                this .vertexIndex = vertexIndex;
074:                loadCurrentLine();
075:            }
076:
077:            private void loadCurrentLine() {
078:                if (componentIndex >= numLines) {
079:                    currentLine = null;
080:                    return;
081:                }
082:                currentLine = (LineString) linear.getGeometryN(componentIndex);
083:            }
084:
085:            /**
086:             * Tests whether there are any vertices left to iterator over.
087:             * @return <code>true</code> if there are more vertices to scan
088:             */
089:            public boolean hasNext() {
090:                if (componentIndex >= numLines)
091:                    return false;
092:                if (componentIndex == numLines - 1
093:                        && vertexIndex >= currentLine.getNumPoints())
094:                    return false;
095:                return true;
096:            }
097:
098:            /**
099:             * Moves the iterator ahead to the next vertex and (possibly) linear component.
100:             */
101:            public void next() {
102:                if (!hasNext())
103:                    return;
104:
105:                vertexIndex++;
106:                if (vertexIndex >= currentLine.getNumPoints()) {
107:                    componentIndex++;
108:                    loadCurrentLine();
109:                    vertexIndex = 0;
110:                }
111:            }
112:
113:            /**
114:             * Checks whether the iterator cursor is pointing to the
115:             * endpoint of a linestring.
116:             *
117:             * @return <code>true</true> if the iterator is at an endpoint
118:             */
119:            public boolean isEndOfLine() {
120:                if (componentIndex >= numLines)
121:                    return false;
122:                //LineString currentLine = (LineString) linear.getGeometryN(componentIndex);
123:                if (vertexIndex < currentLine.getNumPoints() - 1)
124:                    return false;
125:                return true;
126:            }
127:
128:            /**
129:             * The component index of the vertex the iterator is currently at.
130:             * @return the current component index
131:             */
132:            public int getComponentIndex() {
133:                return componentIndex;
134:            }
135:
136:            /**
137:             * The vertex index of the vertex the iterator is currently at.
138:             * @return the current vertex index
139:             */
140:            public int getVertexIndex() {
141:                return vertexIndex;
142:            }
143:
144:            /**
145:             * Gets the {@link LineString} component the iterator is current at.
146:             * @return a linestring
147:             */
148:            public LineString getLine() {
149:                return currentLine;
150:            }
151:
152:            /**
153:             * Gets the first {@link Coordinate} of the current segment.
154:             * (the coordinate of the current vertex).
155:             * @return a {@link Coordinate}
156:             */
157:            public Coordinate getSegmentStart() {
158:                return currentLine.getCoordinateN(vertexIndex);
159:            }
160:
161:            /**
162:             * Gets the second {@link Coordinate} of the current segment.
163:             * (the coordinate of the next vertex).
164:             * If the iterator is at the end of a line, <code>null</code> is returned.
165:             *
166:             * @return a {@link Coordinate} or <code>null</code>
167:             */
168:            public Coordinate getSegmentEnd() {
169:                if (vertexIndex < getLine().getNumPoints() - 1)
170:                    return currentLine.getCoordinateN(vertexIndex + 1);
171:                return null;
172:            }
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.