Source Code Cross Referenced for FirstExample.java in  » GIS » GeOxygene-1.3 » fr » ign » cogit » geoxygene » example » 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.example 
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.example;
028:
029:        import fr.ign.cogit.geoxygene.datatools.Geodatabase;
030:        import fr.ign.cogit.geoxygene.datatools.ojb.GeodatabaseOjbFactory;
031:        import fr.ign.cogit.geoxygene.feature.FT_Feature;
032:        import fr.ign.cogit.geoxygene.feature.FT_FeatureCollection;
033:        import fr.ign.cogit.geoxygene.generalisation.Filtering;
034:        import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString;
035:        import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_Polygon;
036:        import fr.ign.cogit.geoxygene.util.viewer.ObjectViewer;
037:
038:        /**
039:         * Simple exemple de code pour l'utilisation de GeOxygene.
040:         * On suppose qu'il existe une classe persistante "donnees.defaut.Troncon_route" 
041:         * (sinon changer le nom de la classe dans le code).
042:         * Si la classe a charger contient beaucoup d'objet, lancer le programme avec l'option '-Xmx512M'
043:         * (java -Xmx512M exemple.FirstExample) .
044:         * 
045:         * @author Thierry Badard & Arnaud Braun
046:         * @version 1.1
047:         *
048:         */
049:
050:        public class FirstExample {
051:
052:            ///////////////////////////////////////////////////////////////////////////////////////////////////////
053:            ///////////////////////////////////////////////////////////////////////////////////////////////////////
054:            /* Attributs */
055:            private Geodatabase db; // connection a la base de donnees
056:            private Class tronconClasse; // classe de troncons
057:
058:            private String nomClasse = "geoxygene.geodata.Troncon_route"; // nom de la classe a charger
059:
060:            ///////////////////////////////////////////////////////////////////////////////////////////////////////
061:            ///////////////////////////////////////////////////////////////////////////////////////////////////////
062:            /* Constructeur */
063:            public FirstExample() {
064:
065:                // initialisation de la connection et lecture des fichiers de mapping
066:                System.out.println("Debut initialisation");
067:                db = GeodatabaseOjbFactory.newInstance();
068:                System.out.println("Initialisation OK");
069:                try {
070:                    tronconClasse = Class.forName(nomClasse);
071:                } catch (ClassNotFoundException e) {
072:                    System.out.println(nomClasse + " : non trouvee");
073:                    System.exit(0);
074:                }
075:            }
076:
077:            ///////////////////////////////////////////////////////////////////////////////////////////////////////
078:            ///////////////////////////////////////////////////////////////////////////////////////////////////////
079:            /* méthode main */
080:            public static void main(String args[]) {
081:                FirstExample test = new FirstExample();
082:
083:                test.exemple1();
084:                test.exemple2();
085:
086:            }
087:
088:            ///////////////////////////////////////////////////////////////////////////////////////////////////////
089:            ///////////////////////////////////////////////////////////////////////////////////////////////////////
090:            /* méthode exemple1 : exemple de traitement sur un objet.*/
091:            public void exemple1() {
092:
093:                // Declaration des variables
094:                FT_Feature troncon;
095:                Resultat resultat;
096:                Resultat buffer;
097:                GM_LineString polyligne;
098:                GM_Polygon polygone;
099:                int rayon = 20; // rayon de buffer
100:
101:                // Debut d'une transaction
102:                System.out.println("Debut transaction");
103:                db.begin();
104:
105:                // Recherche du plus petit identifiant
106:                Integer gid = new Integer(db.maxId(tronconClasse));
107:
108:                // Chargement d'un objet par son identifiant
109:                troncon = (FT_Feature) db.load(tronconClasse, gid);
110:                System.out.println("identifiant de l'objet charge : "
111:                        + troncon.getId());
112:
113:                // Sa géométrie
114:                polyligne = (GM_LineString) troncon.getGeom();
115:                System.out.println(polyligne);
116:
117:                // Creation d'un objet Resultat auquel on affecte la geometrie du Troncon_route
118:                resultat = new Resultat();
119:                resultat.setGeom(polyligne);
120:
121:                // Creation d'un objet Resultat auquel on affecte la geometrie d'un buffer autour du Troncon
122:                System.out.println("Traitement");
123:                polygone = (GM_Polygon) polyligne.buffer(rayon);
124:                buffer = new Resultat();
125:                buffer.setGeom(polygone);
126:
127:                // Ecriture des résultats dans la base
128:                db.makePersistent(resultat);
129:                db.makePersistent(buffer);
130:
131:                //Fermeture transaction et commit ( = validation des ecritures dans la base)
132:                System.out.println("commit");
133:                db.commit();
134:
135:                // Visualisation dans le viewer
136:                ObjectViewer viewer = new ObjectViewer(db);
137:                FT_FeatureCollection iniColl = new FT_FeatureCollection();
138:                iniColl.add(troncon);
139:                FT_FeatureCollection bufferColl = new FT_FeatureCollection();
140:                bufferColl.add(buffer);
141:                viewer.addFeatureCollection(iniColl, "Tronçons");
142:                viewer.addFeatureCollection(bufferColl, "Résultats");
143:
144:            }
145:
146:            ///////////////////////////////////////////////////////////////////////////////////////////////////////
147:            ///////////////////////////////////////////////////////////////////////////////////////////////////////
148:            /* méthode exemple2 : exemple de traitement sur une couche entiere.*/
149:            public void exemple2() {
150:
151:                // Declaration des variables
152:                FT_Feature troncon;
153:                FT_FeatureCollection tronconList;
154:                Resultat resultat;
155:                GM_LineString polyligne1, polyligne2;
156:                double seuil = 80.0; // seuil pour le Douglas-Peucker
157:                int compteur = 0; // pour voir l'avancement
158:
159:                // Debut d'une transaction
160:                System.out.println("Debut transaction");
161:                db.begin();
162:
163:                // Recherche du nombre d'objets a traiter
164:                int n = db.countObjects(tronconClasse);
165:                System.out.println("Nombre d'objets a traiter :" + n);
166:
167:                // Chargement de tous les objets 
168:                tronconList = db.loadAllFeatures(tronconClasse);
169:                System.out.println("chargement termine");
170:
171:                // Création d'une nouvelle collection pour stocker les résultats
172:                FT_FeatureCollection allResults = new FT_FeatureCollection();
173:
174:                // Traitement des les objets        
175:                tronconList.initIterator();
176:                while (tronconList.hasNext()) {
177:                    troncon = tronconList.next();
178:                    polyligne1 = (GM_LineString) troncon.getGeom();
179:                    polyligne2 = (GM_LineString) Filtering.DouglasPeucker(
180:                            polyligne1, seuil);
181:                    resultat = new Resultat();
182:                    resultat.setGeom(polyligne2);
183:                    db.makePersistent(resultat);
184:                    compteur++;
185:                    if (compteur % 100 == 0)
186:                        System.out.println(compteur);
187:                    allResults.add(resultat);
188:                }
189:
190:                //Fermeture transaction et commit ( = validation des ecritures dans la base)
191:                System.out.println("commit");
192:                db.commit();
193:
194:                // Visualisation dans le viewer
195:                ObjectViewer viewer = new ObjectViewer(db);
196:                viewer.addFeatureCollection(tronconList, "Tronçons");
197:                viewer.addFeatureCollection(allResults, "Résultats");
198:            }
199:
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.