📄 testtopo.java
字号:
/*
* This file is part of the GeOxygene project source files.
*
* GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
* the development and deployment of geographic (GIS) applications. It is a open source
* contribution of the COGIT laboratory at the Institut G閛graphique National (the French
* National Mapping Agency).
*
* See: http://oxygene-project.sourceforge.net
*
* Copyright (C) 2005 Institut G閛graphique National
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this library (see file LICENSE if present); if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package fr.ign.cogit.geoxygene.example;
import java.util.List;
import fr.ign.cogit.geoxygene.datatools.Geodatabase;
import fr.ign.cogit.geoxygene.datatools.ojb.GeodatabaseOjbFactory;
import fr.ign.cogit.geoxygene.feature.FT_Feature;
import fr.ign.cogit.geoxygene.feature.FT_FeatureCollection;
import fr.ign.cogit.geoxygene.spatial.topoprim.TP_DirectedEdge;
import fr.ign.cogit.geoxygene.spatial.topoprim.TP_DirectedFace;
import fr.ign.cogit.geoxygene.spatial.topoprim.TP_DirectedNode;
import fr.ign.cogit.geoxygene.spatial.topoprim.TP_DirectedTopo;
import fr.ign.cogit.geoxygene.spatial.topoprim.TP_Edge;
import fr.ign.cogit.geoxygene.spatial.topoprim.TP_EdgeBoundary;
import fr.ign.cogit.geoxygene.spatial.topoprim.TP_Expression;
import fr.ign.cogit.geoxygene.spatial.topoprim.TP_Face;
import fr.ign.cogit.geoxygene.spatial.topoprim.TP_FaceBoundary;
import fr.ign.cogit.geoxygene.spatial.topoprim.TP_Node;
import fr.ign.cogit.geoxygene.spatial.topoprim.TP_Ring;
import fr.ign.cogit.geoxygene.spatial.toporoot.TP_Object;
// A REVOIR APRES REFLEXION SUR LA TOPOLOGIE - N'EST PLUS A JOUR
/**
* Utilisation du package spatial pour la topologie : exemple de code.
* Cet exemple montre comment charger un objet et sa topologie,
* et l'utilisation des diff閞entes m閠hodes des classes du package "topoprim".
* On suppose qu'il existe une classe persistante "donnees.defaut.Troncon_route" pour laquelle
* une topologie de face a ete calculee.
* (sinon changer le nom de la classe dans le code).
*
* @author Thierry Badard & Arnaud Braun
* @version 1.1
*
*/
// RAJOUTER EXEMPLES APRES MODIFS
public class TestTopo {
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
/* Attributs */
private static Geodatabase db; // source de donn閑s
private static Class tronconClass; // classe de troncons
private String nomClasse = "geoxygene.geodata.Troncon_route"; // nom de la classe a charger
private static int identifiant = 664000; // id du troncon a charger
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
/** constructeur : initialisation dses attributs */
public TestTopo() {
db = GeodatabaseOjbFactory.newInstance();
try {
tronconClass = Class.forName(nomClasse);
} catch (ClassNotFoundException e) {
System.out.println(nomClasse+" : non trouvee");
System.exit(0);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
/** chargement d'un objet et appel des m閠hodes sur noeud, brin et face*/
public static void main (String args[]) {
TestTopo test = new TestTopo(); // appel du constructeur
try {
// ouverture transaction
db.begin();
// chargement d'un reseau
// necessaire pour charger toutes les relations
FT_FeatureCollection tronconList = db.loadAllFeatures(tronconClass);
// chargement d'un objet particulier avec son identifiant.
FT_Feature tron = (FT_Feature)db.load(tronconClass, new Integer(identifiant));
// on recupere la topologie
TP_Edge edge = (TP_Edge)tron.getTopo();
System.out.println("identifiant du brin : "+edge.getId());
System.out.println(" identifiant du troncon : "+tron.getId());
// exemples de traitements sur un brin...
edgeMethod(edge);
// exemples de traitements sur unn noeud...
TP_Node node = edge.endNode().topo();
// on applique topo() car endNode() renvoie un TP_DirectedNode et on veut un TP_Node
nodeMethod(node);
// exemples de traitements sur une face...
if (edge.leftFace() != null) {
TP_Face face = edge.leftFace().topo();
// on applique topo() car leftFace() renvoie un TP_DirectedFace et on veut un TP_Face
faceMethod(face);
face = edge.rightFace().topo();
faceMethod(face);
// exemple d'utilisation des TP_Expression...
tp_expression(edge);
}
// fermeture transaction
db.commit();
System.out.println();
System.out.println("OK");
} catch (Exception e) {
e.printStackTrace();
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
/** exemple de traitement sur un noeud */
public static void nodeMethod (TP_Node node) {
System.out.println();
System.out.println("methodes sur un noeud ...");
System.out.println();
System.out.println("identifiant du noeud : "+node.getId());
// container
if (node.getContainer() != null)
System.out.println("identifiant du container : "+node.getContainer().getId());
else System.out.println("pas de container");
// boundary (renvoie null)
System.out.println("boundary : "+node.boundary());
// coBoundary
System.out.println("coBoundary : ");
List node_coBdy = node.coBoundary();
for (int i=0; i<node_coBdy.size(); i++) {
TP_DirectedEdge diredge = (TP_DirectedEdge)node_coBdy.get(i);
System.out.println(" identifiant du brin oriente : "+diredge.getId());
System.out.println(" identifiant du feature : "+diredge.topo().getFeature().getId());
// remarque : getFeature() s'applique sur un TP_Edge et non pas un TP_DirectedEdge (sinon renvoie null)
// c'est pour cela qu'on applique l'operation topo()
}
// asTPDirectedTopo
TP_DirectedNode d_node= node.asTP_DirectedTopo(+1);
System.out.println("identifiant du TP_DirectedNode(+1) : "+d_node.getId());
d_node= (TP_DirectedNode)node.asTP_DirectedTopo(-1);
System.out.println("identifiant du TP_Directednode(-1) : "+d_node.getId());
// topo
System.out.println("identifiant du topo du TP_DirectedNode(-1): "+d_node.topo().getId());
// negate
System.out.println("identifiant du negate : "+node.negate().getId());
// coboundary du negate
System.out.println("coBoundary du negatif : ");
node_coBdy = node.negate().coBoundary();
for (int i=0; i<node_coBdy.size(); i++) {
TP_DirectedEdge diredge = (TP_DirectedEdge)node_coBdy.get(i);
System.out.println(" identifiant du brin oriente : "+diredge.getId());
System.out.println(" identifiant du feature : "+diredge.topo().getFeature().getId());
// meme remarque que plus haut
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
/** exemple de traitement sur un brin */
public static void edgeMethod (TP_Edge edge) {
System.out.println();
System.out.println("methodes sur un brin ...");
System.out.println();
System.out.println("identifiant du brin : "+edge.getId());
System.out.println(" identifiant du feature du brin : "+edge.getFeature().getId());
// boundary
// l'operateur "boundary" renvoie un TP_EdgeBoundary
System.out.println("boundary : ");
TP_EdgeBoundary edge_bdy = edge.boundary();
System.out.println("identifiant du startNode : "+edge_bdy.getStartnode().getId());
System.out.println("identifiant du endNode : "+edge_bdy.getEndnode().getId());
// sans passer par TP_EdgeBoundary
System.out.println("identifiant du startNode : "+edge.startNode().getId());
System.out.println("identifiant du endNode : "+edge.endNode().getId());
// coBoundary
System.out.println("coBoundary : ");
List edge_coBdy = edge.coBoundary();
for (int i=0; i<edge_coBdy.size(); i++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -