Revision 345

View differences:

org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 3
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
28

  
29
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
30

  
31
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
32
		<layout class="org.apache.log4j.PatternLayout">
33
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
34
		</layout>
35
	</appender>
36

  
37
	<category name="org.gvsig.tools">
38
		<priority value="DEBUG" />
39
	</category>
40
	<category name="org.cresques">
41
		<priority value="DEBUG" /> 
42
	</category>
43
	<category name="org.gvsig.fmap.crs">
44
		<priority value="DEBUG" /> 
45
	</category>
46

  
47
	<root>
48
		<priority value="INFO" />
49
		<appender-ref ref="CONSOLE" />
50
	</root>
51
</log4j:configuration>
0 52

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/test/java/org/cresques/cts/AllTests.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.cts;
25

  
26
import junit.framework.Test;
27
import junit.framework.TestSuite;
28

  
29
public class AllTests {
30

  
31
	public static Test suite() {
32
		TestSuite suite = new TestSuite("Test for org.cresques.cts");
33
		//$JUnit-BEGIN$
34

  
35
		//$JUnit-END$
36
		return suite;
37
	}
38

  
39
}
0 40

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/gvsig/fmap/crs/CRSFactory.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.gvsig.fmap.crs;
25

  
26
import org.cresques.cts.ICRSFactory;
27
import org.cresques.cts.IProjection;
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30

  
31
/**
32
 * Fabrica de CRS.
33
 * Centraliza las peticiones de creaci?n de objetos CRS de todo fmap.
34
 * @author luisw
35
 *
36
 */
37
public class CRSFactory {
38
	
39
	private static Logger logger = LoggerFactory.getLogger(CRSFactory.class);
40
	/**
41
	 * @deprecated use {@link #registerCRSFactory(ICRSFactory)}
42
	 */
43
	public static ICRSFactory cp = null;
44
	private static ICRSFactory currentcp = null;
45

  
46
	public static void registerCRSFactory(ICRSFactory cp) {
47
		logger.info("Register CRSFactory " + cp.getClass().getName() + "/" + cp.toString() + ".");
48
		CRSFactory.currentcp = cp;
49
		CRSFactory.cp = cp;
50
	}
51
	
52
	public static ICRSFactory getCRSFactory() {
53
		return currentcp;
54
	}
55
	
56
	public static IProjection getCRS(String code) {
57
		if( cp != currentcp ) {
58
			logger.warn("Changed CRSFactory without calling registerCRSFactory.");
59
			registerCRSFactory(cp);
60
		}
61
		return currentcp.get(code);
62
	}
63
}
0 64

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/gvsig/fmap/crs/persistence/ProjectionPersistenceFactory.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
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {DiSiD Technologies}  {{Task}}
27
 */
28
package org.gvsig.fmap.crs.persistence;
29

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

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

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

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

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

  
70
		DynStruct definition = this.getDefinition();
71

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

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

  
82
	public void saveToState(PersistentState state, Object obj)
83
			throws PersistenceException {
84
		state.set(FIELD_FULLCODE, ((IProjection) obj).getFullCode());
85
	}
86
}
0 87

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/gvsig/fmap/crs/persistence/CoordTransPersistenceFactory.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.gvsig.fmap.crs.persistence;
25

  
26
import org.cresques.DataTypes;
27
import org.cresques.cts.ICoordTrans;
28
import org.cresques.cts.IProjection;
29

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

  
35

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

  
43
    private static final String FIELD_SOURCE_PROJECTION = "source";
44
    private static final String DESCRIPTION_SOURCE_PROJECTION  = "Source projection";
45

  
46
    private static final String FIELD_DESTINATION_PROJECTION = "destination";
47
    private static final String DESCRIPTION_DESTINATION_PROJECTION = "Destination Projection";
48

  
49
    private static final String DYNCLASS_NAME = "CoordTrans";
50
    private static final String DYNCLASS_DESCRIPTION = "Coordinates Transformation";
51

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

  
58
        DynStruct definition = this.getDefinition();
59

  
60
        definition.addDynFieldObject(FIELD_SOURCE_PROJECTION).setDescription(
61
            DESCRIPTION_SOURCE_PROJECTION).setMandatory(true).setClassOfValue(IProjection.class);
62

  
63
        definition.addDynFieldObject(FIELD_DESTINATION_PROJECTION).setDescription(
64
            DESCRIPTION_DESTINATION_PROJECTION).setMandatory(true).setClassOfValue(IProjection.class);
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

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/coerce/CoerceToString.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.coerce;
25

  
26
import org.cresques.cts.IProjection;
27
import org.gvsig.tools.dataTypes.CoercionException;
28
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
29

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

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

  
70
}
0 71

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/coerce/CoerceToCRS.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.coerce;
25

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

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

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

  
54
	}
55

  
56
}
0 57

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/ProjectionLibrary.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
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
*
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
*
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
*
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
42
* MA  02110-1301, USA.
43
*
44
*/
45
package org.cresques;
46

  
47
import org.cresques.coerce.CoerceToCRS;
48
import org.cresques.coerce.CoerceToString;
49
import org.cresques.cts.IProjection;
50
import org.gvsig.fmap.crs.CRSFactory;
51
import org.gvsig.fmap.crs.persistence.CoordTransPersistenceFactory;
52
import org.gvsig.fmap.crs.persistence.ProjectionPersistenceFactory;
53
import org.gvsig.tools.ToolsLibrary;
54
import org.gvsig.tools.ToolsLocator;
55
import org.gvsig.tools.dataTypes.DataTypesManager;
56
import org.gvsig.tools.library.AbstractLibrary;
57
import org.gvsig.tools.library.LibraryException;
58
import org.slf4j.Logger;
59
import org.slf4j.LoggerFactory;
60

  
61
public class ProjectionLibrary extends AbstractLibrary {
62

  
63
	private static final Logger logger = LoggerFactory.getLogger(ProjectionLibrary.class);
64
	
65
    public void doRegistration() {
66
        registerAsAPI(ProjectionLibrary.class);
67
        require(ToolsLibrary.class);
68
    }
69

  
70
	protected void doInitialize() throws LibraryException {
71
	}
72

  
73
	protected void doPostInitialize() throws LibraryException {
74
		if (CRSFactory.getCRSFactory()==null) {
75
			logger.warn("has not registered an implementation of " + this.getClass().getName()+".");
76
		}
77

  
78
		DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
79
        dataTypesManager.addtype(DataTypes.CRS, "CRS", "CRS",
80
            IProjection.class, new CoerceToCRS());
81
        dataTypesManager.setCoercion(DataTypes.STRING, new CoerceToString(
82
            dataTypesManager.getCoercion(DataTypes.STRING)));
83

  
84
		// Register the PersistenceFactory to be able to persist 
85
		// IProjection objects
86
		ToolsLocator.getPersistenceManager().registerFactory(
87
				new ProjectionPersistenceFactory());
88
		ToolsLocator.getPersistenceManager().registerFactory(
89
            new CoordTransPersistenceFactory());
90
	}
91

  
92
}
0 93

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/Messages.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

  
25
package org.cresques;
26

  
27
import java.util.Locale;
28

  
29
import org.gvsig.tools.ToolsLocator;
30
import org.gvsig.tools.i18n.I18nManager;
31

  
32
/**
33
* Bridge class to provide internationalization services to the library.
34
* It uses the gvsig-i18n library as a backend, and includes its
35
* necessary initialization.
36
* 
37
*/
38
public class Messages {
39
	private static I18nManager manager = null;
40
	/**
41
	 * Loads the translations in the dictionary. It initializes the backend
42
	 * gvsig-i18n library
43
	 *
44
	 */
45
	private static void init() {
46
		manager = ToolsLocator.getI18nManager(); 
47
		manager.addResourceFamily("org.cresques.resources.i18n.text", Messages.class.getClassLoader(), Messages.class.getClass().getName());
48
	}
49
	
50
	/**
51
	 * Gets the translation associated with the provided translation key.
52
	 * 
53
	 * @param key The translation key which identifies the target text
54
	 * @return The translation associated with the provided translation key.
55
	 */
56
	public static String getText(String key) {
57
		if (manager == null ) {
58
			init();
59
		}
60
		return manager.getTranslation(key);
61
	}
62

  
63
}
64

  
0 65

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/px/Extent.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.px;
25

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

  
29
import java.text.DecimalFormat;
30

  
31
/**
32
 *	Clase que getiona el extent de una imagen
33
 *	
34
 *  @author Luis W.Sevilla (sevilla_lui@gva.es)
35
 */
