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.conversion;
028:
029: import com.vividsolutions.jts.geom.CoordinateSequence;
030: import com.vividsolutions.jts.geom.Geometry;
031: import com.vividsolutions.jts.geom.GeometryFactory;
032: import com.vividsolutions.jts.geom.Point;
033: import com.vividsolutions.jts.geom.PrecisionModel;
034: import com.vividsolutions.jts.io.WKTReader;
035: import com.vividsolutions.jts.io.WKTWriter;
036:
037: import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPosition;
038: import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPositionList;
039: import fr.ign.cogit.geoxygene.spatial.geomprim.GM_Point;
040: import fr.ign.cogit.geoxygene.spatial.geomroot.GM_Object;
041:
042: /**
043: * Conversions entre les GM_Object GeOxygene et les Geometry JTS.
044: *
045: * @author Thierry Badard, Arnaud Braun & Christophe Pele
046: * @version 1.0
047: *
048: */
049:
050: public class JtsGeOxygene {
051: /*------------------------------------------------------------*/
052: /*-- Fields --------------------------------------------------*/
053: /*------------------------------------------------------------*/
054:
055: // private static int jtsSRID=0;
056: private static PrecisionModel jtsPrecision = new PrecisionModel();
057:
058: // private static GeometryFactory jtsGeomFactory=new GeometryFactory(JtsGeOxygene.jtsPrecision,JtsGeOxygene.jtsSRID);
059: // private static WKTReader jtsWktReader=new WKTReader(JtsGeOxygene.jtsGeomFactory);
060: // private static WKTWriter jtsWktWriter=new WKTWriter();
061:
062: /*------------------------------------------------------------*/
063: /*-- Conversion beetween JTS and GeOxygene objects -----------*/
064: /*------------------------------------------------------------*/
065:
066: public static Geometry makeJtsGeom(GM_Object geOxyGeom)
067: throws Exception {
068: GeometryFactory jtsGeomFactory = new GeometryFactory(
069: JtsGeOxygene.jtsPrecision, geOxyGeom.getCRS());
070: WKTReader jtsWktReader = new WKTReader(jtsGeomFactory);
071: String wktGeom = WktGeOxygene.makeWkt(geOxyGeom);
072: Geometry jtsGeom = jtsWktReader.read(wktGeom);
073: return jtsGeom;
074: }
075:
076: public static GM_Object makeGeOxygeneGeom(Geometry jtsGeom)
077: throws Exception {
078: WKTWriter jtsWktWriter = new WKTWriter();
079: String wktResult = jtsWktWriter.write(jtsGeom);
080: GM_Object geOxyGeom = WktGeOxygene.makeGeOxygene(wktResult);
081: return geOxyGeom;
082: }
083:
084: public static DirectPosition makeDirectPosition(
085: CoordinateSequence jtsCoord) throws Exception {
086: GeometryFactory jtsGeomFactory = new GeometryFactory(
087: JtsGeOxygene.jtsPrecision, 0);
088: Geometry jtsPoint = new Point(jtsCoord, jtsGeomFactory);
089: GM_Point geOxyPoint = (GM_Point) JtsGeOxygene
090: .makeGeOxygeneGeom(jtsPoint);
091: DirectPosition geOxyDirectPos = geOxyPoint.getPosition();
092: return geOxyDirectPos;
093: }
094:
095: public static DirectPositionList makeDirectPositionList(
096: CoordinateSequence[] jtsCoords) throws Exception {
097: DirectPositionList list = new DirectPositionList();
098: for (int i = 0; i < jtsCoords.length; i++) {
099: list.add(JtsGeOxygene.makeDirectPosition(jtsCoords[i]));
100: }
101: return list;
102: }
103: }
|