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.delaunay;
028:
029: import java.util.ArrayList;
030: import java.util.Iterator;
031:
032: import fr.ign.cogit.geoxygene.contrib.cartetopo.CarteTopo;
033: import fr.ign.cogit.geoxygene.contrib.cartetopo.Chargeur;
034: import fr.ign.cogit.geoxygene.contrib.geometrie.Operateurs;
035: import fr.ign.cogit.geoxygene.feature.DataSet;
036: import fr.ign.cogit.geoxygene.feature.FT_Feature;
037: import fr.ign.cogit.geoxygene.feature.FT_FeatureCollection;
038: import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPosition;
039: import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPositionList;
040: import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString;
041: import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_Polygon;
042:
043: /**
044: * @author bonin
045: * @version 1.0
046: */
047:
048: public class ChargeurTriangulation extends Chargeur {
049:
050: public ChargeurTriangulation() {
051: }
052:
053: public static void importLigneEnPoints(String nomClasseGeo,
054: Triangulation carte) throws Exception {
055: FT_Feature objGeo;
056: Class clGeo = Class.forName(nomClasseGeo);
057: NoeudDelaunay noeud;
058: DirectPositionList listePoints;
059: int i, j;
060:
061: System.out.println("Début importLignesEnPoints");
062: FT_FeatureCollection listeFeatures = DataSet.db
063: .loadAllFeatures(clGeo);
064: for (i = 0; i < listeFeatures.size(); i++) {
065: System.out.println("Nombre de lignes importées :" + i);
066: objGeo = listeFeatures.get(i);
067:
068: if (objGeo.getGeom() instanceof fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString) {
069: listePoints = ((GM_LineString) objGeo.getGeom())
070: .getControlPoint();
071: for (j = 0; j < listePoints.size(); j++) {
072: if ((j % 100) == 0) {
073: System.out
074: .println(" Nombre de points créés :"
075: + j);
076: }
077: noeud = (NoeudDelaunay) carte.getPopNoeuds()
078: .nouvelElement();
079: noeud.setCoord(listePoints.get(j));
080:
081: }
082: }
083: }
084: System.out.println("Fin importLigneEnPoints");
085: }
086:
087: public static void importLigneEnPoints(
088: FT_FeatureCollection listeFeatures, Triangulation carte)
089: throws Exception {
090: FT_Feature objGeo;
091: NoeudDelaunay noeud;
092: DirectPositionList listePoints;
093: int i, j;
094:
095: System.out.println("Début importLignesEnPoints");
096: for (i = 0; i < listeFeatures.size(); i++) {
097: System.out.println("Nombre de lignes importées :" + i);
098: objGeo = listeFeatures.get(i);
099:
100: if (objGeo.getGeom() instanceof fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString) {
101: listePoints = ((GM_LineString) objGeo.getGeom())
102: .getControlPoint();
103: for (j = 0; j < listePoints.size(); j++) {
104: if ((j % 100) == 0) {
105: System.out
106: .println(" Nombre de points créés :"
107: + j);
108: }
109: noeud = (NoeudDelaunay) carte.getPopNoeuds()
110: .nouvelElement();
111: noeud.setCoord(listePoints.get(j));
112:
113: }
114: }
115: }
116: System.out.println("Fin importLigneEnPoints");
117: }
118:
119: public static void importSegments(String nomClasseGeo,
120: Triangulation carte) throws Exception {
121: FT_Feature objGeo;
122: Class clGeo = Class.forName(nomClasseGeo);
123:
124: NoeudDelaunay noeud1;
125: ArcDelaunay arc;
126: DirectPositionList listePoints;
127: DirectPosition dp;
128: ArrayList listeTemp, listeNoeuds, listeNoeudsEffaces = null;
129: DirectPositionList tableau = null;
130: Iterator it, itEntrants, itSortants = null;
131: int i, j;
132:
133: FT_FeatureCollection listeFeatures = CarteTopo.db
134: .loadAllFeatures(clGeo);
135: Class[] signaturea = { carte.getPopNoeuds().getClasse(),
136: carte.getPopNoeuds().getClasse() };
137: Object[] parama = new Object[2];
138:
139: for (i = 0; i < listeFeatures.size(); i++) {
140: System.out.println("Nombre de lignes importées :" + i);
141: objGeo = listeFeatures.get(i);
142:
143: if (objGeo.getGeom() instanceof fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString) {
144: listePoints = ((GM_LineString) objGeo.getGeom())
145: .getControlPoint();
146: listeTemp = new ArrayList();
147: for (j = 0; j < listePoints.size(); j++) {
148: if ((j % 100) == 0) {
149: System.out
150: .println(" Nombre de points créés :"
151: + j);
152: }
153: noeud1 = (NoeudDelaunay) carte.getPopNoeuds()
154: .nouvelElement();
155: noeud1.setCoord(listePoints.get(j));
156: listeTemp.add(noeud1);
157:
158: }
159: for (j = 0; j < listeTemp.size() - 1; j++) {
160: parama[0] = (NoeudDelaunay) listeTemp.get(j);
161: parama[1] = (NoeudDelaunay) listeTemp.get(j + 1);
162: arc = (ArcDelaunay) carte.getPopArcs()
163: .nouvelElement(signaturea, parama);
164: }
165: }
166: }
167:
168: // Filtrage des noeuds en double et correction de la topologie
169: System.out.println("Filtrage des noeuds en double");
170: listeNoeuds = new ArrayList(carte.getListeNoeuds());
171: it = carte.getListeNoeuds().iterator();
172: tableau = new DirectPositionList();
173: listeNoeudsEffaces = new ArrayList();
174: while (it.hasNext()) {
175: noeud1 = (NoeudDelaunay) it.next();
176: dp = noeud1.getCoord();
177: if (Operateurs.indice2D(tableau, dp) != -1) {
178: System.out.println("Elimination d'un doublon");
179: itEntrants = noeud1.getEntrants().iterator();
180: while (itEntrants.hasNext()) {
181: arc = (ArcDelaunay) itEntrants.next();
182: arc.setNoeudFin((NoeudDelaunay) listeNoeuds
183: .get(Operateurs.indice2D(tableau, dp)));
184: }
185: itSortants = noeud1.getSortants().iterator();
186: while (itSortants.hasNext()) {
187: arc = (ArcDelaunay) itSortants.next();
188: arc.setNoeudIni((NoeudDelaunay) listeNoeuds
189: .get(Operateurs.indice2D(tableau, dp)));
190: }
191: }
192: tableau.add(dp);
193: }
194: it = listeNoeudsEffaces.iterator();
195: while (it.hasNext()) {
196: noeud1 = (NoeudDelaunay) it.next();
197: carte.getPopNoeuds().remove(noeud1); // pour la bidirection
198: }
199: System.out.println("Fin importSegments");
200: }
201:
202: public static void importSegments(
203: FT_FeatureCollection listeFeatures, Triangulation carte)
204: throws Exception {
205: FT_Feature objGeo;
206:
207: NoeudDelaunay noeud1;
208: ArcDelaunay arc;
209: DirectPositionList listePoints;
210: DirectPosition dp;
211: ArrayList listeTemp, listeNoeuds, listeNoeudsEffaces = null;
212: DirectPositionList tableau = null;
213: Iterator it, itEntrants, itSortants = null;
214: int i, j;
215:
216: Class[] signaturea = { carte.getPopNoeuds().getClasse(),
217: carte.getPopNoeuds().getClasse() };
218: Object[] parama = new Object[2];
219:
220: for (i = 0; i < listeFeatures.size(); i++) {
221: System.out.println("Nombre de lignes importées :" + i);
222: objGeo = listeFeatures.get(i);
223:
224: if (objGeo.getGeom() instanceof fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString) {
225: listePoints = ((GM_LineString) objGeo.getGeom())
226: .coord();
227: listeTemp = new ArrayList();
228: for (j = 0; j < listePoints.size(); j++) {
229: if ((j % 100) == 0) {
230: System.out
231: .println(" Nombre de points créés :"
232: + j);
233: }
234: noeud1 = (NoeudDelaunay) carte.getPopNoeuds()
235: .nouvelElement();
236: noeud1.setCoord(listePoints.get(j));
237: listeTemp.add(noeud1);
238: }
239: for (j = 0; j < listeTemp.size() - 1; j++) {
240: parama[0] = (NoeudDelaunay) listeTemp.get(j);
241: parama[1] = (NoeudDelaunay) listeTemp.get(j + 1);
242: arc = (ArcDelaunay) carte.getPopArcs()
243: .nouvelElement(signaturea, parama);
244: }
245: parama[0] = (NoeudDelaunay) listeTemp.get(listeTemp
246: .size() - 1);
247: parama[1] = (NoeudDelaunay) listeTemp.get(0);
248: arc = (ArcDelaunay) carte.getPopArcs().nouvelElement(
249: signaturea, parama);
250:
251: }
252:
253: if (objGeo.getGeom() instanceof fr.ign.cogit.geoxygene.spatial.coordgeom.GM_Polygon) {
254: listePoints = ((GM_Polygon) objGeo.getGeom()).coord();
255: System.out.println("Polygone " + i + " " + listePoints);
256: listeTemp = new ArrayList();
257: for (j = 0; j < listePoints.size(); j++) {
258: if ((j % 100) == 0) {
259: System.out
260: .println(" Nombre de points créés :"
261: + j);
262: }
263: noeud1 = (NoeudDelaunay) carte.getPopNoeuds()
264: .nouvelElement();
265: noeud1.setCoord(listePoints.get(j));
266: listeTemp.add(noeud1);
267: }
268: for (j = 0; j < listeTemp.size() - 1; j++) {
269: parama[0] = (NoeudDelaunay) listeTemp.get(j);
270: parama[1] = (NoeudDelaunay) listeTemp.get(j + 1);
271: arc = (ArcDelaunay) carte.getPopArcs()
272: .nouvelElement(signaturea, parama);
273: }
274: }
275: }
276:
277: // Filtrage des noeuds en double et correction de la topologie
278: System.out.println("Filtrage des noeuds en double");
279: listeNoeuds = new ArrayList(carte.getListeNoeuds());
280: it = carte.getListeNoeuds().iterator();
281: tableau = new DirectPositionList();
282: listeNoeudsEffaces = new ArrayList();
283: while (it.hasNext()) {
284: noeud1 = (NoeudDelaunay) it.next();
285: dp = noeud1.getCoord();
286: if (Operateurs.indice2D(tableau, dp) != -1) {
287: //System.out.println("Elimination d'un doublon");
288: itEntrants = noeud1.getEntrants().iterator();
289: while (itEntrants.hasNext()) {
290: arc = (ArcDelaunay) itEntrants.next();
291: arc.setNoeudFin((NoeudDelaunay) listeNoeuds
292: .get(Operateurs.indice2D(tableau, dp)));
293: }
294: itSortants = noeud1.getSortants().iterator();
295: while (itSortants.hasNext()) {
296: arc = (ArcDelaunay) itSortants.next();
297: arc.setNoeudIni((NoeudDelaunay) listeNoeuds
298: .get(Operateurs.indice2D(tableau, dp)));
299: }
300: }
301: tableau.add(dp);
302: }
303: it = listeNoeudsEffaces.iterator();
304: while (it.hasNext()) {
305: noeud1 = (NoeudDelaunay) it.next();
306: carte.getPopNoeuds().remove(noeud1); // pour la bidirection
307: }
308: System.out.println("Fin importSegments");
309: System.out.println("liste de noeuds "
310: + carte.getListeNoeuds().size());
311: System.out.println("liste des arcs "
312: + carte.getListeArcs().size());
313: }
314:
315: public static void importPolygoneEnPoints(
316: FT_FeatureCollection listeFeatures, Triangulation carte)
317: throws Exception {
318: FT_Feature objGeo;
319: NoeudDelaunay noeud;
320: DirectPositionList listePoints;
321: int i, j;
322:
323: System.out.println("Début importLignesEnPoints");
324: for (i = 0; i < listeFeatures.size(); i++) {
325: System.out.println("Nombre de lignes importées :" + i);
326: objGeo = listeFeatures.get(i);
327:
328: if (objGeo.getGeom() instanceof fr.ign.cogit.geoxygene.spatial.coordgeom.GM_Polygon) {
329: listePoints = ((GM_Polygon) objGeo.getGeom()).coord();
330: for (j = 0; j < listePoints.size(); j++) {
331: if ((j % 100) == 0) {
332: System.out
333: .println(" Nombre de points créés :"
334: + j);
335: }
336: noeud = (NoeudDelaunay) carte.getPopNoeuds()
337: .nouvelElement();
338: noeud.setCoord(listePoints.get(j));
339: }
340: }
341: }
342: System.out.println("Fin importPolygoneEnPoints");
343: }
344: }
|