36
public class Extent {
37
    Point2D min = null;
38
    Point2D max = null;
39

  
40
    /**
41
     * Constructor sin par?metros
42
     */
43
    public Extent() {
44
        min = new Point2D.Double(999999999.0, 999999999.0);
45
        max = new Point2D.Double(-999999999.0, -999999999.0);
46
    }
47

  
48
    /**
49
     * Constructor 
50
     * @param pt1	punto que representa la esquina superior izquierda
51
     * @param pt2	punto que representa la esquina inferior derecha
52
     */
53
    public Extent(Point2D pt1, Point2D pt2) {
54
        newExtent(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY());
55
    }
56

  
57
    /**
58
     * Contructor
59
     * @param x1 punto que representa la coordenada X de la esquina superior izquierda
60
     * @param y1 punto que representa la coordenada Y de la esquina superior izquierda
61
     * @param x2 punto que representa la coordenada X de la esquina inferior derecha
62
     * @param y2 punto que representa la coordenada Y de la esquina inferior derecha
63
     */
64
    public Extent(double x1, double y1, double x2, double y2) {
65
        newExtent(x1, y1, x2, y2);
66
    }
67

  
68
    /**
69
     * Constructor
70
     * @param r	Rectangulo 2D
71
     */
72
    public Extent(Rectangle2D r) {
73
        newExtent(r.getX(), r.getY(), r.getX() + r.getWidth(),
74
                  r.getY() + r.getHeight());
75
    }
76

  
77
    /**
78
     * Constructor de copia
79
     * @param ext	Objeto Extent
80
     */
81
    public Extent(Extent ext) {
82
        newExtent(ext.minX(), ext.minY(), ext.maxX(), ext.maxY());
83
    }
84

  
85
    /**
86
     * Crea un objeto extent identico y lo retorna
87
     * @return Objeto extent
88
     */
89
    public Object clone() {
90
        Extent e = (Extent) clone();
91
        e.min = (Point2D) min.clone();
92
        e.max = (Point2D) max.clone();
93

  
94
        return e;
95
    }
96

  
97
    private void newExtent(double x1, double y1, double x2, double y2) {
98
        min = new Point2D.Double(Math.min(x1, x2), Math.min(y1, y2));
99
        max = new Point2D.Double(Math.max(x1, x2), Math.max(y1, y2));
100
    }
101

  
102
    /**
103
     * Obtiene la coordenada X m?nima
104
     * @return valor de la coordenada X m?nima
105
     */
106
    public double minX() {
107
        return min.getX();
108
    }
109

  
110
    /**
111
     * Obtiene la coordenada Y m?nima
112
     * @return valor de la coordenada X m?nima
113
     */
114
    public double minY() {
115
        return min.getY();
116
    }
117

  
118
    /**
119
     * Obtiene la coordenada X m?xima
120
     * @return valor de la coordenada X m?xima
121
     */
122
    public double maxX() {
123
        return max.getX();
124
    }
125

  
126
    /**
127
     * Obtiene la coordenada Y m?xima
128
     * @return valor de la coordenada Y m?xima
129
     */
130
    public double maxY() {
131
        return max.getY();
132
    }
133
    
134
    /**
135
     * Obtiene el punto m?nimo
136
     * @return m?nimo
137
     */
138
    public Point2D getMin() {
139
        return min;
140
    }
141

  
142
    /**
143
     * Obtiene el punto m?ximo
144
     * @return m?ximo
145
     */
146
    public Point2D getMax() {
147
        return max;
148
    }
149

  
150
    public boolean isAt(Point2D pt) {
151
        if (pt.getX() < minX()) {
152
            return false;
153
        }
154

  
155
        if (pt.getX() > maxX()) {
156
            return false;
157
        }
158

  
159
        if (pt.getY() < minY()) {
160
            return false;
161
        }
162

  
163
        if (pt.getY() > maxY()) {
164
            return false;
165
        }
166

  
167
        return true;
168
    }
169

  
170
    public double width() {
171
        return Math.abs(maxX() - minX());
172
    }
173

  
174
    public double height() {
175
        return Math.abs(maxY() - minY());
176
    }
177

  
178
    /**
179
     * Verifica un punto, y modifica el extent si no est? incluido
180
     */
181
    public void add(Point2D pt) {
182
        if (pt == null) {
183
            return;
184
        }
185

  
186
        min.setLocation(Math.min(pt.getX(), minX()), Math.min(pt.getY(), minY()));
187
        max.setLocation(Math.max(pt.getX(), maxX()), Math.max(pt.getY(), maxY()));
188
    }
189

  
190
    public void add(Extent ext) {
191
        if (ext == null) {
192
            return;
193
        }
194

  
195
        min.setLocation(Math.min(ext.minX(), minX()),
196
                        Math.min(ext.minY(), minY()));
197
        max.setLocation(Math.max(ext.maxX(), maxX()),
198
                        Math.max(ext.maxY(), maxY()));
199
    }
200

  
201
    /**
202
     * Obtiene la escala
203
     * @param width	Ancho
204
     * @param height	Alto
205
     * @return
206
     */
207
    public double[] getScale(int width, int height) {
208
        return getScale((double) width, (double) height);
209
    }
210

  
211
    public double[] getScale(double width, double height) {
212
        double[] scale = new double[2];
213
        scale[0] = ((float) width) / width();
214
        scale[1] = ((float) height) / height();
215

  
216
        return scale;
217
    }
218

  
219
    public Rectangle2D toRectangle2D() {
220
        return new Rectangle2D.Double(minX(), minY(), width(), height());
221
    }
222

  
223
    public String toString() {
224
        DecimalFormat format = new DecimalFormat("####.000");
225

  
226
        return "Extent: (" + format.format(minX()) + "," +
227
               format.format(minY()) + "), (" + format.format(maxX()) + "," +
228
               format.format(maxY()) + ")";
229
    }
230

  
231
    public interface Has {
232
        public Extent getExtent();
233
    }
234
}
0 235

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/px/.cvsignore
1
*.dfPackage
2
*.wmf
0 3

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/px/package.html
1
<!--
2

  
3
    gvSIG. Desktop Geographic Information System.
