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 java.util.List;
030:
031: import fr.ign.cogit.geoxygene.datatools.Geodatabase;
032: import fr.ign.cogit.geoxygene.datatools.ojb.GeodatabaseOjbFactory;
033: import fr.ign.cogit.geoxygene.feature.FT_Feature;
034: import fr.ign.cogit.geoxygene.feature.FT_FeatureCollection;
035: import fr.ign.cogit.geoxygene.spatial.topoprim.TP_DirectedEdge;
036: import fr.ign.cogit.geoxygene.spatial.topoprim.TP_DirectedFace;
037: import fr.ign.cogit.geoxygene.spatial.topoprim.TP_DirectedNode;
038: import fr.ign.cogit.geoxygene.spatial.topoprim.TP_DirectedTopo;
039: import fr.ign.cogit.geoxygene.spatial.topoprim.TP_Edge;
040: import fr.ign.cogit.geoxygene.spatial.topoprim.TP_EdgeBoundary;
041: import fr.ign.cogit.geoxygene.spatial.topoprim.TP_Expression;
042: import fr.ign.cogit.geoxygene.spatial.topoprim.TP_Face;
043: import fr.ign.cogit.geoxygene.spatial.topoprim.TP_FaceBoundary;
044: import fr.ign.cogit.geoxygene.spatial.topoprim.TP_Node;
045: import fr.ign.cogit.geoxygene.spatial.topoprim.TP_Ring;
046: import fr.ign.cogit.geoxygene.spatial.toporoot.TP_Object;
047:
048: // A REVOIR APRES REFLEXION SUR LA TOPOLOGIE - N'EST PLUS A JOUR
049:
050: /**
051: * Utilisation du package spatial pour la topologie : exemple de code.
052: * Cet exemple montre comment charger un objet et sa topologie,
053: * et l'utilisation des différentes méthodes des classes du package "topoprim".
054: * On suppose qu'il existe une classe persistante "donnees.defaut.Troncon_route" pour laquelle
055: * une topologie de face a ete calculee.
056: * (sinon changer le nom de la classe dans le code).
057: *
058: * @author Thierry Badard & Arnaud Braun
059: * @version 1.1
060: *
061: */
062:
063: // RAJOUTER EXEMPLES APRES MODIFS
064:
065: public class TestTopo {
066:
067: ///////////////////////////////////////////////////////////////////////////////////////////////////////
068: ///////////////////////////////////////////////////////////////////////////////////////////////////////
069: /* Attributs */
070: private static Geodatabase db; // source de données
071: private static Class tronconClass; // classe de troncons
072: private String nomClasse = "geoxygene.geodata.Troncon_route"; // nom de la classe a charger
073: private static int identifiant = 664000; // id du troncon a charger
074:
075: ///////////////////////////////////////////////////////////////////////////////////////////////////////
076: ///////////////////////////////////////////////////////////////////////////////////////////////////////
077: /** constructeur : initialisation dses attributs */
078: public TestTopo() {
079: db = GeodatabaseOjbFactory.newInstance();
080: try {
081: tronconClass = Class.forName(nomClasse);
082: } catch (ClassNotFoundException e) {
083: System.out.println(nomClasse + " : non trouvee");
084: System.exit(0);
085: }
086: }
087:
088: ///////////////////////////////////////////////////////////////////////////////////////////////////////
089: ///////////////////////////////////////////////////////////////////////////////////////////////////////
090: /** chargement d'un objet et appel des méthodes sur noeud, brin et face*/
091: public static void main(String args[]) {
092:
093: TestTopo test = new TestTopo(); // appel du constructeur
094:
095: try {
096:
097: // ouverture transaction
098: db.begin();
099:
100: // chargement d'un reseau
101: // necessaire pour charger toutes les relations
102: FT_FeatureCollection tronconList = db
103: .loadAllFeatures(tronconClass);
104:
105: // chargement d'un objet particulier avec son identifiant.
106: FT_Feature tron = (FT_Feature) db.load(tronconClass,
107: new Integer(identifiant));
108:
109: // on recupere la topologie
110: TP_Edge edge = (TP_Edge) tron.getTopo();
111: System.out.println("identifiant du brin : " + edge.getId());
112: System.out.println(" identifiant du troncon : "
113: + tron.getId());
114:
115: // exemples de traitements sur un brin...
116: edgeMethod(edge);
117:
118: // exemples de traitements sur unn noeud...
119: TP_Node node = edge.endNode().topo();
120: // on applique topo() car endNode() renvoie un TP_DirectedNode et on veut un TP_Node
121: nodeMethod(node);
122:
123: // exemples de traitements sur une face...
124: if (edge.leftFace() != null) {
125: TP_Face face = edge.leftFace().topo();
126: // on applique topo() car leftFace() renvoie un TP_DirectedFace et on veut un TP_Face
127: faceMethod(face);
128: face = edge.rightFace().topo();
129: faceMethod(face);
130:
131: // exemple d'utilisation des TP_Expression...
132: tp_expression(edge);
133: }
134:
135: // fermeture transaction
136: db.commit();
137: System.out.println();
138: System.out.println("OK");
139:
140: } catch (Exception e) {
141: e.printStackTrace();
142: }
143: }
144:
145: ///////////////////////////////////////////////////////////////////////////////////////////////////////
146: ///////////////////////////////////////////////////////////////////////////////////////////////////////
147: /** exemple de traitement sur un noeud */
148: public static void nodeMethod(TP_Node node) {
149:
150: System.out.println();
151: System.out.println("methodes sur un noeud ...");
152: System.out.println();
153:
154: System.out.println("identifiant du noeud : " + node.getId());
155:
156: // container
157: if (node.getContainer() != null)
158: System.out.println("identifiant du container : "
159: + node.getContainer().getId());
160: else
161: System.out.println("pas de container");
162:
163: // boundary (renvoie null)
164: System.out.println("boundary : " + node.boundary());
165:
166: // coBoundary
167: System.out.println("coBoundary : ");
168: List node_coBdy = node.coBoundary();
169: for (int i = 0; i < node_coBdy.size(); i++) {
170: TP_DirectedEdge diredge = (TP_DirectedEdge) node_coBdy
171: .get(i);
172: System.out.println(" identifiant du brin oriente : "
173: + diredge.getId());
174: System.out.println(" identifiant du feature : "
175: + diredge.topo().getFeature().getId());
176: // remarque : getFeature() s'applique sur un TP_Edge et non pas un TP_DirectedEdge (sinon renvoie null)
177: // c'est pour cela qu'on applique l'operation topo()
178: }
179:
180: // asTPDirectedTopo
181: TP_DirectedNode d_node = node.asTP_DirectedTopo(+1);
182: System.out.println("identifiant du TP_DirectedNode(+1) : "
183: + d_node.getId());
184: d_node = (TP_DirectedNode) node.asTP_DirectedTopo(-1);
185: System.out.println("identifiant du TP_Directednode(-1) : "
186: + d_node.getId());
187:
188: // topo
189: System.out
190: .println("identifiant du topo du TP_DirectedNode(-1): "
191: + d_node.topo().getId());
192:
193: // negate
194: System.out.println("identifiant du negate : "
195: + node.negate().getId());
196:
197: // coboundary du negate
198: System.out.println("coBoundary du negatif : ");
199: node_coBdy = node.negate().coBoundary();
200: for (int i = 0; i < node_coBdy.size(); i++) {
201: TP_DirectedEdge diredge = (TP_DirectedEdge) node_coBdy
202: .get(i);
203: System.out.println(" identifiant du brin oriente : "
204: + diredge.getId());
205: System.out.println(" identifiant du feature : "
206: + diredge.topo().getFeature().getId());
207: // meme remarque que plus haut
208: }
209:
210: }
211:
212: ///////////////////////////////////////////////////////////////////////////////////////////////////////
213: ///////////////////////////////////////////////////////////////////////////////////////////////////////
214: /** exemple de traitement sur un brin */
215: public static void edgeMethod(TP_Edge edge) {
216:
217: System.out.println();
218: System.out.println("methodes sur un brin ...");
219: System.out.println();
220:
221: System.out.println("identifiant du brin : " + edge.getId());
222: System.out.println(" identifiant du feature du brin : "
223: + edge.getFeature().getId());
224:
225: // boundary
226: // l'operateur "boundary" renvoie un TP_EdgeBoundary
227: System.out.println("boundary : ");
228: TP_EdgeBoundary edge_bdy = edge.boundary();
229: System.out.println("identifiant du startNode : "
230: + edge_bdy.getStartnode().getId());
231: System.out.println("identifiant du endNode : "
232: + edge_bdy.getEndnode().getId());
233: // sans passer par TP_EdgeBoundary
234: System.out.println("identifiant du startNode : "
235: + edge.startNode().getId());
236: System.out.println("identifiant du endNode : "
237: + edge.endNode().getId());
238:
239: // coBoundary
240: System.out.println("coBoundary : ");
241: List edge_coBdy = edge.coBoundary();
242: for (int i = 0; i < edge_coBdy.size(); i++) {
243: TP_DirectedFace theFace = (TP_DirectedFace) edge_coBdy
244: .get(i);
245: System.out.println(" identifiant de la face : "
246: + theFace.getId());
247: }
248:
249: // face gauche
250: if (edge.leftFace() != null)
251: System.out.println("identifiant de la face gauche : "
252: + edge.leftFace().getId());
253:
254: // face droite
255: if (edge.rightFace() != null)
256: System.out.println("identifiant de la face droite : "
257: + edge.rightFace().getId());
258:
259: // asTPDirectedTopo
260: TP_DirectedEdge d_edge = edge.asTP_DirectedTopo(+1);
261: System.out.println("identifiant du TP_DirectedEdge(+1) : "
262: + d_edge.getId());
263: d_edge = edge.asTP_DirectedTopo(-1);
264: System.out.println("identifiant du TP_DirectedEdge(-1) : "
265: + d_edge.getId());
266:
267: // topo
268: System.out
269: .println("identifiant du topo du TP_DirectedEdge(-1) : "
270: + d_edge.topo().getId());
271:
272: // negate
273: System.out.println("identifiant du negate : "
274: + edge.negate().getId());
275:
276: // boundary du negate
277: System.out.println("boundary du brin oppose : ");
278: edge_bdy = edge.negate().boundary();
279: System.out.println("identifiant du startNode : "
280: + edge_bdy.getStartnode().getId());
281: System.out.println("identifiant du endNode : "
282: + edge_bdy.getEndnode().getId());
283: // sans passer par TP_EdgeBoundary
284: System.out.println("identifiant du startNode : : "
285: + edge.negate().startNode().getId());
286: System.out.println("identifiant du endNode : : "
287: + edge.negate().endNode().getId());
288:
289: // coboundary du negate
290: System.out.println("coBoundary du brin oppose : ");
291: edge_coBdy = edge.negate().coBoundary();
292: for (int i = 0; i < edge_coBdy.size(); i++) {
293: TP_DirectedFace theFace = (TP_DirectedFace) edge_coBdy
294: .get(i);
295: System.out.println(" identifiant de la face : "
296: + theFace.getId());
297: }
298:
299: // face gauche du negate
300: if (edge.leftFace() != null)
301: System.out.println("identifiant de la face gauche : "
302: + edge.negate().leftFace().getId());
303:
304: // face droite du negate
305: if (edge.rightFace() != null)
306: System.out.println("identifiant de la face droite : "
307: + edge.negate().rightFace().getId());
308:
309: // brin suivant
310: System.out.println("identifiant du brin suivant : "
311: + edge.nextEdge().getId());
312: System.out
313: .println(" identifiant du feature du brin suivant : "
314: + edge.nextEdge().topo().getFeature().getId());
315: // remarque : getFeature() s'applique sur un TP_Edge et non pas un TP_DirectedEdge (sinon renvoie null)
316: // c'est pour cela qu'on applique l'operation topo()
317:
318: // brin suivant du negate()
319: System.out
320: .println("identifiant du brin suivant du brin oppose : "
321: + edge.negate().nextEdge().getId());
322: System.out
323: .println(" identifiant du feature du brin suivant du brin oppose : "
324: + edge.negate().nextEdge().topo().getFeature()
325: .getId());
326: // meme remarque que ci-dessus
327:
328: // brin precedent
329: System.out.println("identifiant du brin precedent : "
330: + edge.previousEdge().getId());
331: System.out
332: .println(" identifiant du feature du brin precedent : "
333: + edge.previousEdge().topo().getFeature()
334: .getId());
335: // meme remarque que ci-dessus
336:
337: // brin precedent du negate()
338: System.out
339: .println("identifiant du brin precedent du brin oppose : "
340: + edge.negate().previousEdge().getId());
341: System.out
342: .println(" identifiant du feature du brin precedent du brin oppose : "
343: + edge.negate().previousEdge().topo()
344: .getFeature().getId());
345: // meme remarque que ci-dessus
346:
347: // recherche d'un cycle
348: System.out.println("cycle ...");
349: TP_Ring cycle = edge.cycle();
350: for (int i = 0; i < cycle.sizeTerm(); i++) {
351: TP_DirectedEdge dedge = (TP_DirectedEdge) cycle.getTerm(i);
352: System.out.println(" identifiant du brin : "
353: + dedge.getId());
354: System.out
355: .println(" identifiant du feature du brin : "
356: + dedge.topo().getFeature().getId());
357: }
358:
359: }
360:
361: ///////////////////////////////////////////////////////////////////////////////////////////////////////
362: ///////////////////////////////////////////////////////////////////////////////////////////////////////
363: /** exemple de traitement sur une face */
364: public static void faceMethod(TP_Face face) {
365:
366: System.out.println();
367: System.out.println("methodes sur une face ...");
368: System.out.println();
369:
370: System.out.println("identifiant de la face : " + face.getId());
371:
372: // boundary
373: TP_FaceBoundary face_bdy = face.boundary();
374: System.out.println("boundary exterior: ");
375: TP_Ring ext = face_bdy.getExterior();
376: for (int i = 0; i < ext.sizeTerm(); i++) {
377: TP_DirectedEdge theEdge = (TP_DirectedEdge) ext.getTerm(i);
378: System.out.println(" identifiant du brin : "
379: + theEdge.getId());
380: System.out.println(" identifiant du feature : "
381: + theEdge.topo().getFeature().getId());
382: }
383: for (int j = 0; j < face_bdy.sizeInterior(); j++) {
384: System.out.println("boundary interior: ");
385: TP_Ring inte = face_bdy.getInterior(j);
386: for (int i = 0; i < inte.sizeTerm(); i++) {
387: TP_DirectedEdge theEdge = (TP_DirectedEdge) inte
388: .getTerm(i);
389: System.out.println(" identifiant du brin : "
390: + theEdge.getId());
391: System.out.println(" identifiant du feature : "
392: + theEdge.topo().getFeature().getId());
393: }
394: }
395:
396: // asTPDirectedTopo
397: TP_DirectedFace d_face = face.asTP_DirectedTopo(+1);
398: System.out.println("identifiant du TP_DirectedTopo(+1) : "
399: + d_face.getId());
400: d_face = (TP_DirectedFace) face.asTP_DirectedTopo(-1);
401: System.out.println("identifiant du TP_DirectedTopo(-1) : "
402: + d_face.getId());
403:
404: // topo
405: System.out
406: .println("identifiant du topo du TP_DirectedTopo(-1) : "
407: + d_face.topo().getId());
408:
409: // negate
410: System.out.println("identifiant du negate : "
411: + face.negate().getId());
412:
413: // boundary du negate
414: face_bdy = face.negate().boundary();
415: System.out.println("boundary exterior: ");
416: ext = face_bdy.getExterior();
417: for (int i = 0; i < ext.sizeTerm(); i++) {
418: TP_DirectedEdge theEdge = (TP_DirectedEdge) ext.getTerm(i);
419: System.out.println(" identifiant du brin : "
420: + theEdge.getId());
421: System.out.println(" identifiant du feature : "
422: + theEdge.topo().getFeature().getId());
423: }
424: for (int j = 0; j < face_bdy.sizeInterior(); j++) {
425: System.out.println("boundary interior: ");
426: TP_Ring inte = face_bdy.getInterior(j);
427: for (int i = 0; i < inte.sizeTerm(); i++) {
428: TP_DirectedEdge theEdge = (TP_DirectedEdge) inte
429: .getTerm(i);
430: System.out.println(" identifiant du brin : "
431: + theEdge.getId());
432: System.out.println(" identifiant du feature : "
433: + theEdge.topo().getFeature().getId());
434: }
435: }
436:
437: }
438:
439: ///////////////////////////////////////////////////////////////////////////////////////////////////////
440: ///////////////////////////////////////////////////////////////////////////////////////////////////////
441: /** exemple de traitement sur les TP_Expression */
442: public static void tp_expression(TP_Edge edge1) {
443:
444: System.out.println();
445: System.out.println("TP_Expression...");
446: System.out.println();
447:
448: System.out.println("identifiant du brin1 : " + edge1.getId());
449:
450: // objets qui serviront dans l'exemple
451: // essayer avec differents objets, differentes orientations
452: TP_DirectedEdge edge2 = edge1.nextEdge();
453: //TP_DirectedEdge edge2 = edge1.nextEdge().negate();
454: System.out.println("identifiant du brin2 : " + edge2.getId());
455: TP_DirectedEdge edge3 = edge2.nextEdge();
456: System.out.println("identifiant du brin3 : " + edge3.getId());
457:
458: // construction d'un nouveau TP_Expression
459: TP_Expression exp = new TP_Expression(edge1);
460: exp.addTerm(edge2);
461: exp.addTerm(edge3);
462:
463: // boundary ( ac omparer avec boundary de chacun des brins)
464: System.out.println("boundary...");
465: TP_Expression bdy = exp.boundary();
466: for (int i = 0; i < bdy.sizeTerm(); i++) {
467: TP_DirectedTopo dt = bdy.getTerm(i);
468: System.out.println(dt.getClass().getName() + " "
469: + dt.getId());
470: }
471:
472: // coboundary
473: System.out.println("coBoundary...");
474: TP_Expression cobdy = exp.coBoundary();
475: for (int i = 0; i < cobdy.sizeTerm(); i++) {
476: TP_DirectedTopo dt = cobdy.getTerm(i);
477: System.out.println(dt.getClass().getName() + " "
478: + dt.getId());
479: }
480:
481: // isCycle
482: System.out.println("isCycle...");
483: System.out.println(exp.isCycle());
484:
485: // asSet
486: System.out.println("asSet...");
487: List theList = exp.asSet();
488: for (int i = 0; i < theList.size(); i++) {
489: TP_Object tpo = (TP_Object) theList.get(i);
490: System.out.println(tpo.getClass().getName() + " "
491: + tpo.getId());
492: }
493:
494: // support
495: System.out.println("support...");
496: theList = exp.support();
497: for (int i = 0; i < theList.size(); i++) {
498: TP_Object tpo = (TP_Object) theList.get(i);
499: System.out.println(tpo.getClass().getName() + " "
500: + tpo.getId());
501: }
502:
503: // objets qui serviront dans l'exemple
504: // essayer avec differents objets, differentes orientations
505: TP_DirectedFace face1 = edge1.leftFace().topo();
506: System.out
507: .println("identifiant de la face1 : " + face1.getId());
508: TP_DirectedFace face2 = edge1.rightFace().topo();
509: System.out
510: .println("identifiant de la face2 : " + face2.getId());
511:
512: // autre maniere de construire un TP_Expression
513: exp = face1.asTP_Expression();
514: exp = exp.plus(face2.asTP_Expression());
515:
516: // boundary (a comparer avec le boundary de chacune des faces)
517: System.out.println("boundary...");
518: bdy = exp.boundary();
519: for (int i = 0; i < bdy.sizeTerm(); i++) {
520: TP_DirectedTopo dt = bdy.getTerm(i);
521: System.out.println(dt.getClass().getName() + " "
522: + dt.getId());
523: System.out.println(" feature : "
524: + ((TP_DirectedEdge) dt).topo().getFeature()
525: .getId());
526: }
527:
528: }
529:
530: }
|