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.contrib.cartetopo;
028:
029: import java.util.Iterator;
030:
031: import fr.ign.cogit.geoxygene.feature.DataSet;
032: import fr.ign.cogit.geoxygene.feature.FT_Feature;
033: import fr.ign.cogit.geoxygene.feature.FT_FeatureCollection;
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.spatial.geomprim.GM_Point;
037:
038: /**
039: * Chargeur permettant de créer une carte topo à partir de classes de "FT_Feature"
040: * @author Mustière/Bonin
041: * @version 1.0
042: */
043:
044: public class Chargeur {
045:
046: /** Charge en mémoire les élements de la classe 'nomClasseGeo'
047: * et remplit la carte topo 'carte' avec des correspondants de ces éléments.
048: */
049: public static void importClasseGeo(String nomClasseGeo,
050: CarteTopo carte) {
051: Class clGeo;
052:
053: try {
054: clGeo = Class.forName(nomClasseGeo);
055: } catch (Exception e) {
056: System.out.println("ATTENTION : La classe nommée "
057: + nomClasseGeo + " n'existe pas");
058: System.out
059: .println(" Impossible donc de l'importer");
060: e.printStackTrace();
061: return;
062: }
063:
064: FT_FeatureCollection listeFeatures = DataSet.db
065: .loadAllFeatures(clGeo);
066: importClasseGeo(listeFeatures, carte);
067: }
068:
069: /** Remplit la carte topo 'carte' avec des correspondants des éléments de 'listeFeature'.
070: */
071: public static void importClasseGeo(
072: FT_FeatureCollection listeFeatures, CarteTopo carte) {
073: FT_Feature objGeo;
074: Noeud noeud;
075: Arc arc;
076: Face face;
077: int nbNoeuds = 0, nbArcs = 0, nbFaces = 0;
078: Iterator itFeatures = listeFeatures.getElements().iterator();
079:
080: while (itFeatures.hasNext()) {
081: objGeo = (FT_Feature) itFeatures.next();
082: if (objGeo.getGeom() instanceof fr.ign.cogit.geoxygene.spatial.geomprim.GM_Point) {
083: noeud = (Noeud) carte.getPopNoeuds().nouvelElement();
084: noeud.setGeometrie((GM_Point) objGeo.getGeom());
085: noeud.addCorrespondant(objGeo);
086: nbNoeuds++;
087: continue;
088: }
089: if (objGeo.getGeom() instanceof fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString) {
090: arc = (Arc) carte.getPopArcs().nouvelElement();
091: arc.setGeometrie((GM_LineString) objGeo.getGeom());
092: arc.addCorrespondant(objGeo);
093: nbArcs++;
094: continue;
095: }
096: if (objGeo.getGeom() instanceof fr.ign.cogit.geoxygene.spatial.coordgeom.GM_Polygon) {
097: face = (Face) carte.getPopFaces().nouvelElement();
098: face.setGeometrie((GM_Polygon) objGeo.getGeom());
099: face.addCorrespondant(objGeo);
100: nbFaces++;
101: continue;
102: }
103: System.out.println("Attention: objet non importé (id="
104: + objGeo.getId() + ", géométrie de type "
105: + objGeo.getGeom().getClass() + ")");
106: }
107: System.out.println("Nb de noeuds importés : " + nbNoeuds);
108: System.out.println("Nb d'arcs importés : " + nbArcs);
109: System.out.println("Nb de faces importées : " + nbFaces);
110: }
111: }
|