4

  
5
    Copyright (C) 2007-2013 gvSIG Association.
6

  
7
    This program is free software; you can redistribute it and/or
8
    modify it under the terms of the GNU General Public License
9
    as published by the Free Software Foundation; either version 3
10
    of the License, or (at your option) any later version.
11

  
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16

  
17
    You should have received a copy of the GNU General Public License
18
    along with this program; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
    MA  02110-1301, USA.
21

  
22
    For any additional information, do not hesitate to contact us
23
    at info AT gvsig.com, or visit our website www.gvsig.com.
24

  
25
-->
26
<html>
27
	<body>Pixel: Clases para dibujar.
28
</body>
29
</html>
0 30

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/cts/IDatum.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.cts;
25

  
26

  
27
/**
28
 * @author "Luis W. Sevilla" (sevilla_lui@gva.es)
29
 */
30
public interface IDatum {
31
    /**
32
     * Semieje Mayor del elipsoide.
33
     * @return
34
     */
35
    public double getESemiMajorAxis();
36

  
37
    /**
38
     * Aplanamiento del elipsoide.
39
     * @return
40
     */
41
    public double getEIFlattening();
42
}
0 43

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/cts/IProjection.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.cts;
25

  
26
import org.cresques.geo.ViewPortData;
27

  
28
import java.awt.Color;
29
import java.awt.Graphics2D;
30
import java.awt.geom.Point2D;
31
import java.awt.geom.Rectangle2D;
32

  
33
import org.gvsig.tools.lang.Cloneable;
34

  
35
/**
36
 *
37
 * @author "Luis W. Sevilla" (sevilla_lui@gva.es)
38
 */
