Revision 11091

View differences:

org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3

  
4
    <modelVersion>4.0.0</modelVersion>
5
    <artifactId>org.gvsig.raster.cache</artifactId>
6
    <packaging>pom</packaging>
7
    <name>org.gvsig.raster.cache</name>
8
    <description>Cache management for raster files</description>
9
    <version>2.2.49</version>
10
    <scm>
11
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49</connection>
12
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49</developerConnection>
13
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49</url>
14
    </scm>
15

  
16
    <repositories>
17
      <repository>
18
        <id>gvsig-public-http-repository</id>
19
        <name>gvSIG maven public HTTP repository</name>
20
        <url>http://devel.gvsig.org/m2repo/j2se</url>
21
        <releases>
22
          <enabled>true</enabled>
23
          <updatePolicy>daily</updatePolicy>
24
          <checksumPolicy>warn</checksumPolicy>
25
        </releases>
26
        <snapshots>
27
          <enabled>true</enabled>
28
          <updatePolicy>daily</updatePolicy>
29
          <checksumPolicy>warn</checksumPolicy>
30
        </snapshots>
31
      </repository>
32
    </repositories>
33

  
34
    <parent>
35
      <groupId>org.gvsig</groupId>
36
      <artifactId>org.gvsig.desktop</artifactId>
37
      <version>2.0.274</version>
38
    </parent>
39

  
40
    <developers>
41
        <developer>
42
            <id>nbrodin</id>
43
            <name>Nacho Brodin</name>
44
            <email>nachobrodin@gmail.com</email>
45
            <roles>
46
                <role>Architect</role>
47
                <role>Developer</role>
48
            </roles>
49
        </developer>
50
    </developers>
51

  
52
     <dependencyManagement>
53
        <dependencies>
54

  
55

  
56
            <!--
57
            Versions of child projects
58
            -->
59
            <dependency>
60
                <groupId>org.gvsig</groupId>
61
                <artifactId>org.gvsig.raster.cache.lib.api</artifactId>
62
                <version>2.2.49</version>
63
            </dependency>
64
            <dependency>
65
                <groupId>org.gvsig</groupId>
66
                <artifactId>org.gvsig.raster.cache.lib.impl</artifactId>
67
                <version>2.2.49</version>
68
            </dependency>
69

  
70

  
71
        </dependencies>
72
    </dependencyManagement>
73

  
74

  
75
    <build>
76
        <plugins>
77
            <plugin>
78
                <groupId>org.apache.maven.plugins</groupId>
79
                <artifactId>maven-release-plugin</artifactId>
80
                <configuration>
81
                    <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/</tagBase>
82
                    <goals>deploy</goals>
83
                </configuration>
84
            </plugin>
85
            <plugin>
86
				<groupId>org.apache.maven.plugins</groupId>
87
				<artifactId>maven-compiler-plugin</artifactId>
88
				<configuration>
89
					<source>1.5</source>
90
					<target>1.5</target>
91
				</configuration>
92
			</plugin>
93
			<plugin>
94
                <groupId>org.codehaus.mojo</groupId>
95
                <artifactId>animal-sniffer-maven-plugin</artifactId>
96
                <configuration>
97
                    <skip>true</skip>
98
                </configuration>
99
            </plugin>
100
        </plugins>
101
    </build>
102
    <modules>
103
        <module>org.gvsig.raster.cache.lib.api</module>
104
        <module>org.gvsig.raster.cache.lib.impl</module>
105
    </modules>
106
</project>
0 107

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/org.gvsig.raster.cache.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.cache.tile.impl.TileCacheDefaultImplLibrary
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/pool/ThreadPoolImpl.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.raster.cache.tile.impl.pool;
23

  
24
import java.util.Collections;
25
import java.util.LinkedList;
26

  
27
import org.gvsig.raster.cache.tile.Tile;
28
import org.gvsig.raster.cache.tile.exception.TileGettingException;
29
import org.gvsig.raster.cache.tile.pool.AtomicTask;
30
import org.gvsig.raster.cache.tile.pool.ThreadPool;
31
import org.gvsig.raster.cache.tile.pool.TilePipe;
32
import org.gvsig.raster.cache.tile.provider.TileListener;
33

  
34
/**
35
 * Pool of threads. This class contains a list of tasks and a limited number
36
 * of threads to execute them. When a thread is free will execute the next task 
37
 * in the list. 
38
 *
39
 * @author Nacho Brodin (nachobrodin@gmail.com)
40
 */
41
public class ThreadPoolImpl implements ThreadPool {
42
	private int                        NTHREADS_POOL   = 5;
43
	private ThreadTask[]               threadList      = null;
44
	private LinkedList<AtomicTask>     tasks           = new LinkedList<AtomicTask>();
45
	private boolean                    priorityActive  = false;
46
	private TilePipe                   tilePipe        = null;
47

  
48
	/**
49
	 * Constructor. Only for testing purposes. After this constructor the method init
50
	 * has to be called
51
	 */
52
	public ThreadPoolImpl() {
53
		this.priorityActive = true;
54
		threadList = new ThreadTask[NTHREADS_POOL];
55
	}
56
	
57
	/**
58
	 * Constructor
59
	 * @param priorityActive true if the pool runs using priorities and false if doesn't
60
	 * @param nThreads Number of threads of this pool
61
	 */
62
	public ThreadPoolImpl(boolean priorityActive, int nThreads) {
63
		this.priorityActive = true;
64
		NTHREADS_POOL = nThreads;
65
		init();
66
	}
67
	
68
	/**
69
	 * Constructor
70
	 * @param priorityActive true if the pool runs using priorities and false if doesn't
71
	 */
72
	public ThreadPoolImpl(boolean priorityActive) {
73
		this.priorityActive = priorityActive;
74
		init();
75
	}
76
	
77
	public void init() {
78
		if(threadList == null)
79
			threadList = new ThreadTask[NTHREADS_POOL];
80
		for (int i = 0; i < NTHREADS_POOL; i++) {
81
			threadList[i] = new ThreadTask(this);
82
			threadList[i].start();
83
		}
84
	}
85
	
86
	/**
87
	 * Cancel the pool of threads and destroy the pool
88
	 * @param listener
89
	 */
90
	public void cancelPool(TileListener listener) {
91
		if(threadList != null) {
92
			for (int i = 0; i < NTHREADS_POOL; i++) {
93
				if(threadList[i] != null) {
94
					Runnable r = threadList[i].stopThread();
95
					try {
96
						if(listener != null)
97
							listener.tileReady((Tile)r);
98
					} catch (TileGettingException e) {
99
					}
100
				}
101
			}
102
		}
103
		for (int i = 0; i < tasks.size(); i++) {
104
			try {
105
				if(listener != null)
106
					listener.tileReady((Tile)tasks.get(i));
107
			} catch (TileGettingException e) {
108
			}
109
		}
110
		synchronized (tasks) {
111
			tasks.notifyAll();
112
		}
113
		destroyPool();
114
	}
115
	
116
	/**
117
	 * Cleans the input and output pool
118
	 * @param listener
119
	 */
120
	public void emptyPool() {
121
		//Don't get and set more tiles
122
		for (int i = 0; i < threadList.length; i++) {
123
			threadList[i].cancelTaskInProgress();
124
		}
125
		
126
		//Cleans queues
127
		synchronized (tasks) {
128
			tasks.clear();
129
			getTilePipe().clear();
130
			tasks.notifyAll();
131
		}
132
		
133
		//Gets tiles again
134
		for (int i = 0; i < threadList.length; i++) {
135
			threadList[i].resumeTasks();
136
		}
137
	}
138
	
139
	public LinkedList<AtomicTask> getInputTaskList() {
140
		return tasks;
141
	}
142
	
143
	/*
144
	 * (non-Javadoc)
145
	 * @see org.gvsig.raster.cache.tile.pool.ThreadPool#getTilePipe()
146
	 */
147
	public TilePipe getTilePipe() {
148
		if(tilePipe == null)
149
			tilePipe = new TilePipeImpl();
150
		return tilePipe;
151
	}
152
	
153
	/**
154
	 * Stops all threads in the list and sets the list to null
155
	 * @deprecated
156
	 */
157
	public void destroyPool() {
158
		for (int i = 0; i < NTHREADS_POOL; i++) {
159
			threadList[i].stopThread();
160
			threadList[i] = null;
161
		}
162
		threadList = null;
163
	}
164
	
165
	/**
166
	 * Returns true if the pool is valid
167
	 * @return
168
	 */
169
	public boolean isPoolValid() {
170
		return !(threadList == null);
171
	}
172

  
173
	/**
174
	 * Adds a new task to the list
175
	 * @param task
176
	 */
177
	public void addTask(AtomicTask task) {
178
		synchronized (tasks) {
179
			tasks.addLast(task);
180
			tasks.notify();
181
		}
182
	}
183

  
184
	/**
185
	 * Gets the next task in the list
186
	 * @return
187
	 */
188
	public AtomicTask getNext() {
189
		AtomicTask returnVal = null;
190
		synchronized (tasks) {
191
			while (tasks.isEmpty()) {
192
				try {
193
					tasks.wait();
194
				} catch (InterruptedException ex) {
195
					System.err.println("Interrupted");
196
				}
197
			}
198
			if(priorityActive)
199
				sort(tasks);
200
			returnVal = tasks.removeFirst();
201
		}
202
		return returnVal;
203
	}
204
	
205
	/**
206
	 * Sorts the array of tasks. Each atomic task have to implement AtomicTask interface
207
	 * which is Runnable and Comparable. The last one allow to sort the array 
208
	 * by priorities.
209
	 * @param tasks
210
	 */
211
	private void sort(LinkedList<AtomicTask> tasks) {
212
		Collections.sort(tasks);
213
	}
214
}
0 215

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/pool/ThreadTask.java
1
package org.gvsig.raster.cache.tile.impl.pool;
2

  
3
import org.gvsig.raster.cache.tile.pool.AtomicTask;
4

  
5
/**
6
 * This represents one thread in the pool. This thread gets a new task in
7
 * the pool and executes it.
8
 *
9
 * @author Nacho Brodin (nachobrodin@gmail.com)
10
 */
11
class ThreadTask extends Thread {
12
	private ThreadPoolImpl pool         = null;
13
	private boolean        stop         = false;
14
	private AtomicTask     currentJob   = null; 
15
	private boolean        getMoreTiles = true;
16

  
17
	public ThreadTask(ThreadPoolImpl thePool) {
18
		pool = thePool;
19
	}
20

  
21
	public void run() {
22
		while (!stop) {
23
			if(getMoreTiles) {
24
				currentJob = pool.getNext();
25
				currentJob.run();
26
			} else {
27
				try {
28
					Thread.sleep(500);
29
				} catch (InterruptedException e) {
30
				}
31
			}
32
		}
33
	}
34
	
35
	/**
36
	 * Stops this thread
37
	 */
38
	public Runnable stopThread() {
39
		stop = true;
40
		return currentJob;
41
	}
42
	
43
	/**
44
	 * Cancels the task in progress and avoids that next tiles are gotten
45
	 */
46
	public void cancelTaskInProgress() {
47
		if(currentJob != null)
48
			currentJob.cancelTask();
49
		getMoreTiles = false;
50
	}
51
	
52
	/**
53
	 * Gets new tiles to processed of the input queue
54
	 */
55
	public void resumeTasks() {
56
		getMoreTiles = true;
57
	}
58
}
0 59

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/pool/TilePipeImpl.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.raster.cache.tile.impl.pool;
23

  
24
import java.util.LinkedList;
25
import java.util.Queue;
26

  
27
import org.gvsig.raster.cache.tile.Tile;
28
import org.gvsig.raster.cache.tile.pool.AtomicTask;
29
import org.gvsig.raster.cache.tile.pool.TilePipe;
30

  
31
/**
32
 * This class manages transactions between the producer and the consumer. The
33
 * producer download tiles from a server and the consumer is a tile provider
34
 * which will return downloaded tiles.
35
 *
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class TilePipeImpl implements TilePipe {
39
	private boolean              isEmpty        = true;
40
	private Queue<AtomicTask>    buffer         = new LinkedList<AtomicTask>();
41
	private boolean              debug          = false;
42
	
43
	public TilePipeImpl() {
44
		this.debug = false;
45
	}
46
	
47
	public TilePipeImpl(boolean debug) {
48
		this.debug = debug;
49
	}
50
	
51
	/**
52
	 * Sets a tile in the pipe
53
	 * @param tile
54
	 */
