Mercurial > dive4elements > gnv-client
comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/RasterObject.java @ 544:33f93898cbbf
Added RasterObject for caching the Rastertiles to get a better performance
geo-backend/trunk@508 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 05 Jan 2010 14:09:53 +0000 |
parents | |
children | 347c84467478 |
comparison
equal
deleted
inserted
replaced
543:fac02bf1c685 | 544:33f93898cbbf |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package de.intevation.gnv.geobackend.sde.datasources; | |
5 | |
6 import com.vividsolutions.jts.geom.Coordinate; | |
7 import com.vividsolutions.jts.geom.Envelope; | |
8 | |
9 /** | |
10 * @author Tim Englich <tim.englich@intevation.de> | |
11 * | |
12 */ | |
13 public class RasterObject { | |
14 | |
15 private int rasterSize; | |
16 private int rowIndex; | |
17 private int columnIndex; | |
18 private int rasterWidth; | |
19 private int rasterHeight; | |
20 private Envelope envelope = null; | |
21 private Envelope rasterEnvelope = null; | |
22 | |
23 private double[] rasterData = null; | |
24 /** | |
25 * Constructor | |
26 */ | |
27 public RasterObject(Envelope envelope , double[] rasterData, | |
28 int rasterSize, int rowIndex, | |
29 int columnIndex, int rasterWidth, int rasterHeight ){ | |
30 this.envelope = envelope; | |
31 this.rasterData = rasterData; | |
32 this.rasterSize = rasterSize; | |
33 this.rowIndex = rowIndex; | |
34 this.columnIndex = columnIndex; | |
35 this.rasterHeight = rasterHeight; | |
36 this.rasterWidth = rasterWidth; | |
37 } | |
38 public synchronized Envelope getEnvelope() { | |
39 if (this.rasterEnvelope == null){ | |
40 double minX = (columnIndex* rasterSize * | |
41 (envelope.getWidth() / rasterWidth)+ envelope.getMinX()); | |
42 double maxX = minX + (rasterSize * (envelope.getWidth() / rasterWidth)); | |
43 | |
44 double maxY = envelope.getMaxY() - | |
45 (rowIndex * rasterSize * | |
46 (envelope.getHeight() / rasterHeight)); | |
47 double minY = maxY - | |
48 (rasterSize * (envelope.getHeight() / rasterHeight)); | |
49 this.rasterEnvelope = new Envelope( | |
50 new Coordinate(minX, minY), | |
51 new Coordinate(maxX, maxY)); | |
52 } | |
53 return this.rasterEnvelope; | |
54 } | |
55 | |
56 public synchronized double getValue(Coordinate coordinate){ | |
57 double dxNature = coordinate.x - envelope.getMinX(); | |
58 double dyNature = envelope.getMaxY() - coordinate.y; | |
59 double widthNature = envelope.getMaxX()-envelope.getMinX(); | |
60 double heightNature = envelope.getMaxY()-envelope.getMinY(); | |
61 | |
62 int pixelX = (int)Math.round(dxNature * rasterWidth / widthNature); | |
63 int pixelY = (int)Math.round(dyNature * rasterHeight/ heightNature); | |
64 | |
65 | |
66 int localPixelX = pixelX - (columnIndex*rasterSize); | |
67 int localPixelY = pixelY - (rowIndex*rasterSize); | |
68 | |
69 int pos = localPixelY * rasterSize + localPixelX; | |
70 | |
71 | |
72 if (pos < rasterData.length){ | |
73 return this.rasterData[pos]; | |
74 } | |
75 | |
76 return Double.NaN; | |
77 } | |
78 | |
79 } |