Revision 39175

View differences:

tags/v2_0_0_Build_2057/libraries/libProjection/src-test/org/cresques/cts/AllTests.java
1
package org.cresques.cts;
2

  
3
import junit.framework.Test;
4
import junit.framework.TestSuite;
5

  
6
public class AllTests {
7

  
8
	public static Test suite() {
9
		TestSuite suite = new TestSuite("Test for org.cresques.cts");
10
		//$JUnit-BEGIN$
11

  
12
		//$JUnit-END$
13
		return suite;
14
	}
15

  
16
}
0 17

  
tags/v2_0_0_Build_2057/libraries/libProjection/config/org/cresques/resources/i18n/text_de.properties
1
#Translations for language [de]
2
#Mon Oct 30 09:38:21 CET 2006
3
Aceptar=OK
4
Aplicar=Anwenden
5
Block_Size_=
6
Cancelar=Abbrechen
7
Compression_=
8
datum=
9
Generate_Tfw_=
10
Interleave_=
11
Photometric_=
12
Progressive_=
13
projection=
14
reference_system=
15
zone=
0 16

  
tags/v2_0_0_Build_2057/libraries/libProjection/config/org/cresques/resources/i18n/text_eu.properties
1
#Translations for language [eu]
2
#Mon Oct 30 09:38:21 CET 2006
3
Aceptar=Ados
4
Aplicar=Aplikatu
5
Block_Size_=
6
Cancelar=Utzi
7
Compression_=
8
datum=
9
Generate_Tfw_=
10
Interleave_=
11
Photometric_=
12
Progressive_=
13
projection=
14
reference_system=
15
zone=
0 16

  
tags/v2_0_0_Build_2057/libraries/libProjection/config/org/cresques/resources/i18n/text_it.properties
1
#Translations for language [it]
2
#Tue Nov 07 12:30:01 CET 2006
3
Aceptar=Accetta
4
Aplicar=Applica
5
Block_Size_=Dimensioni blocco\:
6
Cancelar=Cancella
7
Compression_=Compressione
8
datum=Datum
9
Generate_Tfw_=Genera Tfw\:
10
Interleave_=Interlacciato\:
11
Photometric_=Fotometrica\:
12
Progressive_=Progressivo\:
13
projection=Proiezione
14
reference_system=Sistema di riferimento
15
zone=Fuso
0 16

  
tags/v2_0_0_Build_2057/libraries/libProjection/config/org/cresques/resources/i18n/text.properties
1
#Translations for language [es]
2
#Mon Oct 30 09:38:21 CET 2006
3
Aceptar=Aceptar
4
Aplicar=Aplicar
5
Block_Size_=Tama\u00f1o de bloque\:
6
Cancelar=Cancelar
7
Compression_=Compresi\u00f3n\:
8
datum=Datum
9
Generate_Tfw_=Generar Tfw\:
10
Interleave_=Entrelazado\:
11
Photometric_=Fotom\u00e9trica\:
12
Progressive_=Progresivo\:
13
projection=Proyecci\u00f3n
14
reference_system=Sistema de Referencia
15
zone=Huso
0 16

  
tags/v2_0_0_Build_2057/libraries/libProjection/config/org/cresques/resources/i18n/text_en.properties
1
#Translations for language [en]
2
#Mon Oct 30 09:38:21 CET 2006
3
Aceptar=Accept
4
Aplicar=Apply
5
Block_Size_=Block Size\:
6
Cancelar=Cancel
7
Compression_=Compression\:
8
datum=Datum
9
Generate_Tfw_=Generate Tfw\:
10
Interleave_=Interleave\:
11
Photometric_=Photometric\:
12
Progressive_=Progressive\:
13
projection=Projection
14
reference_system=Reference System
15
zone=Zone
0 16

  
tags/v2_0_0_Build_2057/libraries/libProjection/config/org/cresques/resources/i18n/text_gl.properties
1
#Translations for language [gl]
2
#Mon Oct 30 09:38:21 CET 2006
3
Aceptar=Aceptar
4
Aplicar=Aplicar
5
Block_Size_=
6
Cancelar=Cancelar
7
Compression_=
8
datum=
9
Generate_Tfw_=
10
Interleave_=
11
Photometric_=
12
Progressive_=
13
projection=
14
reference_system=
15
zone=
0 16

  
tags/v2_0_0_Build_2057/libraries/libProjection/config/org/cresques/resources/i18n/text_ca.properties
1
#Translations for language [ca]
2
#Mon Oct 30 09:38:21 CET 2006
3
Aceptar=Acceptar
4
Aplicar=Aplicar
5
Block_Size_=
6
Cancelar=Cancel\u00b7lar
7
Compression_=
8
datum=
9
Generate_Tfw_=
10
Interleave_=
11
Photometric_=
12
Progressive_=
13
projection=Projecci\u00f3
14
reference_system=Sistema de refer\u00e8ncia
15
zone=
0 16

  
tags/v2_0_0_Build_2057/libraries/libProjection/config/org/cresques/resources/i18n/text_pt.properties
1
#Translations for language [pt]
2
#Mon Oct 30 09:38:21 CET 2006
3
Aceptar=Aceitar
4
Aplicar=Aplicar
5
Block_Size_=
6
Cancelar=Cancelar
7
Compression_=
8
datum=
9
Generate_Tfw_=
10
Interleave_=
11
Photometric_=
12
Progressive_=
13
projection=
14
reference_system=
15
zone=
0 16

  
tags/v2_0_0_Build_2057/libraries/libProjection/config/org/cresques/resources/i18n/text_cs.properties
1
#Translations for language [cs]
2
#Mon Nov 06 09:04:31 CET 2006
3
Aceptar=Budi\u017e
4
Aplicar=Pou\u017e\u00edt
5
Block_Size_=
6
Cancelar=Zru\u0161it
7
Compression_=
8
datum=Datum
9
Generate_Tfw_=
10
Interleave_=
11
Photometric_=
12
Progressive_=
13
projection=Projekce
14
reference_system=Prostorov\u00fd referen\u010dn\u00ed syst\u00e9m
15
zone=Z\u00f3na
0 16

  
tags/v2_0_0_Build_2057/libraries/libProjection/config/org/cresques/resources/i18n/text_fr.properties
1
#Translations for language [fr]
2
#Mon Oct 30 09:38:21 CET 2006
3
Aceptar=Accepter
4
Aplicar=Appliquer
5
Block_Size_=
6
Cancelar=Annuler
7
Compression_=
8
datum=
9
Generate_Tfw_=
10
Interleave_=
11
Photometric_=
12
Progressive_=
13
projection=
14
reference_system=
15
zone=
0 16

  
tags/v2_0_0_Build_2057/libraries/libProjection/resources-test/log4j.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
5

  
6
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
7
		<layout class="org.apache.log4j.PatternLayout">
