Revision 4306
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.16/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
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 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.raster.multifile</artifactId> |
|
5 |
<packaging>pom</packaging> |
|
6 |
<version>2.2.16</version> |
|
7 |
<name>Raster multifile support for gvSIG</name> |
|
8 |
<description>Raster multifile support for gvSIG</description> |
|
9 |
<inceptionYear>2013</inceptionYear> |
|
10 |
<parent> |
|
11 |
<groupId>org.gvsig</groupId> |
|
12 |
<artifactId>org.gvsig.desktop</artifactId> |
|
13 |
<version>2.0.115</version> |
|
14 |
</parent> |
|
15 |
<properties> |
|
16 |
<!-- El plugin versions:use-latest-versions falla con scope import --> |
|
17 |
<!-- asi que toca usar el versions:update-properties que si que funciona --> |
|
18 |
<org.gvsig.raster.version>2.2.26</org.gvsig.raster.version> |
|
19 |
</properties> |
|
20 |
|
|
21 |
<repositories> |
|
22 |
<repository> |
|
23 |
<id>gvsig-public-http-repository</id> |
|
24 |
<name>gvSIG maven public HTTP repository</name> |
|
25 |
<url>http://devel.gvsig.org/m2repo/j2se</url> |
|
26 |
<releases> |
|
27 |
<enabled>true</enabled> |
|
28 |
<updatePolicy>daily</updatePolicy> |
|
29 |
<checksumPolicy>warn</checksumPolicy> |
|
30 |
</releases> |
|
31 |
<snapshots> |
|
32 |
<enabled>true</enabled> |
|
33 |
<updatePolicy>daily</updatePolicy> |
|
34 |
<checksumPolicy>warn</checksumPolicy> |
|
35 |
</snapshots> |
|
36 |
</repository> |
|
37 |
</repositories> |
|
38 |
|
|
39 |
<scm> |
|
40 |
<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.16</connection> |
|
41 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.16</developerConnection> |
|
42 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.16</url> |
|
43 |
</scm> |
|
44 |
|
|
45 |
<developers> |
|
46 |
<developer> |
|
47 |
<id>nbrodin</id> |
|
48 |
<name>Nacho Brodin</name> |
|
49 |
<email>nachobrodin@gmail.com</email> |
|
50 |
<roles> |
|
51 |
<role>Architect</role> |
|
52 |
<role>Developer</role> |
|
53 |
</roles> |
|
54 |
</developer> |
|
55 |
</developers> |
|
56 |
|
|
57 |
<dependencyManagement> |
|
58 |
<dependencies> |
|
59 |
<dependency> |
|
60 |
<groupId>org.gvsig</groupId> |
|
61 |
<artifactId>org.gvsig.raster</artifactId> |
|
62 |
<version>${org.gvsig.raster.version}</version> |
|
63 |
<type>pom</type> |
|
64 |
<scope>import</scope> |
|
65 |
</dependency> |
|
66 |
|
|
67 |
<dependency> |
|
68 |
<groupId>org.gvsig</groupId> |
|
69 |
<artifactId>org.gvsig.raster.multifile.io</artifactId> |
|
70 |
<version>2.2.16</version> |
|
71 |
</dependency> |
|
72 |
|
|
73 |
</dependencies> |
|
74 |
</dependencyManagement> |
|
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.multifile/tags/</tagBase> |
|
82 |
<goals>deploy</goals> |
|
83 |
</configuration> |
|
84 |
</plugin> |
|
85 |
</plugins> |
|
86 |
</build> |
|
87 |
|
|
88 |
<modules> |
|
89 |
<module>org.gvsig.raster.multifile.io</module> |
|
90 |
<module>org.gvsig.raster.multifile.app.multifileclient</module> |
|
91 |
</modules> |
|
92 |
|
|
93 |
</project> |
|
0 | 94 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.16/org.gvsig.raster.multifile.io/src/main/java/org/gvsig/raster/multifile/io/DefaultMultiFileIOLibrary.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.multifile.io; |
|
23 |
|
|
24 |
import org.gvsig.fmap.dal.DALFileLibrary; |
|
25 |
import org.gvsig.fmap.dal.DALLibrary; |
|
26 |
import org.gvsig.tools.ToolsLibrary; |
|
27 |
import org.gvsig.tools.library.AbstractLibrary; |
|
28 |
import org.gvsig.tools.library.Library; |
|
29 |
import org.gvsig.tools.library.LibraryException; |
|
30 |
/** |
|
31 |
* |
|
32 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
33 |
*/ |
|
34 |
public class DefaultMultiFileIOLibrary extends AbstractLibrary { |
|
35 |
|
|
36 |
@SuppressWarnings("deprecation") |
|
37 |
public DefaultMultiFileIOLibrary() { |
|
38 |
super(DefaultMultiFileIOLibrary.class,Library.TYPE.IMPL); |
|
39 |
require(ToolsLibrary.class); |
|
40 |
require(DALLibrary.class); |
|
41 |
require(DALFileLibrary.class); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
protected void doInitialize() throws LibraryException { |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void doPostInitialize() throws LibraryException { |
|
50 |
MultiFileServerExplorerParameters.registerDynClass(); |
|
51 |
MultiFileDataParametersImpl.registerDynClass(); |
|
52 |
MultiFileProvider.register(); |
|
53 |
} |
|
54 |
} |
|
0 | 55 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.16/org.gvsig.raster.multifile.io/src/main/java/org/gvsig/raster/multifile/io/MultiFileFormatSerializer.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.multifile.io; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.io.FileWriter; |
|
26 |
import java.io.IOException; |
|
27 |
import java.io.Reader; |
|
28 |
import java.io.StringReader; |
|
29 |
import java.text.ParseException; |
|
30 |
|
|
31 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
|
32 |
import org.gvsig.raster.impl.store.rmf.ClassSerializer; |
|
33 |
import org.gvsig.raster.impl.store.rmf.RmfBlocksManager; |
|
34 |
import org.kxml2.io.KXmlParser; |
|
35 |
import org.xmlpull.v1.XmlPullParserException; |
|
36 |
/** |
|
37 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
38 |
*/ |
|
39 |
public class MultiFileFormatSerializer extends ClassSerializer { |
|
40 |
//TAGS |
|
41 |
public static final String MAIN_TAG = "MultiFileFormat"; |
|
42 |
public static final String URIS = "URIs"; |
|
43 |
public static final String URI = "URI"; |
|
44 |
public static final String NAME = "Name"; |
|
45 |
private MultiFileFormat multiFileFormat = null; |
|
46 |
|
|
47 |
public MultiFileFormatSerializer(MultiFileFormat timeSeriesFormat) { |
|
48 |
this.multiFileFormat = timeSeriesFormat; |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* Parsers a date list |
|
53 |
* @param tInfo |
|
54 |
* @param parser |
|
55 |
* @param xml |
|
56 |
* @param tag |
|
57 |
* @throws XmlPullParserException |
|
58 |
* @throws IOException |
|
59 |
* @throws ParsingException |
|
60 |
* @throws NumberFormatException |
|
61 |
* @throws ParseException |
|
62 |
*/ |
|
63 |
public void parseURIs(KXmlParser parser, String xml, String parseableTag) throws XmlPullParserException, IOException, NumberFormatException, ParsingException, ParseException { |
|
64 |
boolean end = false; |
|
65 |
boolean init = false; |
|
66 |
boolean readFile = false; |
|
67 |
int tag = parser.next(); |
|
68 |
while (!end) { |
|
69 |
switch (tag) { |
|
70 |
case KXmlParser.END_DOCUMENT: |
|
71 |
return; |
|
72 |
case KXmlParser.START_TAG: |
|
73 |
if (parser.getName().compareTo(parseableTag) == 0) { |
|
74 |
init = true; |
|
75 |
} |
|
76 |
if(init) { |
|
77 |
if (parser.getName().compareTo(URI) == 0) { |
|
78 |
readFile = true; |
|
79 |
} |
|
80 |
} |
|
81 |
break; |
|
82 |
case KXmlParser.END_TAG: |
|
83 |
if (parser.getName().compareTo(parseableTag) == 0) |
|
84 |
end = true; |
|
85 |
break; |
|
86 |
case KXmlParser.TEXT: |
|
87 |
if(readFile) { |
|
88 |
String file = parser.getText(); |
|
89 |
multiFileFormat.addFile(new File(file)); |
|
90 |
readFile = false; |
|
91 |
} |
|
92 |
break; |
|
93 |
} |
|
94 |
if (!end) |
|
95 |
tag = parser.next(); |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
/* |
|
100 |
* (non-Javadoc) |
|
101 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#read(java.lang.String) |
|
102 |
*/ |
|
103 |
public void read(String xml) throws ParsingException { |
|
104 |
if(multiFileFormat == null) |
|
105 |
multiFileFormat = new MultiFileFormat(); |
|
106 |
else { |
|
107 |
multiFileFormat.clean(); |
|
108 |
} |
|
109 |
boolean init = false; |
|
110 |
boolean end = false; |
|
111 |
|
|
112 |
KXmlParser parser = new KXmlParser(); |
|
113 |
Reader reader = new StringReader(xml); |
|
114 |
try { |
|
115 |
parser.setInput(reader); |
|
116 |
} catch (XmlPullParserException e) { |
|
117 |
throw new ParsingException(xml); |
|
118 |
} |
|
119 |
try { |
|
120 |
int tag = parser.nextTag(); |
|
121 |
|
|
122 |
if ( parser.getEventType() != KXmlParser.END_DOCUMENT ){ |
|
123 |
parser.require(KXmlParser.START_TAG, null, MAIN_TAG); |
|
124 |
while(tag != KXmlParser.END_DOCUMENT) { |
|
125 |
switch(tag) { |
|
126 |
case KXmlParser.START_TAG: |
|
127 |
if (parser.getName().compareTo(MAIN_TAG) == 0) |
|
128 |
init = true; |
|
129 |
break; |
|
130 |
case KXmlParser.END_TAG: |
|
131 |
if(parser.getName().compareTo(MAIN_TAG) == 0) |
|
132 |
end = true; |
|
133 |
break; |
|
134 |
case KXmlParser.TEXT: |
|
135 |
if(init) { |
|
136 |
String name = parserString(parser, NAME, null); |
|
137 |
multiFileFormat.setName(name); |
|
138 |
parseURIs(parser, xml, URIS); |
|
139 |
init = false; |
|
140 |
} |
|
141 |
break; |
|
142 |
} |
|
143 |
if(end) |
|
144 |
break; |
|
145 |
tag = parser.next(); |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
} catch (XmlPullParserException e) { |
|
150 |
throw new ParsingException(xml); |
|
151 |
} catch (IOException e) { |
|
152 |
throw new ParsingException(xml); |
|
153 |
} catch (NumberFormatException e) { |
|
154 |
throw new ParsingException(xml); |
|
155 |
} catch (ParseException e) { |
|
156 |
throw new ParsingException(xml); |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Writes a MultiFileFormat to disk |
|
162 |
* @param multiFileFormat |
|
163 |
* @param file |
|
164 |
* @throws IOException |
|
165 |
*/ |
|
166 |
public static void write(MultiFileFormat multiFileFormat, String fileName) throws IOException { |
|
167 |
File file = new File(fileName); |
|
168 |
file.createNewFile(); |
|
169 |
FileWriter writer = new FileWriter(file); |
|
170 |
MultiFileFormatSerializer serializer = new MultiFileFormatSerializer(multiFileFormat); |
|
171 |
writer.write(serializer.write()); |
|
172 |
writer.close(); |
|
173 |
} |
|
174 |
|
|
175 |
/** |
|
176 |
* Reads a TimeSeriesFormat from disk |
|
177 |
* @param timeSeriesFormat |
|
178 |
* @param file |
|
179 |
* @throws IOException |
|
180 |
* @throws ParsingException |
|
181 |
*/ |
|
182 |
public static MultiFileFormat read(MultiFileFormat timeSeriesFormat, String file) throws IOException, ParsingException { |
|
183 |
RmfBlocksManager manager = new RmfBlocksManager(file); |
|
184 |
MultiFileFormatSerializer serializer = new MultiFileFormatSerializer(timeSeriesFormat); |
|
185 |
manager.addClient(serializer); |
|
186 |
manager.read(null); |
|
187 |
return timeSeriesFormat; |
|
188 |
} |
|
189 |
|
|
190 |
/* |
|
191 |
* (non-Javadoc) |
|
192 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#write() |
|
193 |
*/ |
|
194 |
public String write() { |
|
195 |
StringBuffer b = new StringBuffer(); |
|
196 |
b.append("<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\n"); |
|
197 |
b.append("<" + MAIN_TAG + ">\n"); |
|
198 |
putProperty(b, NAME, multiFileFormat.getName(), 2); |
|
199 |
|
|
200 |
b.append("\t\t<" + URIS + ">\n"); |
|
201 |
for (int i = 0; i < multiFileFormat.getNumberOfFiles(); i++) { |
|
202 |
putProperty(b, URI, multiFileFormat.getPathToFile(i), 3); |
|
203 |
} |
|
204 |
b.append("\t\t</" + URIS + ">\n"); |
|
205 |
b.append("</" + MAIN_TAG + ">\n"); |
|
206 |
return b.toString(); |
|
207 |
} |
|
208 |
|
|
209 |
/* |
|
210 |
* (non-Javadoc) |
|
211 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#getResult() |
|
212 |
*/ |
|
213 |
public Object getResult() { |
|
214 |
return multiFileFormat; |
|
215 |
} |
|
216 |
|
|
217 |
/* |
|
218 |
* (non-Javadoc) |
|
219 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#getMainTag() |
|
220 |
*/ |
|
221 |
public String getMainTag() { |
|
222 |
return MAIN_TAG; |
|
223 |
} |
|
224 |
} |
|
0 | 225 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.16/org.gvsig.raster.multifile.io/src/main/java/org/gvsig/raster/multifile/io/MultiFileServerExplorer.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.raster.multifile.io; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import org.gvsig.fmap.dal.DALLocator; |
|
34 |
import org.gvsig.fmap.dal.DataManager; |
|
35 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
36 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
37 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
38 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
39 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
40 |
import org.gvsig.fmap.dal.exception.CreateException; |
|
41 |
import org.gvsig.fmap.dal.exception.DataException; |
|
42 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
43 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
44 |
import org.gvsig.fmap.dal.exception.RemoveException; |
|
45 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider; |
|
46 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
|
47 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
|
48 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
|
49 |
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters; |
|
50 |
|
|
51 |
/** |
|
52 |
* Explorer for a Multifile |
|
53 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
54 |
*/ |
|
55 |
public class MultiFileServerExplorer extends AbstractFilesystemServerExplorerProvider implements DataServerExplorerProvider { |
|
56 |
|
|
57 |
public MultiFileServerExplorer() { |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
public MultiFileServerExplorer( |
|
62 |
MultiFileServerExplorerParameters parameters, |
|
63 |
DataServerExplorerProviderServices services) |
|
64 |
throws InitializeException { |
|
65 |
System.out.println(); |
|
66 |
} |
|
67 |
|
|
68 |
public String getDataStoreProviderName() { |
|
69 |
return MultiFileProvider.NAME; |
|
70 |
} |
|
71 |
|
|
72 |
public String getDescription() { |
|
73 |
return MultiFileProvider.DESCRIPTION; |
|
74 |
} |
|
75 |
|
|
76 |
public DataStoreParameters getStoreParameters() { |
|
77 |
DataManager manager = DALLocator.getDataManager(); |
|
78 |
try { |
|
79 |
return manager.createStoreParameters(this.getDataStoreProviderName()); |
|
80 |
} catch (InitializeException e) { |
|
81 |
e.printStackTrace(); |
|
82 |
} catch (ProviderNotRegisteredException e) { |
|
83 |
e.printStackTrace(); |
|
84 |
} |
|
85 |
return null; |
|
86 |
} |
|
87 |
|
|
88 |
public List<?> getDataStoreProviderNames() { |
|
89 |
return null; |
|
90 |
} |
|
91 |
|
|
92 |
public String getProviderName() { |
|
93 |
return MultiFileProvider.NAME; |
|
94 |
} |
|
95 |
|
|
96 |
public DataServerExplorerProviderServices getServerExplorerProviderServices() { |
|
97 |
return null; |
|
98 |
} |
|
99 |
|
|
100 |
public boolean canCreate() { |
|
101 |
return false; |
|
102 |
} |
|
103 |
|
|
104 |
public boolean canCreate(NewDataStoreParameters parameters) { |
|
105 |
return false; |
|
106 |
} |
|
107 |
|
|
108 |
public void create(NewDataStoreParameters parameters, boolean overwrite) |
|
109 |
throws CreateException { |
|
110 |
throw new UnsupportedOperationException(); |
|
111 |
} |
|
112 |
|
|
113 |
public NewDataStoreParameters getCreateParameters() throws DataException { |
|
114 |
return null; |
|
115 |
} |
|
116 |
|
|
117 |
public void initialize( |
|
118 |
FilesystemServerExplorerProviderServices serverExplorer) { |
|
119 |
} |
|
120 |
|
|
121 |
public boolean accept(File pathname) { |
|
122 |
return RasterLocator.getManager().getProviderServices().isExtensionSupported( |
|
123 |
pathname.getAbsolutePath(), |
|
124 |
MultiFileProvider.class); |
|
125 |
} |
|
126 |
|
|
127 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
|
128 |
throw new UnsupportedOperationException(); |
|
129 |
} |
|
130 |
|
|
131 |
public boolean add(String provider, NewDataStoreParameters parameters, |
|
132 |
boolean overwrite) throws DataException { |
|
133 |
return false; |
|
134 |
} |
|
135 |
|
|
136 |
public boolean canAdd() { |
|
137 |
return false; |
|
138 |
} |
|
139 |
|
|
140 |
public boolean canAdd(String storeName) throws DataException { |
|
141 |
return false; |
|
142 |
} |
|
143 |
|
|
144 |
public NewDataStoreParameters getAddParameters(String storeName) |
|
145 |
throws DataException { |
|
146 |
return null; |
|
147 |
} |
|
148 |
|
|
149 |
public DataStoreParameters getParameters(File file) throws DataException { |
|
150 |
DataManager manager = DALLocator.getDataManager(); |
|
151 |
AbstractRasterFileDataParameters params = (AbstractRasterFileDataParameters) manager |
|
152 |
.createStoreParameters(this.getDataStoreProviderName()); |
|
153 |
params.setFile(file); |
|
154 |
return params; |
|
155 |
} |
|
156 |
|
|
157 |
public DataServerExplorerParameters getParameters() { |
|
158 |
return null; |
|
159 |
} |
|
160 |
|
|
161 |
public List<?> list() throws DataException { |
|
162 |
return null; |
|
163 |
} |
|
164 |
|
|
165 |
public List<?> list(int mode) throws DataException { |
|
166 |
return null; |
|
167 |
} |
|
168 |
|
|
169 |
public void dispose() { |
|
170 |
} |
|
171 |
|
|
172 |
public int getMode() { |
|
173 |
return DataServerExplorer.MODE_RASTER; |
|
174 |
} |
|
175 |
|
|
176 |
} |
|
0 | 177 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.16/org.gvsig.raster.multifile.io/src/main/java/org/gvsig/raster/multifile/io/MultiFileFormat.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.multifile.io; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.io.IOException; |
|
26 |
import java.util.ArrayList; |
|
27 |
|
|
28 |
/** |
|
29 |
* MultiFileFormat information |
|
30 |
* |
|
31 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
32 |
*/ |
|
33 |
public class MultiFileFormat { |
|
34 |
public ArrayList<File> fileList = new ArrayList<File>(); |
|
35 |
private String name = null; |
|
36 |
|
|
37 |
/** |
|
38 |
* Gets the name of this serial |
|
39 |
* @return |
|
40 |
*/ |
|
41 |
public String getName() { |
|
42 |
return name; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Sets the name of this serie |
|
47 |
* @param name |
|
48 |
*/ |
|
49 |
public void setName(String name) { |
|
50 |
this.name = name; |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* Gets the number of files of this serial |
|
55 |
* @return |
|
56 |
*/ |
|
57 |
public int getNumberOfFiles() { |
|
58 |
return fileList.size(); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Gets the path of the file in the selected position |
|
63 |
* @param file |
|
64 |
* @return |
|
65 |
*/ |
|
66 |
public String getPathToFile(int file) { |
|
67 |
return fileList.get(file).getAbsolutePath(); |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* Adds a file to the list |
|
72 |
* @param file |
|
73 |
*/ |
|
74 |
public void addFile(File file) { |
|
75 |
fileList.add(file); |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* Cleans the list of files |
|
80 |
*/ |
|
81 |
public void clean() { |
|
82 |
fileList.clear(); |
|
83 |
name = null; |
|
84 |
} |
|
85 |
|
|
86 |
public static String saveMultiFileFormat(String fileName, String path, ArrayList<File> uriList) throws IOException { |
|
87 |
path = path + File.separator + fileName + ".mff"; |
|
88 |
|
|
89 |
MultiFileFormat format = new MultiFileFormat(); |
|
90 |
for (int i = 0; i < uriList.size(); i++) { |
|
91 |
format.addFile(uriList.get(i)); |
|
92 |
} |
|
93 |
format.setName(fileName); |
|
94 |
|
|
95 |
format.write(path); |
|
96 |
return path; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Writes a MultiFileFormat to disk |
|
101 |
* @param file |
|
102 |
* @throws IOException |
|
103 |
*/ |
|
104 |
public void write(String fileName) throws IOException { |
|
105 |
MultiFileFormatSerializer.write(this, fileName); |
|
106 |
} |
|
107 |
} |
|
0 | 108 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.16/org.gvsig.raster.multifile.io/src/main/java/org/gvsig/raster/multifile/io/MultiFileProvider.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.multifile.io; |
|
23 |
|
|
24 |
|
|
25 |
import java.awt.geom.AffineTransform; |
|
26 |
import java.awt.geom.Point2D; |
|
27 |
import java.awt.geom.Rectangle2D; |
|
28 |
import java.io.File; |
|
29 |
import java.io.IOException; |
|
30 |
import java.net.URI; |
|
31 |
import java.net.URISyntaxException; |
|
32 |
import java.util.List; |
|
33 |
|
|
34 |
import org.slf4j.Logger; |
|
35 |
import org.slf4j.LoggerFactory; |
|
36 |
|
|
37 |
import org.gvsig.fmap.dal.DALFileLocator; |
|
38 |
import org.gvsig.fmap.dal.DALLocator; |
|
39 |
import org.gvsig.fmap.dal.DataStore; |
|
40 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
41 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
42 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
|
43 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
44 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
|
45 |
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException; |
|
46 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
|
47 |
import org.gvsig.fmap.dal.coverage.exception.FileNotSupportedException; |
|
48 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
49 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
|
50 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
51 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
|
52 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
53 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
54 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
|
55 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
56 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
|
57 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
|
58 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
|
59 |
import org.gvsig.fmap.dal.coverage.util.ProviderServices; |
|
60 |
import org.gvsig.fmap.dal.exception.CloseException; |
|
61 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
62 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
63 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
64 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
65 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
|
66 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
|
67 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
|
68 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
69 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
|
70 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
71 |
import org.gvsig.metadata.MetadataLocator; |
|
72 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
73 |
import org.gvsig.raster.impl.buffer.SpiRasterQuery; |
|
74 |
import org.gvsig.raster.impl.datastruct.BandListImpl; |
|
75 |
import org.gvsig.raster.impl.datastruct.DatasetBandImpl; |
|
76 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
|
77 |
import org.gvsig.raster.impl.provider.AbstractRasterProvider; |
|
78 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
79 |
import org.gvsig.raster.impl.provider.tile.FileTileServer; |
|
80 |
import org.gvsig.raster.impl.store.DefaultRasterStore; |
|
81 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
|
82 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
|
83 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
|
84 |
import org.gvsig.raster.impl.store.properties.MultiProviderHistogramComputer; |
|
85 |
import org.gvsig.raster.impl.store.properties.MultiProviderStatistics; |
|
86 |
import org.gvsig.tools.ToolsLocator; |
|
87 |
import org.gvsig.tools.locator.LocatorException; |
|
88 |
/** |
|
89 |
* A data provider for a multiband image readed from different files |
|
90 |
* |
|
91 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
92 |
*/ |
|
93 |
public class MultiFileProvider extends AbstractRasterProvider { |
|
94 |
public static String NAME = "Multifile Raster"; |
|
95 |
public static String DESCRIPTION = "Multifile Raster Support"; |
|
96 |
public final String METADATA_DEFINITION_NAME = NAME; |
|
97 |
private Extent viewRequest = null; |
|
98 |
private TileServer tileServer = null; |
|
99 |
private boolean open = false; |
|
100 |
|
|
101 |
private DataStoreTransparency fileTransparency = null; |
|
102 |
private static final Logger logger = LoggerFactory.getLogger(MultiFileProvider.class); |
|
103 |
protected static String[] formatList = null; |
|
104 |
|
|
105 |
public static void register() { |
|
106 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
107 |
registerFormats(); |
|
108 |
|
|
109 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
|
110 |
dataman.registerStoreProvider(NAME, |
|
111 |
MultiFileProvider.class, MultiFileDataParametersImpl.class); |
|
112 |
} |
|
113 |
|
|
114 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
|
115 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
|
116 |
NAME, DESCRIPTION, |
|
117 |
MultiFileServerExplorer.class); |
|
118 |
|
|
119 |
if (!dataman.getExplorerProviders().contains(NAME)) { |
|
120 |
dataman.registerExplorerProvider(NAME, MultiFileServerExplorer.class, MultiFileServerExplorerParameters.class); |
|
121 |
} |
|
122 |
|
|
123 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
|
124 |
} |
|
125 |
|
|
126 |
private static void registerFormats() { |
|
127 |
formatList = new String[] { |
|
128 |
"mff"}; |
|
129 |
for (int i = 0; i < formatList.length; i++) |
|
130 |
RasterLocator.getManager().getProviderServices().addFormat( |
|
131 |
formatList[i], |
|
132 |
MultiFileProvider.class); |
|
133 |
} |
|
134 |
|
|
135 |
public MultiFileProvider() { |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* Opens the dataset. |
|
140 |
* @param proj Projection |
|
141 |
* @param fName File name |
|
142 |
* @throws NotSupportedExtensionException |
|
143 |
* @deprecated use {@link #MultiFileProvider(URI)}, this constructor will be removed in gvSIG 2.5 |
|
144 |
*/ |
|
145 |
public MultiFileProvider(String params) throws NotSupportedExtensionException, OpenException { |
|
146 |
super(params); |
|
147 |
logger.info("Deprecated use of MultiFileProvider constructor"); |
|
148 |
if(params instanceof String) { |
|
149 |
MultiFileDataParameters p = new MultiFileDataParametersImpl(); |
|
150 |
URI uriObj; |
|
151 |
try { |
|
152 |
uriObj = new URI((String)params); |
|
153 |
} catch (URISyntaxException e) { |
|
154 |
throw new OpenException("Can't create uri from "+(String)params, e); |
|
155 |
} |
|
156 |
p.setURI(uriObj); |
|
157 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
|
158 |
.createDynObject( |
|
159 |
MetadataLocator.getMetadataManager().getDefinition( |
|
160 |
DataStore.METADATA_DEFINITION_NAME))); |
|
161 |
init(p, null); |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Opens the dataset. |
|
167 |
* @param proj Projection |
|
168 |
* @param fName File name |
|
169 |
* @throws NotSupportedExtensionException |
|
170 |
*/ |
|
171 |
public MultiFileProvider(URI uri) throws NotSupportedExtensionException, OpenException { |
|
172 |
super(uri); |
|
173 |
MultiFileDataParameters p = new MultiFileDataParametersImpl(); |
|
174 |
p.setURI(uri); |
|
175 |
super.init( |
|
176 |
p, |
|
177 |
null, |
|
178 |
ToolsLocator.getDynObjectManager().createDynObject( |
|
179 |
MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME))); |
|
180 |
init(p, null); |
|
181 |
} |
|
182 |
|
|
183 |
public MultiFileProvider(MultiFileDataParametersImpl params, |
|
184 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
|
185 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
|
186 |
.createDynObject( |
|
187 |
MetadataLocator.getMetadataManager().getDefinition( |
|
188 |
DataStore.METADATA_DEFINITION_NAME))); |
|
189 |
init(params, storeServices); |
|
190 |
} |
|
191 |
|
|
192 |
/** |
|
193 |
* Build file references |
|
194 |
* @param proj Projection |
|
195 |
* @param param Load parameters |
|
196 |
* @throws NotSupportedExtensionException |
|
197 |
*/ |
|
198 |
public void init(MultiFileDataParameters params, |
|
199 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
|
200 |
|
|
201 |
openFromMff(); |
|
202 |
|
|
203 |
uri = getParameters().getURI(); |
|
204 |
setParam(storeServices, params); |
|
205 |
|
|
206 |
try { |
|
207 |
setFirstProviderToNotTiled(); |
|
208 |
} catch (InvalidSourceException e1) { |
|
209 |
throw new OpenException(e1.getMessage(), e1); |
|
210 |
} |
|
211 |
|
|
212 |
super.init(); |
|
213 |
|
|
214 |
try { |
|
215 |
loadFromRmf(getRmfBlocksManager()); |
|
216 |
} catch (ParsingException e) { |
|
217 |
logger.debug("Problems reading from RMF", e); |
|
218 |
} |
|
219 |
|
|
220 |
open = true; |
|
221 |
} |
|
222 |
|
|
223 |
/** |
|
224 |
* Open from a .mff file. |
|
225 |
* This method loads all providers and adds these to the parameters |
|
226 |
* @throws OpenException |
|
227 |
*/ |
|
228 |
private void openFromMff() throws OpenException { |
|
229 |
if(getParameters().getURI() != null && new File(getParameters().getURI()).exists()) { |
|
230 |
boolean loadedProviders = true; |
|
231 |
if(getParameters().hasProviders()) { |
|
232 |
//solo se considera que est�n todos los providers cargados si existen y est�n open, |
|
233 |
//sino se leeran de disco |
|
234 |
for (int i = 0; i < getParameters().getProviders().size(); i++) { |
|
235 |
if(!getParameters().getProviders().get(i).isOpen()) |
|
236 |
loadedProviders = false; |
|
237 |
} |
|
238 |
} else |
|
239 |
loadedProviders = false; |
|
240 |
|
|
241 |
if(loadedProviders) |
|
242 |
return; |
|
243 |
|
|
244 |
try { |
|
245 |
if(getParameters().hasProviders()) |
|
246 |
getParameters().removeAllProviders(); |
|
247 |
MultiFileFormat multiFileFormat = new MultiFileFormat(); |
|
248 |
multiFileFormat = MultiFileFormatSerializer.read(multiFileFormat, getParameters().getURI().getPath()); |
|
249 |
for (int i = 0; i < multiFileFormat.getNumberOfFiles(); i++) { |
|
250 |
try { |
|
251 |
File file = new File(multiFileFormat.getPathToFile(i)); |
|
252 |
if(file.exists()) { |
|
253 |
RasterProvider prov = loadProvider(multiFileFormat.getPathToFile(i), storeServices); |
|
254 |
getParameters().addProvider(prov); |
|
255 |
} |
|
256 |
} catch (ProviderNotRegisteredException e) { |
|
257 |
throw new OpenException("A provider can't be loaded", e); |
|
258 |
} catch (InitializeException e) { |
|
259 |
throw new OpenException("A provider can't be initialized", e); |
|
260 |
} |
|
261 |
} |
|
262 |
} catch (IOException e1) { |
|
263 |
throw new OpenException("File .mff can't be read", e1); |
|
264 |
} catch (ParsingException e1) { |
|
265 |
throw new OpenException("File .mff can't be parsed", e1); |
|
266 |
} |
|
267 |
} |
|
268 |
} |
|
269 |
|
|
270 |
/** |
|
271 |
* Loads the specific provider |
|
272 |
* @param file |
|
273 |
* @return |
|
274 |
* @throws NotSupportedExtensionException |
|
275 |
* @throws FileNotSupportedException |
|
276 |
*/ |
|
277 |
@SuppressWarnings("unchecked") |
|
278 |
private RasterProvider loadProvider(String file, DataStoreProviderServices storeServices) throws ProviderNotRegisteredException, InitializeException { |
|
279 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
|
280 |
DataStoreProvider prov = null; |
|
281 |
|
|
282 |
if(file != null) { |
|
283 |
//We have to locate a provider's name which manages the selected file |
|
284 |
//A FilesystemServerExplorer will give a getProviderNames service |
|
285 |
FilesystemServerExplorerParameters paramsExplorer = (FilesystemServerExplorerParameters)dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
|
286 |
FilesystemServerExplorer serverExplorer = null; |
|
287 |
try { |
|
288 |
paramsExplorer.setRoot(File.separator); |
|
289 |
serverExplorer = (FilesystemServerExplorer)dataManager.openServerExplorer(FilesystemServerExplorer.NAME, paramsExplorer); |
|
290 |
} catch (ValidateDataParametersException e) { |
|
291 |
throw new InitializeException(e); |
|
292 |
} |
|
293 |
File f = new File(file); |
|
294 |
//Gets the list of provider's name to manage the file |
|
295 |
List<String> provName = serverExplorer.getProviderNameList(f); |
|
296 |
if(provName.size() > 0) { |
|
297 |
for (int i = 0; i < provName.size(); i++) { |
|
298 |
//Gets the first provider what is not a TileProvider |
|
299 |
if(provName.get(i).compareTo("Tile Store") != 0) { |
|
300 |
DataStoreParameters newparams = dataManager.createStoreParameters(provName.get(i)); |
|
301 |
((FilesystemStoreParameters)newparams).setFile(f); |
|
302 |
prov = dataManager.createProvider(storeServices, newparams); |
|
303 |
} |
|
304 |
} |
|
305 |
} |
|
306 |
} |
|
307 |
|
|
308 |
if(prov != null && prov instanceof RasterProvider) { |
|
309 |
if(((RasterProvider)prov).isRotated()) |
|
310 |
throw new InitializeException("Rotation not supported tiling files", new Throwable()); |
|
311 |
|
|
312 |
return (RasterProvider)prov; |
|
313 |
} |
|
314 |
|
|
315 |
return null; |
|
316 |
} |
|
317 |
|
|
318 |
/** |
|
319 |
* Checks if the new file is compatible with the old one |
|
320 |
* @param file |
|
321 |
* @return |
|
322 |
* @throws LocatorException |
|
323 |
* @throws NotSupportedExtensionException |
|
324 |
* @throws RasterDriverException |
|
325 |
* @throws CloseException |
|
326 |
*/ |
|
327 |
private boolean checkNewProvider(RasterProvider p) { |
|
328 |
Rectangle2D extentOrigin = getExtent().toRectangle2D(); |
|
329 |
|
|
330 |
Extent extentNewFile = p.getExtent(); |
|
331 |
|
|
332 |
// Comprobamos que el extent y tama�o del fichero a�adido sea igual al |
|
333 |
// fichero original. Si no es as� no abrimos la capa y mostramos un aviso |
|
334 |
|
|
335 |
double widthNewFile = (extentNewFile.getMax().getX() - extentNewFile.getMin().getX()); |
|
336 |
double heightNewFile = (extentNewFile.getMax().getY() - extentNewFile.getMin().getY()); |
|
337 |
|
|
338 |
if ((widthNewFile - extentOrigin.getWidth()) > 1.0 || (widthNewFile - extentOrigin.getWidth()) < -1.0 || (heightNewFile - extentOrigin.getHeight()) > 1.0 |
|
339 |
|| (heightNewFile - extentOrigin.getHeight()) < -1.0) { |
|
340 |
return false; |
|
341 |
} |
|
342 |
|
|
343 |
if ((extentNewFile.getMax().getX() - extentNewFile.getMin().getX()) != extentOrigin.getWidth() |
|
344 |
|| (extentNewFile.getMax().getY() - extentNewFile.getMin().getY()) != extentOrigin.getHeight()) { |
|
345 |
return false; |
|
346 |
} |
|
347 |
|
|
348 |
return true; |
|
349 |
} |
|
350 |
|
|
351 |
public MultiFileDataParameters getParameters() { |
|
352 |
try { |
|
353 |
return (MultiFileDataParameters)parameters; |
|
354 |
} catch (ClassCastException e) { |
|
355 |
return null; |
|
356 |
} |
|
357 |
} |
|
358 |
|
|
359 |
public RasterProvider load() { |
|
360 |
return this; |
|
361 |
} |
|
362 |
|
|
363 |
public int getBandCount() { |
|
364 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
365 |
int bandCount = 0; |
|
366 |
for (int i = 0; i < providerList.size(); i++) { |
|
367 |
bandCount += providerList.get(i).getBandCount(); |
|
368 |
} |
|
369 |
return bandCount; |
|
370 |
} |
|
371 |
|
|
372 |
public int[] getDataType() { |
|
373 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
374 |
int[] datatypes = new int[getBandCount()]; |
|
375 |
int k = 0; |
|
376 |
for (int i = 0; i < providerList.size(); i++) { |
|
377 |
int[] dtByProv = providerList.get(i).getDataType(); |
|
378 |
for (int j = 0; j < dtByProv.length; j++) { |
|
379 |
datatypes[k] = dtByProv[j]; |
|
380 |
k++; |
|
381 |
} |
|
382 |
} |
|
383 |
return datatypes; |
|
384 |
} |
|
385 |
|
|
386 |
public URI[] getURIByProvider() { |
|
387 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
388 |
URI[] uris = new URI[providerList.size()]; |
|
389 |
for (int i = 0; i < uris.length; i++) { |
|
390 |
uris[i] = providerList.get(i).getURIOfFirstProvider(); |
|
391 |
} |
|
392 |
return uris; |
|
393 |
} |
|
394 |
|
|
395 |
public int getBandPositionByProvider(int band) { |
|
396 |
return getSubBandByBandNumber(band)[1]; |
|
397 |
} |
|
398 |
|
|
399 |
public URI getURIOfFirstProvider() { |
|
400 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
401 |
return providerList.get(0).getURIOfFirstProvider(); |
|
402 |
} |
|
403 |
|
|
404 |
|
|
405 |
public Extent getExtent() { |
|
406 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
407 |
if(providerList != null && providerList.size() > 0) |
|
408 |
return providerList.get(0).getExtent(); |
|
409 |
return null; |
|
410 |
} |
|
411 |
|
|
412 |
public AffineTransform getAffineTransform() { |
|
413 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
414 |
return providerList.get(0).getAffineTransform(); |
|
415 |
} |
|
416 |
|
|
417 |
public void setAffineTransform(AffineTransform t) { |
|
418 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
419 |
for (int i = 0; i < providerList.size(); i++) { |
|
420 |
providerList.get(i).setAffineTransform(t); |
|
421 |
} |
|
422 |
} |
|
423 |
|
|
424 |
public int getInternalProviderCount() { |
|
425 |
return getParameters().getProviders().size(); |
|
426 |
} |
|
427 |
|
|
428 |
public RasterProvider getInternalProvider(int i) { |
|
429 |
return getParameters().getProviders().get(i); |
|
430 |
} |
|
431 |
|
|
432 |
public int[] getBandCountByProvider() { |
|
433 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
434 |
int[] bc = new int[providerList.size()]; |
|
435 |
for (int i = 0; i < bc.length; i++) { |
|
436 |
bc[i] = providerList.get(i).getBandCount(); |
|
437 |
} |
|
438 |
return bc; |
|
439 |
} |
|
440 |
|
|
441 |
public long[] getFileSizeByProvider() { |
|
442 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
443 |
long[] fs = new long[providerList.size()]; |
|
444 |
for (int i = 0; i < fs.length; i++) { |
|
445 |
fs[i] = ((AbstractRasterProvider)providerList.get(i)).getFileSize(); |
|
446 |
} |
|
447 |
return fs; |
|
448 |
} |
|
449 |
|
|
450 |
public Point2D rasterToWorld(Point2D pt) { |
|
451 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
452 |
return providerList.get(0).rasterToWorld(pt); |
|
453 |
} |
|
454 |
|
|
455 |
public Point2D worldToRaster(Point2D pt) { |
|
456 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
457 |
return providerList.get(0).worldToRaster(pt); |
|
458 |
} |
|
459 |
|
|
460 |
public boolean isInside(Point2D p){ |
|
461 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
462 |
return providerList.get(0).isInside(p); |
|
463 |
} |
|
464 |
|
|
465 |
public double getCellSize() { |
|
466 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
467 |
return providerList.get(0).getCellSize(); |
|
468 |
} |
|
469 |
|
|
470 |
public Statistics getStatistics() { |
|
471 |
if(stats == null || (stats instanceof MultiProviderStatistics && |
|
472 |
((MultiProviderStatistics)stats).getNumberOfProviders() != getParameters().getProviders().size())) { |
|
473 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
474 |
stats = new MultiProviderStatistics(providerList, this); |
|
475 |
} |
|
476 |
|
|
477 |
return stats; |
|
478 |
} |
|
479 |
|
|
480 |
public HistogramComputer getHistogramComputer() { |
|
481 |
if(histogram == null || |
|
482 |
(histogram instanceof MultiProviderHistogramComputer && |
|
483 |
((MultiProviderHistogramComputer)histogram).getNumberOfProviders() != getParameters().getProviders().size())) { |
|
484 |
histogram = new MultiProviderHistogramComputer(this); |
|
485 |
} |
|
486 |
|
|
487 |
return histogram; |
|
488 |
} |
|
489 |
|
|
490 |
/** |
|
491 |
* A multiband provider doesn't have a color table because this will have |
|
492 |
* more than one band. |
|
493 |
*/ |
|
494 |
public ColorTable getColorTable() { |
|
495 |
return null; |
|
496 |
} |
|
497 |
|
|
498 |
public boolean isOpen() { |
|
499 |
return open; |
|
500 |
} |
|
501 |
|
|
502 |
public void close() { |
|
503 |
} |
|
504 |
|
|
505 |
public URI translateURI(URI uri) { |
|
506 |
return uri; |
|
507 |
} |
|
508 |
|
|
509 |
/** |
|
510 |
* Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci�n |
|
511 |
* de la vista asignada ya que la petici�n viene en coordenadas del fichero .rmf y la vista (v) |
|
512 |
* ha de estar en coordenadas del fichero. |
|
513 |
*/ |
|
514 |
public void setView(Extent e) { |
|
515 |
viewRequest = new ExtentImpl(e); |
|
516 |
} |
|
517 |
|
|
518 |
public Extent getView() { |
|
519 |
return viewRequest; |
|
520 |
} |
|
521 |
|
|
522 |
public double getWidth() { |
|
523 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
524 |
if(providerList != null && providerList.size() > 0) { |
|
525 |
return providerList.get(0).getWidth(); |
|
526 |
} |
|
527 |
return 0; |
|
528 |
} |
|
529 |
|
|
530 |
public double getHeight() { |
|
531 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
532 |
if(providerList != null && providerList.size() > 0) { |
|
533 |
return providerList.get(0).getHeight(); |
|
534 |
} |
|
535 |
return 0; |
|
536 |
|
|
537 |
} |
|
538 |
|
|
539 |
public Object readBlock(int pos, int blockHeight, double scale) |
|
540 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException { |
|
541 |
return null; |
|
542 |
} |
|
543 |
|
|
544 |
/** |
|
545 |
* Gets a number of provider and the band of this provider |
|
546 |
* @param band |
|
547 |
* @return |
|
548 |
*/ |
|
549 |
private int[] getSubBandByBandNumber(int band) { |
|
550 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
551 |
int[] res = new int[2]; |
|
552 |
int acum = 0; |
|
553 |
for (int i = 0; i < providerList.size(); i++) { |
|
554 |
acum += providerList.get(i).getBandCount(); |
|
555 |
if(acum > band) { |
|
556 |
res[0] = i; |
|
557 |
int aux = (acum - providerList.get(i).getBandCount()); |
|
558 |
res[1] = band - aux; |
|
559 |
return res; |
|
560 |
} |
|
561 |
} |
|
562 |
return res; |
|
563 |
} |
|
564 |
|
|
565 |
@Override |
|
566 |
public void loadBuffer(SpiRasterQuery q) |
|
567 |
throws ProcessInterruptedException, RasterDriverException { |
|
568 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
569 |
|
|
570 |
for (int i = 0; i < providerList.size(); i++) { |
|
571 |
SpiRasterQuery query = (SpiRasterQuery)q.clone(); |
|
572 |
BandList bandListByFile = createBandListByProvider(q.getBandList(), providerList.get(i)); |
|
573 |
query.setBandList(bandListByFile); |
|
574 |
providerList.get(i).getDataSet(q); |
|
575 |
} |
|
576 |
|
|
577 |
/*for (int i = 0; i < providerList.size(); i++) { |
|
578 |
DefaultRasterStore store = new DefaultRasterStore(); |
|
579 |
store.setProvider(providerList.get(i)); |
|
580 |
RasterQuery query = ((DefaultRasterQuery)q).clone(); |
|
581 |
BandList bandListByFile = createBandListByProvider(q.getBandList(), providerList.get(i)); |
|
582 |
query.set |
|
583 |
try { |
|
584 |
store.query((RasterQuery)q); |
|
585 |
} catch (QueryException e) { |
|
586 |
throw new RasterDriverException("Error in query to the provider " + i, e); |
|
587 |
} |
|
588 |
}*/ |
|
589 |
} |
|
590 |
|
|
591 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
592 |
int[] sub = getSubBandByBandNumber(band); |
|
593 |
RasterProvider prov = getParameters().getProviders().get(sub[0]); |
|
594 |
return prov.getData(x, y, sub[1]); |
|
595 |
} |
|
596 |
|
|
597 |
|
|
598 |
/*public Buffer getWindow(Extent extent, BandList bandList, Buffer rasterBuf, TaskStatus status) |
|
599 |
throws ProcessInterruptedException, RasterDriverException { |
|
600 |
providerList = getParameters().getProviders(); |
|
601 |
|
|
602 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery(); |
|
603 |
q.setAreaOfInterest(extent); |
|
604 |
q.setBandList(bandList); |
|
605 |
q.setBuffer(rasterBuf); |
|
606 |
|
|
607 |
for (int i = 0; i < providerList.size(); i++) { |
|
608 |
rasterBuf = ((DefaultRasterProvider)providerList.get(i)).getDataSet(q); |
|
609 |
} |
|
610 |
return rasterBuf; |
|
611 |
}*/ |
|
612 |
|
|
613 |
/*public Buffer getWindow(double ulx, double uly, double w, double h, |
|
614 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
615 |
providerList = getParameters().getProviders(); |
|
616 |
|
|
617 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery(); |
|
618 |
q.setAreaOfInterest(ulx, uly, w, h); |
|
619 |
q.setBandList(bandList); |
|
620 |
q.setBuffer(rasterBuf); |
|
621 |
q.setAdjustToExtent(adjustToExtent); |
|
622 |
|
|
623 |
for (int i = 0; i < providerList.size(); i++) { |
|
624 |
rasterBuf = ((DefaultRasterProvider)providerList.get(i)).getDataSet(q); |
|
625 |
} |
|
626 |
return rasterBuf; |
|
627 |
}*/ |
|
628 |
|
|
629 |
/*public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, |
|
630 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
631 |
providerList = getParameters().getProviders(); |
|
632 |
|
|
633 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery(); |
|
634 |
q.setAreaOfInterest(extent, bufWidth, bufHeight); |
|
635 |
q.setBuffer(rasterBuf); |
|
636 |
q.setAdjustToExtent(adjustToExtent); |
|
637 |
|
|
638 |
for (int i = 0; i < providerList.size(); i++) { |
|
639 |
BandList bandListByFile = createBandListByProvider(bandList, providerList.get(i)); |
|
640 |
if(bandListByFile != null) { |
|
641 |
q.setBandList(bandListByFile); |
|
642 |
rasterBuf = ((DefaultRasterProvider)providerList.get(i)).getDataSet(q); |
|
643 |
} |
|
644 |
} |
|
645 |
return rasterBuf; |
|
646 |
}*/ |
|
647 |
|
|
648 |
/** |
|
649 |
* Creates a <code>BandList</code> for each provider of this <code>MultiFileProvider</code>. |
|
650 |
* When a request is made, the <code>BandList</code> is global for all files. A specific |
|
651 |
* <code>BandList</code> has to be built for each provider. |
|
652 |
* @param globalBandList |
|
653 |
* @param provider |
|
654 |
* @return |
|
655 |
*/ |
|
656 |
private BandList createBandListByProvider(BandList globalBandList, RasterProvider provider) { |
|
657 |
if(provider.isTiled()) { |
|
658 |
//Si los proveedores que hay por debajo son tileados estos crear�n su propio buffer para escribir |
|
659 |
//cada tile. Por ello no usar� el buffer que viene del store. Esto quiere decir que el BandList ha |
|
660 |
//de ser distinto para que escriba bien en su buffer |
|
661 |
|
|
662 |
//TODO: De momento no se permiten MultiFiles con proveedores tileados. Esto es porque |
|
663 |
//los tiles crean su propio buffer y no escriben en el buffer creado en el Store |
|
664 |
|
|
665 |
} else { |
|
666 |
BandList bandListByFile = new BandListImpl(); |
|
667 |
for (int i = 0; i < provider.getBandCount(); i++) { |
|
668 |
try { |
|
669 |
bandListByFile.addBand(new DatasetBandImpl(provider.getURI().getPath(), i, provider.getDataType()[0], provider.getBandCount())); |
|
670 |
} catch (BandNotFoundInListException e1) { |
|
671 |
} |
|
672 |
} |
|
673 |
|
|
674 |
boolean areThereBandsToDraw = false; |
|
675 |
for (int i = 0; i < provider.getBandCount(); i++) { |
|
676 |
int[] bandsToDrawByProviderBand = globalBandList.getBufferBandToDraw(provider.getURI().getPath(), i); |
|
677 |
if(bandsToDrawByProviderBand != null) { |
|
678 |
areThereBandsToDraw = true; |
|
679 |
for (int j = 0; j < bandsToDrawByProviderBand.length; j++) { |
|
680 |
bandListByFile.getBand(i).addPositionToDrawInBuffer(bandsToDrawByProviderBand[j]); |
|
681 |
} |
|
682 |
} |
|
683 |
} |
|
684 |
|
|
685 |
if(areThereBandsToDraw) |
|
686 |
return bandListByFile; |
|
687 |
} |
|
688 |
return null; |
|
689 |
} |
|
690 |
|
|
691 |
/*public Buffer getWindow(int x, int y, int w, int h, |
|
692 |
BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
693 |
providerList = getParameters().getProviders(); |
|
694 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery(); |
|
695 |
q.setAreaOfInterest(x, y, w, h); |
|
696 |
q.setBandList(bandList); |
|
697 |
q.setBuffer(rasterBuf); |
|
698 |
for (int i = 0; i < providerList.size(); i++) { |
|
699 |
rasterBuf = ((DefaultRasterProvider)providerList.get(i)).getDataSet(q); |
|
700 |
} |
|
701 |
return rasterBuf; |
|
702 |
}*/ |
|
703 |
|
|
704 |
public int getBlockSize() { |
|
705 |
return 0; |
|
706 |
} |
|
707 |
|
|
708 |
public ColorInterpretation getColorInterpretation() { |
|
709 |
if(super.getColorInterpretation() == null) { |
|
710 |
String[] cis = new String[getBandCount()]; |
|
711 |
for (int i = 0; i < cis.length; i++) { |
|
712 |
if(i == 0) |
|
713 |
cis[i] = ColorInterpretation.GRAY_BAND; |
|
714 |
else |
|
715 |
cis[i] = ColorInterpretation.UNDEF_BAND; |
|
716 |
} |
|
717 |
setColorInterpretation(new DataStoreColorInterpretation(cis)); |
|
718 |
} |
|
719 |
return super.getColorInterpretation(); |
|
720 |
} |
|
721 |
|
|
722 |
public DataStoreTransparency getTransparency() { |
|
723 |
if(fileTransparency == null) |
|
724 |
fileTransparency = new DataStoreTransparency(getColorInterpretation()); |
|
725 |
return fileTransparency; |
|
726 |
} |
|
727 |
|
|
728 |
/** |
|
729 |
* Informa de si el driver ha supersampleado en el �ltimo dibujado. Es el driver el que colocar� |
|
730 |
* el valor de esta variable cada vez que dibuja. |
|
731 |
* @return true si se ha supersampleado y false si no se ha hecho. |
|
732 |
*/ |
|
733 |
public boolean isSupersampling() { |
|
734 |
return false; |
|
735 |
} |
|
736 |
|
|
737 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
|
738 |
if(band >= getBandCount()) |
|
739 |
throw new BandAccessException("Wrong band"); |
|
740 |
return 0; |
|
741 |
} |
|
742 |
|
|
743 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
|
744 |
if (band >= getBandCount()) |
|
745 |
throw new BandAccessException("Wrong band"); |
|
746 |
return 0; |
|
747 |
} |
|
748 |
|
|
749 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
|
750 |
if (band >= getBandCount()) |
|
751 |
throw new BandAccessException("Wrong band"); |
|
752 |
return 0; |
|
753 |
} |
|
754 |
|
|
755 |
public boolean isMultiFile() { |
|
756 |
return true; |
|
757 |
} |
|
758 |
|
|
759 |
public boolean isOverviewsSupported() { |
|
760 |
return true; |
|
761 |
} |
|
762 |
|
|
763 |
public boolean isReproyectable() { |
|
764 |
return true; |
|
765 |
} |
|
766 |
|
|
767 |
public String getProviderName() { |
|
768 |
return NAME; |
|
769 |
} |
|
770 |
|
|
771 |
public void setStatus(RasterProvider provider) { |
|
772 |
if(provider instanceof MultiFileProvider) { |
|
773 |
//Not implemented yet |
|
774 |
} |
|
775 |
} |
|
776 |
|
|
777 |
public boolean isTimeSupported() { |
|
778 |
return true; |
|
779 |
} |
|
780 |
|
|
781 |
public URI getURIByBand(int band) { |
|
782 |
int[] sub = getSubBandByBandNumber(band); |
|
783 |
RasterProvider prov = getParameters().getProviders().get(sub[0]); |
|
784 |
return prov.getURIOfFirstProvider(); |
|
785 |
} |
|
786 |
|
|
787 |
public void addFile(String file) throws InvalidSourceException { |
Also available in: Unified diff