Revision 38292

View differences:

tags/v2_0_0_Build_2047/libraries/libProjection/.cvsignore
1
bin
2
bin-test
0 3

  
tags/v2_0_0_Build_2047/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_2047/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_2047/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_2047/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_2047/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_2047/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_2047/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_2047/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_2047/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_2047/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_2047/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_2047/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_2047/libraries/libProjection/src/org/gvsig/fmap/crs/persistence/ProjectionPersistenceFactory.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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {DiSiD Technologies}  {{Task}}
26
 */
27
package org.gvsig.fmap.crs.persistence;
28

  
29
import org.cresques.cts.IProjection;
30
import org.gvsig.fmap.crs.CRSFactory;
31
import org.gvsig.tools.dataTypes.DataTypes;
32
import org.gvsig.tools.dynobject.DynStruct;
33
import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory;
34
import org.gvsig.tools.persistence.PersistenceManager;
35
import org.gvsig.tools.persistence.PersistentState;
36
import org.gvsig.tools.persistence.exception.PersistenceException;
37

  
38
/**
39
 * Factory to persist {@link IProjection} objects. The information about the
40
 * {@link IProjection} which will be persisted is its full code, containing all
41
 * required information to be able to reconstruct the {@link IProjection} object
42
 * through the {@link CRSFactory#getCRS(String)} method.
43
 * <p>
44
 * <strong>NOTE:</strong>To activate this factory, it must be instanced and
45
 * registered in the {@link PersistenceManager}. This will be usually performed
46
 * from the project Library.
47
 * </p>
48
 * 
49
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
50
 * @author 2010- <a href="jjdelcerro@gvsig.org">Joaquin Jose del Cerro</a> -
51
 *         gvSIG team
52
 */
53
public class ProjectionPersistenceFactory extends
54
		AbstractSinglePersistenceFactory {
55

  
56
	private static final String FIELD_FULLCODE = "fullcode";
57
	private static final String DESCRIPTION_FULLCODE = "Projection abbreviature";
58

  
59
	private static final String DYNCLASS_NAME = "Projection";
60
	private static final String DYNCLASS_DESCRIPTION = "Projection";
61

  
62
	/**
63
	 * Creates a new {@link ProjectionPersistenceFactory}.
64
	 */
65
	public ProjectionPersistenceFactory() {
66
		super(IProjection.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null,
67
				null);
68

  
69
		DynStruct definition = this.getDefinition();
70

  
71
		definition.addDynField(FIELD_FULLCODE).setDescription(
72
				DESCRIPTION_FULLCODE).setMandatory(true).setType(
73
				DataTypes.STRING);
74
	}
75

  
76
	public Object createFromState(PersistentState state)
77
			throws PersistenceException {
78
		return CRSFactory.getCRS(state.getString(FIELD_FULLCODE));
79
	}
80

  
81
	public void saveToState(PersistentState state, Object obj)
82
			throws PersistenceException {
83
		state.set(FIELD_FULLCODE, ((IProjection) obj).getFullCode());
84
	}
85
}
tags/v2_0_0_Build_2047/libraries/libProjection/src/org/gvsig/fmap/crs/persistence/CoordTransPersistenceFactory.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.gvsig.fmap.crs.persistence;
23

  
24
import org.cresques.DataTypes;
25
import org.cresques.cts.ICoordTrans;
26
import org.cresques.cts.IProjection;
27

  
28
import org.gvsig.tools.dynobject.DynStruct;
29
import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory;
30
import org.gvsig.tools.persistence.PersistentState;
31
import org.gvsig.tools.persistence.exception.PersistenceException;
32

  
33

  
34
/**
35
 * @author gvSIG Team
36
 * @version $Id$
37
 *
38
 */
