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.util.loader;
028:
029: import fr.ign.cogit.geoxygene.datatools.Geodatabase;
030: import fr.ign.cogit.geoxygene.feature.FT_Feature;
031: import fr.ign.cogit.geoxygene.feature.FT_FeatureCollection;
032: import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString;
033: import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_Polygon;
034: import fr.ign.cogit.geoxygene.spatial.geomaggr.GM_MultiCurve;
035: import fr.ign.cogit.geoxygene.spatial.geomaggr.GM_MultiPoint;
036: import fr.ign.cogit.geoxygene.spatial.geomaggr.GM_MultiSurface;
037: import fr.ign.cogit.geoxygene.spatial.geomprim.GM_Curve;
038: import fr.ign.cogit.geoxygene.spatial.geomprim.GM_Point;
039: import fr.ign.cogit.geoxygene.spatial.geomprim.GM_Surface;
040: import fr.ign.cogit.geoxygene.spatial.geomroot.GM_Object;
041:
042: /**
043: * Usage interne.
044: * Homogeneise les geometries d'une table geographique :
045: * les collections sont repassees en primitive.
046: *
047: *
048: * @author Thierry Badard & Arnaud Braun
049: * @version 1.1
050: *
051: */
052:
053: public class TypeGeom {
054:
055: private Class theClass;
056: private Geodatabase db;
057:
058: ///////////////////////////////////////////////////////////////////////////////////////////////////////
059: ///////////////////////////////////////////////////////////////////////////////////////////////////////
060: public TypeGeom(Geodatabase DB, Class TheClass) {
061: theClass = TheClass;
062: db = DB;
063: }
064:
065: ///////////////////////////////////////////////////////////////////////////////////////////////////////
066: ///////////////////////////////////////////////////////////////////////////////////////////////////////
067: public void multi() {
068: try {
069: db.begin();
070: try {
071: FT_FeatureCollection list;
072: try {
073: list = db.loadAllFeatures(theClass);
074: } catch (java.lang.OutOfMemoryError mem) {
075: System.out
076: .println(" ##### ATTENTION MANQUE DE MEMOIRE POUR TRAITER LA CLASSE "
077: + theClass.getName());
078: System.out
079: .println(" Pour cette classe, relancer le traitement avec l'option -Xmx ");
080: list = new FT_FeatureCollection();
081: }
082: list.initIterator();
083: int i = 0;
084: while (list.hasNext()) {
085: i++;
086: FT_Feature f = (FT_Feature) list.next();
087: GM_Object o = f.getGeom();
088: if (o instanceof GM_MultiSurface) {
089: FT_Feature f1 = (FT_Feature) f.cloneGeom();
090: db.deletePersistent(f);
091: this .multiSurface(f1);
092: } else if (o instanceof GM_MultiCurve) {
093: FT_Feature f1 = (FT_Feature) f.cloneGeom();
094: db.deletePersistent(f);
095: this .multiCurve(f1);
096: } else if (o instanceof GM_MultiPoint) {
097: FT_Feature f1 = (FT_Feature) f.cloneGeom();
098: db.deletePersistent(f);
099: this .multiPoint(f1);
100: } else if (!((o instanceof GM_Point)
101: || (o instanceof GM_LineString) || (o instanceof GM_Polygon)))
102: System.out.println("## ATTENTION ###"
103: + o.getClass().getName() + " - id = "
104: + f.getId());
105:
106: /* if ((i%1000) == 0) {
107: System.out.println(i+" ...");
108: db.checkpoint();
109: }*/
110: }
111: } catch (Exception e1) {
112: System.out.println(e1.getMessage());
113: // e1.printStackTrace();
114: }
115:
116: db.commit();
117:
118: } catch (Exception e) {
119: e.printStackTrace();
120: }
121:
122: }
123:
124: ///////////////////////////////////////////////////////////////////////////////////////////////////////
125: ///////////////////////////////////////////////////////////////////////////////////////////////////////
126: private void multiSurface(FT_Feature theFeature) {
127: System.out.println(" GM_MultiSurface detecte dans "
128: + theClass.getName() + " - id = " + theFeature.getId());
129: try {
130: GM_MultiSurface ms = (GM_MultiSurface) theFeature.getGeom();
131: ms.initIterator();
132: while (ms.hasNext()) {
133: GM_Surface p = (GM_Surface) ms.next();
134: FT_Feature newFeature = (FT_Feature) theFeature
135: .cloneGeom();
136: newFeature.setGeom(p);
137: newFeature.setId(0);
138: db.makePersistent(newFeature);
139: }
140: } catch (Exception e) {
141: e.printStackTrace();
142: }
143: }
144:
145: ///////////////////////////////////////////////////////////////////////////////////////////////////////
146: ///////////////////////////////////////////////////////////////////////////////////////////////////////
147: private void multiCurve(FT_Feature theFeature) {
148: System.out.println(" GM_MultiCurve detecte dans "
149: + theClass.getName() + " - id = " + theFeature.getId());
150: try {
151: GM_MultiCurve mc = (GM_MultiCurve) theFeature.getGeom();
152: mc.initIterator();
153: while (mc.hasNext()) {
154: GM_Curve c = (GM_Curve) mc.next();
155: FT_Feature newFeature = (FT_Feature) theFeature
156: .cloneGeom();
157: newFeature.setGeom(c);
158: newFeature.setId(0);
159: db.makePersistent(newFeature);
160: }
161: } catch (Exception e) {
162: e.printStackTrace();
163: }
164: }
165:
166: ///////////////////////////////////////////////////////////////////////////////////////////////////////
167: ///////////////////////////////////////////////////////////////////////////////////////////////////////
168: private void multiPoint(FT_Feature theFeature) {
169: System.out.println(" GM_MultiPoint detecte dans "
170: + theClass.getName() + " - id = " + theFeature.getId());
171: try {
172: GM_MultiPoint mp = (GM_MultiPoint) theFeature.getGeom();
173: mp.initIterator();
174: while (mp.hasNext()) {
175: GM_Point p = (GM_Point) mp.next();
176: FT_Feature newFeature = (FT_Feature) theFeature
177: .cloneGeom();
178: newFeature.setGeom(p);
179: newFeature.setId(0);
180: db.makePersistent(newFeature);
181: }
182: } catch (Exception e) {
183: e.printStackTrace();
184: }
185: }
186:
187: }
|