gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.fmap.dal.file.jimi / src / main / java / org / gvsig / fmap / dal / file / jimi / JimiRasterStoreProviderParameters.java @ 6336
History | View | Annotate | Download (5.72 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2016 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.dal.file.jimi; |
24 |
|
25 |
import java.io.File; |
26 |
import java.io.IOException; |
27 |
import java.util.List; |
28 |
|
29 |
import org.apache.commons.io.FileUtils; |
30 |
import org.apache.commons.io.FilenameUtils; |
31 |
import org.apache.commons.lang3.StringUtils; |
32 |
import org.cresques.cts.ICRSFactory; |
33 |
import org.cresques.cts.IProjection; |
34 |
import org.gvsig.fmap.crs.CRSFactory; |
35 |
import org.gvsig.fmap.dal.FileHelper; |
36 |
import org.gvsig.fmap.dal.OpenDataStoreParameters; |
37 |
import org.gvsig.fmap.dal.raster.spi.OpenRasterStoreParameters; |
38 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
39 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
40 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
41 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
42 |
import org.slf4j.Logger; |
43 |
import org.slf4j.LoggerFactory; |
44 |
|
45 |
/**
|
46 |
* Parameters to create a JIMI Provider
|
47 |
* @author dmartinezizquierdo
|
48 |
*
|
49 |
*/
|
50 |
public class JimiRasterStoreProviderParameters extends AbstractDataParameters implements |
51 |
OpenRasterStoreParameters, FilesystemStoreParameters{ |
52 |
|
53 |
private static final Logger logger = LoggerFactory.getLogger(JimiRasterStoreProviderParameters.class); |
54 |
|
55 |
public static final String PARAMETERS_DEFINITION_NAME = "JimiRasterStoreProviderParameters"; |
56 |
public static final String FILE_PARAMTER_NAME = "file"; |
57 |
public static final String CRS_PARAMTER_NAME = "crs"; |
58 |
public static final String WLD_PARAMS_NAME= "wldParams"; |
59 |
|
60 |
|
61 |
private DelegatedDynObject parameters;
|
62 |
|
63 |
/**
|
64 |
* Constructor
|
65 |
*/
|
66 |
public JimiRasterStoreProviderParameters() {
|
67 |
this(PARAMETERS_DEFINITION_NAME);
|
68 |
} |
69 |
|
70 |
protected JimiRasterStoreProviderParameters(String parametersDefinitionName) { |
71 |
this(parametersDefinitionName, JimiRasterStoreProvider.NAME);
|
72 |
} |
73 |
|
74 |
|
75 |
/**
|
76 |
* Constructor
|
77 |
* @param parametersDefinitionName
|
78 |
* @param name
|
79 |
*/
|
80 |
public JimiRasterStoreProviderParameters(String parametersDefinitionName, String name) { |
81 |
super();
|
82 |
this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName);
|
83 |
this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name);
|
84 |
} |
85 |
|
86 |
@Override
|
87 |
public String getDataStoreName() { |
88 |
return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME); |
89 |
} |
90 |
|
91 |
@Override
|
92 |
public boolean isValid() { |
93 |
return (this.getFile() != null); |
94 |
} |
95 |
|
96 |
@Override
|
97 |
public String getDescription() { |
98 |
return this.getDynClass().getDescription(); |
99 |
} |
100 |
|
101 |
@Override
|
102 |
public File getFile() { |
103 |
return (File) this.getDynValue(FILE_PARAMTER_NAME); |
104 |
} |
105 |
|
106 |
@Override
|
107 |
public void setFile(File file) { |
108 |
this.setDynValue(FILE_PARAMTER_NAME, file);
|
109 |
loadWLD(file); |
110 |
if (getCRS()==null){ |
111 |
loadPRJ(file); |
112 |
} |
113 |
} |
114 |
|
115 |
/**
|
116 |
* Sets CRS
|
117 |
* @param crsCode
|
118 |
*/
|
119 |
public void setCRS(String crsCode) { |
120 |
IProjection crs=CRSFactory.getCRS(crsCode); |
121 |
setDynValue(CRS_PARAMTER_NAME, crs); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Sets CRS
|
126 |
* @param crs
|
127 |
*/
|
128 |
public void setCRS(IProjection crs) { |
129 |
setDynValue(CRS_PARAMTER_NAME, crs); |
130 |
} |
131 |
|
132 |
|
133 |
/**
|
134 |
* Gets CRS
|
135 |
* @return IProjection
|
136 |
*/
|
137 |
public IProjection getCRS() {
|
138 |
return (IProjection) getDynValue(CRS_PARAMTER_NAME);
|
139 |
} |
140 |
|
141 |
/**
|
142 |
* Gets the 6 params of a WLD file as Strings.
|
143 |
* @return Returns WLD parameters
|
144 |
*/
|
145 |
public List<String> getWldParams(){ |
146 |
return (List<String>) getDynValue(WLD_PARAMS_NAME); |
147 |
} |
148 |
|
149 |
/**
|
150 |
* Sets the params of a wld file
|
151 |
* @param wldParams
|
152 |
*/
|
153 |
public void setWldParams(List<String> wldParams){ |
154 |
setDynValue(WLD_PARAMS_NAME,wldParams); |
155 |
} |
156 |
|
157 |
@Override
|
158 |
protected DelegatedDynObject getDelegatedDynObject() {
|
159 |
return parameters;
|
160 |
} |
161 |
|
162 |
|
163 |
private void loadPRJ(File file){ |
164 |
File prjFile = new File(FilenameUtils.removeExtension(file.getAbsolutePath())+".prj"); |
165 |
if (prjFile.exists()) {
|
166 |
try {
|
167 |
String contentFile = FileUtils.readFileToString(prjFile);
|
168 |
if (StringUtils.isNotEmpty(contentFile)){
|
169 |
IProjection crs=CRSFactory.getCRSFactory().get(ICRSFactory.FORMAT_WKT_ESRI, contentFile); |
170 |
setCRS(crs); |
171 |
} |
172 |
|
173 |
} catch (IOException e) { |
174 |
logger.warn("Couldn't read wld file");
|
175 |
} |
176 |
} |
177 |
} |
178 |
|
179 |
private void loadWLD(File file){ |
180 |
File wldFile = new File(FilenameUtils.removeExtension(file.getAbsolutePath())+".wld"); |
181 |
if (wldFile.exists()) {
|
182 |
try {
|
183 |
List<String> lines = FileUtils.readLines(wldFile); |
184 |
if (lines!=null && lines.size()==6){ |
185 |
setWldParams(lines); |
186 |
} |
187 |
|
188 |
} catch (IOException e) { |
189 |
logger.warn("Couldn't read wld file");
|
190 |
} |
191 |
} |
192 |
} |
193 |
|
194 |
} |