001: package com.vividsolutions.jump.workbench.imagery;
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.util.Map;
035: import java.util.WeakHashMap;
036:
037: import com.vividsolutions.jts.geom.GeometryFactory;
038: import com.vividsolutions.jump.feature.AttributeType;
039: import com.vividsolutions.jump.feature.Feature;
040: import com.vividsolutions.jump.feature.FeatureSchema;
041: import com.vividsolutions.jts.geom.Envelope;
042: import com.vividsolutions.jts.geom.Geometry;
043:
044: public class ImageryLayerDataset {
045: public static final String ATTR_GEOMETRY = "GEOMETRY";
046: public static final String ATTR_FILE = "IMAGEFILE";
047: public static final String ATTR_FORMAT = "IMAGEFORMAT";
048: public static final String ATTR_ERROR = "IMAGEERROR";
049: public static final String ATTR_TYPE = "IMAGETYPE";
050: public static final String ATTR_FACTORY = "IMAGEFACT";
051:
052: public static FeatureSchema SCHEMA = new FeatureSchema() {
053: {
054: addAttribute(ATTR_GEOMETRY, AttributeType.GEOMETRY);
055: addAttribute(ATTR_FILE, AttributeType.STRING);
056: addAttribute(ATTR_FORMAT, AttributeType.STRING);
057: addAttribute(ATTR_FACTORY, AttributeType.STRING);
058: addAttribute(ATTR_ERROR, AttributeType.STRING);
059: addAttribute(ATTR_TYPE, AttributeType.STRING);
060: }
061: };
062:
063: public static FeatureSchema getSchema() {
064: return SCHEMA;
065: }
066:
067: public void createImage(Feature feature) {
068: String factoryClassPath = (String) feature
069: .getString(ATTR_FACTORY);
070: String imageFilePath = (String) feature.getString(ATTR_FILE);
071: GeometryFactory geometryFactory = new GeometryFactory();
072:
073: try {
074: ReferencedImageFactory imageFactory = (ReferencedImageFactory) Class
075: .forName(factoryClassPath).newInstance();
076: ReferencedImage referencedImage = imageFactory
077: .createImage(imageFilePath);
078:
079: featureToReferencedImageMap.put(feature, referencedImage);
080: Envelope env = referencedImage.getEnvelope();
081: Geometry boundingBox = geometryFactory.toGeometry(env);
082: feature.setGeometry(boundingBox);
083:
084: feature.setAttribute(ATTR_TYPE, referencedImage.getType());
085: } catch (Exception e) {
086: feature.setAttribute(ATTR_ERROR, e.toString());
087: e.printStackTrace();
088: }
089: }
090:
091: public ReferencedImage referencedImage(Feature feature) {
092: if (!(feature.getString(ATTR_ERROR) == null || feature
093: .getString(ATTR_ERROR).equals(""))) {
094: return null;
095: }
096: if (!featureToReferencedImageMap.containsKey(feature)) {
097: createImage(feature);
098: }
099: // Will be null if an exception occurs [Jon Aquino 2005-04-12]
100: return (ReferencedImage) featureToReferencedImageMap
101: .get(feature);
102: }
103:
104: private Map featureToReferencedImageMap = new WeakHashMap();
105: }
|