55
	public synchronized void setAtomicTask(AtomicTask task) {
56
		if(task != null)
57
			buffer.add(task);
58
		isEmpty = false;
59
		
60
		if(debug)
61
			System.err.println("Setting tile " + ((Tile)task).getCol() + " " + ((Tile)task).getRow());
62
		
63
		notify();
64
	}
65

  
66
	/**
67
	 * Gets a tile from the pipe
68
	 * @return
69
	 */
70
	public synchronized AtomicTask getAtomicTask() {
71
		if(debug)
72
			System.out.println("0-Getting tile ");
73
		while( isEmpty == true ) {
74
			try {
75
				wait();
76
			} catch( InterruptedException e ) {
77
			}
78
		}
79

  
80
		AtomicTask task = buffer.poll() ;
81
		
82
		if(debug)
83
			System.out.println("1-Getting tile " + ((Tile)task).getCol() + " " + ((Tile)task).getRow());
84
		
85
		if( getSize() == 0 )
86
			isEmpty = true;
87

  
88
		return task;
89
	}
90
	
91
	/**
92
	 * Returns the number of elements in the queue
93
	 * @return
94
	 */
95
	public synchronized int getSize() {
96
		return buffer.size();
97
	}
98
	
99
	/*
100
	 * (non-Javadoc)
101
	 * @see org.gvsig.raster.cache.tile.pool.TilePipe#clear()
102
	 */
103
	public void clear() {
104
		synchronized (buffer) {
105
			buffer.clear();
106
		}
107
	}
108
}
0 109

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/disk/FlatXFileSystemStrategy.java
1
/* TileRasterCache, a library to download tiles from several sources.
2
 *
3
 * Copyright (C) 2010 Prodevelop SL.
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
 *   Prodevelop Integraci๏ฟฝn de Tecnolog๏ฟฝas SL
22
 *   Plaza don Juan de Vilarrasa , 14-5
23
 *   46000 Valencia
24
 *   Spain
25
 *
26
 *   +34 963 510 612
27
 *   +34 963 510 968
28
 *   gis@prodevelop.es
29
 *   http://www.prodevelop.es
30
 *   
31
 *   author: Alberto Romeu Carrasco (aromeu@prodevelop.es)
32
 */
33

  
34
package org.gvsig.raster.cache.tile.impl.disk;
35

  
36
import java.io.File;
37

  
38

  
39
/**
40
 * This IFileSystemStrategy creates a directory for each zoom level of a layer.
41
 * Inside the directory of a zoom level, creates a directory for each X row and
42
 * inside the directory of an X row stores a file with the Y row, so
43
 * OSM/0/0/0.tile represents the tile http://osm/0/0/0.png
44
 * 
45
 * This strategy is the most spread for mobile map viewers (although is not the most efficient)
46
 * @author aromeu
47
 *
48
 */
49
public class FlatXFileSystemStrategy extends DefaultFileSystemStrategy {
50
	
51
	public FlatXFileSystemStrategy() {
52
		super();
53
	}
54

  
55
	public FlatXFileSystemStrategy(String tileNameSuffix) {
56
		super(tileNameSuffix);		
57
	}
58

  
59
	public String getRelativeToLayerDirTilePath(int row, 
60
			int col, 
61
			int zoomLevel, 
62
			String var, 
63
			String z, 
64
			String time) {
65
		if(zoomLevel < 0) {  //Real zoom level
66
			return new StringBuffer()
67
			.append(var)
68
			.append(File.separator)
69
			.append(z)
70
			.append(File.separator)
71
			.append(time)
72
			.append(File.separator)
73
			.append("real")
74
			.append(File.separator)
75
			.append(col)
76
			.append(File.separator)
77
			.append(row).toString();
78
		} else {
79
			return new StringBuffer()
80
			.append(var)
81
			.append(File.separator)
82
			.append(z)
83
			.append(File.separator)
84
			.append(time)
85
			.append(File.separator)
86
			.append(zoomLevel)
87
			.append(File.separator)
88
			.append(col)
89
			.append(File.separator)
90
			.append(row).toString();
91
		}
92
	}
93
	
94
	public String getLayerNameSuffix() {
95
		return "_flatx";
96
	}	
97

  
98
	public String getName() {
99
		return FLATX;
100
	}	
101
}
0 102

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/disk/DefaultFileSystemStrategy.java
1
package org.gvsig.raster.cache.tile.impl.disk;
2

  
3
import org.gvsig.raster.cache.tile.disk.ITileFileSystemStrategy;
4

  
5

  
6
public abstract class DefaultFileSystemStrategy implements ITileFileSystemStrategy {
7
		
8
	private String              tileNameSuffix;
9
	private final static String DEFAULT_TILE_SUFFIX = ".tile.gvsig";
10
	
11
	public DefaultFileSystemStrategy() {
12
		
13
	}
14
	
15
	public DefaultFileSystemStrategy(String tileNameSuffix) {	
16
		this.tileNameSuffix = tileNameSuffix;	
17
	}
18
	
19
	public String getTileNameSuffix() {
20
		if (tileNameSuffix == null)
21
			return DEFAULT_TILE_SUFFIX;
22
		return this.tileNameSuffix;
23
	}
24
	
25
	public void setTileNameSuffix(String suffix) {
26
		this.tileNameSuffix = suffix;
27
	}
28
}
0 29

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/provider/TileMatrix.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.raster.cache.tile.impl.provider;
23

  
24

  
25
/**
26
 * Description of a tile matrix
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public class TileMatrix {
30
    private double                      scaleDenominator    = 0;
31
    private double[]                    topLeftCorner       = null;
32
    private int                         tileWidth           = 0;
33
    private int                         tileHeight          = 0;
34
    private long                        matrixWidth         = 0;
35
    private long                        matrixHeight        = 0;
36
    private static final double         MTS_X_GRADO         = 111319.490793274;
37
    
38
	public double getScaleDenominator() {
39
		return scaleDenominator;
40
	}
41

  
42
	public void setScaleDenominator(double scaleDenominator) {
43
		this.scaleDenominator = scaleDenominator;
44
	}
45

  
46
	public int getTileWidth() {
47
		return tileWidth;
48
	}
49

  
50
	public void setTileWidth(int tileWidth) {
51
		this.tileWidth = tileWidth;
52
	}
53

  
54
	public int getTileHeight() {
55
		return tileHeight;
56
	}
57

  
58
	public void setTileHeight(int tileHeight) {
59
		this.tileHeight = tileHeight;
60
	}
61

  
62
	public long getMatrixWidth() {
63
		return matrixWidth;
64
	}
65

  
66
	public void setMatrixWidth(long matrixWidth) {
67
		this.matrixWidth = matrixWidth;
68
	}
69

  
70
	public long getMatrixHeight() {
71
		return matrixHeight;
72
	}
73

  
74
	public void setMatrixHeight(long matrixHeight) {
75
		this.matrixHeight = matrixHeight;
76
	}
77

  
78
	public double[] getTopLeftCorner() {
79
		return topLeftCorner;
80
	}
81
	
82
	public void setTopLeftCorner(double[] topLeftCorner) {
83
		this.topLeftCorner = topLeftCorner;
84
	}
85
    
86
    /**
87
     * Gets the width in meters of a tile
88
     * @param projected
89
     * @return
90
     */
