001: package com.vividsolutions.jump.workbench.imagery.mrsid;
002:
003: /*
004: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
005: * for visualizing and manipulating spatial features with geometry and attributes.
006: *
007: * Copyright (C) 2003 Vivid Solutions
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * For more information, contact:
024: *
025: * Vivid Solutions
026: * Suite #1A
027: * 2328 Government Street
028: * Victoria BC V8T 5G5
029: * Canada
030: *
031: * (250)385-6040
032: * www.vividsolutions.com
033: */
034: import java.io.BufferedReader;
035: import java.io.File;
036: import java.io.FileReader;
037:
038: import com.vividsolutions.jump.JUMPException;
039:
040: public class SIDInfo {
041: private String fileName;
042: private int pixelWidth;
043: private int pixelHeight;
044: private double xres;
045: private double xrot;
046: private double yrot;
047: private double yres;
048: private double upper_left_x; //realworld coords
049: private double upper_left_y; //realworld coords
050:
051: private int numLevels;
052: private String colorSpace;
053:
054: SIDInfo(String fileName, int pixelWidth, int pixelHeight,
055: double xres, double xrot, double yrot, double yres,
056: double ulx, double uly, int numLevels, String colorSpace) {
057: this .fileName = fileName;
058: this .pixelWidth = pixelWidth;
059: this .pixelHeight = pixelHeight;
060: this .xres = xres;
061: this .xrot = xrot;
062: this .yrot = yrot;
063: this .yres = yres;
064: this .upper_left_x = ulx;
065: this .upper_left_y = uly;
066: this .numLevels = numLevels;
067: this .colorSpace = colorSpace;
068: }
069:
070: String getFileName() {
071: return fileName;
072: }
073:
074: int getPixelWidth() {
075: return pixelWidth;
076: }
077:
078: int getPixelHeight() {
079: return pixelHeight;
080: }
081:
082: double getXRes() {
083: return xres;
084: }
085:
086: double getXRot() {
087: return xrot;
088: }
089:
090: double getYRot() {
091: return yrot;
092: }
093:
094: double getYRes() {
095: return yres;
096: }
097:
098: double getUpperLeftX() {
099: return upper_left_x;
100: }
101:
102: double getUpperLeftY() {
103: return upper_left_y;
104: }
105:
106: int getNumLevels() {
107: return numLevels;
108: }
109:
110: String getColorSpace() {
111: return colorSpace;
112: }
113:
114: static SIDInfo readInfo(String sidFilename) throws JUMPException {
115: int sidPixelWidth = 0;
116: int sidPixelHeight = 0;
117: double sid_xres = 1;
118: double sid_xrot = 0;
119: double sid_yrot = 0;
120: double sid_yres = 1;
121: double sid_ulx = 0; //realworld coords
122: double sid_uly = 0; //realworld coords
123: int maxLevel = 0;
124:
125: int numInfoItems = 0;
126: String colorSpace = null;
127:
128: try {
129: File file = File.createTempFile("MrSIDinfo", "txt");
130: String[] runStr = { MrSIDImageFactory.MRSIDINFO,
131: sidFilename,
132: // "-sid",
133: "-quiet", "-log", file.getPath() };
134:
135: Process p = Runtime.getRuntime().exec(runStr);
136: p.waitFor();
137: p.destroy();
138:
139: if (!(file.exists() && file.isFile() && file.canRead()))
140: return null; //this could happen if mrsidinfo.exe couldn't produce a file
141:
142: //read the info
143: FileReader fin = new FileReader(file);
144: BufferedReader in = new BufferedReader(fin);
145: String lineIn = in.readLine();
146:
147: while (in.ready()) {
148: String value = "";
149:
150: if (lineIn.indexOf("width:") != -1) {
151: value = lineIn.substring(lineIn.indexOf(":") + 1);
152: sidPixelWidth = Integer.parseInt(value.trim());
153: numInfoItems++;
154: }
155:
156: if (lineIn.indexOf("height:") != -1) {
157: value = lineIn.substring(lineIn.indexOf(":") + 1);
158: sidPixelHeight = Integer.parseInt(value.trim());
159: numInfoItems++;
160: }
161:
162: if (lineIn.indexOf("number of levels:") != -1) {
163: value = lineIn.substring(lineIn.indexOf(":") + 1);
164: maxLevel = Integer.parseInt(value.trim());
165: numInfoItems++;
166: }
167:
168: if (lineIn.indexOf("X UL:") != -1) {
169: value = lineIn.substring(lineIn.indexOf(":") + 1);
170: sid_ulx = Double.parseDouble(value.trim());
171: numInfoItems++;
172: }
173:
174: if (lineIn.indexOf("Y UL:") != -1) {
175: value = lineIn.substring(lineIn.indexOf(":") + 1);
176: sid_uly = Double.parseDouble(value.trim());
177: numInfoItems++;
178: }
179:
180: if (lineIn.indexOf("X res:") != -1) {
181: value = lineIn.substring(lineIn.indexOf(":") + 1);
182: sid_xres = Double.parseDouble(value.trim());
183: numInfoItems++;
184: }
185:
186: if (lineIn.indexOf("Y res:") != -1) {
187: value = lineIn.substring(lineIn.indexOf(":") + 1);
188: sid_yres = Double.parseDouble(value.trim());
189: numInfoItems++;
190: }
191:
192: if (lineIn.indexOf("color space:") != -1) {
193: value = lineIn.substring(lineIn.indexOf(":") + 1);
194: colorSpace = value.trim();
195: numInfoItems++;
196: }
197:
198: lineIn = in.readLine();
199: }
200:
201: in.close();
202: fin.close();
203:
204: if (numInfoItems == 8)
205: return new SIDInfo(sidFilename, sidPixelWidth,
206: sidPixelHeight, sid_xres, sid_xrot, sid_yrot,
207: sid_yres, sid_ulx, sid_uly, maxLevel,
208: colorSpace);
209: else
210: return null;
211:
212: } catch (Throwable t) {
213: throw new JUMPException(t.getMessage());
214: }
215: }
216: }
|