Revision 21357
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.228/org.gvsig.raster.multifile.io/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/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.raster.multifile.io</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>org.gvsig.raster.multifile.io</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.raster.multifile</artifactId> |
|
10 |
<version>2.2.228</version> |
|
11 |
</parent> |
|
12 |
<dependencies> |
|
13 |
<dependency> |
|
14 |
<groupId>org.gvsig</groupId> |
|
15 |
<artifactId>org.gvsig.raster.lib.api</artifactId> |
|
16 |
<scope>compile</scope> |
|
17 |
</dependency> |
|
18 |
<dependency> |
|
19 |
<groupId>org.gvsig</groupId> |
|
20 |
<artifactId>org.gvsig.raster.lib.impl</artifactId> |
|
21 |
<scope>compile</scope> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>org.gvsig</groupId> |
|
25 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
|
26 |
<scope>compile</scope> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>org.gvsig</groupId> |
|
30 |
<artifactId>org.gvsig.raster.cache.lib.api</artifactId> |
|
31 |
<scope>compile</scope> |
|
32 |
</dependency> |
|
33 |
<!--<dependency> |
|
34 |
<groupId>org.gvsig</groupId> |
|
35 |
<artifactId>org.gvsig.jproj</artifactId> |
|
36 |
<classifier>${native_classifier}</classifier> |
|
37 |
<type>tar.gz</type> |
|
38 |
<scope>runtime</scope> |
|
39 |
</dependency>--> |
|
40 |
<dependency> |
|
41 |
<groupId>org.gvsig</groupId> |
|
42 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
43 |
<scope>compile</scope> |
|
44 |
</dependency> |
|
45 |
|
|
46 |
|
|
47 |
<dependency> |
|
48 |
<groupId>org.gvsig</groupId> |
|
49 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
50 |
<scope>compile</scope> |
|
51 |
</dependency> |
|
52 |
<dependency> |
|
53 |
<groupId>org.gvsig</groupId> |
|
54 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
55 |
<scope>compile</scope> |
|
56 |
</dependency> |
|
57 |
<dependency> |
|
58 |
<groupId>org.gvsig</groupId> |
|
59 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
|
60 |
<scope>compile</scope> |
|
61 |
</dependency> |
|
62 |
<dependency> |
|
63 |
<groupId>org.gvsig</groupId> |
|
64 |
<artifactId>org.gvsig.fmap.dal.spi</artifactId> |
|
65 |
<scope>compile</scope> |
|
66 |
</dependency> |
|
67 |
<dependency> |
|
68 |
<groupId>org.gvsig</groupId> |
|
69 |
<artifactId>org.gvsig.projection.api</artifactId> |
|
70 |
<scope>compile</scope> |
|
71 |
</dependency> |
|
72 |
<dependency> |
|
73 |
<groupId>org.gvsig</groupId> |
|
74 |
<artifactId>org.gvsig.projection.cresques.impl</artifactId> |
|
75 |
<scope>runtime</scope> |
|
76 |
</dependency> |
|
77 |
<dependency> |
|
78 |
<groupId>org.gvsig</groupId> |
|
79 |
<artifactId>org.gvsig.compat.api</artifactId> |
|
80 |
<scope>compile</scope> |
|
81 |
</dependency> |
|
82 |
<dependency> |
|
83 |
<groupId>org.gvsig</groupId> |
|
84 |
<artifactId>org.gvsig.compat.se</artifactId> |
|
85 |
<scope>compile</scope> |
|
86 |
</dependency> |
|
87 |
<dependency> |
|
88 |
<groupId>org.gvsig</groupId> |
|
89 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
90 |
<scope>compile</scope> |
|
91 |
</dependency> |
|
92 |
<!-- |
|
93 |
<dependency> |
|
94 |
<groupId>org.gvsig</groupId> |
|
95 |
<artifactId>org.gvsig.fmap.geometry.generalpath</artifactId> |
|
96 |
<scope>runtime</scope> |
|
97 |
</dependency> |
|
98 |
<dependency> |
|
99 |
<groupId>org.gvsig</groupId> |
|
100 |
<artifactId>org.gvsig.fmap.geometry.operation</artifactId> |
|
101 |
<scope>runtime</scope> |
|
102 |
</dependency> |
|
103 |
--> |
|
104 |
</dependencies> |
|
105 |
</project> |
|
0 | 106 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.228/org.gvsig.raster.multifile.io/src/main/java/org/gvsig/raster/multifile/io/MultiFileDataParametersImpl.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.net.URI; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.List; |
|
33 |
|
|
34 |
import org.gvsig.fmap.dal.DALLocator; |
|
35 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
36 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
|
37 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
38 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
39 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
40 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
|
41 |
import org.gvsig.raster.impl.provider.AbstractRasterProvider; |
|
42 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
43 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
|
44 |
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters; |
|
45 |
import org.gvsig.raster.impl.store.DefaultRasterStore; |
|
46 |
import org.gvsig.tools.ToolsLocator; |
|
47 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
48 |
import org.gvsig.tools.dynobject.DynStruct; |
|
49 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
50 |
import org.gvsig.tools.persistence.PersistentState; |
|
51 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
52 |
|
|
53 |
/** |
|
54 |
* Parameters for the Multifile provider |
|
55 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
56 |
*/ |
|
57 |
public class MultiFileDataParametersImpl extends AbstractRasterFileDataParameters implements MultiFileDataParameters { |
|
58 |
private List<RasterProvider> providerList = null; |
|
59 |
|
|
60 |
public MultiFileDataParametersImpl() { |
|
61 |
super(); |
|
62 |
providerList = new ArrayList<RasterProvider>(); |
|
63 |
initialize(); |
|
64 |
} |
|
65 |
|
|
66 |
protected void initialize() { |
|
67 |
delegatedDynObject = (DelegatedDynObject) ToolsLocator |
|
68 |
.getDynObjectManager().createDynObject( |
|
69 |
registerDynClass()); |
|
70 |
} |
|
71 |
|
|
72 |
@SuppressWarnings("unchecked") |
|
73 |
public void loadFromState(PersistentState state) |
|
74 |
throws PersistenceException { |
|
75 |
super.loadFromState(state); |
|
76 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
|
77 |
|
|
78 |
List<RasterDataParameters> parameters = state.getList("parameters"); |
|
79 |
for (int i = 0; i < parameters.size(); i++) { |
|
80 |
try { |
|
81 |
DefaultRasterStore dSet = new DefaultRasterStore(); |
|
82 |
AbstractRasterProvider provider = (AbstractRasterProvider)dataManager.createProvider(dSet, parameters.get(i)); |
|
83 |
addProvider(provider); |
|
84 |
} catch (InitializeException e) { |
|
85 |
throw new PersistenceException(e); |
|
86 |
} catch (ProviderNotRegisteredException e) { |
|
87 |
throw new PersistenceException(e); |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
93 |
super.saveToState(state); |
|
94 |
List<RasterProvider> provList = getProviders(); |
|
95 |
List<RasterDataParameters> rasterDataParametersList = new ArrayList<RasterDataParameters>(); |
|
96 |
for (int j = 0; j < provList.size(); j++) { |
|
97 |
rasterDataParametersList.add(provList.get(j).getDataParameters()); |
|
98 |
} |
|
99 |
|
|
100 |
state.set("parameters", rasterDataParametersList); |
|
101 |
} |
|
102 |
|
|
103 |
public static DynStruct registerDynClass() { |
|
104 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
105 |
DynStruct definition = manager.getDefinition("MultiFileDataParameters_Persistent"); |
|
106 |
if( definition == null ) { |
|
107 |
definition = manager.addDefinition( |
|
108 |
MultiFileDataParametersImpl.class, |
|
109 |
"MultiFileDataParameters_Persistent", |
|
110 |
"MultiFileDataParameters Persistent", |
|
111 |
null, |
|
112 |
null |
|
113 |
); |
|
114 |
AbstractRasterDataParameters.registerDynClass(definition); |
|
115 |
} |
|
116 |
|
|
117 |
definition.addDynFieldList("parameters") |
|
118 |
.setClassOfItems(RasterDataParameters.class) |
|
119 |
.setMandatory(false); |
|
120 |
|
|
121 |
return definition; |
|
122 |
} |
|
123 |
|
|
124 |
public void removeAllProviders() { |
|
125 |
getProviders().clear(); |
|
126 |
getParams().clear(); |
|
127 |
} |
|
128 |
|
|
129 |
public boolean hasProviders() { |
|
130 |
return getProviders().size() > 0; |
|
131 |
} |
|
132 |
|
|
133 |
public void removeProvider(URI uri) { |
|
134 |
if(getProviders() != null) { |
|
135 |
List<RasterProvider> provList = getProviders(); |
|
136 |
List<RasterDataParameters> paramList = getParams(); |
|
137 |
for (int i = 0; i < provList.size(); i++) { |
|
138 |
RasterProvider rProv = provList.get(i); |
|
139 |
if(rProv.getURIOfFirstProvider().compareTo(uri) == 0) { |
|
140 |
provList.remove(i); |
|
141 |
paramList.remove(i); |
|
142 |
return; |
|
143 |
} |
|
144 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
public void addProviderNotTiled(DataStoreProvider provider) { |
|
149 |
if(provider instanceof RasterProvider) { |
|
150 |
RasterProvider prov = (RasterProvider)provider; |
|
151 |
if(!prov.isTiled()) { |
|
152 |
addToList(prov); |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
public void setFirstProvider(DataStoreProvider provider) { |
|
158 |
if(provider instanceof RasterProvider) { |
|
159 |
RasterProvider prov = (RasterProvider)provider; |
|
160 |
if(getProviders() != null) { |
|
161 |
getProviders().set(0, prov); |
|
162 |
getParams().set(0, prov.getDataParameters()); |
|
163 |
} |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
public void addProvider(DataStoreProvider provider) { |
|
168 |
if(provider instanceof RasterProvider) { |
|
169 |
RasterProvider prov = (RasterProvider)provider; |
|
170 |
addToList(prov); |
|
171 |
} |
|
172 |
} |
|
173 |
|
|
174 |
public void addProvider(RasterDataStore rasterDataStore) { |
|
175 |
if(rasterDataStore instanceof DefaultRasterStore) { |
|
176 |
RasterProvider prov = (RasterProvider)((DefaultRasterStore)rasterDataStore).getProvider(); |
|
177 |
addToList(prov); |
|
178 |
} |
|
179 |
} |
|
180 |
|
|
181 |
private void addToList(RasterProvider prov) { |
|
182 |
addProviderToList(prov); |
|
183 |
addParamToList(prov); |
|
184 |
} |
|
185 |
|
|
186 |
@SuppressWarnings("unchecked") |
|
187 |
private List<RasterDataParameters> getParams() { |
|
188 |
return (List<RasterDataParameters>)getDynValue("parameters"); |
|
189 |
} |
|
190 |
|
|
191 |
private void addParamToList(RasterProvider prov) { |
|
192 |
List<RasterDataParameters> paramList = getParams(); |
|
193 |
if(paramList == null) { |
|
194 |
paramList = new ArrayList<RasterDataParameters>(); |
|
195 |
paramList.add(prov.getDataParameters()); |
|
196 |
setDynValue("parameters", paramList); |
|
197 |
} else { |
|
198 |
paramList.add(prov.getDataParameters()); |
|
199 |
} |
|
200 |
} |
|
201 |
|
|
202 |
public List<RasterProvider> getProviders() { |
|
203 |
return this.providerList; |
|
204 |
} |
|
205 |
|
|
206 |
private void addProviderToList(RasterProvider prov) { |
|
207 |
List<RasterProvider> provList = getProviders(); |
|
208 |
if(provList == null) { |
|
209 |
provList = new ArrayList<RasterProvider>(); |
|
210 |
provList.add(prov); |
|
211 |
setDynValue("parameters", provList); |
|
212 |
} else { |
|
213 |
provList.add(prov); |
|
214 |
} |
|
215 |
} |
|
216 |
|
|
217 |
|
|
218 |
public void setProviders(ArrayList<RasterProvider> provList) { |
|
219 |
List<RasterDataParameters> paramsList = new ArrayList<RasterDataParameters>(); |
|
220 |
for (int i = 0; i < provList.size(); i++) { |
|
221 |
paramsList.add(provList.get(i).getDataParameters()); |
|
222 |
} |
|
223 |
setDynValue("parameters", paramsList); |
|
224 |
providerList = provList; |
|
225 |
} |
|
226 |
|
|
227 |
public String getDataStoreName() { |
|
228 |
return MultiFileProvider.NAME; |
|
229 |
} |
|
230 |
|
|
231 |
public String getDescription() { |
|
232 |
return MultiFileProvider.DESCRIPTION; |
|
233 |
} |
|
234 |
|
|
235 |
} |
|
0 | 236 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.228/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.228/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 |
/** |
|
48 |
* @param timeSeriesFormat |
|
49 |
*/ |
|
50 |
public MultiFileFormatSerializer(MultiFileFormat timeSeriesFormat) { |
|
51 |
this.multiFileFormat = timeSeriesFormat; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Parsers a date list |
|
56 |
* @param tInfo |
|
57 |
* @param parser |
|
58 |
* @param xml |
|
59 |
* @param parseableTag |
|
60 |
* @param tag |
|
61 |
* @throws XmlPullParserException |
|
62 |
* @throws IOException |
|
63 |
* @throws ParsingException |
|
64 |
* @throws NumberFormatException |
|
65 |
* @throws ParseException |
|
66 |
*/ |
|
67 |
public void parseURIs(KXmlParser parser, String xml, String parseableTag) throws XmlPullParserException, IOException, NumberFormatException, ParsingException, ParseException { |
|
68 |
boolean end = false; |
|
69 |
boolean init = false; |
|
70 |
boolean readFile = false; |
|
71 |
int tag = parser.next(); |
|
72 |
while (!end) { |
|
73 |
switch (tag) { |
|
74 |
case KXmlParser.END_DOCUMENT: |
|
75 |
return; |
|
76 |
case KXmlParser.START_TAG: |
|
77 |
if (parser.getName().compareTo(parseableTag) == 0) { |
|
78 |
init = true; |
|
79 |
} |
|
80 |
if(init) { |
|
81 |
if (parser.getName().compareTo(URI) == 0) { |
|
82 |
readFile = true; |
|
83 |
} |
|
84 |
} |
|
85 |
break; |
|
86 |
case KXmlParser.END_TAG: |
|
87 |
if (parser.getName().compareTo(parseableTag) == 0) |
|
88 |
end = true; |
|
89 |
break; |
|
90 |
case KXmlParser.TEXT: |
|
91 |
if(readFile) { |
|
92 |
String file = parser.getText(); |
|
93 |
multiFileFormat.addFile(new File(file)); |
|
94 |
readFile = false; |
|
95 |
} |
|
96 |
break; |
|
97 |
} |
|
98 |
if (!end) |
|
99 |
tag = parser.next(); |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
/* |
|
104 |
* (non-Javadoc) |
|
105 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#read(java.lang.String) |
|
106 |
*/ |
|
107 |
public void read(String xml) throws ParsingException { |
|
108 |
if(multiFileFormat == null) |
|
109 |
multiFileFormat = new MultiFileFormat(); |
|
110 |
else { |
|
111 |
multiFileFormat.clean(); |
|
112 |
} |
|
113 |
boolean init = false; |
|
114 |
boolean end = false; |
|
115 |
|
|
116 |
KXmlParser parser = new KXmlParser(); |
|
117 |
Reader reader = new StringReader(xml); |
|
118 |
try { |
|
119 |
parser.setInput(reader); |
|
120 |
} catch (XmlPullParserException e) { |
|
121 |
throw new ParsingException(xml); |
|
122 |
} |
|
123 |
try { |
|
124 |
int tag = parser.nextTag(); |
|
125 |
|
|
126 |
if ( parser.getEventType() != KXmlParser.END_DOCUMENT ){ |
|
127 |
parser.require(KXmlParser.START_TAG, null, MAIN_TAG); |
|
128 |
while(tag != KXmlParser.END_DOCUMENT) { |
|
129 |
switch(tag) { |
|
130 |
case KXmlParser.START_TAG: |
|
131 |
if (parser.getName().compareTo(MAIN_TAG) == 0) |
|
132 |
init = true; |
|
133 |
break; |
|
134 |
case KXmlParser.END_TAG: |
|
135 |
if(parser.getName().compareTo(MAIN_TAG) == 0) |
|
136 |
end = true; |
|
137 |
break; |
|
138 |
case KXmlParser.TEXT: |
|
139 |
if(init) { |
|
140 |
String name = parserString(parser, NAME, null); |
|
141 |
multiFileFormat.setName(name); |
|
142 |
parseURIs(parser, xml, URIS); |
|
143 |
init = false; |
|
144 |
} |
|
145 |
break; |
|
146 |
} |
|
147 |
if(end) |
|
148 |
break; |
|
149 |
tag = parser.next(); |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
} catch (XmlPullParserException e) { |
|
154 |
throw new ParsingException(xml); |
|
155 |
} catch (IOException e) { |
|
156 |
throw new ParsingException(xml); |
|
157 |
} catch (NumberFormatException e) { |
|
158 |
throw new ParsingException(xml); |
|
159 |
} catch (ParseException e) { |
|
160 |
throw new ParsingException(xml); |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* Writes a MultiFileFormat to disk |
|
166 |
* @param multiFileFormat |
|
167 |
* @param fileName |
|
168 |
* @param file |
|
169 |
* @throws IOException |
|
170 |
*/ |
|
171 |
public static void write(MultiFileFormat multiFileFormat, String fileName) throws IOException { |
|
172 |
File file = new File(fileName); |
|
173 |
file.createNewFile(); |
|
174 |
FileWriter writer = new FileWriter(file); |
|
175 |
MultiFileFormatSerializer serializer = new MultiFileFormatSerializer(multiFileFormat); |
|
176 |
writer.write(serializer.write()); |
|
177 |
writer.close(); |
|
178 |
} |
|
179 |
|
|
180 |
/** |
|
181 |
* Reads a TimeSeriesFormat from disk |
|
182 |
* @param timeSeriesFormat |
|
183 |
* @param file |
|
184 |
* @return MultiFileFormat |
|
185 |
* @throws IOException |
|
186 |
* @throws ParsingException |
|
187 |
*/ |
|
188 |
public static MultiFileFormat read(MultiFileFormat timeSeriesFormat, String file) throws IOException, ParsingException { |
|
189 |
RmfBlocksManager manager = new RmfBlocksManager(file); |
|
190 |
MultiFileFormatSerializer serializer = new MultiFileFormatSerializer(timeSeriesFormat); |
|
191 |
manager.addClient(serializer); |
|
192 |
manager.read(null); |
|
193 |
return timeSeriesFormat; |
|
194 |
} |
|
195 |
|
|
196 |
/* |
|
197 |
* (non-Javadoc) |
|
198 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#write() |
|
199 |
*/ |
|
200 |
public String write() { |
|
201 |
StringBuffer b = new StringBuffer(); |
|
202 |
b.append("<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\n"); |
|
203 |
b.append("<" + MAIN_TAG + ">\n"); |
|
204 |
putProperty(b, NAME, multiFileFormat.getName(), 2); |
|
205 |
|
|
206 |
b.append("\t\t<" + URIS + ">\n"); |
|
207 |
for (int i = 0; i < multiFileFormat.getNumberOfFiles(); i++) { |
|
208 |
putProperty(b, URI, multiFileFormat.getPathToFile(i), 3); |
|
209 |
} |
|
210 |
b.append("\t\t</" + URIS + ">\n"); |
|
211 |
b.append("</" + MAIN_TAG + ">\n"); |
|
212 |
return b.toString(); |
|
213 |
} |
|
214 |
|
|
215 |
/* |
|
216 |
* (non-Javadoc) |
|
217 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#getResult() |
|
218 |
*/ |
|
219 |
public Object getResult() { |
|
220 |
return multiFileFormat; |
|
221 |
} |
|
222 |
|
|
223 |
/* |
|
224 |
* (non-Javadoc) |
|
225 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#getMainTag() |
|
226 |
*/ |
|
227 |
public String getMainTag() { |
|
228 |
return MAIN_TAG; |
|
229 |
} |
|
230 |
} |
|
0 | 231 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.228/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 |
package org.gvsig.raster.multifile.io; |
|
24 |
|
|
25 |
import java.util.List; |
|
26 |
|
|
27 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
28 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
29 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
30 |
import org.gvsig.fmap.dal.exception.DataException; |
|
31 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
32 |
import org.gvsig.fmap.dal.exception.RemoveException; |
|
33 |
import org.gvsig.fmap.dal.spi.AbstractDataServerExplorer; |
|
34 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
|
35 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
|
36 |
|
|
37 |
/** |
|
38 |
* Explorer for a Multifile |
|
39 |
*/ |
|
40 |
public class MultiFileServerExplorer extends AbstractDataServerExplorer implements DataServerExplorerProvider { |
|
41 |
|
|
42 |
/** |
|
43 |
* |
|
44 |
*/ |
|
45 |
public MultiFileServerExplorer() { |
|
46 |
super(null, null); |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* @param parameters |
|
51 |
* @param services |
|
52 |
* @throws InitializeException |
|
53 |
*/ |
|
54 |
public MultiFileServerExplorer( |
|
55 |
MultiFileServerExplorerParameters parameters, |
|
56 |
DataServerExplorerProviderServices services) |
|
57 |
throws InitializeException { |
|
58 |
super(parameters, services); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public DataStoreParameters get(String string) throws DataException { |
|
63 |
return null; |
|
64 |
} |
|
65 |
|
|
66 |
public String getDataStoreProviderName() { |
|
67 |
return MultiFileProvider.NAME; |
|
68 |
} |
|
69 |
|
|
70 |
public String getDescription() { |
|
71 |
return MultiFileProvider.DESCRIPTION; |
|
72 |
} |
|
73 |
|
|
74 |
public List<String> getDataStoreProviderNames() { |
|
75 |
return null; |
|
76 |
} |
|
77 |
|
|
78 |
public String getProviderName() { |
|
79 |
return MultiFileProvider.NAME; |
|
80 |
} |
|
81 |
|
|
82 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
|
83 |
throw new UnsupportedOperationException(); |
|
84 |
} |
|
85 |
|
|
86 |
public boolean add(String provider, NewDataStoreParameters parameters, |
|
87 |
boolean overwrite) throws DataException { |
|
88 |
return false; |
|
89 |
} |
|
90 |
|
|
91 |
public boolean canAdd() { |
|
92 |
return false; |
|
93 |
} |
|
94 |
|
|
95 |
public boolean canAdd(String storeName) throws DataException { |
|
96 |
return false; |
|
97 |
} |
|
98 |
|
|
99 |
public NewDataStoreParameters getAddParameters(String storeName) |
|
100 |
throws DataException { |
|
101 |
return null; |
|
102 |
} |
|
103 |
|
|
104 |
public List<DataStoreParameters> list() throws DataException { |
|
105 |
return null; |
|
106 |
} |
|
107 |
|
|
108 |
public List<DataStoreParameters> list(int mode) throws DataException { |
|
109 |
return null; |
|
110 |
} |
|
111 |
|
|
112 |
public int getMode() { |
|
113 |
return DataServerExplorer.MODE_RASTER; |
|
114 |
} |
|
115 |
|
|
116 |
|
|
117 |
} |
|
0 | 118 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.228/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 String |
|
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 int |
|
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 String |
|
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 |
/** |
|
87 |
* @param fileName |
|
88 |
* @param path |
|
89 |
* @param uriList |
|
90 |
* @return String |
|
91 |
* @throws IOException |
|
92 |
*/ |
|
93 |
public static String saveMultiFileFormat(String fileName, String path, ArrayList<File> uriList) throws IOException { |
|
94 |
path = path + File.separator + fileName + ".mff"; |
|
95 |
|
|
96 |
MultiFileFormat format = new MultiFileFormat(); |
|
97 |
for (int i = 0; i < uriList.size(); i++) { |
|
98 |
format.addFile(uriList.get(i)); |
|
99 |
} |
|
100 |
format.setName(fileName); |
|
101 |
|
|
102 |
format.write(path); |
|
103 |
return path; |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* Writes a MultiFileFormat to disk |
|
108 |
* @param fileName |
|
109 |
* @param file |
|
110 |
* @throws IOException |
|
111 |
*/ |
|
112 |
public void write(String fileName) throws IOException { |
|
113 |
MultiFileFormatSerializer.write(this, fileName); |
|
114 |
} |
|
115 |
} |
|
0 | 116 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.228/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 |
/** |
|
106 |
* |
|
107 |
*/ |
|
108 |
public static void register() { |
|
109 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
110 |
registerFormats(); |
|
111 |
|
|
112 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
|
113 |
dataman.registerStoreProvider(NAME, |
|
114 |
MultiFileProvider.class, MultiFileDataParametersImpl.class); |
|
115 |
} |
|
116 |
|
|
117 |
// if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
|
118 |
// DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
|
119 |
// NAME, DESCRIPTION, |
|
120 |
// MultiFileServerExplorer.class); |
|
121 |
// |
|
122 |
// if (!dataman.getExplorerProviders().contains(NAME)) { |
|
123 |
// dataman.registerExplorerProvider(NAME, MultiFileServerExplorer.class, MultiFileServerExplorerParameters.class); |
|
124 |
// } |
|
125 |
|
|
126 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
|
127 |
} |
|
128 |
|
|
129 |
private static void registerFormats() { |
|
130 |
formatList = new String[] { |
|
131 |
"mff"}; |
|
132 |
for (int i = 0; i < formatList.length; i++) |
|
133 |
RasterLocator.getManager().getProviderServices().addFormat( |
|
134 |
formatList[i], |
|
135 |
MultiFileProvider.class); |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* |
|
140 |
*/ |
|
141 |
public MultiFileProvider() { |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Opens the dataset. |
|
146 |
* @param params |
|
147 |
* @param proj Projection |
|
148 |
* @param fName File name |
|
149 |
* @throws NotSupportedExtensionException |
|
150 |
* @throws OpenException |
|
151 |
* @deprecated use {@link #MultiFileProvider(URI)}, this constructor will be removed in gvSIG 2.5 |
|
152 |
*/ |
|
153 |
public MultiFileProvider(String params) throws NotSupportedExtensionException, OpenException { |
|
154 |
super(params); |
|
155 |
logger.info("Deprecated use of MultiFileProvider constructor"); |
|
156 |
if(params instanceof String) { |
|
157 |
MultiFileDataParameters p = new MultiFileDataParametersImpl(); |
|
158 |
URI uriObj; |
|
159 |
try { |
|
160 |
uriObj = new URI((String)params); |
|
161 |
} catch (URISyntaxException e) { |
|
162 |
throw new OpenException("Can't create uri from "+(String)params, e); |
|
163 |
} |
|
164 |
p.setURI(uriObj); |
|
165 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
|
166 |
.createDynObject( |
|
167 |
MetadataLocator.getMetadataManager().getDefinition( |
|
168 |
DataStore.METADATA_DEFINITION_NAME))); |
|
169 |
init(p, null); |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* Opens the dataset. |
|
175 |
* @param uri |
|
176 |
* @param proj Projection |
|
177 |
* @param fName File name |
|
178 |
* @throws NotSupportedExtensionException |
|
179 |
* @throws OpenException |
|
180 |
*/ |
|
181 |
public MultiFileProvider(URI uri) throws NotSupportedExtensionException, OpenException { |
|
182 |
super(uri); |
|
183 |
MultiFileDataParameters p = new MultiFileDataParametersImpl(); |
|
184 |
p.setURI(uri); |
|
185 |
super.init( |
|
186 |
p, |
|
187 |
null, |
|
188 |
ToolsLocator.getDynObjectManager().createDynObject( |
|
189 |
MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME))); |
|
190 |
init(p, null); |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* @param params |
|
195 |
* @param storeServices |
|
196 |
* @throws NotSupportedExtensionException |
|
197 |
* @throws OpenException |
|
198 |
*/ |
|
199 |
public MultiFileProvider(MultiFileDataParametersImpl params, |
|
200 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
|
201 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
|
202 |
.createDynObject( |
|
203 |
MetadataLocator.getMetadataManager().getDefinition( |
|
204 |
DataStore.METADATA_DEFINITION_NAME))); |
|
205 |
init(params, storeServices); |
|
206 |
} |
|
207 |
|
|
208 |
/** |
|
209 |
* Build file references |
|
210 |
* @param params |
|
211 |
* @param storeServices |
|
212 |
* @param proj Projection |
|
213 |
* @param param Load parameters |
|
214 |
* @throws NotSupportedExtensionException |
|
215 |
* @throws OpenException |
|
216 |
*/ |
|
217 |
public void init(MultiFileDataParameters params, |
|
218 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
|
219 |
|
|
220 |
openFromMff(); |
|
221 |
|
|
222 |
uri = getParameters().getURI(); |
|
223 |
setParam(storeServices, params); |
|
224 |
|
|
225 |
try { |
|
226 |
setFirstProviderToNotTiled(); |
|
227 |
} catch (InvalidSourceException e1) { |
|
228 |
throw new OpenException(e1.getMessage(), e1); |
|
229 |
} |
|
230 |
|
|
231 |
super.init(); |
|
232 |
|
|
233 |
try { |
|
234 |
loadFromRmf(getRmfBlocksManager()); |
|
235 |
} catch (ParsingException e) { |
|
236 |
logger.debug("Problems reading from RMF", e); |
|
237 |
} |
|
238 |
|
|
239 |
open = true; |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* Open from a .mff file. |
|
244 |
* This method loads all providers and adds these to the parameters |
|
245 |
* @throws OpenException |
|
246 |
*/ |
|
247 |
private void openFromMff() throws OpenException { |
|
248 |
URI uriParam = getParameters().getURI(); |
|
249 |
if (uriParam != null) { |
|
250 |
File fileFromUriParam = new File(uriParam); |
|
251 |
if (fileFromUriParam.exists()) { |
|
252 |
boolean loadedProviders = true; |
|
253 |
if (getParameters().hasProviders()) { |
|
254 |
// solo se considera que est?n todos los providers cargados |
|
255 |
// si existen y est?n open, |
|
256 |
// sino se leer?n de disco |
|
257 |
for (int i = 0; i < getParameters().getProviders().size(); i++) { |
|
258 |
if (!getParameters().getProviders().get(i).isOpen()) |
|
259 |
loadedProviders = false; |
|
260 |
} |
|
261 |
} else |
|
262 |
loadedProviders = false; |
|
263 |
|
|
264 |
if (loadedProviders) |
|
265 |
return; |
|
266 |
|
|
267 |
try { |
|
268 |
if (getParameters().hasProviders()) |
|
269 |
getParameters().removeAllProviders(); |
|
270 |
MultiFileFormat multiFileFormat = new MultiFileFormat(); |
|
271 |
multiFileFormat = MultiFileFormatSerializer.read(multiFileFormat, fileFromUriParam.getAbsolutePath()); |
|
272 |
for (int i = 0; i < multiFileFormat.getNumberOfFiles(); i++) { |
|
273 |
try { |
|
274 |
File file = new File(multiFileFormat.getPathToFile(i)); |
|
275 |
if (file.exists()) { |
|
276 |
RasterProvider prov = loadProvider(multiFileFormat.getPathToFile(i), storeServices); |
|
277 |
getParameters().addProvider(prov); |
|
278 |
} |
|
279 |
} catch (ProviderNotRegisteredException e) { |
|
280 |
throw new OpenException("A provider can't be loaded", e); |
|
281 |
} catch (InitializeException e) { |
|
282 |
throw new OpenException("A provider can't be initialized", e); |
|
283 |
} |
|
284 |
} |
|
285 |
} catch (IOException e1) { |
|
286 |
throw new OpenException("File .mff can't be read", e1); |
|
287 |
} catch (ParsingException e1) { |
|
288 |
throw new OpenException("File .mff can't be parsed", e1); |
|
289 |
} |
|
290 |
} |
|
291 |
} |
|
292 |
} |
|
293 |
|
|
294 |
/** |
|
295 |
* Loads the specific provider |
|
296 |
* @param file |
|
297 |
* @return |
|
298 |
* @throws NotSupportedExtensionException |
|
299 |
* @throws FileNotSupportedException |
|
300 |
*/ |
|
301 |
@SuppressWarnings("unchecked") |
|
302 |
private RasterProvider loadProvider(String file, DataStoreProviderServices storeServices) throws ProviderNotRegisteredException, InitializeException { |
|
303 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
|
304 |
DataStoreProvider prov = null; |
|
305 |
|
|
306 |
if(file != null) { |
|
307 |
//We have to locate a provider's name which manages the selected file |
|
308 |
//A FilesystemServerExplorer will give a getProviderNames service |
|
309 |
FilesystemServerExplorerParameters paramsExplorer = (FilesystemServerExplorerParameters)dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
|
310 |
FilesystemServerExplorer serverExplorer = null; |
|
311 |
try { |
|
312 |
paramsExplorer.setRoot(File.separator); |
|
313 |
serverExplorer = (FilesystemServerExplorer)dataManager.openServerExplorer(FilesystemServerExplorer.NAME, paramsExplorer); |
|
314 |
} catch (ValidateDataParametersException e) { |
|
315 |
throw new InitializeException(e); |
|
316 |
} |
|
317 |
File f = new File(file); |
|
318 |
//Gets the list of provider's name to manage the file |
|
319 |
List<String> provName = serverExplorer.getProviderNameList(f); |
|
320 |
if(provName.size() > 0) { |
|
321 |
for (int i = 0; i < provName.size(); i++) { |
|
322 |
//Gets the first provider what is not a TileProvider |
|
323 |
if(provName.get(i).compareTo("Tile Store") != 0) { |
|
324 |
DataStoreParameters newparams = dataManager.createStoreParameters(provName.get(i)); |
|
325 |
((FilesystemStoreParameters)newparams).setFile(f); |
|
326 |
prov = dataManager.createProvider(storeServices, newparams); |
|
327 |
} |
|
328 |
} |
|
329 |
} |
|
330 |
} |
|
331 |
|
|
332 |
if(prov != null && prov instanceof RasterProvider) { |
|
333 |
if(((RasterProvider)prov).isRotated()) |
|
334 |
throw new InitializeException("Rotation not supported tiling files", new Throwable()); |
|
335 |
|
|
336 |
return (RasterProvider)prov; |
|
337 |
} |
|
338 |
|
|
339 |
return null; |
|
340 |
} |
|
341 |
|
|
342 |
/** |
|
343 |
* Checks if the new file is compatible with the old one |
|
344 |
* @param file |
|
345 |
* @return |
|
346 |
* @throws LocatorException |
|
347 |
* @throws NotSupportedExtensionException |
|
348 |
* @throws RasterDriverException |
|
349 |
* @throws CloseException |
|
350 |
*/ |
|
351 |
private boolean checkNewProvider(RasterProvider p) { |
|
352 |
Rectangle2D extentOrigin = getExtent().toRectangle2D(); |
|
353 |
|
|
354 |
Extent extentNewFile = p.getExtent(); |
|
355 |
|
|
356 |
// Comprobamos que el extent y tama�o del fichero a�adido sea igual al |
|
357 |
// fichero original. Si no es as� no abrimos la capa y mostramos un aviso |
|
358 |
|
|
359 |
double widthNewFile = (extentNewFile.getMax().getX() - extentNewFile.getMin().getX()); |
|
360 |
double heightNewFile = (extentNewFile.getMax().getY() - extentNewFile.getMin().getY()); |
|
361 |
|
|
362 |
if ((widthNewFile - extentOrigin.getWidth()) > 1.0 || (widthNewFile - extentOrigin.getWidth()) < -1.0 || (heightNewFile - extentOrigin.getHeight()) > 1.0 |
|
363 |
|| (heightNewFile - extentOrigin.getHeight()) < -1.0) { |
|
364 |
return false; |
|
365 |
} |
|
366 |
|
|
367 |
if ((extentNewFile.getMax().getX() - extentNewFile.getMin().getX()) != extentOrigin.getWidth() |
|
368 |
|| (extentNewFile.getMax().getY() - extentNewFile.getMin().getY()) != extentOrigin.getHeight()) { |
|
369 |
return false; |
|
370 |
} |
|
371 |
|
|
372 |
return true; |
|
373 |
} |
|
374 |
|
|
375 |
/** |
|
376 |
* @return MultiFileDataParameters |
|
377 |
*/ |
|
378 |
public MultiFileDataParameters getParameters() { |
|
379 |
try { |
|
380 |
return (MultiFileDataParameters)parameters; |
|
381 |
} catch (ClassCastException e) { |
|
382 |
return null; |
|
383 |
} |
|
384 |
} |
|
385 |
|
|
386 |
public RasterProvider load() { |
|
387 |
return this; |
|
388 |
} |
|
389 |
|
|
390 |
public int getBandCount() { |
|
391 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
392 |
int bandCount = 0; |
|
393 |
for (int i = 0; i < providerList.size(); i++) { |
|
394 |
bandCount += providerList.get(i).getBandCount(); |
|
395 |
} |
|
396 |
return bandCount; |
|
397 |
} |
|
398 |
|
|
399 |
public int[] getDataType() { |
|
400 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
401 |
int[] datatypes = new int[getBandCount()]; |
|
402 |
int k = 0; |
|
403 |
for (int i = 0; i < providerList.size(); i++) { |
|
404 |
int[] dtByProv = providerList.get(i).getDataType(); |
|
405 |
for (int j = 0; j < dtByProv.length; j++) { |
|
406 |
datatypes[k] = dtByProv[j]; |
|
407 |
k++; |
|
408 |
} |
|
409 |
} |
|
410 |
return datatypes; |
|
411 |
} |
|
412 |
|
|
413 |
public URI[] getURIByProvider() { |
|
414 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
415 |
URI[] uris = new URI[providerList.size()]; |
|
416 |
for (int i = 0; i < uris.length; i++) { |
|
417 |
uris[i] = providerList.get(i).getURIOfFirstProvider(); |
|
418 |
} |
|
419 |
return uris; |
|
420 |
} |
|
421 |
|
|
422 |
public int getBandPositionByProvider(int band) { |
|
423 |
return getSubBandByBandNumber(band)[1]; |
|
424 |
} |
|
425 |
|
|
426 |
public URI getURIOfFirstProvider() { |
|
427 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
428 |
return providerList.get(0).getURIOfFirstProvider(); |
|
429 |
} |
|
430 |
|
|
431 |
|
|
432 |
public Extent getExtent() { |
|
433 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
434 |
if(providerList != null && providerList.size() > 0) |
|
435 |
return providerList.get(0).getExtent(); |
|
436 |
return null; |
|
437 |
} |
|
438 |
|
|
439 |
public AffineTransform getAffineTransform() { |
|
440 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
441 |
return providerList.get(0).getAffineTransform(); |
|
442 |
} |
|
443 |
|
|
444 |
public void setAffineTransform(AffineTransform t) { |
|
445 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
446 |
for (int i = 0; i < providerList.size(); i++) { |
|
447 |
providerList.get(i).setAffineTransform(t); |
|
448 |
} |
|
449 |
} |
|
450 |
|
|
451 |
public int getInternalProviderCount() { |
|
452 |
return getParameters().getProviders().size(); |
|
453 |
} |
|
454 |
|
|
455 |
public RasterProvider getInternalProvider(int i) { |
|
456 |
return getParameters().getProviders().get(i); |
|
457 |
} |
|
458 |
|
|
459 |
public int[] getBandCountByProvider() { |
|
460 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
461 |
int[] bc = new int[providerList.size()]; |
|
462 |
for (int i = 0; i < bc.length; i++) { |
|
463 |
bc[i] = providerList.get(i).getBandCount(); |
|
464 |
} |
|
465 |
return bc; |
|
466 |
} |
|
467 |
|
|
468 |
public long[] getFileSizeByProvider() { |
|
469 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
470 |
long[] fs = new long[providerList.size()]; |
|
471 |
for (int i = 0; i < fs.length; i++) { |
|
472 |
fs[i] = ((AbstractRasterProvider)providerList.get(i)).getFileSize(); |
|
473 |
} |
|
474 |
return fs; |
|
475 |
} |
|
476 |
|
|
477 |
public Point2D rasterToWorld(Point2D pt) { |
|
478 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
479 |
return providerList.get(0).rasterToWorld(pt); |
|
480 |
} |
|
481 |
|
|
482 |
public Point2D worldToRaster(Point2D pt) { |
|
483 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
484 |
return providerList.get(0).worldToRaster(pt); |
|
485 |
} |
|
486 |
|
|
487 |
public boolean isInside(Point2D p){ |
|
488 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
489 |
return providerList.get(0).isInside(p); |
|
490 |
} |
|
491 |
|
|
492 |
public double getCellSize() { |
|
493 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
494 |
return providerList.get(0).getCellSize(); |
|
495 |
} |
|
496 |
|
|
497 |
public Statistics getStatistics() { |
|
498 |
if(stats == null || (stats instanceof MultiProviderStatistics && |
|
499 |
((MultiProviderStatistics)stats).getNumberOfProviders() != getParameters().getProviders().size())) { |
|
500 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
501 |
stats = new MultiProviderStatistics(providerList, this); |
|
502 |
} |
|
503 |
|
|
504 |
return stats; |
|
505 |
} |
|
506 |
|
|
507 |
public HistogramComputer getHistogramComputer() { |
|
508 |
if(histogram == null || |
|
509 |
(histogram instanceof MultiProviderHistogramComputer && |
|
510 |
((MultiProviderHistogramComputer)histogram).getNumberOfProviders() != getParameters().getProviders().size())) { |
|
511 |
histogram = new MultiProviderHistogramComputer(this); |
|
512 |
} |
|
513 |
|
|
514 |
return histogram; |
|
515 |
} |
|
516 |
|
|
517 |
/** |
|
518 |
* A multiband provider doesn't have a color table because this will have |
|
519 |
* more than one band. |
|
520 |
*/ |
|
521 |
public ColorTable getColorTable() { |
|
522 |
return null; |
|
523 |
} |
|
524 |
|
|
525 |
public boolean isOpen() { |
|
526 |
return open; |
|
527 |
} |
|
528 |
|
|
529 |
public void close() { |
|
530 |
} |
|
531 |
|
|
532 |
public URI translateURI(URI uri) { |
|
533 |
return uri; |
|
534 |
} |
|
535 |
|
|
536 |
/** |
|
537 |
* Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci�n |
|
538 |
* de la vista asignada ya que la petici�n viene en coordenadas del fichero .rmf y la vista (v) |
|
539 |
* ha de estar en coordenadas del fichero. |
|
540 |
*/ |
|
541 |
public void setView(Extent e) { |
|
542 |
viewRequest = new ExtentImpl(e); |
|
543 |
} |
|
544 |
|
|
545 |
public Extent getView() { |
|
546 |
return viewRequest; |
|
547 |
} |
|
548 |
|
|
549 |
public double getWidth() { |
|
550 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
551 |
if(providerList != null && providerList.size() > 0) { |
|
552 |
return providerList.get(0).getWidth(); |
|
553 |
} |
|
554 |
return 0; |
|
555 |
} |
|
556 |
|
|
557 |
public double getHeight() { |
|
558 |
List<RasterProvider> providerList = getParameters().getProviders(); |
|
559 |
if(providerList != null && providerList.size() > 0) { |
|
560 |
return providerList.get(0).getHeight(); |
|
561 |
} |
|
562 |
return 0; |
|
563 |
|
|
564 |
} |
|
565 |
|
|
566 |
public Object readBlock(int pos, int blockHeight, double scale) |
|
567 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException { |
|
568 |
return null; |
|
569 |
} |
|
570 |
|
|
571 |
/** |
|
572 |
* Gets a number of provider and the band of this provider |
|
573 |
* @param band |
|
574 |
* @return |
Also available in: Unified diff