91
    public double getWidthMtsTile(boolean projected) {
92
    	if(!projected) {
93
    		return (scaleDenominator * tileWidth * 0.00028) / MTS_X_GRADO;
94
    	} else {
95
    		return (scaleDenominator * tileWidth * 0.00028);
96
    	}
97
    }
98
    
99
    /**
100
     * Gets the height in meters of a tile
101
     * @param projected
102
     * @return
103
     */
104
    public double getHeightMtsTile(boolean projected) {
105
    	if(!projected) {
106
    		return (scaleDenominator * tileHeight * 0.00028) / MTS_X_GRADO;
107
    	} else {
108
    		return (scaleDenominator * tileHeight * 0.00028);
109
    	}
110
    }
111
    
112
	public void print() {
113
		System.out.println("   *****TileMatrix******");
114
		System.out.println("   scaleDenominator:" + getScaleDenominator());
115
		if(topLeftCorner != null)
116
			System.out.println("   topLeftCorner:" + topLeftCorner[0] + ", " + topLeftCorner[1]);
117
		System.out.println("   tileWidth:" + getTileWidth());
118
		System.out.println("   tileHeight:" + getTileHeight());
119
		System.out.println("   matrixWidth:" + getMatrixWidth());
120
		System.out.println("   matrixHeight:" + getMatrixHeight());
121
	}
122
}
0 123

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/provider/TileMatrixLimits.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.raster.cache.tile.impl.provider;
23

  
24
import java.awt.geom.Point2D;
25

  
26
/**
27
 * Limits of a tile matrix
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public class TileMatrixLimits {
31
	private TileMatrix             tileMatrix           = null;
32
	private int                    minTileRow           = 0;
33
	private int                    maxTileRow           = 0;
34
	private int                    minTileCol           = 0;
35
	private int                    maxTileCol           = 0;
36
	
37
	public TileMatrix getTileMatrix() {
38
		if(tileMatrix == null)
39
			tileMatrix = new TileMatrix();
40
		return tileMatrix;
41
	}
42

  
43
	/**
44
	 * Gets the upper left corner and the lower right corner of the 
45
	 * selected tile
46
	 * @param x X tile position
47
	 * @param y Y tile position
48
	 * @return
49
	 */
50
	public Point2D[] getTileExtent(int x, int y) {
51
		double sizeTile = getTileMatrix().getTileWidth() * getTileMatrix().getScaleDenominator();
52
		double initX = getTileMatrix().getTopLeftCorner()[0] + (sizeTile * x);
53
		double initY = getTileMatrix().getTopLeftCorner()[1] - (sizeTile * y);
54
		Point2D[] p = new Point2D[2];
55
		p[0] = new Point2D.Double(initX, initY);
56
		p[1] = new Point2D.Double(initX + sizeTile, initY - sizeTile);
57
		return p;
58
	}
59
	
60
	public int getMinTileRow() {
61
		return minTileRow;
62
	}
63
	
64
	public void setMinTileRow(int minTileRow) {
65
		this.minTileRow = minTileRow;
66
	}
67
	
68
	public int getMaxTileRow() {
69
		return maxTileRow;
70
	}
71
	
72
	public void setMaxTileRow(int maxTileRow) {
73
		this.maxTileRow = maxTileRow;
74
	}
75
	
76
	public int getMinTileCol() {
77
		return minTileCol;
78
	}
79
	
80
	public void setMinTileCol(int minTileCol) {
81
		this.minTileCol = minTileCol;
82
	}
83
	
84
	public int getMaxTileCol() {
85
		return maxTileCol;
86
	}
87
	
88
	public void setMaxTileCol(int maxTileCol) {
89
		this.maxTileCol = maxTileCol;
90
	}
91
	
92
	public void print() {
93
		System.out.println("  *****TileMatrixLimits******");
94
		System.out.println("  MaxTileCol:" + getMaxTileCol());
95
		System.out.println("  MaxTileRow:" + getMaxTileRow());
96
		System.out.println("  MinTileCol:" + getMinTileCol());
97
		System.out.println("  MinTileRow:" + getMinTileRow());
98
		if(tileMatrix != null)
99
			tileMatrix.print();
100
	}
101
}
0 102

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/provider/DefaultCacheStruct.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.raster.cache.tile.impl.provider;
23

  
24
import java.awt.geom.Point2D;
25
import java.awt.geom.Rectangle2D;
26
import java.util.ArrayList;
27
import java.util.List;
28

  
29
import org.gvsig.raster.cache.tile.Tile;
30
import org.gvsig.raster.cache.tile.TileCacheLocator;
31
import org.gvsig.raster.cache.tile.disk.ITileFileSystemStrategy;
32
import org.gvsig.raster.cache.tile.exception.TileBuildException;
33
import org.gvsig.raster.cache.tile.impl.TileImpl;
34
import org.gvsig.raster.cache.tile.provider.CacheStruct;
35

  
36
/**
37
 * Implementation for a structure of a cache
38
 * @author Nacho Brodin (nachobrodin@gmail.com)
39
 */
40
public class DefaultCacheStruct implements CacheStruct {
41
    private TileMatrixSet                 tileMatrixSet  = null;
42
    private ArrayList<TileMatrixLimits>   limits         = null;
43
    private String                        layerName      = null;
44
    private String                        uri            = null;
45
	private Rectangle2D                   worldExtent    = null;
46
	private String                        fileSuffix     = null;
47
	private String                        epsg           = null;
48
	private long                          fileSize       = 0;
49
	private double                        realPixelSize  = 0;
50
	private Rectangle2D                   layerExtent    = null;
51
    
52
    public DefaultCacheStruct(int typeOfCoords, 
53
    		int levels, 
54
    		Rectangle2D layerExtent, 
55
    		double pixelSize,
56
    		int tilePxWidth,
57
    		int tilePxHeight,
58
    		String uri,
59
    		String layerName,
60
    		ITileFileSystemStrategy strategy,
61
    		String baseDir,
62
    		String fileSuffix,
63
    		String epsg,
64
    		long size) {
65
    	this.uri = uri;
66
    	this.layerName = layerName;
67
    	this.fileSuffix = fileSuffix;
68
    	this.fileSize = size;
69
    	this.realPixelSize = pixelSize;
70
    	this.layerExtent = layerExtent;
71
    	if(epsg != null && epsg.startsWith("EPSG:"))
72
    		this.epsg = epsg;
73
    	
74
    	//Coordenadas del mundo en geogr๏ฟฝficas y planas
75
    	
76
    	if(typeOfCoords == CacheStruct.GEOGRAFIC) {
77
    		worldExtent = new Rectangle2D.Double(-180, -90, 360, 180);
78
    	} 
79
    	if(typeOfCoords == CacheStruct.FLAT) {
80
    		worldExtent = new Rectangle2D.Double(-20037508, -20037508, 40075016, 40075016);
81
    	}
82
    	
83
    	double[] pixelSizeList = buildWorldMatrix(typeOfCoords, levels, tilePxWidth, tilePxHeight, worldExtent);
84
        buildLayerMatrix(levels, tilePxWidth, tilePxHeight, worldExtent, layerExtent, pixelSizeList, pixelSize);
85
    }
86
    
87
    private void buildLayerMatrix(int levels, 
88
    		int tilePxWidth, 
89
    		int tilePxHeight,
90
    		Rectangle2D worldExtent,
91
    		Rectangle2D layerExtent,
92
    		double[] pixelSizeList,
93
    		double maxPixelSize) {
94
    	limits = new ArrayList<TileMatrixLimits>();
95

  
96
    	for (int i = 0; i < levels; i++) {
97
    		//Calculo de tiles para ese nivel en la capa actual
98
    		int minTileCol = (int)(Math.abs(layerExtent.getMinX() - worldExtent.getMinX()) / pixelSizeList[i]) / tilePxWidth;
99
    		int minTileRow = (int)(Math.abs(layerExtent.getMaxY() - worldExtent.getMaxY()) / pixelSizeList[i]) / tilePxHeight;
100
    		int maxTileCol = (int)(Math.abs(layerExtent.getMaxX() - worldExtent.getMinX()) / pixelSizeList[i]) / tilePxWidth;
101
    		int maxTileRow = (int)(Math.abs(layerExtent.getMinY() - worldExtent.getMaxY()) / pixelSizeList[i]) / tilePxHeight;
102
    		
103
    		//int imageTileWidth = (int)Math.ceil((layerExtent.getWidth() / pixelSizeList[i]) / tilePxWidth);
104
    		//int imageTileHeight = (int)Math.ceil((layerExtent.getHeight() / pixelSizeList[i]) / tilePxHeight);
105
    		TileMatrixLimits limit = new TileMatrixLimits();
106
    		limit.setMinTileRow(minTileRow);
107
    		limit.setMinTileCol(minTileCol);
108
    		limit.setMaxTileRow(maxTileRow);
109
    		limit.setMaxTileCol(maxTileCol);
110
    		
111
    		//Calcula las coordenadas de la esquina superior izquierda del TileMatrixLimits
112
    		double ulx = worldExtent.getMinX() + (minTileCol * tilePxWidth * pixelSizeList[i]);
113
    		double uly = worldExtent.getMaxY() - (minTileRow * tilePxHeight * pixelSizeList[i]);
114
    		limit.getTileMatrix().setTopLeftCorner(new double[]{ulx, uly});
115
    		limit.getTileMatrix().setScaleDenominator(pixelSizeList[i]);
116
    		limit.getTileMatrix().setTileWidth(tilePxWidth);
117
    		limit.getTileMatrix().setTileHeight(tilePxHeight);
118
    		
119
    		limits.add(limit);
120
    		if(i == (levels - 1) || (maxPixelSize != Double.POSITIVE_INFINITY && maxPixelSize != Double.NEGATIVE_INFINITY && pixelSizeList[i] < maxPixelSize)) {
121
    			//System.out.println("Image res:" + maxPixelSize + " Real res:" + pixelSizeList[i]);
122
    			break;
123
    		}
124
    	}
125
    }
126
    
127
    private double[] buildWorldMatrix(int typeOfCoords,
128
    		int levels, 
129
    		int tilePxWidth, 
130
    		int tilePxHeight,
131
    		Rectangle2D worldExtent) {
132
    	double[] pixelSizeList = new double[levels];
133
    	
134
    	limits = new ArrayList<TileMatrixLimits>();
135
    	tileMatrixSet = new TileMatrixSet();
136
    	tileMatrixSet.setBbox(worldExtent);
137
    	
138
    	int nTilesWidth = 0;
139
    	int nTilesHeight = 0;
140
    		
141
    	for (int i = 0; i < levels; i++) {
142
    		TileMatrix tm = new TileMatrix();
143
    		tm.setTileWidth(tilePxWidth);
144
    		tm.setTileHeight(tilePxHeight);
145
    		if(i == 0) {
146
    			nTilesWidth = (typeOfCoords == CacheStruct.FLAT) ? 1 : 2;
147
    			nTilesHeight = 1;
148
    		} else {
149
    			nTilesWidth *= 2;
150
    			nTilesHeight *= 2;
151
    		}
152
    		
153
    		tm.setMatrixWidth(nTilesWidth);
154
    		tm.setMatrixHeight(nTilesHeight);
155
    		if(tilePxWidth > 0 && nTilesWidth > 0)
156
    			pixelSizeList[i] = worldExtent.getWidth() / ((long)tilePxWidth * (long)nTilesWidth);
157
    		else
158
    			pixelSizeList[i] = 0;
159
    		//System.out.println("-Level:" + i + " " + nTilesWidth + " " + nTilesHeight + " " + pixelSizeList[i]);
160
    		tm.setScaleDenominator(pixelSizeList[i]);
161
    		tileMatrixSet.getTileMatrix().add(tm);
162
    	}
163
    	return pixelSizeList;
164
    }
165
    
166
    public Rectangle2D getWorldExtent() {
167
    	return worldExtent;
168
    }
169

  
170
	public int getNumberOfLevels() {
171
		return tileMatrixSet.getTileMatrix().size();
172
	}
173

  
174
	public String getLayerName() {
175
		return layerName;
176
	}
177

  
178
	public String getServerURL() {
179
		return uri;
180
	}
181

  
182
	public String getFileSuffix() {
183
		return fileSuffix;
184
	}
185

  
186
	public int[] getTileSizeByLevel(int level) {
187
		return new int[] {
188
			tileMatrixSet.getTileMatrix().get(level).getTileWidth(),
189
			tileMatrixSet.getTileMatrix().get(level).getTileHeight()
190
		};
191
	}
192

  
193
	public double[] getTileSizeInRealCoordsByLevel(int level) {
194
		return new double[] {
195
				getPixelSizeByLevel(level) * tileMatrixSet.getTileMatrix().get(level).getTileWidth(),
196
				getPixelSizeByLevel(level) *  tileMatrixSet.getTileMatrix().get(level).getTileHeight()
197
			};
198
	}
199

  
200
	public int getLayerWidthOfTileMatrixByLevel(int level) {
201
		if(level < limits.size()) {
202
			TileMatrixLimits l = limits.get(level);
203
			return (l.getMaxTileRow() - l.getMinTileRow()) + 1;
204
		}
205
		return 0;
206
	}
207

  
208
	public int getLayerHeightOfTileMatrixByLevel(int level) {
209
		if(level < limits.size()) {
210
			TileMatrixLimits l = limits.get(level);
211
			return (l.getMaxTileCol() - l.getMinTileCol()) + 1;
212
		}
213
		return 0;
214
	}
215

  
216
	public int getLayerInitXTilePositionByLevel(int level) {
217
		TileMatrixLimits l = limits.get(level);
218
		return l.getMinTileCol();
219
	}
220

  
221
	public int getLayerInitYTilePositionByLevel(int level) {
222
		TileMatrixLimits l = limits.get(level);
223
		return l.getMinTileRow();
224
	}
225

  
226
	public long getWorldHeightOfTileMatrixByLevel(int level) {
227
		return tileMatrixSet.getTileMatrix().get(level).getMatrixWidth();
228
	}
229

  
230
	public long getWorldWidthOfTileMatrixByLevel(int level) {
231
		return tileMatrixSet.getTileMatrix().get(level).getMatrixHeight();
232
	}
233
	
234
	public double getPixelSizeByLevel(int level) {
235
		if(level < 0)
236
			return realPixelSize;
237
		return tileMatrixSet.getTileMatrix().get(level).getScaleDenominator();
238
	}
239
	
240
	public Point2D[] getTileExtent(Tile tile) {
241
		return limits.get(tile.getLevel()).getTileExtent(tile.getRow(), tile.getCol());
242
	}
243
	
244
	public Point2D[] getTileExtent(int level, int col, int row) {
245
		return limits.get(level).getTileExtent(row, col);
246
	}
247
	
248
	public Tile getTileStructure(int level, int tileCol, int tileRow, Point2D ul, Point2D lr) throws TileBuildException  {
249
		int[] size = getTileSizeByLevel(level);
250
		Tile tile = TileCacheLocator.getManager().createTile(level, tileRow, tileCol);
251
		tile.setUl(ul);
252
		tile.setLr(lr);
253
		tile.setWidthPx(size[0]);
254
		tile.setHeightPx(size[1]);
255
		
256
		return tile;
257
	}
258
	
259
	public List<Tile> getTileList(Rectangle2D r) {
260
		int tilePxWidth = tileMatrixSet.getTileMatrix().get(0).getTileWidth();
261
		int tilePxHeight = tileMatrixSet.getTileMatrix().get(0).getTileHeight();
262
		int minTileCol = (int)(r.getX() / tilePxWidth);
263
		int minTileRow = (int)(r.getY() / tilePxHeight);
264
		int maxTileCol = (int)((r.getX() + r.getWidth()) / tilePxWidth);
265
		int maxTileRow = (int)((r.getY() + r.getHeight()) / tilePxHeight);
266
		double tileWCWidth = tilePxWidth * realPixelSize;
267
		double tileWCHeight = tilePxHeight * realPixelSize;
268
		
269
		//Calculo de tiles con sus coordenadas
270
		List<Tile> tileList = new ArrayList<Tile>();
271
		for (int i = minTileRow; i <= maxTileRow; i++) {
272
			for (int j = minTileCol; j <= maxTileCol; j++) {
273
				Point2D ulTile = new Point2D.Double(
274
						layerExtent.getMinX() + (tileWCWidth * j),
275
						layerExtent.getMaxY() - (tileWCHeight * i));
276
				Point2D lrTile = new Point2D.Double(ulTile.getX() + tileWCWidth, ulTile.getY() - tileWCHeight);
277
				Tile t = new TileImpl(tilePxWidth, tilePxHeight, i, j, ulTile, lrTile);
278
				t.setLevel(-1);
279
				int initTileX = tilePxWidth * j;
280
				int initTileY = tilePxHeight * i;
281
				Rectangle2D rTile = new Rectangle2D.Double(initTileX, initTileY, tilePxWidth, tilePxHeight);
282
				t.setCoordsPx(rTile);
283
				tileList.add(t);
284
			}
285
		}
286
		return tileList;
287
	}
288
	
289
	public List<Tile> getTileList(Point2D ul, Point2D lr, double mtsPixelRequest) {
290
		return getTileList(ul, lr, mtsPixelRequest, false);
291
	}
292
	
293
	public List<Tile> getTileList(Point2D ul, Point2D lr, double mtsPixelRequest, boolean increaseResolution) {
294
		//Selecci?n de nivel de resoluci?n
295
		int tilePxWidth = 0;
296
		int tilePxHeight = 0;
297
		double tileWCWidth = 0;
298
		double tileWCHeight = 0;
299
		int level = 0;
300
		double mtsPixelLevel = 0;
301
		boolean levelAssigned = false;
302
		for (int i = 0; i < tileMatrixSet.getTileMatrix().size(); i++) {
303
			mtsPixelLevel = tileMatrixSet.getTileMatrix().get(i).getScaleDenominator();
304
			if(clipDecimals(mtsPixelRequest, 6) >= clipDecimals(mtsPixelLevel, 6) || 
305
			   (!levelAssigned && i == (tileMatrixSet.getTileMatrix().size() - 1))) {
306
				level = Math.max(i, 0);
307
				if(increaseResolution)
308
					level ++;
309
				
310
				//Se ajusta al m?ximo nivel disponible para esa capa
311
				if(level > (limits.size() - 1)) {
312
					level = limits.size() - 1;
313
				}
314
				
315
				mtsPixelLevel = tileMatrixSet.getTileMatrix().get(level).getScaleDenominator();
316
				
317
				tilePxWidth = tileMatrixSet.getTileMatrix().get(level).getTileWidth();
318
				tilePxHeight = tileMatrixSet.getTileMatrix().get(level).getTileHeight();
319
				
320
				tileWCWidth = tilePxWidth * mtsPixelLevel;
321
				tileWCHeight = tilePxHeight * mtsPixelLevel;
322
				levelAssigned = true;
323
				break;
324
			}
325
		}
326
		
327
		//Calculo del rectangulo de tiles
328
		int minTileCol = (int)((Math.abs(ul.getX() - worldExtent.getMinX()) / mtsPixelLevel) / tilePxWidth);
329
		int minTileRow = (int)((Math.abs(ul.getY() - worldExtent.getMaxY()) / mtsPixelLevel) / tilePxHeight);
330
		double maxTC = ((Math.abs(lr.getX() - worldExtent.getMinX()) / mtsPixelLevel) / tilePxWidth);
331
		double maxTR = ((Math.abs(lr.getY() - worldExtent.getMaxY()) / mtsPixelLevel) / tilePxHeight);
332
		int maxTileCol = ((maxTC - ((int)maxTC)) == 0) ? (int)(maxTC - 1) : (int)maxTC;
333
		int maxTileRow = ((maxTR - ((int)maxTR)) == 0) ? (int)(maxTR - 1) : (int)maxTR;
334
		
335
		//Calculo de tiles con sus coordenadas
336
		List<Tile> tileList = new ArrayList<Tile>();
337
		for (int i = minTileRow; i <= maxTileRow; i++) {
338
			for (int j = minTileCol; j <= maxTileCol; j++) {
339
				Point2D ulTile = new Point2D.Double(
340
						worldExtent.getMinX() + (tileWCWidth * j),
341
						worldExtent.getMaxY() - (tileWCHeight * i));
342
				Point2D lrTile = new Point2D.Double(ulTile.getX() + tileWCWidth, ulTile.getY() - tileWCHeight);
343
				Tile t = new TileImpl(tilePxWidth, tilePxHeight, i, j, ulTile, lrTile);
344
				t.setLevel(level);
345
				tileList.add(t);
346
			}
347
		}
348
		return tileList;
349
	}
350
	
351
	public boolean compare(CacheStruct struct) {
352
		//Compara: n?mero de niveles, tama?o de tile, 
353
		//anchoXalto de la matriz, tama?o de pixel por nivel, 
354
		//coordenadas de al menos un tile de la matriz
355
		if(struct.getNumberOfLevels() == getNumberOfLevels()) {
356
			for (int i = 0; i < getNumberOfLevels(); i++) {
357
				if(	struct.getTileSizeByLevel(i)[0] == getTileSizeByLevel(i)[0] && 
358
					struct.getTileSizeByLevel(i)[1] == getTileSizeByLevel(i)[1] &&
359
					struct.getWorldHeightOfTileMatrixByLevel(i) == getWorldHeightOfTileMatrixByLevel(i) &&
360
					struct.getWorldWidthOfTileMatrixByLevel(i) == getWorldWidthOfTileMatrixByLevel(i) &&
361
					clipDecimals(struct.getPixelSizeByLevel(i), 2) == clipDecimals(getPixelSizeByLevel(i), 2) &&
362
					compareExtents(struct.getTileExtent(i, 0, 0), getTileExtent(i, 0, 0))) {
363
					return true;
364
				}
365
			}
366
		}
367
		return false;
368
	}
369
	
370
	public String getEPSG() {
371
		return epsg;
372
	}
373

  
374
	public String getFileSize() {
375
		return fileSize + "";
376
	}
377
	
378
	private boolean compareExtents(Point2D[] p, Point2D[] p1) {
379
		return (p[0].getX() == p1[0].getX() && p[0].getY() == p1[0].getY() &&
380
				p[1].getX() == p1[1].getX() && p[1].getY() == p1[1].getY());
381
	}
382
	
383
	public double clipDecimals(double num, int n) {
384
		long m = (long) Math.pow(10, n);
385
		long aux = Math.round(num * m);
386
		return (double) aux / (double) m;
387
	}
388

  
389
}
0 390

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/provider/TileMatrixSet.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.raster.cache.tile.impl.provider;
23

  
24
import java.awt.geom.Rectangle2D;
25
import java.io.IOException;
26
import java.util.ArrayList;
27

  
28
import org.kxml2.io.KXmlParser;
29
import org.xmlpull.v1.XmlPullParserException;
30

  
31

  
32
/**
33
 * <p>Defines a set of tiles</p>
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 */
36
public class TileMatrixSet {
37
    protected Rectangle2D                 bbox                = null;
38
    private String                        supportedCRS        = null;
39
    protected ArrayList<TileMatrix>       tileMatrix          = null;
40
    
41
	public void setBbox(Rectangle2D bbox) {
42
		this.bbox = bbox;
43
	}
44
	
45
    public Rectangle2D getBoundingBox() {
46
    	return bbox;
47
    }
48
	
49
	public ArrayList<TileMatrix> getTileMatrix() {
50
		if(tileMatrix == null)
51
			tileMatrix = new ArrayList<TileMatrix>();
52
		return tileMatrix;
53
	}
54

  
55
	public String getSupportedCRS() {
56
		return supportedCRS;
57
	}
58

  
59
	public void setSupportedCRS(String supportedCRS) {
60
		this.supportedCRS = supportedCRS;
61
	}
62
	
63
	public void parse(KXmlParser parser) throws IOException,
64
			XmlPullParserException {
65
	}
66
	
67
	public void print() {
68
		System.out.println("*****TileMatrixSet******");
69
		if(bbox != null)
70
			System.out.println(bbox.toString());
71
		System.out.println("supportedCRS:" + getSupportedCRS());
72
		for (int i = 0; i < tileMatrix.size(); i++) {
73
			((TileMatrix)tileMatrix.get(i)).print();	
74
		}
75
		
76
	}
77
}
0 78

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.49/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/layer/TiledLayerImpl.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.raster.cache.tile.impl.layer;
23

  
24
import java.io.File;
25
import java.security.MessageDigest;
26
import java.security.NoSuchAlgorithmException;
27
import java.util.List;
28

  
29
import org.gvsig.raster.cache.tile.Tile;
30
import org.gvsig.raster.cache.tile.disk.ITileFileSystemStrategy;
31
import org.gvsig.raster.cache.tile.exception.TileGettingException;
32
import org.gvsig.raster.cache.tile.impl.TileCacheImpl;
33
import org.gvsig.raster.cache.tile.impl.TileImpl;
34
import org.gvsig.raster.cache.tile.impl.pool.ThreadPoolImpl;
35
import org.gvsig.raster.cache.tile.layer.TiledLayer;
36
import org.gvsig.raster.cache.tile.provider.CacheStruct;
37
import org.gvsig.raster.cache.tile.provider.TileListener;
38
import org.gvsig.raster.cache.tile.provider.TileServer;
39
import org.gvsig.tools.task.TaskStatus;
40

  
41
/**
42
 * Main implementation for the tile cache
43
 *
44
 * @author Nacho Brodin (nachobrodin@gmail.com)
45
 */
46
public class TiledLayerImpl implements TiledLayer {
47
	private TileServer                  provider          = null;
48
	private TileCacheImpl               tileCache         = null;
49
	private String                      basePath          = null;
50
	private String                      pathToDirLayer    = null;
51
	private String                      idLayer           = null;
52
	//private LRUTileCache                memoryCache = null;
53
	private ThreadPoolImpl              pool              = null;
54
	private ITileFileSystemStrategy     strategy          = null;
55
	private TimerOneTile                timerOneTile      = null;
56
	private TimerTilePool               timerTilePool     = null;
57
	
58
	public TiledLayerImpl(TileCacheImpl tileCache, 
59
			TileServer provider, 
60
			ITileFileSystemStrategy strategy
61
			/*LRUTileCache memCache*/) {
62
		this.tileCache = tileCache;
63
		this.provider = provider;
64
		this.basePath = tileCache.getBaseDirectory();
65
		//this.memoryCache = memCache;
66
		this.strategy = strategy;
67
	}
68
	
69
	/**
70
	 * Gets the timer of one tile
71
	 * @return
72
	 */
73
	private TimerOneTile getTimerOneTile() {
74
		if(timerOneTile == null)
75
			timerOneTile = new TimerOneTile();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff