Source Code Cross Referenced for JtsAlgorithms.java in  » GIS » GeOxygene-1.3 » fr » ign » cogit » geoxygene » util » algo » 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 » GeOxygene 1.3 » fr.ign.cogit.geoxygene.util.algo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the GeOxygene project source files. 
003:         * 
004:         * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for 
005:         * the development and deployment of geographic (GIS) applications. It is a open source 
006:         * contribution of the COGIT laboratory at the Institut Géographique National (the French 
007:         * National Mapping Agency).
008:         * 
009:         * See: http://oxygene-project.sourceforge.net 
010:         *  
011:         * Copyright (C) 2005 Institut Géographique National
012:         *
013:         * This library is free software; you can redistribute it and/or modify it under the terms
014:         * of the GNU Lesser General Public License as published by the Free Software Foundation; 
015:         * either version 2.1 of the License, or any later version.
016:         *
017:         * This library is distributed in the hope that it will be useful, but WITHOUT ANY 
018:         * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
019:         * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020:         *
021:         * You should have received a copy of the GNU Lesser General Public License along with 
022:         * this library (see file LICENSE if present); if not, write to the Free Software 
023:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:         *  
025:         */
026:
027:        package fr.ign.cogit.geoxygene.util.algo;
028:
029:        import com.vividsolutions.jts.geom.Coordinate;
030:        import com.vividsolutions.jts.geom.CoordinateFilter;
031:        import com.vividsolutions.jts.geom.Geometry;
032:
033:        import fr.ign.cogit.geoxygene.spatial.geomroot.GM_Object;
034:        import fr.ign.cogit.geoxygene.util.conversion.JtsGeOxygene;
035:
036:        /**
037:         * Appel des methodes JTS sur des GM_Object.
038:         * cf. http://www.vividsolutions.com/jts/jtshome.htm
039:         *
040:         * @author Thierry Badard, Arnaud Braun & Christophe Pele 
041:         * @version 1.0
042:         * 
043:         */
044:
045:        public class JtsAlgorithms implements  GeomAlgorithms {
046:
047:            public JtsAlgorithms() {
048:            }
049:
050:            public GM_Object centroid(GM_Object geom) {
051:                try {
052:                    Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom);
053:                    Geometry jtsCentroid = jtsGeom.getCentroid();
054:                    return (JtsGeOxygene.makeGeOxygeneGeom(jtsCentroid));
055:                } catch (Exception e) {
056:                    System.out
057:                            .println("## CALCUL DE CENTROIDE AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
058:                    e.printStackTrace();
059:                    return null;
060:                }
061:            }
062:
063:            public GM_Object convexHull(GM_Object geom) {
064:                try {
065:                    Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom);
066:                    Geometry jtsHull = jtsGeom.convexHull();
067:                    GM_Object result = JtsGeOxygene.makeGeOxygeneGeom(jtsHull);
068:                    return result;
069:                } catch (Exception e) {
070:                    System.out
071:                            .println("## CALCUL D'ENVELOPPE CONVEXE AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
072:                    e.printStackTrace();
073:                    return null;
074:                }
075:            }
076:
077:            public GM_Object buffer(GM_Object geom, double distance) {
078:                try {
079:                    Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom);
080:                    Geometry jtsBuffer = jtsGeom.buffer(distance);
081:                    return JtsGeOxygene.makeGeOxygeneGeom(jtsBuffer);
082:                } catch (Exception e) {
083:                    System.out
084:                            .println("## CALCUL DE BUFFER AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
085:                    e.printStackTrace();
086:                    return null;
087:                }
088:            }
089:
090:            public GM_Object buffer(GM_Object geom, double distance,
091:                    int nSegments) {
092:                try {
093:                    Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom);
094:                    Geometry jtsBuffer = jtsGeom.buffer(distance, nSegments);
095:                    return JtsGeOxygene.makeGeOxygeneGeom(jtsBuffer);
096:                } catch (Exception e) {
097:                    System.out
098:                            .println("## CALCUL DE BUFFER AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
099:                    e.printStackTrace();
100:                    return null;
101:                }
102:            }
103:
104:            public GM_Object buffer10(GM_Object geom) {
105:                return buffer(geom, 10);
106:            }
107:
108:            public GM_Object boundary(GM_Object geom) {
109:                try {
110:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(geom);
111:                    Geometry jtsResult = jtsGeom1.getBoundary();
112:                    return JtsGeOxygene.makeGeOxygeneGeom(jtsResult);
113:                } catch (Exception e) {
114:                    System.out
115:                            .println("## CALCUL DE FRONTIERE AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
116:                    e.printStackTrace();
117:                    return null;
118:                }
119:            }
120:
121:            public GM_Object union(GM_Object g1, GM_Object g2) {
122:                try {
123:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
124:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
125:                    Geometry jtsUnion = jtsGeom1.union(jtsGeom2);
126:                    return JtsGeOxygene.makeGeOxygeneGeom(jtsUnion);
127:                } catch (Exception e) {
128:                    System.out
129:                            .println("## CALCUL D'UNION AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
130:                    e.printStackTrace();
131:                    return null;
132:                }
133:            }
134:
135:            public GM_Object intersection(GM_Object g1, GM_Object g2) {
136:                try {
137:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
138:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
139:                    Geometry jtsInter = jtsGeom1.intersection(jtsGeom2);
140:                    return JtsGeOxygene.makeGeOxygeneGeom(jtsInter);
141:                } catch (Exception e) {
142:                    System.out
143:                            .println("## CALCUL D'INTERSECTION AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
144:                    e.printStackTrace();
145:                    return null;
146:                }
147:            }
148:
149:            public GM_Object difference(GM_Object g1, GM_Object g2) {
150:                try {
151:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
152:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
153:                    Geometry jtsResult = jtsGeom1.difference(jtsGeom2);
154:                    return JtsGeOxygene.makeGeOxygeneGeom(jtsResult);
155:                } catch (Exception e) {
156:                    System.out
157:                            .println("## CALCUL DE DIFFERENCE AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
158:                    e.printStackTrace();
159:                    return null;
160:                }
161:            }
162:
163:            public GM_Object symDifference(GM_Object g1, GM_Object g2) {
164:                try {
165:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
166:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
167:                    Geometry jtsSymDiff = jtsGeom1.symDifference(jtsGeom2);
168:                    return JtsGeOxygene.makeGeOxygeneGeom(jtsSymDiff);
169:                } catch (Exception e) {
170:                    System.out
171:                            .println("## CALCUL DE DIFFERENCE SYMETRIQUE AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
172:                    e.printStackTrace();
173:                    return null;
174:                }
175:            }
176:
177:            public boolean equals(GM_Object g1, GM_Object g2) {
178:                try {
179:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
180:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
181:                    return jtsGeom1.equals(jtsGeom2);
182:                } catch (Exception e) {
183:                    System.out
184:                            .println("## PREDICAT EQUALS AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
185:                    e.printStackTrace();
186:                    return false;
187:                }
188:            }
189:
190:            public boolean equalsExact(GM_Object g1, GM_Object g2) {
191:                try {
192:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
193:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
194:                    return jtsGeom1.equalsExact(jtsGeom2);
195:                } catch (Exception e) {
196:                    System.out
197:                            .println("## PREDICAT EQUALSEXACT AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
198:                    e.printStackTrace();
199:                    return false;
200:                }
201:            }
202:
203:            public boolean equalsExact(GM_Object g1, GM_Object g2, double tol) {
204:                try {
205:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
206:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
207:                    return jtsGeom1.equalsExact(jtsGeom2, tol);
208:                } catch (Exception e) {
209:                    System.out
210:                            .println("## PREDICAT EQUALSEXACT AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
211:                    e.printStackTrace();
212:                    return false;
213:                }
214:            }
215:
216:            public boolean contains(GM_Object g1, GM_Object g2) {
217:                try {
218:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
219:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
220:                    return jtsGeom1.contains(jtsGeom2);
221:                } catch (Exception e) {
222:                    System.out
223:                            .println("## PREDICAT CONTAINS AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
224:                    e.printStackTrace();
225:                    return false;
226:                }
227:            }
228:
229:            public boolean crosses(GM_Object g1, GM_Object g2) {
230:                try {
231:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
232:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
233:                    return jtsGeom1.crosses(jtsGeom2);
234:                } catch (Exception e) {
235:                    System.out
236:                            .println("## PREDICAT CROSSES AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
237:                    e.printStackTrace();
238:                    return false;
239:                }
240:            }
241:
242:            public boolean disjoint(GM_Object g1, GM_Object g2) {
243:                try {
244:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
245:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
246:                    return jtsGeom1.disjoint(jtsGeom2);
247:                } catch (Exception e) {
248:                    System.out
249:                            .println("## PREDICAT DISJOINT AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
250:                    e.printStackTrace();
251:                    return false;
252:                }
253:            }
254:
255:            public boolean within(GM_Object g1, GM_Object g2) {
256:                try {
257:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
258:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
259:                    return jtsGeom1.within(jtsGeom2);
260:                } catch (Exception e) {
261:                    System.out
262:                            .println("## PREDICAT WITHIN AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
263:                    e.printStackTrace();
264:                    return false;
265:                }
266:            }
267:
268:            public boolean isWithinDistance(GM_Object g1, GM_Object g2,
269:                    double dist) {
270:                try {
271:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
272:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
273:                    return jtsGeom1.isWithinDistance(jtsGeom2, dist);
274:                } catch (Exception e) {
275:                    System.out
276:                            .println("## PREDICAT iisWithinDistance AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
277:                    e.printStackTrace();
278:                    return false;
279:                }
280:            }
281:
282:            public boolean intersects(GM_Object g1, GM_Object g2) {
283:                try {
284:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
285:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
286:                    return jtsGeom1.intersects(jtsGeom2);
287:                } catch (Exception e) {
288:                    System.out
289:                            .println("## PREDICAT INTERSECTS AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
290:                    e.printStackTrace();
291:                    return false;
292:                }
293:            }
294:
295:            public boolean overlaps(GM_Object g1, GM_Object g2) {
296:                try {
297:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
298:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
299:                    return jtsGeom1.overlaps(jtsGeom2);
300:                } catch (Exception e) {
301:                    System.out
302:                            .println("## PREDICAT OVERLAPS AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
303:                    e.printStackTrace();
304:                    return false;
305:                }
306:            }
307:
308:            public boolean touches(GM_Object g1, GM_Object g2) {
309:                try {
310:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
311:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
312:                    return jtsGeom1.touches(jtsGeom2);
313:                } catch (Exception e) {
314:                    System.out
315:                            .println("## PREDICAT TOUCHES AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
316:                    e.printStackTrace();
317:                    return false;
318:                }
319:            }
320:
321:            public boolean isEmpty(GM_Object geom) {
322:                try {
323:                    Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom);
324:                    return jtsGeom.isEmpty();
325:                } catch (Exception e) {
326:                    System.out
327:                            .println("## ISEMPTY() AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
328:                    e.printStackTrace();
329:                    return false;
330:                }
331:            }
332:
333:            public boolean isSimple(GM_Object geom) {
334:                try {
335:                    Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom);
336:                    return jtsGeom.isSimple();
337:                } catch (Exception e) {
338:                    System.out
339:                            .println("## ISSIMPLE() AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
340:                    e.printStackTrace();
341:                    return false;
342:                }
343:            }
344:
345:            public boolean isValid(GM_Object geom) {
346:                try {
347:                    Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom);
348:                    return jtsGeom.isValid();
349:                } catch (Exception e) {
350:                    System.out
351:                            .println("## ISVALID() AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
352:                    e.printStackTrace();
353:                    return false;
354:                }
355:            }
356:
357:            public double distance(GM_Object g1, GM_Object g2) {
358:                try {
359:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
360:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
361:                    return jtsGeom1.distance(jtsGeom2);
362:                } catch (Exception e) {
363:                    System.out
364:                            .println("## DISTANCE() AVEC JTS : PROBLEME (le resultat renvoie 0.0) ##");
365:                    e.printStackTrace();
366:                    return 0.0;
367:                }
368:            }
369:
370:            public double area(GM_Object geom) {
371:                try {
372:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(geom);
373:                    return jtsGeom1.getArea();
374:                } catch (Exception e) {
375:                    System.out
376:                            .println("## AREA() AVEC JTS : PROBLEME (le resultat renvoie 0.0) ##");
377:                    e.printStackTrace();
378:                    return 0.0;
379:                }
380:            }
381:
382:            public double length(GM_Object geom) {
383:                try {
384:                    Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom);
385:                    return jtsGeom.getLength();
386:                } catch (Exception e) {
387:                    System.out
388:                            .println("## LENGTH() AVEC JTS : PROBLEME (le resultat renvoie 0.0) ##");
389:                    e.printStackTrace();
390:                    return 0.0;
391:                }
392:            }
393:
394:            public int dimension(GM_Object geom) {
395:                try {
396:                    Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom);
397:                    return jtsGeom.getDimension();
398:                } catch (Exception e) {
399:                    System.out
400:                            .println("## DIMENSION() AVEC JTS : PROBLEME (le resultat renvoie 0) ##");
401:                    e.printStackTrace();
402:                    return 0;
403:                }
404:            }
405:
406:            public int numPoints(GM_Object geom) {
407:                try {
408:                    Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom);
409:                    return jtsGeom.getNumPoints();
410:                } catch (Exception e) {
411:                    System.out
412:                            .println("## NUMPOINTS() AVEC JTS : PROBLEME (le resultat renvoie 0) ##");
413:                    e.printStackTrace();
414:                    return 0;
415:                }
416:            }
417:
418:            public GM_Object translate(GM_Object geom, final double tx,
419:                    final double ty, final double tz) {
420:                try {
421:                    Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom);
422:                    CoordinateFilter translateCoord = new CoordinateFilter() {
423:                        public void filter(Coordinate coord) {
424:                            coord.x += tx;
425:                            coord.y += ty;
426:                            coord.z += tz;
427:                        }
428:                    };
429:                    jtsGeom.apply(translateCoord);
430:                    GM_Object result = JtsGeOxygene.makeGeOxygeneGeom(jtsGeom);
431:                    return result;
432:                } catch (Exception e) {
433:                    System.out
434:                            .println("## TRANSLATE() AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
435:                    e.printStackTrace();
436:                    return null;
437:                }
438:            }
439:
440:            public String relate(GM_Object g1, GM_Object g2) {
441:                try {
442:                    Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
443:                    Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
444:                    return jtsGeom1.relate(jtsGeom2).toString();
445:                } catch (Exception e) {
446:                    System.out.println("## RELATE AVEC JTS : PROBLEME ##");
447:                    e.printStackTrace();
448:                    return " RELATE AVEC JTS : PROBLEME ";
449:                }
450:            }
451:
452:        } // class
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.