39
public class CoordTransPersistenceFactory extends AbstractSinglePersistenceFactory {
40

  
41
    private static final String FIELD_SOURCE_PROJECTION = "source";
42
    private static final String DESCRIPTION_SOURCE_PROJECTION  = "Source projection";
43
    
44
    private static final String FIELD_DESTINATION_PROJECTION = "destination";
45
    private static final String DESCRIPTION_DESTINATION_PROJECTION = "Destination Projection";
46

  
47
    private static final String DYNCLASS_NAME = "CoordTrans";
48
    private static final String DYNCLASS_DESCRIPTION = "Coordinates Transformation";
49

  
50
    /**
51
     * Creates a new {@link CoordTransPersistenceFactory}.
52
     */
53
    public CoordTransPersistenceFactory() {
54
        super(ICoordTrans.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null, null);
55

  
56
        DynStruct definition = this.getDefinition();
57

  
58
        definition.addDynField(FIELD_SOURCE_PROJECTION).setDescription(
59
            DESCRIPTION_SOURCE_PROJECTION).setMandatory(true).setType(
60
                DataTypes.CRS);
61
        
62
        definition.addDynField(FIELD_DESTINATION_PROJECTION).setDescription(
63
            DESCRIPTION_DESTINATION_PROJECTION).setMandatory(true).setType(
64
                DataTypes.CRS);
65
    }
66

  
67
    public Object createFromState(PersistentState state)
68
            throws PersistenceException {
69
        IProjection sourceProjection = (IProjection)state.get(FIELD_SOURCE_PROJECTION);
70
        IProjection destinationProjection = (IProjection)state.get(FIELD_DESTINATION_PROJECTION);      
71
        return sourceProjection.getCT(destinationProjection);
72
    }
73

  
74
    public void saveToState(PersistentState state, Object obj)
75
            throws PersistenceException {
76
        state.set(FIELD_SOURCE_PROJECTION, ((ICoordTrans) obj).getPOrig());
77
        state.set(FIELD_DESTINATION_PROJECTION, ((ICoordTrans) obj).getPDest());
78
    }
79
}
0 80

  
tags/v2_0_0_Build_2047/libraries/libProjection/src/org/gvsig/fmap/crs/CRSFactory.java
1
package org.gvsig.fmap.crs;
2

  
3
import org.cresques.cts.ICRSFactory;
4
import org.cresques.cts.IProjection;
5

  
6
/**
7
 * Fabrica de CRS.
8
 * Centraliza las peticiones de creaci?n de objetos CRS de todo fmap.
9
 * @author luisw
10
 *
11
 */
12
public class CRSFactory {
13
	public static ICRSFactory cp = null;
14

  
15
	public static IProjection getCRS(String code) {
16
		return cp.get(code);
17
	}
18
}
0 19

  
tags/v2_0_0_Build_2047/libraries/libProjection/src/org/cresques/DataTypes.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
/**
25
 * @author gvSIG Team
26
 * @version $Id$
27
 * 
28
 */
29
public interface DataTypes extends org.gvsig.tools.dataTypes.DataTypes {
30

  
31
    /*
32
	 * 
33
	 */
34
    public static final int CRS = OBJECT + 1;
35
}
0 36

  
tags/v2_0_0_Build_2047/libraries/libProjection/src/org/cresques/coerce/CoerceToString.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.coerce;
23

  
24
import org.cresques.cts.IProjection;
25
import org.gvsig.tools.dataTypes.CoercionException;
26
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
27

  
28
/**
29
 * Convert a Projection to String.
30
 * 
31
 * Support convert:
32
 * - Projection to String (do nothing)
33
 * 
34
 * @author gvSIG Team
35
 * @version $Id$
36
 * 
37
 */
38
public class CoerceToString implements Coercion {
39

  
40
	Coercion previous = null;
41
	
42
	public CoerceToString() {
43
		// Do nothing
44
	}
45
	
46
	public CoerceToString(Coercion previous) {
47
		this.previous = previous;
48
	}
49
	
50
	
51
	public Object coerce(Object value) throws CoercionException {
52
		try {
53
			if( value == null || value instanceof String ) {
54
				return value;
55
			}
56
			if( value instanceof IProjection ) {
57
				return ((IProjection)value).getFullCode();
58
			}
59
			if( previous != null ) {
60
				return previous.coerce(value);
61
			}
62
		} catch (Exception e) {
63
			throw new CoercionException(e);
64
		}
65
		throw new CoercionException();
66
	}
67

  
68
}
0 69

  
tags/v2_0_0_Build_2047/libraries/libProjection/src/org/cresques/coerce/CoerceToCRS.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.coerce;
23

  
24
import org.cresques.cts.IProjection;
25
import org.gvsig.fmap.crs.CRSFactory;
26
import org.gvsig.tools.dataTypes.CoercionException;
27
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
28

  
29
/**
30
 * Convert a string value of projection code to IProjection
31
 * 
32
 * @author gvSIG Team
33
 * @version $Id$
34
 * 
35
 */
36
public class CoerceToCRS implements Coercion {
37

  
38
	public Object coerce(Object value) throws CoercionException {
39
		try {
40
			if( value == null || value instanceof IProjection) {
41
				return value;
42
			}
43
			Object proj = CRSFactory.getCRS(value.toString());
44
			if( proj == null ) {
45
				throw new CoercionException("Can't convert value '"+value.toString()+"' to Projection.");
46
			}
47
			return proj;
48
		} catch (Exception e) {
49
			throw new CoercionException(e);
50
		}
51

  
52
	}
53

  
54
}
0 55

  
tags/v2_0_0_Build_2047/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_2047/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_2047/libraries/libProjection/src/org/cresques/impl/cts/gt2/CSUTM.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-7.
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.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/v2_0_0_Build_2047/libraries/libProjection/src/org/cresques/impl/cts/gt2/CSGaussPt.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.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/v2_0_0_Build_2047/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_2047/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\"]]," +
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff