001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.catalog.internal.geotiff;
018:
019: import java.io.File;
020: import java.io.IOException;
021: import java.net.URL;
022: import java.text.MessageFormat;
023: import java.util.ArrayList;
024: import java.util.List;
025:
026: import net.refractions.udig.catalog.IServiceInfo;
027: import net.refractions.udig.catalog.geotiff.internal.Messages;
028: import net.refractions.udig.catalog.rasterings.AbstractRasterGeoResource;
029: import net.refractions.udig.catalog.rasterings.AbstractRasterService;
030:
031: import org.eclipse.core.runtime.IProgressMonitor;
032: import org.geotools.data.coverage.grid.GridFormatFactorySpi;
033: import org.geotools.gce.geotiff.GeoTiffFormat;
034: import org.opengis.coverage.grid.GridCoverageReader;
035:
036: /**
037: * Provides a handle to a geotiff service allowing the service to be lazily
038: * loaded.
039: * @author mleslie
040: * @since 0.6.0
041: */
042: public class GeoTiffServiceImpl extends AbstractRasterService {
043: private GeoTiffServiceInfo info;
044:
045: /**
046: * Construct <code>GeoTiffServiceImpl</code>.
047: *
048: * @param id
049: * @param factory
050: */
051: public GeoTiffServiceImpl(URL id, GridFormatFactorySpi factory) {
052: super (id, factory);
053: }
054:
055: @Override
056: public List<AbstractRasterGeoResource> members(
057: IProgressMonitor monitor) throws IOException {
058: if (monitor != null) {
059: String msg = MessageFormat.format(
060: Messages.GeoTiffServiceImpl_connecting_to,
061: new Object[] {});
062: monitor.beginTask(msg, 5);
063: }
064: if (reader != null && monitor != null)
065: monitor.worked(3);
066:
067: GeoTiffGeoResourceImpl res = new GeoTiffGeoResourceImpl(this ,
068: getTitle());
069: List<AbstractRasterGeoResource> list = new ArrayList<AbstractRasterGeoResource>();
070: list.add(res);
071: if (monitor != null)
072: monitor.done();
073: return list;
074: }
075:
076: public void dispose(IProgressMonitor monitor) {
077: // do nothing
078: }
079:
080: public GridCoverageReader getReader() {
081: if (this .reader == null) {
082: try {
083: File file = new File(getIdentifier().toURI());
084: this .reader = ((GeoTiffFormat) getFormat())
085: .getReader(file);
086: } catch (Exception ex) {
087: this .message = ex;
088: }
089: }
090: return this .reader;
091: }
092:
093: public IServiceInfo getInfo(IProgressMonitor monitor) {
094: if (monitor != null)
095: monitor.beginTask(
096: Messages.GeoTiffServiceImpl_loading_task_title, 2);
097: if (this .info == null) {
098: if (monitor != null)
099: monitor.worked(1);
100: this .info = new GeoTiffServiceInfo();
101: }
102: if (monitor != null)
103: monitor.done();
104: return this .info;
105: }
106:
107: /**
108: * Provides descriptive information about this service.
109: * @author mleslie
110: * @since 0.6.0
111: */
112: public class GeoTiffServiceInfo extends IServiceInfo {
113: GeoTiffServiceInfo() {
114: super ();
115: this .keywords = new String[] {
116: "WorldImage", "world image", ".gif", ".jpg", ".jpeg", //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$
117: ".tif", ".tiff", ".png" }; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
118: }
119:
120: public String getTitle() {
121: return getIdentifier().getFile();
122: }
123:
124: public String getDescription() {
125: return getIdentifier().toString();
126: }
127: }
128: }
|