001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2007, GeoTools Project Managment Committee (PMC)
005: * (C) 2007, Geomatys
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.image.io.metadata;
018:
019: // OpenGIS dependencies
020: import org.opengis.referencing.datum.Datum; // For javadoc
021: import org.opengis.referencing.datum.TemporalDatum; // For javadoc
022: import org.opengis.referencing.cs.AxisDirection; // For javadoc
023: import org.opengis.referencing.cs.CoordinateSystem; // For javadoc
024: import org.opengis.referencing.cs.CoordinateSystemAxis; // For javadoc
025: import org.opengis.referencing.crs.CoordinateReferenceSystem; // For javadoc
026:
027: /**
028: * A {@code <CoordinateReferenceSystem>} element in
029: * {@linkplain GeographicMetadataFormat geographic metadata format}, together with its
030: * {@code <CoordinateSystem>} and {@code <Datum>} child elements.
031: *
032: * @since 2.4
033: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/coverageio/src/main/java/org/geotools/image/io/metadata/ImageReferencing.java $
034: * @version $Id: ImageReferencing.java 27544 2007-10-18 19:16:40Z desruisseaux $
035: * @author Martin Desruisseaux
036: */
037: public class ImageReferencing extends MetadataAccessor {
038: /**
039: * The {@code "CoordinateReferenceSystem/Datum"} node.
040: */
041: private final MetadataAccessor datum;
042:
043: /**
044: * The {@code "CoordinateReferenceSystem/CoordinateSystem"} node.
045: */
046: final ChildList/*<Axis>*/cs;
047:
048: /**
049: * Creates a parser for a coordinate system. This constructor should not be invoked
050: * directly; use {@link GeographicMetadata#getReferencing} instead.
051: *
052: * @param metadata The metadata node.
053: */
054: protected ImageReferencing(final GeographicMetadata metadata) {
055: super (metadata, "CoordinateReferenceSystem", null);
056: datum = new MetadataAccessor(metadata,
057: "CoordinateReferenceSystem/Datum", null);
058: cs = new ChildList.Axes(metadata);
059: }
060:
061: /**
062: * Returns the {@linkplain Identification#name name} and {@linkplain Identification#type type}
063: * of the {@linkplain CoordinateReferenceSystem coordinate reference system}.
064: *
065: * @see CoordinateReferenceSystem
066: */
067: public Identification getCoordinateReferenceSystem() {
068: return new Identification(this );
069: }
070:
071: /**
072: * Sets the {@linkplain Identification#name name} and {@linkplain Identification#type type}
073: * of the {@linkplain CoordinateReferenceSystem coordinate reference system}.
074: *
075: * @param name The coordinate reference system name, or {@code null} if unknown.
076: * @param type The coordinate reference system type (usually
077: * {@value GeographicMetadataFormat#GEOGRAPHIC} or
078: * {@value GeographicMetadataFormat#PROJECTED}), or {@code null} if unknown.
079: *
080: * @see CoordinateReferenceSystem
081: */
082: public void setCoordinateReferenceSystem(final String name,
083: final String type) {
084: setString("name", name);
085: setEnum("type", type, GeographicMetadataFormat.CRS_TYPES);
086: }
087:
088: /**
089: * Returns the {@linkplain Identification#name name} and {@linkplain Identification#type type}
090: * of the {@linkplain CoordinateSystem coordinate system}.
091: *
092: * @see CoordinateSystem
093: */
094: public Identification getCoordinateSystem() {
095: return new Identification(cs);
096: }
097:
098: /**
099: * Sets the {@linkplain Identification#name name} and {@linkplain Identification#type type}
100: * of the {@linkplain CoordinateSystem coordinate system}.
101: *
102: * @param name The coordinate system name, or {@code null} if unknown.
103: * @param type The coordinate system type (usually
104: * {@value GeographicMetadataFormat#ELLIPSOIDAL} or
105: * {@value GeographicMetadataFormat#CARTESIAN}), or {@code null} if unknown.
106: *
107: * @see CoordinateSystem
108: */
109: public void setCoordinateSystem(final String name, final String type) {
110: cs.setString("name", name);
111: cs.setEnum("type", type, GeographicMetadataFormat.CS_TYPES);
112: }
113:
114: /**
115: * Returns the {@linkplain Identification#name name} and {@linkplain Identification#type type}
116: * of the {@linkplain Datum datum}.
117: *
118: * @see Datum
119: */
120: public Identification getDatum() {
121: return new Identification(datum);
122: }
123:
124: /**
125: * Sets the {@linkplain Identification#name name} and {@linkplain Identification#type type}
126: * of the {@linkplain Datum datum}.
127: *
128: * @param name The datum name, or {@code null} if unknown.
129: *
130: * @see Datum
131: */
132: public void setDatum(final String name) {
133: datum.setString("name", name);
134: }
135:
136: /**
137: * Returns the number of dimensions.
138: */
139: public int getDimension() {
140: return cs.childCount();
141: }
142:
143: /**
144: * Returns the axis at the specified index.
145: *
146: * @param index the axis index, ranging from 0 inclusive to {@link #getDimension} exclusive.
147: * @throws IndexOutOfBoundsException if the index is out of bounds.
148: */
149: public Axis getAxis(final int index)
150: throws IndexOutOfBoundsException {
151: return (Axis) cs.getChild(index);
152: }
153:
154: /**
155: * Adds an {@linkplain CoordinateSystemAxis axis} to the
156: * {@linkplain CoordinateSystem coordinate system}.
157: *
158: * @param name The axis name, or {@code null} if unknown.
159: * @param direction The {@linkplain AxisDirection axis direction}
160: * (usually {@code "east"}, {@code "weast"}, {@code "north"}, {@code "south"},
161: * {@code "up"} or {@code "down"}), or {@code null} if unknown.
162: * @param units The axis units symbol, or {@code null} if unknown.
163: *
164: * @see CoordinateSystemAxis
165: * @see AxisDirection
166: */
167: public Axis addAxis(final String name, final String direction,
168: final String units) {
169: final Axis axis = (Axis) cs.addChild();
170: axis.setName(name);
171: axis.setDirection(direction);
172: axis.setUnits(units);
173: return axis;
174: }
175:
176: /**
177: * Returns the {@linkplain CoordinateReferenceSystem coordinate reference system} in
178: * <A HREF="http://geoapi.sourceforge.net/snapshot/javadoc/org/opengis/referencing/doc-files/WKT.html"><cite>Well
179: * Known Text</cite> format</A>, or {@code null} if none.
180: */
181: public String getWKT() {
182: return getString("WKT");
183: }
184:
185: /**
186: * Sets the {@linkplain CoordinateReferenceSystem coordinate reference system} in
187: * <A HREF="http://geoapi.sourceforge.net/snapshot/javadoc/org/opengis/referencing/doc-files/WKT.html"><cite>Well
188: * Known Text</cite> format</A>.
189: */
190: public void setWKT(final String wkt) {
191: setString("WKT", wkt);
192: }
193: }
|