39
public interface IProjection extends Cloneable{
40

  
41
    public IDatum getDatum();
42

  
43
    public Point2D createPoint(double x, double y);
44

  
45
    // TODO Quitar si no son necesarias.
46
    public String getAbrev();
47
    
48
    /**
49
     * Devuelve getAbrev() mas los parametros de transformacion si los hay
50
     * ej.: (EPSG:23030:proj@+proj...@...)
51
     * 
52
     * @return getAbrev() o getAbrev()+parametros
53
     */
54
    public String getFullCode();
55

  
56
    public void drawGrid(Graphics2D g, ViewPortData vp);
57

  
58
    public void setGridColor(Color c);
59

  
60
    public Color getGridColor();
61

  
62
    /**
63
     * Crea un ICoordTrans para transformar coordenadas
64
     * desde el IProjection actual al dest.
65
     * @param dest
66
     * @return
67
     */
68

  
69
    public ICoordTrans getCT(IProjection dest);
70

  
71
    public Point2D toGeo(Point2D pt);
72

  
73
    public Point2D fromGeo(Point2D gPt, Point2D mPt);
74

  
75
    public boolean isProjected();
76

  
77
    /**
78
     * First two parameters must be in meters.
79
     * This should be changed (map units should be used) and then
80
     * change the places where this method is used.
81
     * 
82
     * @param minX in meters
83
     * @param maxX in meters
84
     * @param width in pixels (dots)
85
     * @param dpi dots per inch
86
     * @return Scale denominator ( the "X" in "1 : X" )
87
     */
88
    public double getScale(double minX, double maxX, double width, double dpi);
89
    
90
    public Rectangle2D getExtent(Rectangle2D extent,double scale,double wImage,double hImage,double mapUnits,double distanceUnits,double dpi);
91
}
0 92

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/cts/UTM.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.cts;
25

  
26
public interface UTM extends IProjection {
27

  
28
}
0 29

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/cts/ICoordTrans.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.cts;
25

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

  
29

  
30
/**
31
 * @author "Luis W. Sevilla" (sevilla_lui@gva.es)
32
 */
33
public interface ICoordTrans {
34
    public IProjection getPOrig();
35

  
36
    public IProjection getPDest();
37

  
38
    public Point2D convert(Point2D ptOrig, Point2D ptDest);
39

  
40
    /**
41
     * Reprojects the input rectangle and returns the minimum rectangle
42
     * containing the result of that reprojection (which was not
43
     * necessarily a rectangle).
44
     * 
45
     * Reprojecting the diagonal an assuming that
46
     * the result is the diagonal of the rectangle to be returned is wrong
47
     * 
48
     * Reprojecting the four corners and searching for min and max
49
     * to create the resulting rectangle is not completely accurate
50
     * but provides an acceptable approximation 
51
     * 
52
     * @param rect
53
     * @return
54
     */
55
    public Rectangle2D convert(Rectangle2D rect);
56

  
57
    public ICoordTrans getInverted();
58
}
0 59

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/cts/ICRSFactory.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.cts;
25

  
26
public interface ICRSFactory {
27
	
28
	public boolean doesRigurousTransformations();
29
	
30
    /**
31
     * Devuelve una proyeccion a partir de una cadena.
32
     * @param name abreviatura de la proyecccion (i.e. EPSG:23030)
33
     * @return Proyeccion si existe
34
     */
35
    public IProjection get(String name);
36
}
0 37

  
org.gvsig.projection/tags/org.gvsig.projection.api-2.0.17/src/main/java/org/cresques/cts/GeoCalc.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.cts;
25

  
26
import java.awt.geom.Point2D;
27

  
28

  
29
/**
30
 * Operaciones relacionadas con las proyecciones y sistemas
31
 * de coordenadas.
32
 *
33
 * cmartinez: Esta clase no deber?a formar parte de una API, pero
34
 * se deja hasta que se aborde el refactoring de libProjection.
35
 *
36
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
37
 */
38
public class GeoCalc {
39
    IProjection proj;
40

  
41
    /**
42
     *
43
     * @param proj
44
     */
45
    public GeoCalc(IProjection proj) {
46
        this.proj = proj;
47
    }
48

  
49
    /* (non-Javadoc)
50
	 * @see org.cresques.impl.cts.GeoCalc#distanceGeo(java.awt.geom.Point2D, java.awt.geom.Point2D)
51
	 */
52
    public double distanceGeo(Point2D pt1, Point2D pt2) {
53
        double R2 = Math.pow(proj.getDatum().getESemiMajorAxis(), 2);
54
        double dLat = Math.toRadians(pt2.getY() - pt1.getY());
55
        double dLong = Math.toRadians(pt2.getX() - pt1.getX());
56

  
57
        double alfa = Math.toRadians(pt1.getY());
58
        double alfa2 = Math.toRadians(pt2.getY());
59

  
60
        if (Math.abs(alfa2) < Math.abs(alfa)) {
61
            alfa = alfa2;
62
        }
63

  
64
        double ds2 = (R2 * dLat * dLat) +
65
                     (R2 * Math.cos(alfa) * Math.cos(alfa) * dLong * dLong);
66

  
67
        return Math.sqrt(ds2);
68
    }
69

  
70
    /* (non-Javadoc)
71
	 * @see org.cresques.impl.cts.GeoCalc#distanceEli(java.awt.geom.Point2D, java.awt.geom.Point2D)
72
	 */
73
    public double distanceEli(Point2D pt1, Point2D pt2) {
74
        double lat1 = Math.toRadians(pt1.getY());
75
        double lon1 = -Math.toRadians(pt1.getX());
76
        double lat2 = Math.toRadians(pt2.getY());
77
        double lon2 = -Math.toRadians(pt2.getX());
78

  
79
        double F = (lat1 + lat2) / 2D;
80
        double G = (lat1 - lat2) / 2D;
81
        double L = (lon1 - lon2) / 2D;
82

  
83
        double sing = Math.sin(G);
84
        double cosl = Math.cos(L);
85
        double cosf = Math.cos(F);
86
        double sinl = Math.sin(L);
87
        double sinf = Math.sin(F);
88
        double cosg = Math.cos(G);
89

  
90
        double flat = 1D / proj.getDatum().getEIFlattening();
91

  
92
        double S = (sing * sing * cosl * cosl) + (cosf * cosf * sinl * sinl);
93
        double C = (cosg * cosg * cosl * cosl) + (sinf * sinf * sinl * sinl);
94
        double W = Math.atan2(Math.sqrt(S), Math.sqrt(C));
95
        double R = Math.sqrt((S * C)) / W;
96
        double H1 = ((3D * R) - 1D) / (2D * C);
97
        double H2 = ((3D * R) + 1D) / (2D * S);
98
        double D = 2D * W * proj.getDatum().getESemiMajorAxis();
99

  
100
        return (D * ((1D + (flat * H1 * sinf * sinf * cosg * cosg)) -
101
               (flat * H2 * cosf * cosf * sing * sing)));
102
    }
103

  
104
    /**
105
     * Algrothims from Geocentric Datum of Australia Technical Manual
106
     *
107
     * http://www.anzlic.org.au/icsm/gdatum/chapter4.html
108
     *
109
     * This page last updated 11 May 1999
110
     *
111
     * Computations on the Ellipsoid
112
     *
113
     * There are a number of formulae that are available
114
     * to calculate accurate geodetic positions,
115
     * azimuths and distances on the ellipsoid.
116
     *
117
     * Vincenty's formulae (Vincenty, 1975) may be used
118
     * for lines ranging from a few cm to nearly 20,000 km,
119
     * with millimetre accuracy.
120
     * The formulae have been extensively tested
121
     * for the Australian region, by comparison with results
122
     * from other formulae (Rainsford, 1955 & Sodano, 1965).
123
     *
124
     * * Inverse problem: azimuth and distance from known
125
     *                 latitudes and longitudes
126
     * * Direct problem: Latitude and longitude from known
127
     *                 position, azimuth and distance.
128
     * * Sample data
129
     * * Excel spreadsheet
130
     *
131
     * Vincenty's Inverse formulae
132
     * Given: latitude and longitude of two points
133
     *                 (phi1, lembda1 and phi2, lembda2),
134
     * Calculate: the ellipsoidal distance (s) and
135
     * forward and reverse azimuths between the points (alpha12, alpha21).
136
     */
137
    /* (non-Javadoc)
138
	 * @see org.cresques.impl.cts.GeoCalc#distanceVincenty(java.awt.geom.Point2D, java.awt.geom.Point2D)
139
	 */
140
    public double distanceVincenty(Point2D pt1, Point2D pt2) {
141
        return distanceAzimutVincenty(pt1, pt2).dist;
142
    }
143

  
144
    /**
145
     * Returns the distance between two geographic points on the ellipsoid
146
     *        and the forward and reverse azimuths between these points.
147
     *       lats, longs and azimuths are in decimal degrees, distance in metres
148
     *        Returns ( s, alpha12,  alpha21 ) as a tuple
149
     * @param pt1
150
     * @param pt2
151
     * @return
152
     */
153
    protected GeoData distanceAzimutVincenty(Point2D pt1, Point2D pt2) {
154
        GeoData gd = new GeoData(0, 0);
155
        double f = 1D / proj.getDatum().getEIFlattening();
156
        double a = proj.getDatum().getESemiMajorAxis();
157
        double phi1 = pt1.getY();
158
        double lembda1 = pt1.getX();
159
        double phi2 = pt2.getY();
160
        double lembda2 = pt2.getX();
161

  
162
        if ((Math.abs(phi2 - phi1) < 1e-8) &&
163
                (Math.abs(lembda2 - lembda1) < 1e-8)) {
164
            return gd;
165
        }
166

  
167
        double piD4 = Math.atan(1.0);
168
        double two_pi = piD4 * 8.0;
169

  
170
        phi1 = (phi1 * piD4) / 45.0;
171
        lembda1 = (lembda1 * piD4) / 45.0; // unfortunately lambda is a key word!
172
        phi2 = (phi2 * piD4) / 45.0;
173
        lembda2 = (lembda2 * piD4) / 45.0;
174

  
175
        double b = a * (1.0 - f);
176

  
177
        double TanU1 = (1 - f) * Math.tan(phi1);
178
        double TanU2 = (1 - f) * Math.tan(phi2);
179

  
180
        double U1 = Math.atan(TanU1);
181
        double U2 = Math.atan(TanU2);
182

  
183
        double lembda = lembda2 - lembda1;
184
        double last_lembda = -4000000.0; // an impossibe value
185
        double omega = lembda;
186

  
187
        // Iterate the following equations,
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff