Revision 84
org.gvsig.projection/trunk/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.cresques.ProjectionLibrary |
org.gvsig.projection/trunk/src/main/java/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 |
org.gvsig.projection/trunk/src/main/java/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 |
} |
|
0 | 86 |
org.gvsig.projection/trunk/src/main/java/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 |
org.gvsig.projection/trunk/src/main/java/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 |
org.gvsig.projection/trunk/src/main/java/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 |
org.gvsig.projection/trunk/src/main/java/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 |
public void doRegistration() { |
|
40 |
registerAsAPI(ProjectionLibrary.class); |
|
41 |
require(ToolsLibrary.class); |
|
42 |
} |
|
43 |
|
|
44 |
protected void doInitialize() throws LibraryException { |
|
45 |
} |
|
46 |
|
|
47 |
protected void doPostInitialize() throws LibraryException { |
|
48 |
if (CRSFactory.cp==null) { |
|
49 |
throw new CRSFactoryNotRegisteredException(); |
|
50 |
} |
|
51 |
|
|
52 |
DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager(); |
|
53 |
dataTypesManager.addtype(DataTypes.CRS, "CRS", "CRS", |
|
54 |
IProjection.class, new CoerceToCRS()); |
|
55 |
dataTypesManager.setCoercion(DataTypes.STRING, new CoerceToString( |
|
56 |
dataTypesManager.getCoercion(DataTypes.STRING))); |
|
57 |
|
|
58 |
// Register the PersistenceFactory to be able to persist |
|
59 |
// IProjection objects |
|
60 |
ToolsLocator.getPersistenceManager().registerFactory( |
|
61 |
new ProjectionPersistenceFactory()); |
|
62 |
ToolsLocator.getPersistenceManager().registerFactory( |
|
63 |
new CoordTransPersistenceFactory()); |
|
64 |
} |
|
65 |
|
|
66 |
} |
|
0 | 67 |
org.gvsig.projection/trunk/src/main/java/org/cresques/Messages.java | ||
---|---|---|
1 |
/* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
|
2 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana. |
|
3 |
* |
|
4 |
* This program is free software; you can redistribute it and/or |
|
5 |
* modify it under the terms of the GNU General Public License |
|
6 |
* as published by the Free Software Foundation; either version 2 |
|
7 |
* of the License, or (at your option) any later version. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
17 |
* |
|
18 |
* For more information, contact: |
|
19 |
* |
|
20 |
* Generalitat Valenciana |
|
21 |
* Conselleria d'Infraestructures i Transport |
|
22 |
* Av. Blasco Ib??ez, 50 |
|
23 |
* 46010 VALENCIA |
|
24 |
* SPAIN |
|
25 |
* |
|
26 |
* +34 963862235 |
|
27 |
* gvsig@gva.es |
|
28 |
* www.gvsig.gva.es |
|
29 |
* |
|
30 |
* or |
|
31 |
* |
|
32 |
* IVER T.I. S.A |
|
33 |
* Salamanca 50 |
|
34 |
* 46005 Valencia |
|
35 |
* Spain |
|
36 |
* |
|
37 |
* +34 963163400 |
|
38 |
* dac@iver.es |
|
39 |
*/ |
|
40 |
|
|
41 |
|
|
42 |
package org.cresques; |
|
43 |
|
|
44 |
import java.util.Locale; |
|
45 |
|
|
46 |
import org.gvsig.tools.ToolsLocator; |
|
47 |
import org.gvsig.tools.i18n.I18nManager; |
|
48 |
|
|
49 |
/** |
|
50 |
* Bridge class to provide internationalization services to the library. |
|
51 |
* It uses the gvsig-i18n library as a backend, and includes its |
|
52 |
* necessary initialization. |
|
53 |
* |
|
54 |
* @author Cesar Martinez Izquierdo |
|
55 |
* |
|
56 |
*/ |
|
57 |
public class Messages { |
|
58 |
private static I18nManager manager = null; |
|
59 |
/** |
|
60 |
* Loads the translations in the dictionary. It initializes the backend |
|
61 |
* gvsig-i18n library |
|
62 |
* |
|
63 |
*/ |
|
64 |
private static void init() { |
|
65 |
I18nManager manager = ToolsLocator.getI18nManager(); |
|
66 |
manager.addResourceFamily("org.cresques.resources.i18n.text", Messages.class.getClassLoader(), Messages.class.getClass().getName()); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Gets the translation associated with the provided translation key. |
|
71 |
* |
|
72 |
* @param key The translation key which identifies the target text |
|
73 |
* @return The translation associated with the provided translation key. |
|
74 |
*/ |
|
75 |
public static String getText(String key) { |
|
76 |
if (manager == null ) { |
|
77 |
init(); |
|
78 |
} |
|
79 |
return manager.getTranslation(key); |
|
80 |
} |
|
81 |
|
|
82 |
} |
|
83 |
|
|
0 | 84 |
org.gvsig.projection/trunk/src/main/java/org/cresques/px/Extent.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.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/trunk/src/main/java/org/cresques/px/.cvsignore | ||
---|---|---|
1 |
*.dfPackage |
|
2 |
*.wmf |
|
0 | 3 |
org.gvsig.projection/trunk/src/main/java/org/cresques/px/package.html | ||
---|---|---|
1 |
<html> |
|
2 |
<body>Pixel: Clases para dibujar. |
|
3 |
</body> |
|
4 |
</html> |
|
0 | 5 |
org.gvsig.projection/trunk/src/main/java/org/cresques/cts/GeoCalc.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.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, |
|
188 |
// until there is no significant change in lembda |
|
189 |
double Sin_sigma = 0; |
|
190 |
|
|
191 |
// Iterate the following equations, |
|
192 |
// until there is no significant change in lembda |
|
193 |
double Cos_sigma = 0; |
|
194 |
double Cos2sigma_m = 0; |
|
195 |
double alpha = 0; |
|
196 |
double sigma = 0; |
|
197 |
double sqr_sin_sigma = 0; |
|
198 |
|
|
199 |
while ((last_lembda < -3000000.0) || |
|
200 |
((lembda != 0) && |
|
201 |
(Math.abs((last_lembda - lembda) / lembda) > 1.0e-9))) { |
|
202 |
sqr_sin_sigma = Math.pow(Math.cos(U2) * Math.sin(lembda), 2) + |
|
203 |
Math.pow(((Math.cos(U1) * Math.sin(U2)) - |
|
204 |
(Math.sin(U1) * Math.cos(U2) * Math.cos(lembda))), |
|
205 |
2); |
|
206 |
|
|
207 |
Sin_sigma = Math.sqrt(sqr_sin_sigma); |
|
208 |
|
|
209 |
Cos_sigma = (Math.sin(U1) * Math.sin(U2)) + |
|
210 |
(Math.cos(U1) * Math.cos(U2) * Math.cos(lembda)); |
|
211 |
|
|
212 |
sigma = Math.atan2(Sin_sigma, Cos_sigma); |
|
213 |
|
|
214 |
double Sin_alpha = (Math.cos(U1) * Math.cos(U2) * Math.sin(lembda)) / Math.sin(sigma); |
|
215 |
alpha = Math.asin(Sin_alpha); |
|
216 |
|
|
217 |
Cos2sigma_m = Math.cos(sigma) - |
|
218 |
((2 * Math.sin(U1) * Math.sin(U2)) / Math.pow(Math.cos(alpha), |
|
219 |
2)); |
|
220 |
|
|
221 |
double C = (f / 16) * Math.pow(Math.cos(alpha), 2) * (4 + |
|
222 |
(f * (4 - (3 * Math.pow(Math.cos(alpha), 2))))); |
|
223 |
|
|
224 |
last_lembda = lembda; |
|
225 |
|
|
226 |
lembda = omega + |
|
227 |
((1 - C) * f * Math.sin(alpha) * (sigma + |
|
228 |
(C * Math.sin(sigma) * (Cos2sigma_m + |
|
229 |
(C * Math.cos(sigma) * (-1 + |
|
230 |
(2 * Math.pow(Cos2sigma_m, 2)))))))); |
|
231 |
} |
|
232 |
|
|
233 |
double u2 = (Math.pow(Math.cos(alpha), 2) * ((a * a) - (b * b))) / (b * b); |
|
234 |
|
|
235 |
double A = 1 + |
|
236 |
((u2 / 16384) * (4096 + |
|
237 |
(u2 * (-768 + (u2 * (320 - (175 * u2))))))); |
|
238 |
|
|
239 |
double B = (u2 / 1024) * (256 + |
|
240 |
(u2 * (-128 + (u2 * (74 - (47 * u2)))))); |
|
241 |
|
|
242 |
double delta_sigma = B * Sin_sigma * (Cos2sigma_m + |
|
243 |
((B / 4) * ((Cos_sigma * (-1 + |
|
244 |
(2 * Math.pow(Cos2sigma_m, 2)))) - |
|
245 |
((B / 6) * Cos2sigma_m * (-3 + |
|
246 |
(4 * sqr_sin_sigma)) * (-3 + |
|
247 |
(4 * Math.pow(Cos2sigma_m, 2))))))); |
|
248 |
|
|
249 |
double s = b * A * (sigma - delta_sigma); |
|
250 |
|
|
251 |
double alpha12 = Math.atan2((Math.cos(U2) * Math.sin(lembda)), |
|
252 |
((Math.cos(U1) * Math.sin(U2)) - |
|
253 |
(Math.sin(U1) * Math.cos(U2) * Math.cos(lembda)))); |
|
254 |
|
|
255 |
double alpha21 = Math.atan2((Math.cos(U1) * Math.sin(lembda)), |
|
256 |
((-Math.sin(U1) * Math.cos(U2)) + |
|
257 |
(Math.cos(U1) * Math.sin(U2) * Math.cos(lembda)))); |
|
258 |
|
|
259 |
if (alpha12 < 0.0) { |
|
260 |
alpha12 = alpha12 + two_pi; |
|
261 |
} |
|
262 |
|
|
263 |
if (alpha12 > two_pi) { |
|
264 |
alpha12 = alpha12 - two_pi; |
|
265 |
} |
|
266 |
|
|
267 |
alpha21 = alpha21 + (two_pi / 2.0); |
|
268 |
|
|
269 |
if (alpha21 < 0.0) { |
|
270 |
alpha21 = alpha21 + two_pi; |
|
271 |
} |
|
272 |
|
|
273 |
if (alpha21 > two_pi) { |
|
274 |
alpha21 = alpha21 - two_pi; |
|
275 |
} |
|
276 |
|
|
277 |
alpha12 = (alpha12 * 45.0) / piD4; |
|
278 |
alpha21 = (alpha21 * 45.0) / piD4; |
|
279 |
|
|
280 |
return new GeoData(0, 0, s, alpha12, alpha21); |
|
281 |
} |
|
282 |
|
|
283 |
/** |
|
284 |
* Vincenty's Direct formulae |
|
285 |
* Given: latitude and longitude of a point (phi1, lembda1) and |
|
286 |
* the geodetic azimuth (alpha12) |
|
287 |
* and ellipsoidal distance in metres (s) to a second point, |
|
288 |
* |
|
289 |
* Calculate: the latitude and longitude of the second point (phi2, lembda2) |
|
290 |
* and the reverse azimuth (alpha21). |
|
291 |
*/ |
|
292 |
/** |
|
293 |
* Returns the lat and long of projected point and reverse azimuth |
|
294 |
* given a reference point and a distance and azimuth to project. |
|
295 |
* lats, longs and azimuths are passed in decimal degrees. |
|
296 |
* Returns ( phi2, lambda2, alpha21 ) as a tuple |
|
297 |
* @param pt |
|
298 |
* @param azimut |
|
299 |
* @param dist |
|
300 |
* @return |
|
301 |
*/ |
|
302 |
protected GeoData getPointVincenty(Point2D pt, double azimut, double dist) { |
|
303 |
GeoData ret = new GeoData(0, 0); |
|
304 |
double f = 1D / proj.getDatum().getEIFlattening(); |
|
305 |
double a = proj.getDatum().getESemiMajorAxis(); |
|
306 |
double phi1 = pt.getY(); |
|
307 |
double lembda1 = pt.getX(); |
|
308 |
double alpha12 = azimut; |
|
309 |
double s = dist; |
|
310 |
|
|
311 |
double piD4 = Math.atan(1.0); |
|
312 |
double two_pi = piD4 * 8.0; |
|
313 |
|
|
314 |
phi1 = (phi1 * piD4) / 45.0; |
|
315 |
lembda1 = (lembda1 * piD4) / 45.0; |
|
316 |
alpha12 = (alpha12 * piD4) / 45.0; |
|
317 |
|
|
318 |
if (alpha12 < 0.0) { |
|
319 |
alpha12 = alpha12 + two_pi; |
|
320 |
} |
|
321 |
|
|
322 |
if (alpha12 > two_pi) { |
|
323 |
alpha12 = alpha12 - two_pi; |
|
324 |
} |
|
325 |
|
|
326 |
double b = a * (1.0 - f); |
|
327 |
|
|
328 |
double TanU1 = (1 - f) * Math.tan(phi1); |
|
329 |
double U1 = Math.atan(TanU1); |
|
330 |
double sigma1 = Math.atan2(TanU1, Math.cos(alpha12)); |
|
331 |
double Sinalpha = Math.cos(U1) * Math.sin(alpha12); |
|
332 |
double cosalpha_sq = 1.0 - (Sinalpha * Sinalpha); |
|
333 |
|
|
334 |
double u2 = (cosalpha_sq * ((a * a) - (b * b))) / (b * b); |
|
335 |
double A = 1.0 + |
|
336 |
((u2 / 16384) * (4096 + |
|
337 |
(u2 * (-768 + (u2 * (320 - (175 * u2))))))); |
|
338 |
double B = (u2 / 1024) * (256 + |
|
339 |
(u2 * (-128 + (u2 * (74 - (47 * u2)))))); |
|
340 |
|
|
341 |
// Starting with the approximation |
|
342 |
double sigma = (s / (b * A)); |
|
343 |
|
|
344 |
double last_sigma = (2.0 * sigma) + 2.0; // something impossible |
|
345 |
|
|
346 |
// Iterate the following three equations |
|
347 |
// until there is no significant change in sigma |
|
348 |
// two_sigma_m , delta_sigma |
|
349 |
double two_sigma_m = 0; |
|
350 |
|
|
351 |
while (Math.abs((last_sigma - sigma) / sigma) > 1.0e-9) { |
|
352 |
two_sigma_m = (2 * sigma1) + sigma; |
|
353 |
|
|
354 |
double delta_sigma = B * Math.sin(sigma) * (Math.cos(two_sigma_m) + |
|
355 |
((B / 4) * (Math.cos(sigma) * ((-1 + |
|
356 |
(2 * Math.pow(Math.cos(two_sigma_m), 2))) - |
|
357 |
((B / 6) * Math.cos(two_sigma_m) * (-3 + |
|
358 |
(4 * Math.pow(Math.sin(sigma), 2))) * (-3 + |
|
359 |
(4 * Math.pow(Math.cos(two_sigma_m), 2)))))))); |
|
360 |
|
|
361 |
last_sigma = sigma; |
|
362 |
sigma = (s / (b * A)) + delta_sigma; |
|
363 |
} |
|
364 |
|
|
365 |
double phi2 = Math.atan2(((Math.sin(U1) * Math.cos(sigma)) + |
|
366 |
(Math.cos(U1) * Math.sin(sigma) * Math.cos(alpha12))), |
|
367 |
((1 - f) * Math.sqrt(Math.pow(Sinalpha, 2) + |
|
368 |
Math.pow((Math.sin(U1) * Math.sin(sigma)) - |
|
369 |
(Math.cos(U1) * Math.cos(sigma) * Math.cos(alpha12)), |
|
370 |
2)))); |
|
371 |
|
|
372 |
double lembda = Math.atan2((Math.sin(sigma) * Math.sin(alpha12)), |
|
373 |
((Math.cos(U1) * Math.cos(sigma)) - |
|
374 |
(Math.sin(U1) * Math.sin(sigma) * Math.cos(alpha12)))); |
|
375 |
|
|
376 |
double C = (f / 16) * cosalpha_sq * (4 + (f * (4 - (3 * cosalpha_sq)))); |
|
377 |
|
|
378 |
double omega = lembda - |
|
379 |
((1 - C) * f * Sinalpha * (sigma + |
|
380 |
(C * Math.sin(sigma) * (Math.cos(two_sigma_m) + |
|
381 |
(C * Math.cos(sigma) * (-1 + |
|
382 |
(2 * Math.pow(Math.cos(two_sigma_m), 2)))))))); |
|
383 |
|
|
384 |
double lembda2 = lembda1 + omega; |
|
385 |
|
|
386 |
double alpha21 = Math.atan2(Sinalpha, |
|
387 |
((-Math.sin(U1) * Math.sin(sigma)) + |
|
388 |
(Math.cos(U1) * Math.cos(sigma) * Math.cos(alpha12)))); |
|
389 |
|
|
390 |
alpha21 = alpha21 + (two_pi / 2.0); |
|
391 |
|
|
392 |
if (alpha21 < 0.0) { |
|
393 |
alpha21 = alpha21 + two_pi; |
|
394 |
} |
|
395 |
|
|
396 |
if (alpha21 > two_pi) { |
|
397 |
alpha21 = alpha21 - two_pi; |
|
398 |
} |
|
399 |
|
|
400 |
phi2 = (phi2 * 45.0) / piD4; |
|
401 |
lembda2 = (lembda2 * 45.0) / piD4; |
|
402 |
alpha21 = (alpha21 * 45.0) / piD4; |
|
403 |
|
|
404 |
ret.pt = new Point2D.Double(lembda2, phi2); |
|
405 |
ret.azimut = alpha21; |
|
406 |
|
|
407 |
return ret; |
|
408 |
} |
|
409 |
|
|
410 |
/* (non-Javadoc) |
|
411 |
* @see org.cresques.impl.cts.GeoCalc#surfaceSphere(java.awt.geom.Point2D, java.awt.geom.Point2D, java.awt.geom.Point2D) |
|
412 |
*/ |
|
413 |
public double surfaceSphere(Point2D pt1, Point2D pt2, Point2D pt3) { |
|
414 |
double sup = -1; |
|
415 |
double A = distanceGeo(pt1, pt2); |
|
416 |
double B = distanceGeo(pt2, pt3); |
|
417 |
double C = distanceGeo(pt3, pt1); |
|
418 |
sup = (((A + B + C) - Math.toRadians(180D)) * Math.PI * proj.getDatum() |
|
419 |
.getESemiMajorAxis()) / Math.toRadians(180D); |
|
420 |
|
|
421 |
return sup; |
|
422 |
} |
|
423 |
|
|
424 |
/* |
|
425 |
* F?rmulas de Vincenty's. |
|
426 |
* (pasadas de http://wegener.mechanik.tu-darmstadt.de/GMT-Help/Archiv/att-8710/Geodetic_py |
|
427 |
* http://www.icsm.gov.au/icsm/gda/gdatm/index.html |
|
428 |
*/ |
|
429 |
protected class GeoData { |
|
430 |
Point2D pt; |
|
431 |
double azimut; |
|
432 |
double revAzimut; |
|
433 |
double dist; |
|
434 |
|
|
435 |
public GeoData(double x, double y) { |
|
436 |
pt = new Point2D.Double(x, y); |
|
437 |
azimut = revAzimut = dist = 0; |
|
438 |
} |
|
439 |
|
|
440 |
public GeoData(double x, double y, double dist, double azi, double rAzi) { |
|
441 |
pt = new Point2D.Double(x, y); |
|
442 |
azimut = azi; |
|
443 |
revAzimut = rAzi; |
|
444 |
this.dist = dist; |
|
445 |
} |
|
446 |
} |
|
447 |
} |
|
0 | 448 |
org.gvsig.projection/trunk/src/main/java/org/cresques/cts/cts.dfPackage | ||
---|---|---|
1 |
package id3efajdxljqzpfdxljrqze; |
|
2 |
|
|
3 |
/** |
|
4 |
@version 2.0 |
|
5 |
@physicalPackage |
|
6 |
@__modelType diagram |
|
7 |
*/ |
|
8 |
class diagram { |
|
9 |
/** |
|
10 |
@__ref <oiref:java#Class#org.cresques.cts.IProjection:oiref><oihard> |
|
11 |
@__modelType reference |
|
12 |
*/ |
|
13 |
class reference { |
|
14 |
}/** |
|
15 |
@__ref <oiref:design#Class#id453jodxljqzpfdxljry0t.diagram:oiref><oihard> |
|
16 |
@__modelType reference |
|
17 |
@__fqn <oiref:#Package#cms.org.cresques.cts.gt2:oiref> |
|
18 |
*/ |
|
19 |
class reference8 { |
|
20 |
}/** |
|
21 |
@__ref <oiref:java#Class#org.cresques.cts.ProjectionPool:oiref><oihard> |
|
22 |
@__modelType reference |
|
23 |
*/ |
|
24 |
class reference1 { |
|
25 |
}/** |
|
26 |
@__ref <oiref:java#Class#org.cresques.cts.ICoordTrans:oiref><oihard> |
|
27 |
@__modelType reference |
|
28 |
*/ |
|
29 |
class reference2 { |
|
30 |
}/** |
|
31 |
@__ref <oiref:java#Class#org.cresques.cts.IDatum:oiref><oihard> |
|
32 |
@__modelType reference |
|
33 |
*/ |
|
34 |
class reference3 { |
|
35 |
}}/** |
|
36 |
@__tags |
|
37 |
@shapeType ClassDiagram |
|
38 |
*/ |
|
39 |
class __tags { |
|
40 |
}/** |
|
41 |
@__options |
|
42 |
*/ |
|
43 |
class __options { |
|
44 |
}/** |
|
45 |
@__positions <oigroup:<oiref:java#Class#org.cresques.cts.ICoordTrans:oiref>=10,270,148,165,1:oigroup> |
|
46 |
<oigroup:<oiref:java#Class#org.cresques.cts.ProjectionPool:oiref>=176,10,138,126,1:oigroup> |
|
47 |
<oigroup:<oiref:java#Class#org.cresques.cts.IProjection:oiref>=10,10,146,229,1:oigroup> |
|
48 |
<oigroup:<oiref:java#Class#org.cresques.cts.IDatum:oiref>=178,170,83,98,1:oigroup> |
|
49 |
<oigroup:<oiref:design#Class#id453jodxljqzpfdxljry0t.diagram:oiref>=334,10,102,184,1:oigroup> |
|
50 |
*/ |
|
51 |
class __positions { |
|
52 |
} |
org.gvsig.projection/trunk/src/main/java/org/cresques/cts/package.html | ||
---|---|---|
1 |
<html> |
|
2 |
<body>Clases relacionadas con el manejo de proyecciones. |
|
3 |
</body> |
|
4 |
</html> |
|
0 | 5 |
org.gvsig.projection/trunk/src/main/java/org/cresques/cts/IDatum.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.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/trunk/src/main/java/org/cresques/cts/IProjection.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.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 |
public double getScale(double minX, double maxX, double width, double dpi); |
|
78 |
public Rectangle2D getExtent(Rectangle2D extent,double scale,double wImage,double hImage,double mapUnits,double distanceUnits,double dpi); |
|
79 |
} |
|
0 | 80 |
org.gvsig.projection/trunk/src/main/java/org/cresques/cts/UTM.java | ||
---|---|---|
1 |
package org.cresques.cts; |
|
2 |
|
|
3 |
public interface UTM extends IProjection { |
|
4 |
|
|
5 |
} |
|
0 | 6 |
Also available in: Unified diff