Source Code Cross Referenced for LineStringGraphGenerator.java in  » GIS » GeoTools-2.4.1 » org » geotools » graph » build » line » 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 » GeoTools 2.4.1 » org.geotools.graph.build.line 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005:         *    (C) 2002, Refractions Reserach Inc.
006:         *
007:         *    This library is free software; you can redistribute it and/or
008:         *    modify it under the terms of the GNU Lesser General Public
009:         *    License as published by the Free Software Foundation;
010:         *    version 2.1 of the License.
011:         *
012:         *    This library is distributed in the hope that it will be useful,
013:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *    Lesser General Public License for more details.
016:         */
017:        package org.geotools.graph.build.line;
018:
019:        import org.geotools.graph.structure.Edge;
020:        import org.geotools.graph.structure.Graphable;
021:        import org.geotools.graph.structure.Node;
022:
023:        import com.vividsolutions.jts.geom.Coordinate;
024:        import com.vividsolutions.jts.geom.GeometryFactory;
025:        import com.vividsolutions.jts.geom.LineSegment;
026:        import com.vividsolutions.jts.geom.LineString;
027:        import com.vividsolutions.jts.geom.MultiLineString;
028:
029:        /**
030:         * Builds a graph representing a line network in which edges in the network are
031:         * represented by LineString geometries. This implementation is a wrapper around
032:         * a LineGraphGenerator which sets underlying edge objects to be LineString
033:         * objects, and underlying Node objects to be Point objects. While generating
034:         * the graph, the generator uses the visited flag of created components to 
035:         * determine when to create underying objects. For this reason it is not recomended 
036:         * to modify the visited flag of any graph components. 
037:         * 
038:         * @see com.vividsolutions.jts.geom.LineString
039:         * @see com.vividsolutions.jts.geom.Point
040:         * 
041:         * @author Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
042:         *
043:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/graph/src/main/java/org/geotools/graph/build/line/LineStringGraphGenerator.java $
044:         */
045:        public class LineStringGraphGenerator extends BasicLineGraphGenerator {
046:
047:            private static GeometryFactory gf = new GeometryFactory();
048:
049:            public Graphable add(Object obj) {
050:                LineString ls = null;
051:                if (obj instanceof  MultiLineString)
052:                    ls = (LineString) ((MultiLineString) obj).getGeometryN(0);
053:                else
054:                    ls = (LineString) obj;
055:
056:                //parent class expects a line segment
057:                Edge e = (Edge) super .add(new LineSegment(ls.getCoordinateN(0),
058:                        ls.getCoordinateN(ls.getNumPoints() - 1)));
059:
060:                //over write object to be the linestring
061:                e.setObject(ls);
062:                return (e);
063:            }
064:
065:            public Graphable remove(Object obj) {
066:                LineString ls = (LineString) obj;
067:
068:                //parent ecpexts a line segment
069:                return (super .remove(new LineSegment(ls.getCoordinateN(0), ls
070:                        .getCoordinateN(ls.getNumPoints() - 1))));
071:            }
072:
073:            public Graphable get(Object obj) {
074:                LineString ls = (LineString) obj;
075:
076:                //parent ecpexts a line segment
077:                return (super .get(new LineSegment(ls.getCoordinateN(0), ls
078:                        .getCoordinateN(ls.getNumPoints() - 1))));
079:            }
080:
081:            protected void setObject(Node n, Object obj) {
082:                //set underlying object to be point instead of coordinate
083:                Coordinate c = (Coordinate) obj;
084:                n.setObject(gf.createPoint(c));
085:            }
086:
087:            //  /** underlying line graph generator **/
088:            //  private LineGraphGenerator m_generator;
089:            //  
090:            //  /**
091:            //   * Constructs a new LineStringGraphGenerator.
092:            //   *
093:            //   */
094:            //  public LineStringGraphGenerator() {
095:            //    this(new BasicLineGraphGenerator());	
096:            //  }
097:            //  
098:            //  /**
099:            //   * Constructs a new LineStringGraphGenerator.
100:            //   * 
101:            //   * @param generator Underlying generator.
102:            //   */
103:            //  public LineStringGraphGenerator(LineGraphGenerator generator) {
104:            //    m_generator = generator;  
105:            //  }
106:            //  
107:            //  /**
108:            //   * Adds a LineString object to the graph. An edge is created to represent the 
109:            //   * LineString and its underlying object is set to the LineString.
110:            //   * 
111:            //   * @param obj A LineString.
112:            //   * 
113:            //   * @see GraphGenerator#add(Object)
114:            //   */
115:            //  public Graphable add(Object obj) {
116:            //    LineString line = (LineString)obj;
117:            //    Coordinate[] c = line.getCoordinates();
118:            //    
119:            //    //instruct the underlying line graph generate and edge represented by 
120:            //    // the endpoints of the linestring, set the underlying object to be the
121:            //    //linstring itself
122:            //    Edge e = (Edge)m_generator.add(
123:            //      new LineSegment(c[0], c[c.length-1])
124:            //    );  
125:            //    e.setObject(line);
126:            //    
127:            //    //check nodes of edge, if not visited, set object to point
128:            //    if (!e.getNodeA().isVisited()) {
129:            //      e.getNodeA().setVisited(true);
130:            //      e.getNodeA().setObject(line.getPointN(0));
131:            //    }
132:            //    
133:            //    if (!e.getNodeB().isVisited()) {
134:            //      e.getNodeB().setVisited(true);
135:            //      e.getNodeB().setObject(line.getPointN(c.length-1));  
136:            //    }
137:            //    
138:            //    return(e);
139:            //  }
140:            //
141:            //  /**
142:            //   * Returns the edge created to represent a LineString object.
143:            //   * 
144:            //   * @param obj A LineString.
145:            //   * 
146:            //   * @see GraphGenerator#get(Object)
147:            //   */
148:            //  public Graphable get(Object obj) {
149:            //    LineString line = (LineString)obj;
150:            //    Coordinate[] c = line.getCoordinates();
151:            //    
152:            //    Edge e = (Edge)m_generator.get(
153:            //      new LineSegment(c[0], c[c.length-1])
154:            //    );
155:            //    
156:            //    return(e);
157:            //  }
158:            //
159:            //  /**
160:            //   * Removes an edge from the graph which represents a LineString object.
161:            //   * 
162:            //   * @param A LineString.
163:            //   * 
164:            //   * @see GraphGenerator#remove(Object)
165:            //   */
166:            //  public Graphable remove(Object obj) {
167:            //    LineString line = (LineString)obj;
168:            //    Coordinate[] c = line.getCoordinates();
169:            //    
170:            //    Edge e = (Edge)m_generator.remove(
171:            //      new LineSegment(c[0], c[c.length-1])
172:            //    );
173:            //    
174:            //    return(e);
175:            //  }
176:            //
177:            //  /**
178:            //   * Sets the underlying builder of the underlying generator.
179:            //   * 
180:            //   * @see GraphGenerator#setGraphBuilder(GraphBuilder)
181:            //   */
182:            //  public void setGraphBuilder(GraphBuilder builder) {
183:            //    m_generator.setGraphBuilder(builder);  
184:            //  }
185:            //
186:            //  /**
187:            //   * Returns the underlying builder of the underlying generator.
188:            //   * 
189:            //   * @see GraphGenerator#getGraphBuilder()
190:            //   */
191:            //  public GraphBuilder getGraphBuilder() {
192:            //    return(m_generator.getGraphBuilder());
193:            //  }
194:            //
195:            //  /**
196:            //   * @see GraphGenerator#getGraph()
197:            //   */
198:            //  public Graph getGraph() {
199:            //    return(m_generator.getGraph());
200:            //  }
201:            //
202:            //  public Node getNode(Coordinate c) {
203:            //    return(m_generator.getNode(c)); 
204:            //  }
205:            //
206:            //  public Edge getEdge(Coordinate c1, Coordinate c2) {
207:            //    return(m_generator.getEdge(c1,c2));
208:            //  }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.