svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.spi / src / main / java / org / gvsig / fmap / dal / raster / spi / AbstractOpenRasterStoreParameters.java @ 44831
History | View | Annotate | Download (3.76 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2018 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.raster.spi; |
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.slf4j.Logger; |
35 |
import org.slf4j.LoggerFactory; |
36 |
|
37 |
import org.gvsig.fmap.crs.CRSFactory; |
38 |
import org.gvsig.fmap.dal.DataStore; |
39 |
import org.gvsig.fmap.dal.raster.OpenRasterStoreParameters; |
40 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
41 |
|
42 |
|
43 |
/**
|
44 |
* @author fdiaz
|
45 |
*
|
46 |
*/
|
47 |
public abstract class AbstractOpenRasterStoreParameters extends AbstractDataParameters implements OpenRasterStoreParameters{ |
48 |
|
49 |
private static final Logger logger = LoggerFactory.getLogger(AbstractOpenRasterStoreParameters.class); |
50 |
public static final String WLD_PARAMS_NAME= "wldParams"; |
51 |
|
52 |
/**
|
53 |
* Sets CRS
|
54 |
* @param crsCode
|
55 |
*/
|
56 |
public void setCRS(String crsCode) { |
57 |
IProjection crs=CRSFactory.getCRS(crsCode); |
58 |
setDynValue(DataStore.METADATA_CRS, crs); |
59 |
} |
60 |
|
61 |
/**
|
62 |
* Sets CRS
|
63 |
* @param crs
|
64 |
*/
|
65 |
public void setCRS(IProjection crs) { |
66 |
setDynValue(DataStore.METADATA_CRS, crs); |
67 |
} |
68 |
|
69 |
|
70 |
/**
|
71 |
* Gets CRS
|
72 |
* @return IProjection
|
73 |
*/
|
74 |
public IProjection getCRS() {
|
75 |
return (IProjection) getDynValue(DataStore.METADATA_CRS);
|
76 |
} |
77 |
|
78 |
/**
|
79 |
* Gets the 6 params of a WLD file as Strings.
|
80 |
* @return Returns WLD parameters
|
81 |
*/
|
82 |
public List<String> getWldParams(){ |
83 |
return (List<String>) getDynValue(WLD_PARAMS_NAME); |
84 |
} |
85 |
|
86 |
/**
|
87 |
* Sets the params of a wld file
|
88 |
* @param wldParams
|
89 |
*/
|
90 |
public void setWldParams(List<String> wldParams){ |
91 |
setDynValue(WLD_PARAMS_NAME,wldParams); |
92 |
} |
93 |
|
94 |
|
95 |
protected void loadPRJ(File file){ |
96 |
File prjFile = new File(FilenameUtils.removeExtension(file.getAbsolutePath())+".prj"); |
97 |
if (prjFile.exists()) {
|
98 |
try {
|
99 |
String contentFile = FileUtils.readFileToString(prjFile);
|
100 |
if (StringUtils.isNotEmpty(contentFile)){
|
101 |
IProjection crs=CRSFactory.getCRSFactory().get(ICRSFactory.FORMAT_WKT_ESRI, contentFile); |
102 |
setCRS(crs); |
103 |
} |
104 |
|
105 |
} catch (IOException e) { |
106 |
logger.warn("Couldn't read wld file");
|
107 |
} |
108 |
} |
109 |
} |
110 |
|
111 |
protected void loadWLD(File file){ |
112 |
File wldFile = new File(FilenameUtils.removeExtension(file.getAbsolutePath())+".wld"); |
113 |
if (wldFile.exists()) {
|
114 |
try {
|
115 |
List<String> lines = FileUtils.readLines(wldFile); |
116 |
if (lines!=null && lines.size()==6){ |
117 |
setWldParams(lines); |
118 |
} |
119 |
|
120 |
} catch (IOException e) { |
121 |
logger.warn("Couldn't read wld file");
|
122 |
} |
123 |
} |
124 |
} |
125 |
} |