8
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
9
		</layout>
10
	</appender>
11

  
12
	<category name="org.gvsig.tools">
13
		<priority value="DEBUG" />
14
	</category>
15
	<category name="org.cresques">
16
		<priority value="DEBUG" /> 
17
	</category>
18
	<category name="org.gvsig.fmap.crs">
19
		<priority value="DEBUG" /> 
20
	</category>
21

  
22
	<root>
23
		<priority value="INFO" />
24
		<appender-ref ref="CONSOLE" />
25
	</root>
26
</log4j:configuration>
tags/v2_0_0_Build_2057/libraries/libProjection/src/org/cresques/ProjectionLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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 2
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
*/
22
package org.cresques;
23

  
24
import org.cresques.coerce.CoerceToCRS;
25
import org.cresques.coerce.CoerceToString;
26
import org.cresques.cts.IProjection;
27

  
28
import org.gvsig.fmap.crs.CRSFactory;
29
import org.gvsig.fmap.crs.persistence.CoordTransPersistenceFactory;
30
import org.gvsig.fmap.crs.persistence.ProjectionPersistenceFactory;
31
import org.gvsig.tools.ToolsLibrary;
32
import org.gvsig.tools.ToolsLocator;
33
import org.gvsig.tools.dataTypes.DataTypesManager;
34
import org.gvsig.tools.library.AbstractLibrary;
35
import org.gvsig.tools.library.LibraryException;
36

  
37
public class ProjectionLibrary extends AbstractLibrary {
38

  
39
    @Override
40
    public void doRegistration() {
41
        registerAsAPI(ProjectionLibrary.class);
42
        require(ToolsLibrary.class);
43
    }
44

  
45
	protected void doInitialize() throws LibraryException {
46
	}
47

  
48
	protected void doPostInitialize() throws LibraryException {
49
		if (CRSFactory.cp==null) {
50
			throw new CRSFactoryNotRegisteredException();
51
		}
52

  
53
		DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
54
        dataTypesManager.addtype(DataTypes.CRS, "CRS", "CRS",
55
            IProjection.class, new CoerceToCRS());
56
        dataTypesManager.setCoercion(DataTypes.STRING, new CoerceToString(
57
            dataTypesManager.getCoercion(DataTypes.STRING)));
58

  
59
		// Register the PersistenceFactory to be able to persist 
60
		// IProjection objects
61
		ToolsLocator.getPersistenceManager().registerFactory(
62
				new ProjectionPersistenceFactory());
63
		ToolsLocator.getPersistenceManager().registerFactory(
64
            new CoordTransPersistenceFactory());
65
	}
66

  
67
}
0 68

  
tags/v2_0_0_Build_2057/libraries/libProjection/src/org/cresques/impl/CresquesCtsLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.cresques.impl;
23

  
24
import org.cresques.ProjectionLibrary;
25
import org.cresques.impl.cts.ProjectionPool;
26

  
27
import org.gvsig.fmap.crs.CRSFactory;
28
import org.gvsig.tools.library.AbstractLibrary;
29
import org.gvsig.tools.library.LibraryException;
30

  
31
public class CresquesCtsLibrary extends AbstractLibrary {
32

  
33
    @Override
34
    public void doRegistration() {
35
        registerAsImplementationOf(ProjectionLibrary.class);
36
    }
37

  
38
    protected void doInitialize() throws LibraryException {
39
        CRSFactory.cp = new ProjectionPool();
40
    }
41

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

  
tags/v2_0_0_Build_2057/libraries/libProjection/src/org/cresques/impl/cts/gt2/CoordTrans.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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 2
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.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
        Point2D pt1 = new Point2D.Double(rect.getMinX(), rect.getMinY());
169
        Point2D pt2 = new Point2D.Double(rect.getMaxX(), rect.getMaxY());
170
        pt1 = convert(pt1, null);
171
        pt2 = convert(pt2, null);
172
        rect = new Rectangle2D.Double();
173
        rect.setFrameFromDiagonal(pt1, pt2);
174

  
175
        return rect;
176
    }
177
}
0 178

  
tags/v2_0_0_Build_2057/libraries/libProjection/src/org/cresques/impl/cts/gt2/CSDatum.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-6.
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 2
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.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/v2_0_0_Build_2057/libraries/libProjection/src/org/cresques/impl/cts/gt2/CSLambertCC.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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 2
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.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/v2_0_0_Build_2057/libraries/libProjection/src/org/cresques/impl/cts/gt2/CSMercator.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-6.
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 2
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.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/v2_0_0_Build_2057/libraries/libProjection/src/org/cresques/impl/cts/gt2/CoordSys.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-6.
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 2
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.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.gvsig.fmap.crs.CRSFactory;
40
import org.opengis.referencing.FactoryException;
41

  
42

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

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

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

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

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

  
93
        return coordSys;
94
    }
95

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

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

  
105
        return geogCS;
106
    }
107

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

  
113
        return projCS.getGeographicCoordinateSystem();
114
    }
115

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

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

  
128
        return geogCS.toString();
129
    }
130

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
219
	public String getFullCode() {
220
		return getAbrev();
221
	}
222
	
223
	public Object clone() throws CloneNotSupportedException {
224
	       return CRSFactory.getCRS( this.getFullCode() );
225
	    }
226

  
227
}
0 228

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff