Revision 151

View differences:

org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/MANIFEST.MF
1
Manifest-Version: 1.0
2
Ant-Version: Apache Ant 1.7.1
3
Created-By: 16.0-b13 (Sun Microsystems Inc.)
4
Implementation-Version: 0.7
5
Built-Date: 2012-10-04 11:28:17
6

  
0 7

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.toolbox.core.ToolboxCoreLibrary
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/resources/org/gvsig/toolbox/core/i18n/text.properties
1
[New_model]=[Nuevo modelo]
2

  
3
chart=gr\u00e1fico
4

  
5
raster=raster
6

  
7
text=texto
8

  
9
table=tabla
10

  
11
vector=vectorial
12

  
13
Java_code=C\u00f3digo Java
14

  
15
Toolbox=Caja de herramientas
16

  
17
Toolbox_models=Modelos
0 18

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/resources/org/gvsig/toolbox/core/i18n/text_en.properties
1
[New_model]=[New model]
2

  
3
chart=chart
4

  
5
raster=raster
6

  
7
text=text
8

  
9
table=table
10

  
11
vector=vector
12

  
13
Java_code=Java code
14

  
15
Toolbox=Toolbox
16

  
17
Toolbox_models=Models
0 18

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/resources/org/gvsig/toolbox/core/i18n/text_fr.properties
1
#Modified by DOKSoft PropEditor. http://www.doksoft.com
2
#Fri Feb 18 11:30:32 CET 2011
3
vector=Vectoriel
4
raster=Couche matricielle
5
[New_model]=[Nouveau mod\u00e8le]
6
chart=graphique
7
table=table
8
text=texte
9
Toolbox=Bo\u00eete \u00e0 outils
10
Toolbox_models=Mod\u00e8les
0 11

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/jaitools/tilecache/package.html
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
<html>
3
  <head>
4
    <title>jaitools.tilecache</title>
5
  </head>
6
  <body>
7
  An implementation of TileCache which can use disk caching to supplement
8
  memory, allowing large volumes of image data to be handled
9
  </body>
10
</html>
0 11

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/jaitools/tiledimage/package.html
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
<html>
3
  <head>
4
    <title>jaitools.tiledimage</title>
5
    <meta http-equiv="Content-Type" content="text/html; charset=MacRoman">
6
  </head>
7
  <body>
8
  A writable tiled image class similar to JAI's TiledImage but backed
9
  by disk as well as memory storage to handle very large images within
10
  limited memory.
11
  </body>
12
</html>
0 13

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/jaitools/package.html
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
<html>
3
  <head>
4
    <title>jaitools</title>
5
  </head>
6
  <body>
7
    The JAITools and CollectionFactory helper classes
8
  </body>
9
</html>
0 10

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/WrongAnalysisExtentException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class WrongAnalysisExtentException
4
         extends
5
            GeoAlgorithmExecutionException {
6

  
7
   public WrongAnalysisExtentException(final String s) {
8

  
9
      super(s);
10

  
11
   }
12

  
13

  
14
   public WrongAnalysisExtentException() {
15

  
16
      super("Wrong raster extension exception");
17

  
18
   }
19

  
20
}
0 21

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/IteratorException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class IteratorException
4
         extends
5
            GeoAlgorithmExecutionException {
6

  
7
   public IteratorException() {
8

  
9
      super("Iterator exception");
10

  
11
   }
12

  
13

  
14
   public IteratorException(final String s) {
15

  
16
      super(s);
17

  
18
   }
19

  
20
}
0 21

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/WrongOutputIDException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class WrongOutputIDException
4
         extends
5
            GeoAlgorithmExecutionException {
6

  
7
   public WrongOutputIDException() {
8

  
9
      super("Wrong uoutput ID exception");
10

  
11
   }
12

  
13
}
0 14

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/WrongParameterValueException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class WrongParameterValueException
4
         extends
5
            GeoAlgorithmExecutionException {
6

  
7
   public WrongParameterValueException() {
8

  
9
      super("Wrong parameter value exception");
10

  
11
   }
12

  
13
}
0 14

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/RepeatedParameterNameException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class RepeatedParameterNameException
4
         extends
5
            Exception {
6

  
7
   public RepeatedParameterNameException() {}
8

  
9
}
0 10

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/WrongSerializedStringParameterValueException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class WrongSerializedStringParameterValueException
4
         extends
5
            Exception {
6

  
7
}
0 8

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/WrongParameterTypeException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class WrongParameterTypeException
4
         extends
5
            GeoAlgorithmExecutionException {
6

  
7
   public WrongParameterTypeException() {
8

  
9
      super("Wrong parameter type execption");
10

  
11
   }
12

  
13
}
0 14

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/OptionalParentParameterException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class OptionalParentParameterException
4
         extends
5
            Exception {
6

  
7
   public OptionalParentParameterException() {}
8

  
9
}
0 10

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/WrongOutputChannelDataException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class WrongOutputChannelDataException
4
         extends
5
            Exception {
6

  
7
}
0 8

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/UnsupportedOutputChannelException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class UnsupportedOutputChannelException
4
         extends
5
            GeoAlgorithmExecutionException {
6

  
7
   public UnsupportedOutputChannelException() {
8

  
9
      super("Unsupported output channel");
10

  
11
   }
12

  
13
}
0 14

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/GeoAlgorithmExecutionException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class GeoAlgorithmExecutionException
4
         extends
5
            Exception {
6

  
7
   public GeoAlgorithmExecutionException(final String s) {
8

  
9
      super(s);
10

  
11
   }
12

  
13
}
0 14

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/NullParameterValueException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class NullParameterValueException
4
         extends
5
            GeoAlgorithmExecutionException {
6

  
7
   public NullParameterValueException() {
8

  
9
      super("Null parameter value exception");
10

  
11
   }
12
}
0 13

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/WrongParameterIDException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class WrongParameterIDException
4
         extends
5
            GeoAlgorithmExecutionException {
6

  
7
   public WrongParameterIDException() {
8

  
9
      super("Wrong parameter ID exception");
10

  
11
   }
12

  
13
}
0 14

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/WrongInputException.java
1
package es.unex.sextante.exceptions;
2

  
3
import es.unex.sextante.core.Sextante;
4

  
5
public class WrongInputException
6
         extends
7
            Exception {
8

  
9
   public WrongInputException() {
10

  
11
      super(Sextante.getText("Wrong_or_missing_parameters_definition"));
12

  
13
   }
14

  
15

  
16
   public WrongInputException(final String s) {
17

  
18
      super(s);
19

  
20
   }
21

  
22
}
0 23

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/UndefinedParentParameterNameException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class UndefinedParentParameterNameException
4
         extends
5
            Exception {
6

  
7
   public UndefinedParentParameterNameException() {}
8

  
9
}
0 10

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/exceptions/NullParameterAdditionalInfoException.java
1
package es.unex.sextante.exceptions;
2

  
3
public class NullParameterAdditionalInfoException
4
         extends
5
            GeoAlgorithmExecutionException {
6

  
7
   public NullParameterAdditionalInfoException() {
8

  
9
      super("Null parameter additional info exception");
10

  
11
   }
12
}
0 13

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/dataObjects/AbstractRasterLayer.java
1

  
2

  
3
package es.unex.sextante.dataObjects;
4

  
5
import java.util.Arrays;
6

  
7
import es.unex.sextante.core.AnalysisExtent;
8
import es.unex.sextante.rasterWrappers.GridWrapper;
9
import es.unex.sextante.rasterWrappers.GridWrapperInterpolated;
10
import es.unex.sextante.rasterWrappers.GridWrapperNotInterpolated;
11

  
12

  
13
/**
14
 * A convenience class which implements some of the methods of the IRasterLayer interface. Extending this class is recommended
15
 * instead of implementing the interface directly
16
 * 
17
 * @author volaya
18
 * 
19
 */
20
public abstract class AbstractRasterLayer
21
         implements
