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 net.refractions.udig.catalog.CatalogPlugin;
020: import net.refractions.udig.catalog.IGeoResourceInfo;
021: import net.refractions.udig.catalog.geotiff.internal.Messages;
022: import net.refractions.udig.catalog.rasterings.AbstractRasterGeoResource;
023: import net.refractions.udig.catalog.rasterings.AbstractRasterService;
024:
025: import org.eclipse.core.runtime.IProgressMonitor;
026: import org.eclipse.core.runtime.IStatus;
027: import org.geotools.geometry.jts.ReferencedEnvelope;
028: import org.geotools.referencing.CRS;
029: import org.opengis.coverage.grid.GridCoverage;
030: import org.opengis.referencing.crs.CoordinateReferenceSystem;
031:
032: import com.vividsolutions.jts.geom.Envelope;
033:
034: /**
035: * Provides a handle to a geotiff resource allowing the service to be lazily
036: * loaded.
037: * @author mleslie
038: * @since 0.6.0
039: */
040: public class GeoTiffGeoResourceImpl extends AbstractRasterGeoResource {
041: private GeoTiffGeoResourceInfo info;
042:
043: /**
044: * Construct <code>GeoTiffGeoResourceImpl</code>.
045: *
046: * @param service
047: * @param name
048: */
049: public GeoTiffGeoResourceImpl(AbstractRasterService service,
050: String name) {
051: super (service, name);
052: }
053:
054: public IGeoResourceInfo getInfo(IProgressMonitor monitor) {
055: if (monitor != null) {
056: monitor.beginTask(Messages.GeoTiffGeoResource_connect, 2);
057: monitor.worked(1);
058: }
059: if (this .info == null) {
060: this .info = new GeoTiffGeoResourceInfo();
061: if (monitor != null)
062: monitor.worked(1);
063: }
064: if (monitor != null)
065: monitor.done();
066: return this .info;
067: }
068:
069: /**
070: * Describes this Resource.
071: * </code></pre>
072: * </p>
073: * @author mleslie
074: * @since 0.6.0
075: */
076: public class GeoTiffGeoResourceInfo extends IGeoResourceInfo {
077: GeoTiffGeoResourceInfo() {
078: this .keywords = new String[] { "GeoTiff", ".tif", ".tiff" }; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
079: this .title = getIdentifier().getFile();
080: this .description = getIdentifier().toString();
081: this .bounds = getBounds();
082: }
083:
084: public ReferencedEnvelope getBounds() {
085: if (this .bounds == null) {
086: Envelope env = null;
087: try {
088: GridCoverage source = (GridCoverage) findResource();
089: if (source == null) {
090: return null;
091: }
092: org.opengis.spatialschema.geometry.Envelope ptBounds = source
093: .getEnvelope();
094: env = new Envelope(ptBounds.getMinimum(0), ptBounds
095: .getMaximum(0), ptBounds.getMinimum(1),
096: ptBounds.getMaximum(1));
097:
098: CoordinateReferenceSystem geomcrs = source
099: .getCoordinateReferenceSystem();
100:
101: this .bounds = new ReferencedEnvelope(env, geomcrs);
102: if (geomcrs != null) {
103: if (!geomcrs.equals(CRS.decode("EPSG:4269"))) { //$NON-NLS-1$
104: this .bounds = this .bounds.transform(CRS
105: .decode("EPSG:4269"), true); //$NON-NLS-1$
106: }
107: } else {
108: System.err.println("CRS unknown for GeoTiff"); //$NON-NLS-1$
109: }
110: } catch (Exception e) {
111: CatalogPlugin
112: .getDefault()
113: .getLog()
114: .log(
115: new org.eclipse.core.runtime.Status(
116: IStatus.WARNING,
117: "net.refractions.udig.catalog", 0, "Error while getting the bounds of a layer", e)); //$NON-NLS-1$ //$NON-NLS-2$
118: }
119: }
120: return this.bounds;
121: }
122: }
123: }
|