Source Code Cross Referenced for Polygon.java in  » GIS » GeoTools-2.4.1 » org » geotools » referencing » operation » builder » 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.referencing.operation.builder 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    Geotools2 - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002-2005, Geotools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.referencing.operation.builder;
017:
018:        import org.geotools.geometry.DirectPosition2D;
019:        import org.opengis.geometry.DirectPosition;
020:        import java.awt.geom.GeneralPath;
021:        import java.awt.geom.Point2D;
022:        import java.util.ArrayList;
023:        import java.util.Iterator;
024:        import java.util.List;
025:
026:        /**
027:         * Simple polygons like three - sided (triangle) or four - sided
028:         * (qadrilateral), that are used for triangulation.
029:         *
030:         * @since 2.4
031:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/operation/builder/Polygon.java $
032:         * @version $Id: Polygon.java 28966 2008-01-27 17:36:43Z acuster $
033:         * @author Jan Jezek
034:         */
035:        class Polygon {
036:            /** Vertices of this polygon. */
037:            private DirectPosition[] vertices;
038:
039:            /**
040:             * Creates a polygon using specified vertices.
041:             *
042:             * @param coordinates of vertices
043:             */
044:            Polygon(DirectPosition[] coordinates) {
045:                this .vertices = coordinates;
046:            }
047:
048:            /**
049:             * Sets the vertices of this polygon.
050:             *
051:             * @param coordinates
052:             */
053:            public void setCoordinates(DirectPosition[] coordinates) {
054:                this .vertices = coordinates;
055:            }
056:
057:            /**
058:             * Returns vertices of this polygon.
059:             *
060:             * @return vertices of this polygon.
061:             */
062:            public DirectPosition[] getPoints() {
063:                return vertices;
064:            }
065:
066:            /**
067:             * Returns the LINESTRING representation in WKT.
068:             *
069:             * @return WKT format.
070:             */
071:            public String toString() {
072:                String wkt = "";
073:
074:                for (int i = 0; i < vertices.length; i++) {
075:                    wkt = wkt + vertices[i].getCoordinates()[0] + " "
076:                            + vertices[i].getCoordinates()[1];
077:
078:                    if (i != (vertices.length - 1)) {
079:                        wkt = wkt + ", ";
080:                    }
081:                }
082:
083:                return "LINESTRING (" + wkt + ")";
084:            }
085:
086:            /**
087:             * Generates GeneralPath from the array of points.
088:             *
089:             * @param points vertices of polygon.
090:             *
091:             * @return generated GeneralPath.
092:             */
093:            protected GeneralPath generateGeneralPath(DirectPosition[] points) {
094:                GeneralPath ring = new GeneralPath();
095:
096:                // Set the initiakl coordinates of the general Path
097:                ring.moveTo((float) points[0].getCoordinates()[0],
098:                        (float) points[0].getCoordinates()[1]);
099:
100:                // Create the star. Note: this does not draw the star.
101:                for (int i = 1; i < points.length; i++) {
102:                    ring.lineTo((float) points[i].getCoordinates()[0],
103:                            (float) points[i].getCoordinates()[1]);
104:                }
105:
106:                return ring;
107:            }
108:
109:            /**
110:             * Test whether the coordinate is inside or is vertex of ploygon.
111:             *
112:             * @param dp Point to be tested whether is inside of polygon.
113:             *
114:             * @return True if the point is inside (or is the vertex of polygon, false
115:             *         if not.
116:             */
117:            protected boolean containsOrIsVertex(DirectPosition dp) {
118:                if (generateGeneralPath(vertices).contains((Point2D) dp)
119:                        || (hasVertex(dp))) {
120:                    return true;
121:                }
122:
123:                return false;
124:            }
125:
126:            /**
127:             * Returns whether v is one of the vertices of this polygon.
128:             *
129:             * @param p the candidate point
130:             *
131:             * @return whether v is equal to one of the vertices of this Triangle
132:             */
133:            public boolean hasVertex(DirectPosition p) {
134:                for (int i = 0; i < vertices.length; i++) {
135:                    if (p == vertices[i]) {
136:                        return true;
137:                    }
138:                }
139:
140:                return false;
141:            }
142:
143:            /**
144:             * Enlarge the polygon using homothetic transformation method.
145:             *
146:             * @param scale of enlargement (when scale = 1 then polygon stays
147:             *        unchanged)
148:             */
149:            protected void enlarge(double scale) {
150:                double sumX = 0;
151:                double sumY = 0;
152:
153:                for (int i = 0; i < vertices.length; i++) {
154:                    sumX = sumX + vertices[i].getCoordinates()[0];
155:                    sumY = sumY + vertices[i].getCoordinates()[1];
156:                }
157:
158:                // The center of polygon is calculated.
159:                sumX = sumX / vertices.length;
160:                sumY = sumY / vertices.length;
161:
162:                // The homothetic transformation is made.
163:                for (int i = 0; i < vertices.length; i++) {
164:                    vertices[i].getCoordinates()[0] = (scale * (vertices[i]
165:                            .getCoordinates()[0] - sumX))
166:                            + sumX;
167:                    vertices[i].getCoordinates()[1] = (scale * (vertices[i]
168:                            .getCoordinates()[1] - sumY))
169:                            + sumY;
170:                }
171:            }
172:
173:            /**
174:             * Returns reduced coordinates of vertices so the first vertex has
175:             * [0,0] coordinats.
176:             *
177:             * @return The List of reduced vertives
178:             */
179:            protected List reduce() {
180:                //Coordinate[] redCoords = new Coordinate[coordinates.length];
181:                ArrayList redCoords = new ArrayList();
182:
183:                for (int i = 0; i < vertices.length; i++) {
184:                    redCoords.add(new DirectPosition2D(vertices[i]
185:                            .getCoordinateReferenceSystem(), vertices[i]
186:                            .getCoordinates()[0]
187:                            - vertices[0].getCoordinates()[0], vertices[i]
188:                            .getCoordinates()[1]
189:                            - vertices[0].getCoordinates()[1]));
190:                }
191:
192:                return redCoords;
193:            }
194:
195:            /**
196:             * Returns whether this Polygon contains all of the the given
197:             * coordinates.
198:             *
199:             * @param coordinate of coordinates
200:             *
201:             * @return whether this Polygon contains the all of the given coordinates
202:             */
203:            protected boolean containsAll(List coordinate) {
204:                for (Iterator i = coordinate.iterator(); i.hasNext();) {
205:                    if (!this .containsOrIsVertex((DirectPosition) i.next())) {
206:                        return false;
207:                    }
208:                }
209:
210:                return true;
211:            }
212:
213:            /**
214:             * Returns a copy of this.
215:             *
216:             * @return copy of this object.
217:             */
218:            public Object clone() {
219:                return new Polygon(vertices);
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.