22
            IRasterLayer {
23

  
24
   private final static int    m_iOffsetX[]            = { 0, 1, 1, 1, 0, -1, -1, -1 };
25
   private final static int    m_iOffsetY[]            = { 1, 1, 0, -1, -1, -1, 0, 1 };
26

  
27
   private final static double DEG_90_IN_RAD           = Math.PI / 180. * 90.;
28
   private final static double DEG_180_IN_RAD          = Math.PI;
29
   private final static double DEG_270_IN_RAD          = Math.PI / 180. * 270.;
30

  
31
   private GridWrapper         m_GridWrapper;
32

  
33
   private double              m_dDist[];
34

  
35
   private double              _2DX;
36

  
37
   private int[][]             m_Histogram;
38
   private double[]            m_dMax;
39
   private double[]            m_dMin;
40
   private double[]            m_dMean;
41
   private double[]            m_dVariance;
42
   private boolean             m_bStatisticsCalculated = false;
43
   private boolean             m_bHistogramCalculated  = false;
44

  
45

  
46
   public void setInterpolationMethod(final int iMethod) {
47

  
48
      m_GridWrapper.setInterpolationMethod(iMethod);
49

  
50
   }
51

  
52

  
53
   public byte getCellValueAsByte(final int x,
54
                                  final int y) {
55

  
56
      return m_GridWrapper.getCellValueAsByte(x, y);
57

  
58
   }
59

  
60

  
61
   public byte getCellValueAsByte(final int x,
62
                                  final int y,
63
                                  final int band) {
64

  
65
      return m_GridWrapper.getCellValueAsByte(x, y, band);
66

  
67
   }
68

  
69

  
70
   public short getCellValueAsShort(final int x,
71
                                    final int y) {
72

  
73
      return m_GridWrapper.getCellValueAsShort(x, y);
74

  
75
   }
76

  
77

  
78
   public short getCellValueAsShort(final int x,
79
                                    final int y,
80
                                    final int band) {
81

  
82
      return m_GridWrapper.getCellValueAsShort(x, y, band);
83

  
84
   }
85

  
86

  
87
   public int getCellValueAsInt(final int x,
88
                                final int y) {
89

  
90
      return m_GridWrapper.getCellValueAsInt(x, y);
91

  
92
   }
93

  
94

  
95
   public int getCellValueAsInt(final int x,
96
                                final int y,
97
                                final int band) {
98

  
99
      return m_GridWrapper.getCellValueAsInt(x, y, band);
100

  
101
   }
102

  
103

  
104
   public float getCellValueAsFloat(final int x,
105
                                    final int y) {
106

  
107
      return m_GridWrapper.getCellValueAsFloat(x, y);
108

  
109
   }
110

  
111

  
112
   public float getCellValueAsFloat(final int x,
113
                                    final int y,
114
                                    final int band) {
115

  
116
      return m_GridWrapper.getCellValueAsFloat(x, y, band);
117

  
118
   }
119

  
120

  
121
   public double getCellValueAsDouble(final int x,
122
                                      final int y) {
123

  
124
      return m_GridWrapper.getCellValueAsDouble(x, y);
125

  
126
   }
127

  
128

  
129
   public double getCellValueAsDouble(final int x,
130
                                      final int y,
131
                                      final int band) {
132

  
133
      return m_GridWrapper.getCellValueAsDouble(x, y, band);
134

  
135
   }
136

  
137

  
138
   public double getValueAt(final double x,
139
                            final double y) {
140

  
141
      return m_GridWrapper.getValueAt(x, y, 0);
142

  
143
   }
144

  
145

  
146
   public double getValueAt(final double x,
147
                            final double y,
148
                            final int band) {
149

  
150
      return m_GridWrapper.getValueAt(x, y, band);
151

  
152
   }
153

  
154

  
155
   public boolean isNoDataValue(final double dValue) {
156

  
157
      return dValue == getNoDataValue();
158

  
159
   }
160

  
161

  
162
   public boolean isInWindow(final int x,
163
                             final int y) {
164

  
165
      if ((x < 0) || (y < 0)) {
166
         return false;
167
      }
168

  
169
      if ((x >= m_GridWrapper.getNX()) || (y >= m_GridWrapper.getNY())) {
170
         return false;
171
      }
172

  
173
      return true;
174

  
175
   }
176

  
177

  
178
   public int getNX() {
179

  
180
      return m_GridWrapper.getNX();
181

  
182
   }
183

  
184

  
185
   public int getNY() {
186

  
187
      return m_GridWrapper.getNY();
188

  
189
   }
190

  
191

  
192
   public double getWindowCellSize() {
193

  
194
      return m_GridWrapper.getCellSize();
195

  
196
   }
197

  
198

  
199
   public AnalysisExtent getWindowGridExtent() {
200

  
201
      return m_GridWrapper.getGridExtent();
202

  
203
   }
204

  
205

  
206
   public void assign(final double dValue) {
207

  
208
      int iBand;
209
      int x, y;
210

  
211
      for (iBand = 0; iBand < this.getBandsCount(); iBand++) {
212
         for (y = 0; y < getNY(); y++) {
213
            for (x = 0; x < getNX(); x++) {
214
               setCellValue(x, y, iBand, dValue);
215
            }
216
         }
217
      }
218

  
219
   }
220

  
221

  
222
   public void assign(final IRasterLayer layer) {
223

  
224
      double dValue;
225

  
226
      layer.setWindowExtent(getWindowGridExtent());
227

  
228
      final int iNX = layer.getNX();
229
      final int iNY = layer.getNY();
230

  
231
      for (int y = 0; y < iNY; y++) {
232
         for (int x = 0; x < iNX; x++) {
233
            dValue = layer.getCellValueAsDouble(x, y);
234
            setCellValue(x, y, dValue);
235
         }
236
      }
237

  
238
      setNoDataValue(layer.getNoDataValue());
239

  
240
   }
241

  
242

  
243
   public void add(final IRasterLayer driver) {
244

  
245
      double dValue;
246

  
247
      if (driver.getWindowGridExtent().equals(getWindowGridExtent())) {
248
         for (int y = 0; y < getWindowGridExtent().getNY(); y++) {
249
            for (int x = 0; x < getWindowGridExtent().getNX(); x++) {
250
               dValue = driver.getCellValueAsDouble(x, y) + getCellValueAsDouble(x, y);
251
               setCellValue(x, y, dValue);
252
            }
253
         }
254
         setNoDataValue(driver.getNoDataValue());
255
      }
256

  
257
   }
258

  
259

  
260
   public void assignNoData() {
261

  
262
      assign(getNoDataValue());
263

  
264
   }
265

  
266

  
267
   public void setCellValue(final int x,
268
                            final int y,
269
                            final double dValue) {
270

  
271
      setCellValue(x, y, 0, dValue);
272

  
273
   }
274

  
275

  
276
   public void setNoData(final int x,
277
                         final int y) {
278

  
279
      setCellValue(x, y, getNoDataValue());
280

  
281
   }
282

  
283

  
284
   public void setNoData(final int x,
285
                         final int y,
286
                         final int iBand) {
287

  
288
      setCellValue(x, y, iBand, getNoDataValue());
289

  
290
   }
291

  
292

  
293
   public void addToCellValue(final int x,
294
                              final int y,
295
                              final int iBand,
296
                              final double dValue) {
297

  
298
      double dCellValue = getCellValueAsDouble(x, y, iBand);
299

  
300
      if (!isNoDataValue(dCellValue)) {
301
         dCellValue += dValue;
302
         setCellValue(x, y, iBand, dCellValue);
303
      }
304

  
305
   }
306

  
307

  
308
   public void addToCellValue(final int x,
309
                              final int y,
310
                              final double dValue) {
311

  
312
      addToCellValue(x, y, 0, dValue);
313

  
314
   }
315

  
316

  
317
   public void multiply(final double dValue) {
318

  
319
      int iBand;
320
      int x, y;
321

  
322
      for (iBand = 0; iBand < this.getBandsCount(); iBand++) {
323
         for (y = 0; y < getNY(); y++) {
324
            for (x = 0; x < getNX(); x++) {
325
               final double dVal = getCellValueAsDouble(x, y, iBand);
326
               setCellValue(x, y, iBand, dValue * dVal);
327
            }
328
         }
329
      }
330

  
331
   }
332

  
333

  
334
   public void setWindowExtent(final IRasterLayer layer) {
335

  
336
      final AnalysisExtent layerExtent = new AnalysisExtent(layer);
337

  
338
      setWindowExtent(layerExtent);
339

  
340
   }
341

  
342

  
343
   public void setWindowExtent(final AnalysisExtent extent) {
344

  
345

  
346
      if (extent.fitsIn(this.getLayerGridExtent())) {
347
         m_GridWrapper = new GridWrapperNotInterpolated(this, extent);
348
      }
349
      else {
350
         m_GridWrapper = new GridWrapperInterpolated(this, extent);
351
      }
352

  
353
      setConstants();
354

  
355
      m_bHistogramCalculated = false;
356
      m_bStatisticsCalculated = false;
357

  
358
   }
359

  
360

  
361
   public void setFullExtent() {
362

  
363
      m_GridWrapper = new GridWrapperNotInterpolated(this, getLayerGridExtent());
364

  
365
      setConstants();
366

  
367
      m_bHistogramCalculated = false;
368
      m_bStatisticsCalculated = false;
369

  
370
   }
371

  
372

  
373
   ///////////////////////////////////Statistical stuff//////////////////////
374

  
375
   protected void setConstants() {
376

  
377
      int i;
378
      final double dCellSize = getWindowCellSize();
379

  
380
      m_dDist = new double[8];
381

  
382
      for (i = 0; i < 8; i++) {
383
         m_dDist[i] = Math.sqrt(m_iOffsetX[i] * dCellSize * m_iOffsetX[i] * dCellSize + m_iOffsetY[i] * dCellSize * m_iOffsetY[i]
384
                                * dCellSize);
385
      }
386

  
387
      _2DX = dCellSize * 2;
388

  
389
   }
390

  
391

  
392
   protected void calculateStatistics() {
393

  
394

  
395
      int x, y;
396
      double z;
397
      int iValues;
398

  
399
      final int iBands = getBandsCount();
400

  
401
      m_dMean = new double[iBands];
402
      m_dVariance = new double[iBands];
403
      m_dMin = new double[iBands];
404
      m_dMax = new double[iBands];
405

  
406
      for (int i = 0; i < this.getBandsCount(); i++) {
407
         m_dMean[i] = 0.0;
408
         m_dVariance[i] = 0.0;
409
      }
410

  
411
      if (m_GridWrapper == null) {
412
         this.setFullExtent();
413
      }
414

  
415
      for (int i = 0; i < this.getBandsCount(); i++) {
416
         iValues = 0;
417
         for (y = 0; y < getNY(); y++) {
418
            for (x = 0; x < getNX(); x++) {
419
               z = getCellValueAsDouble(x, y, i);
420
               if (!isNoDataValue(z)) {
421
                  if (iValues == 0) {
422
                     m_dMin[i] = m_dMax[i] = z;
423
                  }
424
                  else if (m_dMin[i] > z) {
425
                     m_dMin[i] = z;
426
                  }
427
                  else if (m_dMax[i] < z) {
428
                     m_dMax[i] = z;
429
                  }
430

  
431
                  m_dMean[i] += z;
432
                  m_dVariance[i] += z * z;
433
                  iValues++;
434
               }
435
            }
436
         }
437

  
438
         if (iValues > 0) {
439
            m_dMean[i] /= iValues;
440
            m_dVariance[i] = m_dVariance[i] / iValues - m_dMean[i] * m_dMean[i];
441
         }
442
      }
443

  
444
      m_bStatisticsCalculated = true;
445

  
446
   }
447

  
448

  
449
   protected void calculateHistogram() {
450

  
451
      int x, y;
452
      int iClass;
453
      double dValue;
454
      double dRange;
455

  
456
      if (!m_bStatisticsCalculated) {
457
         calculateStatistics();
458
      }
459

  
460
      final int iBands = getBandsCount();
461

  
462
      m_Histogram = new int[iBands][256];
463

  
464
      for (int i = 0; i < m_Histogram.length; i++) {
465
         Arrays.fill(m_Histogram[i], 0);
466
      }
467

  
468
      for (int i = 0; i < iBands; i++) {
469
         dRange = m_dMax[i] - m_dMin[i];
470
         for (y = 0; y < getNY(); y++) {
471
            for (x = 0; x < getNX(); x++) {
472
               dValue = getCellValueAsDouble(x, y, i);
473
               if (!isNoDataValue(dValue)) {
474
                  iClass = (int) ((dValue - m_dMin[i]) / dRange * 255.);
475
                  m_Histogram[i][iClass]++;
476
               }
477
            }
478
         }
479
      }
480

  
481
      m_bHistogramCalculated = true;
482

  
483

  
484
   }
485

  
486

  
487
   public int[] getHistogram(final int iBand) {
488

  
489
      if (!m_bHistogramCalculated) {
490
         calculateHistogram();
491
      }
492

  
493
      return m_Histogram[iBand];
494

  
495
   }
496

  
497

  
498
   public int[] getHistogram() {
499

  
500
      return getHistogram(0);
501

  
502
   }
503

  
504

  
505
   public int[] getAccumulatedHistogram(final int iBand) {
506

  
507
      final int[] accHistogram = new int[256];
508

  
509
      Arrays.fill(accHistogram, 0);
510

  
511
      if (!m_bHistogramCalculated) {
512
         calculateHistogram();
513
      }
514

  
515
      for (int i = 1; i < 256; i++) {
516
         accHistogram[i] = m_Histogram[iBand][i] + accHistogram[i - 1];
517
      }
518

  
519
      return accHistogram;
520

  
521
   }
522

  
523

  
524
   public int[] getAccumulatedHistogram() {
525

  
526
      return getAccumulatedHistogram(0);
527

  
528
   }
529

  
530

  
531
   public double getMinValue(final int iBand) {
532

  
533
      if (!m_bStatisticsCalculated) {
534
         calculateStatistics();
535
      }
536

  
537
      return m_dMin[iBand];
538

  
539
   }
540

  
541

  
542
   public double getMaxValue(final int iBand) {
543

  
544
      if (!m_bStatisticsCalculated) {
545
         calculateStatistics();
546
      }
547

  
548
      return m_dMax[iBand];
549

  
550
   }
551

  
552

  
553
   public double getMeanValue(final int iBand) {
554

  
555
      if (!m_bStatisticsCalculated) {
556
         calculateStatistics();
557
      }
558

  
559
      return m_dMean[iBand];
560

  
561
   }
562

  
563

  
564
   public double getVariance(final int iBand) {
565

  
566
      if (!m_bStatisticsCalculated) {
567
         calculateStatistics();
568
      }
569

  
570
      return m_dVariance[iBand];
571

  
572
   }
573

  
574

  
575
   public double getMeanValue() {
576

  
577
      return getMeanValue(0);
578

  
579
   }
580

  
581

  
582
   public double getMinValue() {
583

  
584
      return getMinValue(0);
585

  
586
   }
587

  
588

  
589
   public double getMaxValue() {
590

  
591
      return getMaxValue(0);
592

  
593
   }
594

  
595

  
596
   public double getVariance() {
597

  
598
      return getVariance(0);
599

  
600
   }
601

  
602

  
603
   //////////////////////////////Additional methods for DEM analysis//////
604

  
605

  
606
   protected boolean getSubMatrix3x3(final int x,
607
                                     final int y,
608
                                     final double SubMatrix[]) {
609

  
610
      int i;
611
      int iDir;
612
      double z, z2;
613

  
614
      z = getCellValueAsDouble(x, y);
615

  
616
      if (isNoDataValue(z)) {
617
         return false;
618
      }
619
      else {
620
         //SubMatrix[4]	= 0.0;
621
         for (i = 0; i < 4; i++) {
622

  
623
            iDir = 2 * i;
624
            z2 = getCellValueAsDouble(x + m_iOffsetX[iDir], y + m_iOffsetY[iDir]);
625
            if (!isNoDataValue(z2)) {
626
               SubMatrix[i] = z2 - z;
627
            }
628
            else {
629
               z2 = getCellValueAsDouble(x + m_iOffsetX[(iDir + 4) % 8], y + m_iOffsetY[(iDir + 4) % 8]);
630
               if (!isNoDataValue(z2)) {
631
                  SubMatrix[i] = z - z2;
632
               }
633
               else {
634
                  SubMatrix[i] = 0.0;
635
               }
636
            }
637
         }
638

  
639
         return true;
640
      }
641

  
642
   }
643

  
644

  
645
   public double getSlope(final int x,
646
                          final int y) {
647

  
648
      double zm[], G, H;
649

  
650
      zm = new double[4];
651

  
652
      if (getSubMatrix3x3(x, y, zm)) {
653
         G = (zm[0] - zm[2]) / _2DX;
654
         H = (zm[1] - zm[3]) / _2DX;
655
         return Math.atan(Math.sqrt(G * G + H * H));
656
      }
657
      else {
658
         return getNoDataValue();
659
      }
660
   }
661

  
662

  
663
   public double getAspect(final int x,
664
                           final int y) {
665

  
666
      double zm[], G, H, dAspect;
667

  
668
      zm = new double[4];
669

  
670
      if (getSubMatrix3x3(x, y, zm)) {
671
         G = (zm[0] - zm[2]) / _2DX;
672
         H = (zm[1] - zm[3]) / _2DX;
673
         if (G != 0.0) {
674
            dAspect = DEG_180_IN_RAD + Math.atan2(H, G);
675
         }
676
         else {
677
            dAspect = H > 0.0 ? DEG_270_IN_RAD : (H < 0.0 ? DEG_90_IN_RAD : -1.0);
678
         }
679
         return dAspect;
680
      }
681
      else {
682
         return getNoDataValue();
683
      }
684
   }
685

  
686

  
687
   public double getDistToNeighborInDir(final int iDir) {
688

  
689
      return m_dDist[iDir];
690

  
691
   }
692

  
693

  
694
   public static double getUnitDistToNeighborInDir(final int iDir) {
695

  
696
      return ((iDir % 2 != 0) ? Math.sqrt(2.0) : 1.0);
697

  
698
   }
699

  
700

  
701
   public int getDirToNextDownslopeCell(final int x,
702
                                        final int y) {
703

  
704
      return getDirToNextDownslopeCell(x, y, true);
705

  
706
   }
707

  
708

  
709
   public int getDirToNextDownslopeCell(final int x,
710
                                        final int y,
711
                                        final boolean bForceDirToNoDataCell) {
712

  
713
      int i, iDir;
714
      double z, z2, dSlope, dMaxSlope;
715

  
716
      z = getCellValueAsDouble(x, y);
717

  
718
      if (isNoDataValue(z)) {
719
         return -1;
720
      }
721

  
722
      dMaxSlope = 0.0;
723
      for (iDir = -1, i = 0; i < 8; i++) {
724
         z2 = getCellValueAsDouble(x + m_iOffsetX[i], y + m_iOffsetY[i]);
725
         if (isNoDataValue(z2)) {
726
            if (bForceDirToNoDataCell) {
727
               return i;
728
            }
729
            /*else {
730
               return -1;
731
            }*/
732
         }
733
         else {
734
            dSlope = (z - z2) / getDistToNeighborInDir(i);
735
            if (dSlope > dMaxSlope) {
736
               iDir = i;
737
               dMaxSlope = dSlope;
738
            }
739
         }
740
      }
741

  
742
      return iDir;
743

  
744
   }
745

  
746

  
747
   @Override
748
   public String toString() {
749

  
750
      return this.getName();
751

  
752
   }
753

  
754

  
755
   public void setStatisticsHaveToBeCalculated() {
756

  
757
      m_bHistogramCalculated = false;
758
      m_bStatisticsCalculated = false;
759

  
760
   }
761

  
762
}
0 763

  
org.gvsig.toolbox/tags/org.gvsig.toolbox-1.0.18/org.gvsig.toolbox.core/src/main/java/es/unex/sextante/dataObjects/AbstractVectorLayer.java
1

  
2

  
3
package es.unex.sextante.dataObjects;
4

  
5
import java.awt.geom.Rectangle2D;
6
import java.util.ArrayList;
7
import java.util.List;
8

  
9
import com.vividsolutions.jts.geom.Envelope;
10

  
11
import es.unex.sextante.dataObjects.vectorFilters.IVectorLayerFilter;
12
import es.unex.sextante.exceptions.IteratorException;
13

  
14

  
15
/**
16
 * A convenience class which implements some of the methods of the IVectorLayer interface. Extending this class is recommended
17
 * instead of implementing the interface directly
18
 * 
19
 * @author volaya
20
 * 
21
 */
22
public abstract class AbstractVectorLayer
23
         implements
24
            IVectorLayer {
25

  
26
   private int                                 m_iShapesCount;
27
   private boolean                             m_bShapesCountAndExtentCalculated = false;
28
   private Rectangle2D                         m_Extent;
29
   private final ArrayList<IVectorLayerFilter> m_Filters                         = new ArrayList<IVectorLayerFilter>();
30

  
31

  
32
   public abstract Object getBaseDataObject();
33

  
34

  
35
   public String[] getFieldNames() {
36

  
37
      final String[] names = new String[getFieldCount()];
38

  
39
      for (int i = 0; i < names.length; i++) {
40
         names[i] = getFieldName(i);
41
      }
42

  
43
      return names;
44

  
45
   }
46

  
47

  
48
   public int getFieldIndexByName(final String sFieldName) {
49

  
50
      for (int i = 0; i < this.getFieldCount(); i++) {
51
         final String sName = getFieldName(i);
52
         if (sName.equalsIgnoreCase(sFieldName)) {
53
            return i;
54
         }
55
      }
56

  
57
      return -1;
58

  
59
   }
60

  
61

  
62
   public Class[] getFieldTypes() {
63

  
64
      final Class[] types = new Class[getFieldCount()];
65

  
66
      for (int i = 0; i < types.length; i++) {
67
         types[i] = getFieldType(i);
68
      }
69

  
70
      return types;
71

  
72
   }
73

  
74

  
75
   @Override
76
   public String toString() {
77

  
78
      return this.getName();
79

  
80
   }
81

  
82

  
83
   public void addFeature(final IFeature feature) {
84

  
85
      addFeature(feature.getGeometry(), feature.getRecord().getValues());
86

  
87
   }
88

  
89

  
90
   public int getShapesCount() {
91

  
92
      if (!m_bShapesCountAndExtentCalculated) {
93
         calculateShapesCountAndExtent();
94
      }
95
      return m_iShapesCount;
96

  
97
   }
98

  
99

  
100
   public Rectangle2D getFullExtent() {
101

  
102
      if (!m_bShapesCountAndExtentCalculated) {
103
         calculateShapesCountAndExtent();
104
      }
105
      return m_Extent;
106

  
107
   }
108

  
109

  
110
   private void calculateShapesCountAndExtent() {
111

  
112
      Envelope envelope = null;
113
      final IFeatureIterator iter = iterator();
114
      m_iShapesCount = 0;
115

  
116
      while (iter.hasNext()) {
117
         IFeature feature;
118
         try {
119
            feature = iter.next();
120
         }
121
         catch (final IteratorException e) {
122
            m_Extent = new Rectangle2D.Double(0, 0, 0, 0);
123
            m_iShapesCount = 0;
124
            return;
125
         }
126
         if (m_iShapesCount == 0) {
127
            envelope = feature.getGeometry().getEnvelopeInternal();
128
         }
129
         else {
130
            envelope.expandToInclude(feature.getGeometry().getEnvelopeInternal());
131
         }
132
         m_iShapesCount++;
133
      }
134

  
135
      if (m_iShapesCount == 0) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff