root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / CartographicSupportToolkit.java @ 12657
History | View | Annotate | Download (5.26 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.core; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.MapContext; |
44 |
import com.iver.cit.gvsig.fmap.ViewPort; |
45 |
|
46 |
/**
|
47 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
48 |
*/
|
49 |
public class CartographicSupportToolkit { |
50 |
// private static final int CONVERSION_ARRAY_LENGTH = MapContext.CHANGEM.length;
|
51 |
//
|
52 |
// /**
|
53 |
// * <p><b>Computes the screen size (pixels)</b> of a given <b>length</b> according to the current's rendering
|
54 |
// * context defined by an <b>affine transform</b> in the <b>X axis</b>. The value of the length is expressed in the
|
55 |
// * units specified by <b>unitIndex</b>-th element of the <b>MapContext.NAMES</b> array.</p>
|
56 |
// *
|
57 |
// * <p>If the unitIndex is out of the MapContext.NAMES array range, (it is assumed that the
|
58 |
// * distance units are already in pixel) then the input and output length values are
|
59 |
// * equal.</p>
|
60 |
// * @param length, the length to be transformed to screen units
|
61 |
// * @param at, an affine transform with the current rendering context
|
62 |
// * @param unitIndex, the unit in which the length is given
|
63 |
// * @return
|
64 |
// */
|
65 |
// public static double toScreenUnitXAxis(CartographicSupport graphicElement, double length, ViewPort viewPort) {
|
66 |
// final int unitIndex = graphicElement.getUnit();
|
67 |
// if (unitIndex >= CONVERSION_ARRAY_LENGTH || unitIndex < 0) return length;
|
68 |
// return Math.abs(viewPort.getAffineTransform().getScaleX()*
|
69 |
// toViewPortUnits(length, unitIndex, viewPort));
|
70 |
//
|
71 |
// }
|
72 |
//
|
73 |
// /**
|
74 |
// * <p><b>Computes the screen size (pixels)</b> of a given <b>length</b> according to the current's rendering
|
75 |
// * context defined by an <b>affine transform</b> in the <b>Y axis</b>. The value of the length is expressed in the
|
76 |
// * units specified by <b>unitIndex</b>-th element of the <b>MapContext.NAMES</b> array.</p>
|
77 |
// *
|
78 |
// * <p>If the unitIndex is out of the MapContext.NAMES array range, (it is assumed that the
|
79 |
// * distance units are already in pixel) then the input and output length values are
|
80 |
// * equal.</p>
|
81 |
// * @param length, the length to be transformed to screen units
|
82 |
// * @param at, an affine transform with the current rendering context
|
83 |
// * @param unitIndex, the unit in which the length is given
|
84 |
// * @return
|
85 |
// */
|
86 |
// public static double toScreenUnitYAxis(CartographicSupport graphicElement, double length, ViewPort viewPort) {
|
87 |
// final int unitIndex = graphicElement.getUnit();
|
88 |
// if (unitIndex >= CONVERSION_ARRAY_LENGTH || unitIndex < 0) return length;
|
89 |
// return Math.abs(viewPort.getAffineTransform().getScaleY()*
|
90 |
// toViewPortUnits(length, unitIndex, viewPort));
|
91 |
// }
|
92 |
//
|
93 |
// public static double toViewPortUnits(double length, int unit, ViewPort viewPort) {
|
94 |
// int viewPortUnit = viewPort.getMapUnits();
|
95 |
// if (viewPortUnit == unit) return length;
|
96 |
//
|
97 |
// // for speed, only change if length is not in meters
|
98 |
// if (unit != 1) length = length*MapContext.CHANGEM[unit];
|
99 |
//
|
100 |
// // now length is in meters, translate it to viewport's units
|
101 |
// if (viewPortUnit != 1) return length/MapContext.CHANGEM[viewPortUnit];
|
102 |
//
|
103 |
// // viewport's units are meters too, no tranlation needed.
|
104 |
// return length;
|
105 |
// }
|
106 |
//
|
107 |
// public static double toPaperUnits(double length, int unit, int dpi) {
|
108 |
// // inch units used as canonical.
|
109 |
// if (unit != 7) length = length*MapContext.CHANGE[unit];
|
110 |
//
|
111 |
// // length is now in inches
|
112 |
// return length*dpi;
|
113 |
//
|
114 |
// }
|
115 |
|
116 |
public static double getCartographicLength(CartographicSupport cartographicElement, double length, ViewPort viewPort, double dpi) { |
117 |
int unit = cartographicElement.getUnit();
|
118 |
double widthInPixel;
|
119 |
if (unit==-1) { |
120 |
widthInPixel = length; |
121 |
} else {
|
122 |
double dist1PixelMeter = viewPort.getDist1pixel()*MapContext.CHANGEM[viewPort.getMapUnits()];
|
123 |
double realWidthMeter = length*MapContext.CHANGEM[unit];
|
124 |
widthInPixel = realWidthMeter/dist1PixelMeter; |
125 |
if (cartographicElement.getReferenceSystem() == CartographicSupport.PAPER) {
|
126 |
double dpiScale = dpi / MapContext.getScreenDPI();
|
127 |
widthInPixel *= dpiScale; |
128 |
} |
129 |
} |
130 |
|
131 |
|
132 |
return (widthInPixel);
|
133 |
|
134 |
} |
135 |
|
136 |
} |
137 |
|
138 |
|