Revision 43224

View differences:

tags/org.gvsig.desktop-2.0.179/org.gvsig.desktop.compat.cdc/org.gvsig.projection/org.gvsig.projection.cresques/org.gvsig.projection.cresques.impl/src/main/java/org/cresques/impl/CresquesCtsLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.cresques.impl;
25

  
26
import org.cresques.ProjectionLibrary;
27
import org.cresques.impl.cts.ProjectionPool;
28

  
29
import org.gvsig.fmap.crs.CRSFactory;
30
import org.gvsig.tools.library.AbstractLibrary;
31
import org.gvsig.tools.library.LibraryException;
32

  
33
public class CresquesCtsLibrary extends AbstractLibrary {
34

  
35
    public void doRegistration() {
36
        registerAsImplementationOf(ProjectionLibrary.class,1);
37
    }
38

  
39
    protected void doInitialize() throws LibraryException {
40
        CRSFactory.registerCRSFactory( new ProjectionPool());
41
    }
42

  
43
    protected void doPostInitialize() throws LibraryException {
44
        // Nothing to do
45
    }
46
}
0 47

  
tags/org.gvsig.desktop-2.0.179/org.gvsig.desktop.compat.cdc/org.gvsig.projection/org.gvsig.projection.cresques/org.gvsig.projection.cresques.impl/src/main/java/org/cresques/impl/cts/gt2/CoordSys.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.cresques.impl.cts.gt2;
25

  
26
import java.awt.Color;
27
import java.awt.Graphics2D;
28
import java.awt.geom.Point2D;
29
import java.awt.geom.Rectangle2D;
30

  
31
import org.cresques.cts.ICoordTrans;
32
import org.cresques.cts.IDatum;
33
import org.cresques.cts.IProjection;
34
import org.cresques.geo.ViewPortData;
35
import org.geotools.cs.CoordinateSystem;
36
import org.geotools.cs.CoordinateSystemFactory;
37
import org.geotools.cs.GeographicCoordinateSystem;
38
import org.geotools.cs.ProjectedCoordinateSystem;
39
import org.opengis.referencing.FactoryException;
40

  
41
import org.gvsig.fmap.crs.CRSFactory;
42

  
43

  
44
/**
45
 * Sistema de Coordenadas (Proyecci?n).
46
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
47
 */
48
public class CoordSys implements IProjection {
49
    private static final Color basicGridColor = new Color(64, 64, 64, 128);
50
    protected CoordinateSystemFactory csFactory = CoordinateSystemFactory.getDefault();
51
    protected CSDatum datum = null;
52
    protected GeographicCoordinateSystem geogCS = null;
53
    protected ProjectedCoordinateSystem projCS = null;
54
    protected String abrev = "";
55
    Color gridColor = basicGridColor;
56

  
57
    public CoordSys(CSDatum datum) {
58
        this.datum = datum;
59
        this.geogCS = new GeographicCoordinateSystem(datum.getName(null), datum.getDatum());
60
	}
61

  
62
    public CoordSys(String wkt) {
63
    	try {
64
        	//((GeographicCoordinateSystem)
65
    		CoordinateSystem cs = CoordinateSystemFactory.getDefault().createFromWKT(wkt);
66
//			 ).getHorizontalDatum();
67
    		if (cs instanceof GeographicCoordinateSystem)
68
    			geogCS = (GeographicCoordinateSystem) cs;
69
    		if (cs instanceof ProjectedCoordinateSystem) {
70
    			projCS = (ProjectedCoordinateSystem) cs;
71
    			geogCS = projCS.getGeographicCoordinateSystem();
72
    		}
73
    		datum = new CSDatum(geogCS.getHorizontalDatum());
74
    	} catch (FactoryException e) {
75
			// TODO Auto-generated catch block
76
			e.printStackTrace();
77
		}
78
    }
79

  
80
    /**
81
     * Crea un nuevo CoordSys geogr?fico a partir de uno proyectado.
82
     * Si el actual es geogr?fico retorna el mismo.
83
     * @return
84
     */
85
    public CoordSys toGeo() {
86
        CoordSys coordSys = new CoordSys((CSDatum) getDatum());
87

  
88
        if (geogCS != null) {
89
            coordSys.geogCS = this.geogCS;
90
        } else {
91
            coordSys.geogCS = projCS.getGeographicCoordinateSystem();
92
        }
93

  
94
        return coordSys;
95
    }
96

  
97
    public IDatum getDatum() {
98
        return datum;
99
    }
100

  
101
    public CoordinateSystem getCS() {
102
        if (projCS != null) {
103
            return projCS;
104
        }
105

  
106
        return geogCS;
107
    }
108

  
109
    public CoordinateSystem getGeogCS() {
110
        if (geogCS != null) {
111
            return geogCS;
112
        }
113

  
114
        return projCS.getGeographicCoordinateSystem();
115
    }
116

  
117
    /* (no Javadoc)
118
     * @see org.cresques.cts.IProjection#createPoint(double, double)
119
     */
120
    public Point2D createPoint(double x, double y) {
121
        return new Point2D.Double(x, y);
122
    }
123

  
124
    public String toString() {
125
        if (projCS != null) {
126
            return projCS.toString();
127
        }
128

  
129
        return geogCS.toString();
130
    }
131

  
132
    public void setAbrev(String abrev) {
133
        this.abrev = abrev;
134
    }
135

  
136
    public String getAbrev() {
137
        return abrev;
138
    }
139

  
140
    /* (no Javadoc)
141
     * @see org.cresques.cts.IProjection#drawGrid(java.awt.Graphics2D, org.cresques.geo.ViewPortData)
142
     */
143
    public void drawGrid(Graphics2D g, ViewPortData vp) {
144
        // TODO Ap?ndice de m?todo generado autom?ticamente
145
    }
146

  
147
    public void setGridColor(Color c) {
148
        gridColor = c;
149
    }
150

  
151
    public Color getGridColor() {
152
        return gridColor;
153
    }
154

  
155
    /* (no Javadoc)
156
     * @see org.cresques.cts.IProjection#toGeo(java.awt.geom.Point2D)
157
     */
158
    public Point2D toGeo(Point2D pt) {
159
    //TODO VCN Esto si no lo comento no me trasforma el punto en coordenadas geogr?ficas.
160
//        if (getGeogCS() == geogCS) {
161
//            return pt;
162
//        } else {
163
            CoordTrans ct = new CoordTrans(this, toGeo());
164

  
165
            return ct.convert(pt, null);
166
//        }
167
    }
168

  
169
    /* (no Javadoc)
170
     * @see org.cresques.cts.IProjection#fromGeo(java.awt.geom.Point2D, java.awt.geom.Point2D)
171
     */
172
    public Point2D fromGeo(Point2D gPt, Point2D mPt) {
173
        // TODO Ap?ndice de m?todo generado autom?ticamente
174
        return null;
175
    }
176

  
177
    public double getScale(double minX, double maxX, double w, double dpi) {
178
        double scale = 0D;
179

  
180
        if (projCS == null) { // Es geogr?fico; calcula la escala.
181
            scale = ((maxX - minX) * // grados
182

  
183
            // 1852.0 metros x minuto de meridiano
184
            (dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro
185
                    w; // pixels
186
        }
187

  
188
        return scale;
189
    }
190
    public Rectangle2D getExtent(Rectangle2D extent,double scale,double wImage,double hImage,double mapUnits,double distanceUnits,double dpi) {
191
    	double w =0;
192
		double h =0;
193
		double wExtent =0;
194
		double hExtent =0;
195
    	if (projCS!=null) {
196
			w = ((wImage / dpi) * 2.54);
197
			h = ((hImage / dpi) * 2.54);
198
			wExtent =w * scale*distanceUnits/ mapUnits;
199
			hExtent =h * scale*distanceUnits/ mapUnits;
200

  
201
		}else {
202
			w = ((wImage / dpi) * 2.54);
203
			h = ((hImage / dpi) * 2.54);
204
			wExtent =(w*scale*distanceUnits)/ (mapUnits*1852.0*60.0);
205
			hExtent =(h*scale*distanceUnits)/ (mapUnits*1852.0*60.0);
206
		}
207
    	double xExtent = extent.getCenterX() - wExtent/2;
208
		double yExtent = extent.getCenterY() - hExtent/2;
209
		Rectangle2D rec=new Rectangle2D.Double(xExtent,yExtent,wExtent,hExtent);
210
    	return  rec;
211
    }
212
    public boolean isProjected() {
213
    	return projCS != null;
214
    }
215

  
216
	public ICoordTrans getCT(IProjection dest) {
217
		return new CoordTrans(this, (CoordSys) dest);
218
	}
219

  
220
	public String getFullCode() {
221
		return getAbrev();
222
	}
223

  
224
	public Object clone() throws CloneNotSupportedException {
225
	       return CRSFactory.getCRS( this.getFullCode() );
226
	    }
227

  
228
    /* (non-Javadoc)
229
     * @see org.cresques.cts.IProjection#export(java.lang.String)
230
     */
231
    @Override
232
    public String export(String format) {
233
        // TODO Auto-generated method stub
234
        return null;
235
    }
236

  
237
}
0 238

  
tags/org.gvsig.desktop-2.0.179/org.gvsig.desktop.compat.cdc/org.gvsig.projection/org.gvsig.projection.cresques/org.gvsig.projection.cresques.impl/src/main/java/org/cresques/impl/cts/gt2/CSUTM.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.cresques.impl.cts.gt2;
25

  
26
import org.cresques.cts.UTM;
27
import org.geotools.cs.AxisInfo;
28
import org.geotools.cs.Projection;
29
import org.geotools.units.Unit;
30
import org.gvsig.fmap.crs.CRSFactory;
31
import org.opengis.referencing.FactoryException;
32

  
33

  
34
/**
35
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
36
 */
37
public class CSUTM extends CoordSys implements UTM {
38
    public CSUTM(CSDatum datum, int zone) {
39
        super(datum);
40
        init(datum, zone, "N");
41
    }
42
    
43
    public CSUTM(CSDatum datum, int zone, String ns) {
44
        super(datum);
45
        init(datum, zone, ns);
46
    }
47
 
48
    public void init(CSDatum datum, int zone, String ns) {
49
        Unit linearUnit = Unit.METRE;
50

  
51
        javax.media.jai.ParameterList params = csFactory.createProjectionParameterList("Transverse_Mercator");
52
        params.setParameter("semi_major",
53
                            datum.getDatum().getEllipsoid().getSemiMajorAxis());
54
        params.setParameter("semi_minor",
55
                            datum.getDatum().getEllipsoid().getSemiMinorAxis());
56
        params.setParameter("central_meridian", (double) ((zone * 6) - 183));
57
        params.setParameter("latitude_of_origin", 0.0);
58
        params.setParameter("scale_factor", 0.9996);
59
        params.setParameter("false_easting", 500000.0);
60
        if (ns.toUpperCase().compareTo("S") == 0)
61
        	params.setParameter("false_northing", 10000000.0);
62
        else
63
        	params.setParameter("false_northing", 0.0);
64

  
65
        try {
66
            Projection projection = csFactory.createProjection("UTM" + zone,
67
                                                               "Transverse_Mercator",
68
                                                               params);
69
            projCS = csFactory.createProjectedCoordinateSystem(projection.getName()
70
                                                                         .toString(),
71
                                                               geogCS,
72
                                                               projection,
73
                                                               linearUnit,
74
                                                               AxisInfo.X,
75
                                                               AxisInfo.Y);
76
        } catch (FactoryException e) {
77
            // TODO Bloque catch generado autom?ticamente
78
            e.printStackTrace();
79
        }
80
    }
81

  
82
    public double getScale(double minX, double maxX, double w, double dpi) {
83
        double scale = super.getScale(minX, maxX, w, dpi);
84

  
85
        if (projCS != null) { // Es geogr?fico; calcula la escala.
86
            scale = ((maxX - minX) * // metros
87
                    (dpi / 2.54 * 100.0)) / // px / metro
88
                    w; // pixels
89
        }
90

  
91
        return scale;
92
    }
93

  
94
    public String toString() {
95
        return projCS.toString();
96
    }
97
    
98
    public Object clone() throws CloneNotSupportedException {
99
        return CRSFactory.getCRS( this.getFullCode() );
100
     }
101

  
102
}
0 103

  
tags/org.gvsig.desktop-2.0.179/org.gvsig.desktop.compat.cdc/org.gvsig.projection/org.gvsig.projection.cresques/org.gvsig.projection.cresques.impl/src/main/java/org/cresques/impl/cts/gt2/CSGaussPt.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.cresques.impl.cts.gt2;
25

  
26
import org.geotools.cs.AxisInfo;
27
import org.geotools.cs.GeographicCoordinateSystem;
28
import org.geotools.cs.Projection;
29

  
30
import org.geotools.measure.Angle;
31

  
32
import org.geotools.units.Unit;
33

  
34
import org.opengis.referencing.FactoryException;
35

  
36

  
37
/**
38
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
39
 *
40
 */
41
public class CSGaussPt extends CoordSys {
42
    public static CSGaussPt hgd73 = new CSGaussPt(CSDatum.d73);
43

  
44
    public CSGaussPt(CSDatum datum) {
45
        super(datum);
46
        geogCS = new GeographicCoordinateSystem(datum.getName(null),
47
                                                datum.getDatum());
48

  
49
        Unit linearUnit = Unit.METRE;
50

  
51
        javax.media.jai.ParameterList params = csFactory.createProjectionParameterList("Oblique_Stereographic");
52
        params.setParameter("semi_major",
53
                            datum.getDatum().getEllipsoid().getSemiMajorAxis());
54
        params.setParameter("semi_minor",
55
                            datum.getDatum().getEllipsoid().getSemiMinorAxis());
56
        params.setParameter("central_meridian",
57
                            (new Angle("8?07'54.862\"W")).degrees());
58

  
59
        //params.setParameter("longitude_of_origin", (new Angle("8?07'54.862\"")).degrees());
60
        params.setParameter("latitude_of_origin",
61
                            (new Angle("39?40'N")).degrees());
62
        params.setParameter("scale_factor", 1.0);
63
        params.setParameter("false_easting", 0D); //180598D);
64
        params.setParameter("false_northing", 0D); //-86990D);
65

  
66
        try {
67
            Projection projection = csFactory.createProjection("GAUSS",
68
                                                               "Oblique_Stereographic",
69
                                                               params);
70
            projCS = csFactory.createProjectedCoordinateSystem(projection.getName()
71
                                                                         .toString(),
72
                                                               geogCS,
73
                                                               projection,
74
                                                               linearUnit,
75
                                                               AxisInfo.X,
76
                                                               AxisInfo.Y);
77
        } catch (FactoryException e) {
78
            // TODO Bloque catch generado autom?ticamente
79
            e.printStackTrace();
80
        }
81
    }
82

  
83
    public String toString() {
84
        return projCS.toString();
85
    }
86
}
0 87

  
tags/org.gvsig.desktop-2.0.179/org.gvsig.desktop.compat.cdc/org.gvsig.projection/org.gvsig.projection.cresques/org.gvsig.projection.cresques.impl/src/main/java/org/cresques/impl/cts/gt2/CoordTrans.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.cresques.impl.cts.gt2;
25

  
26
import java.awt.geom.Point2D;
27
import java.awt.geom.Rectangle2D;
28

  
29
import org.cresques.cts.ICoordTrans;
30
import org.cresques.cts.IProjection;
31
import org.geotools.ct.CannotCreateTransformException;
32
import org.geotools.ct.CoordinateTransformation;
33
import org.geotools.ct.CoordinateTransformationFactory;
34
import org.geotools.ct.MathTransform;
35
import org.geotools.pt.CoordinatePoint;
36
import org.opengis.referencing.operation.TransformException;
37

  
38

  
39
//import org.geotools.pt.MismatchedDimensionException;
40

  
41
/**
42
 * Transforma coordenadas entre dos sistemas
43
 * @see org.creques.cts.CoordSys
44
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
45
 */
46
class CoordTrans implements ICoordTrans {
47
    private CoordinateTransformationFactory trFactory = CoordinateTransformationFactory.getDefault();
48
    private CoordinateTransformation tr = null;
49
    private MathTransform mt = null;
50
    private MathTransform mt2 = null;
51
    private MathTransform mt3 = null;
52
    private MathTransform mtDatum = null;
53
    private CoordSys from = null;
54
    private CoordSys to = null;
55
    
56
    private ICoordTrans invertedCT = null;
57

  
58
    public CoordTrans(CoordSys from, CoordSys to) {
59
        this.from = from;
60
        this.to = to;
61

  
62
        // Si los dos CoordSys son proyectados, entonces hay
63
        // que hacer dos transformaciones (pasar por geogr?ficas)
64
        // Si hay cambio de datum son 3 las transformaciones
65
        try {
66
            if (from.getDatum() != to.getDatum()) {
67
                tr = trFactory.createFromCoordinateSystems(from.toGeo().getCS(),
68
                                                           to.toGeo().getCS());
69
                mtDatum = tr.getMathTransform();
70
            }
71

  
72
            if ((from.projCS != null) && (to.projCS != null)) {
73
                CoordSys geogcs = from.toGeo();
74
                tr = trFactory.createFromCoordinateSystems(from.getCS(),
75
                                                           geogcs.getCS());
76
                mt = tr.getMathTransform();
77

  
78
                if (mtDatum != null) {
79
                    mt2 = mtDatum;
80
                }
81

  
82
                geogcs = to.toGeo();
83
                tr = trFactory.createFromCoordinateSystems(geogcs.getCS(),
84
                                                           to.getCS());
85

  
86
                if (mt2 == null) {
87
                    mt2 = tr.getMathTransform();
88
                } else {
89
                    mt3 = tr.getMathTransform();
90
                }
91
            } else {
92
                if (from.projCS == null) {
93
                    mt = mtDatum;
94
                }
95

  
96
                tr = trFactory.createFromCoordinateSystems(from.getCS(),
97
                                                           to.getCS());
98

  
99
                if (mt == null) {
100
                    mt = tr.getMathTransform();
101

  
102
                    if (mtDatum != null) {
103
                        mt2 = mtDatum;
104
                    }
105
                } else {
106
                    mt2 = tr.getMathTransform();
107
                }
108
            }
109
        } catch (CannotCreateTransformException e) {
110
            // TODO Bloque catch generado autom?ticamente
111
            e.printStackTrace();
112
        }
113
    }
114

  
115
    public IProjection getPOrig() {
116
        return from;
117
    }
118

  
119
    public IProjection getPDest() {
120
        return to;
121
    }
122

  
123
    public ICoordTrans getInverted() {
124
        if (invertedCT == null)
125
            invertedCT = new CoordTrans(to, from);
126
        return invertedCT;
127
    }
128

  
129
    public Point2D convert(Point2D ptOrig, Point2D ptDest) {
130
        CoordinatePoint pt1 = new CoordinatePoint(ptOrig);
131
        CoordinatePoint pt2 = new CoordinatePoint(0D, 0D);
132
        ptDest = null;
133

  
134
        try {
135
            mt.transform(pt1, pt2);
136
            ptDest = pt2.toPoint2D();
137

  
138
            if (mt2 != null) {
139
                mt2.transform(pt2, pt1);
140
                ptDest = pt1.toPoint2D();
141

  
142
                if (mt3 != null) {
143
                    mt3.transform(pt1, pt2);
144
                    ptDest = pt2.toPoint2D();
145
                }
146
            }
147

  
148
            /*} catch (MismatchedDimensionException e) {
149
                    // TODO Bloque catch generado autom?ticamente
150
                    e.printStackTrace();
151
            */
152
        } catch (TransformException e) {
153
            // TODO Bloque catch generado autom?ticamente
154
            e.printStackTrace();
155
        }
156

  
157
        return ptDest;
158
    }
159

  
160
    public String toString() {
161
        return tr.toString();
162
    }
163

  
164
    /* (non-Javadoc)
165
     * @see org.cresques.cts.ICoordTrans#convert(java.awt.geom.Rectangle2D)
166
     */
167
    public Rectangle2D convert(Rectangle2D rect) {
168
        
169
        Point2D pt1 = new Point2D.Double(rect.getMinX(), rect.getMinY());
170
        Point2D pt2 = new Point2D.Double(rect.getMaxX(), rect.getMaxY());
171
        Point2D pt3 = new Point2D.Double(rect.getMinX(), rect.getMaxY());
172
        Point2D pt4 = new Point2D.Double(rect.getMaxX(), rect.getMinY());
173
        
174
        convert(pt1, pt1);
175
        convert(pt2, pt2);
176
        convert(pt3, pt3);
177
        convert(pt4, pt4);
178

  
179
        double min_x = Math.min(
180
            Math.min(pt1.getX(), pt2.getX()),
181
            Math.min(pt3.getX(), pt4.getX()));
182
        double min_y = Math.min(
183
            Math.min(pt1.getY(), pt2.getY()),
184
            Math.min(pt3.getY(), pt4.getY()));
185
        double max_x = Math.max(
186
            Math.max(pt1.getX(), pt2.getX()),
187
            Math.max(pt3.getX(), pt4.getX()));
188
        double max_y = Math.max(
189
            Math.max(pt1.getY(), pt2.getY()),
190
            Math.max(pt3.getY(), pt4.getY()));
191
        
192
        return new Rectangle2D.Double(
193
            min_x, min_y, max_x - min_x, max_y - min_y);
194
        
195
    }
196
}
0 197

  
tags/org.gvsig.desktop-2.0.179/org.gvsig.desktop.compat.cdc/org.gvsig.projection/org.gvsig.projection.cresques/org.gvsig.projection.cresques.impl/src/main/java/org/cresques/impl/cts/gt2/CSDatum.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.cresques.impl.cts.gt2;
25

  
26
import java.util.Locale;
27

  
28
import org.cresques.cts.IDatum;
29
import org.geotools.cs.CoordinateSystemFactory;
30
import org.geotools.cs.GeographicCoordinateSystem;
31
import org.geotools.cs.HorizontalDatum;
32
import org.opengis.referencing.FactoryException;
33

  
34

  
35
/**
36
 * Datum (y Ellipsoid) de GeoTools2.
37
 *
38
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
39
 */
40
public class CSDatum implements IDatum {
41
    private static String line1 = "DATUM[\"WGS_1984\"," +
42
                                  "SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]]," +
43
                                  "TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]]";
44
    private static String line2 = "DATUM[\"European_Datum_1950\"," +
45
                                  "SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]]," +
46
                                  "TOWGS84[-84,-107,-120,0,0,0,0],AUTHORITY[\"EPSG\",\"6230\"]]";
47
    private static String line3 = "DATUM[\"Nouvelle_Triangulation_Francaise\"," +
48
                                  "SPHEROID[\"Clarke 1880 (IGN)\",6378249.2,293.466021293627, AUTHORITY[\"EPSG\",\"7011\"]]," +
49
                                  "TOWGS84[-168,-60,320,0,0,0,0],AUTHORITY[\"EPSG\",\"6275\"]]";
50
    private static String line4 = "DATUM[\"Datum 73\"," +
51
                                  "SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]]," +
52
                                  "TOWGS84[-87,-98,-121,0,0,0,0],AUTHORITY[\"EPSG\",\"4274\"]]";
53
    private static String line5 = "DATUM[\"North_American_Datum_1927\"," +
54
                                  "SPHEROID[\"Clarke 1866\",6378206.4,294.978698213901,AUTHORITY[\"EPSG\",\"7008\"]]," +
55
                                  "TOWGS84[-3,142,183,0,0,0,0],AUTHORITY[\"EPSG\",\"6267\"]]";
56
    private static String line6 = "DATUM[\"North_American_Datum_1983\"," +
57
                                  "SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]]," +
58
                                  "TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6269\"]]";
59

  
60
    /*
61
     * INSERT INTO epsg_coordinatereferencesystem VALUES (
62
     * 4288, 'Loma Quintana', 1313, 'geographic 2D', 6422, 6288,
63
     * Null, Null, Null, Null, 'Geodetic survey.',
64
     * 'Superseded by La Canoa (code 4247).', '',
65
     * 'EPSG', '2004/01/06', '2003.37', 1, 0 );
66
     *
67
     *  DX (m) = -270.933
68
            DY (m) =  115.599
69
            DZ (m) = -360.226
70

  
71
            EX (") = -5.266
72
            EY (") = -1.238
73
              EZ (")  =  2.381
74
            FE (ppm) = -5.109
75
     */
76
    private static String line7 = "DATUM[\"Loma Quintana\"," +
77
                                  "SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]]," +
78
                                  "TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6288\"]]";
79

  
80
    /*
81
    # La Canoa
82
    <4247> +proj=longlat +ellps=intl +towgs84=-273.5,110.6,-357.9,0,0,0,0
83
    no_defs <>
84
    # PSAD56
85
    <4248> +proj=longlat +ellps=intl +towgs84=-288,175,-376,0,0,0,0 no_defs <>
86
     */
87
    private static String line8 = "DATUM[\"La Canoa\"," +
88
                                  "SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]]," +
89
                                  "TOWGS84[-270.933,115.599,-360.226,-5.266,-1.238,2.381,-5.109],AUTHORITY[\"EPSG\",\"6288\"]]";
90
    private static String line9 = "GEOGCS[\"NTF (Paris)\","+
91
    	"DATUM[\"Nouvelle_Triangulation_Francaise_Paris\"," +
92
    	"SPHEROID[\"Clarke 1880 (IGN)\",6378249.2,293.4660212936269,AUTHORITY[\"EPSG\",\"7011\"]]," +
93
    	"TOWGS84[-168,-60,320,0,0,0,0],AUTHORITY[\"EPSG\",\"8903\"]]"+
94
        ",PRIMEM[\"Paris\",2.33722917,AUTHORITY[\"EPSG\",\"8903\"]]," +
95
        "UNIT[\"grad\",0.01570796326794897,AUTHORITY[\"EPSG\",\"9105\"]]," +
96
        "AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST]," +
97
        "AUTHORITY[\"EPSG\",\"4807\"]]";
98
    
99
    private static String line10 = "GEOGCS[\"RGF93\"," +
100
		"DATUM[\"Reseau Geodesique Francais 1993\"," +
101
	    "SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]]," +
102
	    "TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6171\"]],"+
103
        "PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]]," +
104
        "UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]]," +
105
        "AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST]," +
106
        "AUTHORITY[\"EPSG\",\"4171\"]]";
107
    private static String line11 = "GEOGCS[\"ETRS89\","+
108
        "DATUM[\"European_Terrestrial_Reference_System_1989\","+
109
            "SPHEROID[\"GRS 1980\",6378137,298.257222101,"+
110
                "AUTHORITY[\"EPSG\",\"7019\"]],"+
111
            "AUTHORITY[\"EPSG\",\"6258\"]],"+
112
        "PRIMEM[\"Greenwich\",0,"+
113
            "AUTHORITY[\"EPSG\",\"8901\"]],"+
114
        "UNIT[\"degree\",0.01745329251994328,"+
115
            "AUTHORITY[\"EPSG\",\"9122\"]],"+
116
        "AUTHORITY[\"EPSG\",\"4258\"]]";
117
    //," +
118
    //"TOWGS84[0,0,0,0,0,0,0]
119
    private static String line12 =
120
    	"GEOGCS[\"Mars 2000\","+
121
	    	"DATUM[\"D_Mars_2000\","+
122
	    		"SPHEROID[\"Mars_2000_IAU_IAG\",3396190.0, 169.89444722361179],"+
123
	    	"TOWGS84[0,0,0,0,0,0,0]],"+
124
		    "PRIMEM[\"Greenwich\",0],"+
125
	    	"UNIT[\"Decimal_Degree\",0.0174532925199433]]";
126

  
127
    public final static CSDatum wgs84 = new CSDatum(line1);
128
    public final static CSDatum ed50 = new CSDatum(line2);
129
    public final static CSDatum ntf = new CSDatum(line3);
130
    public final static CSDatum d73 = new CSDatum(line4);
131
    public final static CSDatum nad27 = new CSDatum(line5);
132
    public final static CSDatum nad83 = new CSDatum(line6);
133
    public final static CSDatum lomaQuintana = new CSDatum(line7);
134
    public final static CSDatum laCanoa = new CSDatum(line8);
135
    public static CSDatum etrs89 = null;
136
    public static CSDatum ntfParis = null;
137
    public static CSDatum posgar = null;
138
    public static CSDatum rgf93 = null;
139
    public static CSDatum mars = null;
140
    public static CSDatum moon = null;
141
    private String sGeo1 = "GEOGCS[\"WGS 84\",";
142
    private String sGeo2 =
143
        ",PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]]," +
144
        "UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]]," +
145
        "AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST]," +
146
        "AUTHORITY[\"EPSG\",\"4326\"]]";
147
    private HorizontalDatum datum = null;
148
    static {
149
    	try {
150
			ntfParis =  new CSDatum().fromWKT(line9);
151
			rgf93 =  new CSDatum().fromWKT(line10);
152
			etrs89 = new CSDatum().fromWKT(line11);
153
			posgar = new CSDatum().fromWKT(
154
				"GEOGCS[\"POSGAR\","+
155
				"DATUM[\"POSGAR\"," +
156
                "SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]]," +
157
                "TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6269\"]]"+
158
                ",PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]]," +
159
                "UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]]," +
160
                "AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST]," +
161
                "AUTHORITY[\"EPSG\",\"4172\"]]");
162
			mars = new CSDatum().fromWKT(line12);
163
			moon = new CSDatum().fromWKT(
164
				"GEOGCS[\"Moon 2000\"," +
165
				"DATUM[\"D_Moon_2000\"," +
166
				"SPHEROID[\"Moon_2000_IAU_IAG\",1737400.0, 0.0]," +
167
		    	"TOWGS84[0,0,0,0,0,0,0]],"+
168
				"PRIMEM[\"Greenwich\",0]," +
169
				"UNIT[\"Decimal_Degree\",0.0174532925199433]]");
170
		} catch (FactoryException e) {
171
			// TODO Auto-generated catch block
172
			e.printStackTrace();
173
		}
174
    }
175

  
176
    public CSDatum() {
177
    }
178

  
179
    public CSDatum(HorizontalDatum datum) {
180
    	this.datum = datum;
181
    }
182

  
183
    public CSDatum(String sDatum) {
184
        try {
185
            fromWKT(sGeo1 + sDatum + sGeo2);
186
        } catch (FactoryException e) {
187
            // TODO Bloque catch generado autom?ticamente
188
            e.printStackTrace();
189
        }
190
    }
191
    
192
    public CSDatum fromWKT(String s) throws FactoryException {
193
        datum = ((GeographicCoordinateSystem) CoordinateSystemFactory.getDefault()
194
                .createFromWKT(s)).getHorizontalDatum();
195
        return this;
196
    }
197

  
198
    public String getName(Locale loc) {
199
        return datum.getName().toString();
200
    }
201

  
202
    HorizontalDatum getDatum() {
203
        return datum;
204
    }
205

  
206
    public double getESemiMajorAxis() {
207
        return datum.getEllipsoid().getSemiMajorAxis();
208
    }
209

  
210
    public double getEIFlattening() {
211
        return datum.getEllipsoid().getInverseFlattening();
212
    }
213

  
214
    public String toString() {
215
        return datum.toString();
216
    }
217
}
0 218

  
tags/org.gvsig.desktop-2.0.179/org.gvsig.desktop.compat.cdc/org.gvsig.projection/org.gvsig.projection.cresques/org.gvsig.projection.cresques.impl/src/main/java/org/cresques/impl/cts/gt2/gt2.dfPackage
1
package id453jodxljqzpfdxljry0t;
2

  
3
/**
4
@version 2.0
5
@physicalPackage
6
@__modelType diagram 
7
*/
8
class diagram {
9
/**
10
@__ref <oiref:java#Class#org.cresques.cts.gt2.CoordTrans:oiref><oihard>
11
@__modelType reference 
12
*/
13
class reference {
14
}/**
15
@__ref <oiref:java#Class#org.cresques.cts.gt2.CoordSys:oiref><oihard>
16
@__modelType reference 
17
*/
18
class reference4 {
19
}/**
20
@__ref <oiref:java#Class#org.cresques.cts.gt2.CSUTM:oiref><oihard>
21
@__modelType reference 
22
*/
23
class reference5 {
24
}/**
25
@__ref <oiref:java#Class#org.cresques.cts.gt2.CSDatum:oiref><oihard>
26
@__modelType reference 
27
*/
28
class reference6 {
29
}/**
30
@__ref <oiref:java#Class#org.cresques.cts.gt2.CSLambertCC:oiref><oihard>
31
@__modelType reference 
32
*/
33
class reference7 {
34
}/**
35
@__ref <oiref:java#Class#org.cresques.cts.gt2.CSGaussPt:oiref><oihard>
36
@__modelType reference 
37
*/
38
class reference8 {
39
}}/**
40
@__tags
41
@shapeType ClassDiagram 
42
*/
43
class __tags {
44
}/**
45
@__options 
46
*/
47
class __options {
48
}/**
49
@__positions <oigroup:MemberLink#<oiref:java#Member#org.cresques.cts.gt2.CSDatum#wgs84:oiref>=560,360,560,530,876,530,876,200,713,200:oigroup>
50
<oigroup:MemberLink#<oiref:java#Member#org.cresques.cts.gt2.CSDatum#d73:oiref>=649,360,649,434,787,434,787,296,713,296:oigroup>
51
<oigroup:<oiref:java#Extends#org.cresques.cts.gt2.CSLambertCC#org.cresques.cts.gt2.CoordSys:oiref>=440,630,440,392:oigroup>
52
<oigroup:<oiref:java#Class#org.cresques.cts.gt2.CoordSys:oiref>=270,10,200,382,1:oigroup>
53
<oigroup:MemberLink#<oiref:java#Member#org.cresques.cts.gt2.CoordSys#datum:oiref>=470,185,550,185:oigroup>
54
<oigroup:MemberLink#<oiref:java#Member#org.cresques.cts.gt2.CSDatum#nad27:oiref>=681,360,681,402,755,402,755,328,713,328:oigroup>
55
<oigroup:<oiref:java#Class#org.cresques.cts.gt2.CSUTM:oiref>=548,630,110,117,1:oigroup>
56
<oigroup:MemberLink#<oiref:java#Member#org.cresques.cts.gt2.CSDatum#ntf:oiref>=617,360,617,466,819,466,819,264,713,264:oigroup>
57
<oigroup:<oiref:java#Class#org.cresques.cts.gt2.CSDatum:oiref>=550,10,163,350,1:oigroup>
58
<oigroup:<oiref:java#Extends#org.cresques.cts.gt2.CSUTM#org.cresques.cts.gt2.CoordSys:oiref>=603,630,455,392:oigroup>
59
<oigroup:<oiref:java#Class#org.cresques.cts.gt2.CSLambertCC:oiref>=426,630,102,101,1:oigroup>
60
<oigroup:<oiref:java#Class#org.cresques.cts.gt2.CSGaussPt:oiref>=230,630,124,110,1:oigroup>
61
<oigroup:MemberLink#<oiref:java#Member#org.cresques.cts.gt2.CSDatum#ed50:oiref>=585,360,585,498,851,498,851,232,713,232:oigroup>
62
<oigroup:MemberLink#<oiref:java#Member#org.cresques.cts.gt2.CSGaussPt#hgd73:oiref>=332,740,332,772,386,772,386,718,354,718:oigroup>
63
<oigroup:<oiref:java#Extends#org.cresques.cts.gt2.CSGaussPt#org.cresques.cts.gt2.CoordSys:oiref>=321,630,321,392:oigroup>
64
<oigroup:<oiref:java#Class#org.cresques.cts.gt2.CoordTrans:oiref>=10,630,200,318,1:oigroup>
65
<oigroup:MemberLink#<oiref:java#Member#org.cresques.cts.gt2.CoordTrans#from:oiref>=110,630,295,392:oigroup> 
66
*/
67
class __positions {
68
}
tags/org.gvsig.desktop-2.0.179/org.gvsig.desktop.compat.cdc/org.gvsig.projection/org.gvsig.projection.cresques/org.gvsig.projection.cresques.impl/src/main/java/org/cresques/impl/cts/gt2/CSLambertCC.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.cresques.impl.cts.gt2;
25

  
26
import org.geotools.cs.AxisInfo;
27
import org.geotools.cs.GeographicCoordinateSystem;
28
import org.geotools.cs.Projection;
29

  
30
import org.geotools.units.Unit;
31

  
32
import org.opengis.referencing.FactoryException;
33

  
34

  
35
/**
36
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
37
 *
38
 */
39
public class CSLambertCC extends CoordSys {
40
    public CSLambertCC(CSDatum datum, double meridian, double origin,
41
                       double sp1, double sp2, double est, double nort) {
42
        super(datum);
43

  
44
        geogCS = new GeographicCoordinateSystem(datum.getName(null),
45
                                                datum.getDatum());
46

  
47
        Unit linearUnit = Unit.METRE;
48

  
49
        javax.media.jai.ParameterList params = csFactory.createProjectionParameterList("Lambert_Conformal_Conic_2SP");
50
        params.setParameter("semi_major",
51
                            datum.getDatum().getEllipsoid().getSemiMajorAxis());
52
        params.setParameter("semi_minor",
53
                            datum.getDatum().getEllipsoid().getSemiMinorAxis());
54
        params.setParameter("central_meridian", meridian);
55
        params.setParameter("latitude_of_origin", origin);
56
        params.setParameter("standard_parallel_1", sp1);
57
        params.setParameter("standard_parallel_2", sp2);
58
        params.setParameter("false_easting", est);
59
        params.setParameter("false_northing", nort);
60

  
61
        try {
62
            Projection projection = csFactory.createProjection("Lambert",
63
                                                               "Lambert_Conformal_Conic_2SP",
64
                                                               params);
65
            projCS = csFactory.createProjectedCoordinateSystem(projection.getName()
66
                                                                         .toString(),
67
                                                               geogCS,
68
                                                               projection,
69
                                                               linearUnit,
70
                                                               AxisInfo.X,
71
                                                               AxisInfo.Y);
72
        } catch (FactoryException e) {
73
            // TODO Bloque catch generado autom?ticamente
74
            e.printStackTrace();
75
        }
76
    }
77

  
78
    public CSLambertCC(CSDatum datum, double meridian, double origin,
79
    		double sf, double est, double nort) {
80
    	super(datum);
81
    	
82
    	geogCS = new GeographicCoordinateSystem(datum.getName(null),
83
    			datum.getDatum());
84
    	
85
    	Unit linearUnit = Unit.METRE;
86
    	
87
    	javax.media.jai.ParameterList params = csFactory.createProjectionParameterList("Lambert_Conformal_Conic_1SP");
88
    	params.setParameter("semi_major",
89
    			datum.getDatum().getEllipsoid().getSemiMajorAxis());
90
    	params.setParameter("semi_minor",
91
    			datum.getDatum().getEllipsoid().getSemiMinorAxis());
92
    	params.setParameter("central_meridian", meridian);
93
    	params.setParameter("latitude_of_origin", origin);
94
    	params.setParameter("scale_factor", sf);
95
    	params.setParameter("false_easting", est);
96
    	params.setParameter("false_northing", nort);
97
    	
98
    	try {
99
    		Projection projection = csFactory.createProjection("Lambert",
100
    				"Lambert_Conformal_Conic_1SP",
101
					params);
102
    		projCS = csFactory.createProjectedCoordinateSystem(projection.getName()
103
    				.toString(),
104
					geogCS,
105
					projection,
106
					linearUnit,
107
					AxisInfo.X,
108
					AxisInfo.Y);
109
    	} catch (FactoryException e) {
110
    		// TODO Bloque catch generado autom?ticamente
111
    		e.printStackTrace();
112
    	}
113
    }
114
    
115
    public double getScale(double minX, double maxX, double w, double dpi) {
116
        double scale = super.getScale(minX, maxX, w, dpi);
117

  
118
        if (projCS != null) { // Es geogr?fico; calcula la escala.
119
            scale = ((maxX - minX) * // metros
120
                    (dpi / 2.54 * 100.0)) / // px / metro
121
                    w; // pixels
122
        }
123

  
124
        return scale;
125
    }
126
    
127
    public String toString() {
128
        return projCS.toString();
129
    }
130
}
0 131

  
tags/org.gvsig.desktop-2.0.179/org.gvsig.desktop.compat.cdc/org.gvsig.projection/org.gvsig.projection.cresques/org.gvsig.projection.cresques.impl/src/main/java/org/cresques/impl/cts/gt2/CSMercator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.cresques.impl.cts.gt2;
25

  
26
import org.geotools.cs.AxisInfo;
27
import org.geotools.cs.GeographicCoordinateSystem;
28
import org.geotools.cs.Projection;
29

  
30
import org.geotools.units.Unit;
31

  
32
import org.opengis.referencing.FactoryException;
33

  
34

  
35
/**
36
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
37
 */
38
public class CSMercator extends CoordSys {
39
    public CSMercator(CSDatum datum) {
40
        super(datum);
41
        geogCS = new GeographicCoordinateSystem(datum.getName(null),
42
                                                datum.getDatum());
43

  
44
        Unit linearUnit = Unit.METRE;
45

  
46
        javax.media.jai.ParameterList params = csFactory.createProjectionParameterList("Mercator");
47
        params.setParameter("semi_major",
48
                            datum.getDatum().getEllipsoid().getSemiMajorAxis());
49
        params.setParameter("semi_minor",
50
                            datum.getDatum().getEllipsoid().getSemiMinorAxis());
51
        params.setParameter("central_meridian", 0D);
52
        params.setParameter("latitude_of_origin", 0D);
53
        params.setParameter("scale_factor", 1D);
54
        params.setParameter("false_easting", 0D);
55
        params.setParameter("false_northing", 0D);
56

  
57
        try {
58
            Projection projection = csFactory.createProjection("Mercator",
59
                                                               "Mercator_1SP",
60
                                                               params);
61
            projCS = csFactory.createProjectedCoordinateSystem(projection.getName()
62
                                                                         .toString(),
63
                                                               geogCS,
64
                                                               projection,
65
                                                               linearUnit,
66
                                                               AxisInfo.X,
67
                                                               AxisInfo.Y);
68
        } catch (FactoryException e) {
69
            // TODO Bloque catch generado autom?ticamente
70
            e.printStackTrace();
71
        }
72
    }
73

  
74
    public double getScale(double minX, double maxX, double w, double dpi) {
75
        double scale = super.getScale(minX, maxX, w, dpi);
76

  
77
        if (projCS != null) { // Es geogr?fico; calcula la escala.
78
            scale = ((maxX - minX) * // metros
79
                    (dpi / 2.54 * 100.0)) / // px / metro
80
                    w; // pixels
81
        }
82

  
83
        return scale;
84
    }
85

  
86
    public String toString() {
87
        return projCS.toString();
88
    }
89
}
0 90

  
tags/org.gvsig.desktop-2.0.179/org.gvsig.desktop.compat.cdc/org.gvsig.projection/org.gvsig.projection.cresques/org.gvsig.projection.cresques.impl/src/main/java/org/cresques/impl/cts/wkt/WKT.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.cresques.impl.cts.wkt;
25

  
26
import java.util.ArrayList;
27

  
28
/**
29
 * Generates a WKT from CRS parameters.
30
 * as, for example in
31
 * "GEOGCS[\"ETRS89\","+
32
        "DATUM[\"European_Terrestrial_Reference_System_1989\","+
33
            "SPHEROID[\"GRS 1980\",6378137,298.257222101,"+
34
                "AUTHORITY[\"EPSG\",\"7019\"]],"+
35
            "AUTHORITY[\"EPSG\",\"6258\"]," +
36
            "TOWGS84[0,0,0,0,0,0,0]],"+
37
        "PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],"+
38
        "UNIT[\"degree\",0.01745329251994328, AUTHORITY[\"EPSG\",\"9122\"]],"+
39
        "AUTHORITY[\"EPSG\",\"4258\"]]";
40
    
41
 * @author Luis W. Sevilla <sevilla_lui@gva.es>
42
 *
43
 */
44
public abstract class WKT {
45

  
46
	static class Authority {
47
		String name;
48
		String code;
49
		public Authority(String n, String c) {
50
			name = n;
51
			code = c;
52
		}
53
		public String toWKT() {
54
			return "AUTHORITY[\""+name+"\",\""+code+"\"]";
55
		}
56
	}
57

  
58
	static class Parameter {
59
		protected String name;
60
		private String value;
61
		protected Authority authority; // optional
62
		
63
		public Parameter(String n) {
64
			name = n;
65
		}
66
		
67
		public Parameter(String n, String v) {
68
			name = n;
69
			value = v;
70
		}
71
		public Parameter(String n, Authority a) {
72
			name = n;
73
			authority = a;
74
		}
75
		
76
		public String toWKT() {
77
			String txt = "PARAMETER[\""+name+"\","+value;
78
			if (authority != null)
79
				txt += ","+authority.toWKT();
80
			return txt + "]";
81
		}
82
	}
83

  
84
	static class Spheroid {
85
		String name;
86
		double semiMajor;
87
		double inverseFlattening;
88
		Authority authority = null; // optional
89
		
90
		public Spheroid(String n, double s, double f) {
91
			name = n;
92
			semiMajor = s;
93
			inverseFlattening = f;
94
		}
95
		public Spheroid(String n, double s, double f, Authority a) {
96
			name = n;
97
			semiMajor = s;
98
			inverseFlattening = f;
99
			authority = a;
100
		}
101
		public String toWKT() {
102
			String txt = "SPHEROID[\""+name+"\","+
103
				semiMajor+","+inverseFlattening;
104
			if (authority != null)
105
				txt += ","+authority.toWKT();
106
			return txt + "]";
107
		}
108
	}
109

  
110
	static class ToWGS84 {
111
		double dx = 0;
112
		double dy = 0;
113
		double dz = 0;
114
		double ex = 0;
115
		double ey = 0;
116
		double ez = 0;
117
		double ppm = 0;
118
		public ToWGS84() {
119
		}
120
		public ToWGS84(double dx, double dy, double dz, double ex, double ey, double ez, double ppm) {
121
			this.dx = dx;
122
			this.dy = dy;
123
			this.dz = dz;
124
			this.ex = ex;
125
			this.ey = ey;
126
			this.ez = ez;
127
			this.ppm = ppm;
128
		}
129
		public String toWKT() {
130
			return "TOWGS84["+dx+","+dy+","+dz+","+ex+","+ey+","+ez+","+ppm+"]";
131
		}
132
	}
133

  
134
	static class Datum {
135
		String name;
136
		Spheroid spheroid;
137
		ToWGS84 towgs84 = new ToWGS84(); // optional
138
		Authority authority; // optional
139
		public Datum(String n, Spheroid s) {
140
			init (n, s, new ToWGS84(), null);
141
		}
142
		public Datum(String n, Spheroid s, ToWGS84 t) {
143
			init (n, s, t, null);
144
		}
145
		public Datum(String n, Spheroid s, Authority a) {
146
			init (n, s, new ToWGS84(), a);
147
		}
148
		public Datum(String n, Spheroid s, ToWGS84 t, Authority a) {
149
			init (n, s, t, a);
150
		}
151
		private void init(String n, Spheroid s,
152
			ToWGS84 t, Authority a) {
153
			name = n;
154
			spheroid = s;
155
			towgs84 = t;
156
			authority = a;
157
		}
158
		public String toWKT() {
159
			String txt = "DATUM[\""+name+"\","+spheroid.toWKT();
160
			if (towgs84 != null)
161
				txt += ","+towgs84.toWKT();
162
			if (authority != null)
163
				txt += ","+authority.toWKT();
164
			return txt+"]";
165
		}
166
	}
167

  
168
	static class PrimeM {
169
		String name;
170
		double longitude;
171
		Authority authority = null; // optional
172
		
173
		public PrimeM(String n, double l) {
174
			name = n;
175
			longitude = l;
176
		}
177
		
178
		public PrimeM(String n, double l, Authority a) {
179
			name = n;
180
			longitude = l;
181
			authority = a;
182
		}
183
		
184
		public String toWKT() {
185
			String txt = "PRIMEM[\""+name+"\","+longitude;
186
			if (authority != null)
187
				txt += ","+authority.toWKT();
188
			return txt + "]";
189
		}
190
	}
191

  
192
	static class Unit {
193
		String name;
194
		double conversionFactor;
195
		Authority authority; // optional
196
		
197
		public Unit(String n, double l) {
198
			name = n;
199
			conversionFactor = l;
200
		}
201
		
202
		public Unit(String n, double l, Authority a) {
203
			name = n;
204
			conversionFactor = l;
205
			authority = a;
206
		}
207
		
208
		public String toWKT() {
209
			String txt = "UNIT[\""+name+"\","+conversionFactor;
210
			if (authority != null)
211
				txt += ","+authority.toWKT();
212
			return txt + "]";
213
		}
214
	}
215
	
216
	static class Orientation {
217
		public final static int NORTH = 0;
218
		public final static int SOUTH = 1;
219
		public final static int EAST = 2;
220
		public final static int WEST = 3;
221
		public final static int UP = 4;
222
		public final static int DOWN = 5;
223
		public final static int OTHER = 6;
224
		protected final String [] txt = {
225
			"NORTH","SOUTH","EAST","WEST","UP","DOWN","OTHER"
226
		};
227
		protected int to = -1;
228
		
229
		public Orientation(int to) {
230
			this.to = to;
231
		}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff