001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
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; either
009: * version 2.1 of the License, or (at your option) any later version.
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: package org.geotools.data.ows;
017:
018: import org.geotools.geometry.GeneralDirectPosition;
019: import org.opengis.referencing.crs.CoordinateReferenceSystem;
020: import org.opengis.geometry.DirectPosition;
021: import org.opengis.geometry.Envelope;
022:
023: /**
024: * A pair of coordinates and a reference system that represents a section of
025: * the Earth
026: *
027: * @author Richard Gould
028: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wms/src/main/java/org/geotools/data/ows/CRSEnvelope.java $
029: */
030: public class CRSEnvelope implements Envelope {
031: /** Represents the Coordinate Reference System this bounding box is in */
032: private String epsgCode;
033: protected double minX;
034: protected double minY;
035: protected double maxX;
036: protected double maxY;
037:
038: /**
039: * Construct an empty BoundingBox
040: */
041: public CRSEnvelope() {
042: super ();
043: }
044:
045: /**
046: * Create a bounding box with the specified properties
047: *
048: * @param epsgCode The Coordinate Reference System this bounding box is in
049: * @param minX
050: * @param minY
051: * @param maxX
052: * @param maxY
053: */
054: public CRSEnvelope(String epsgCode, double minX, double minY,
055: double maxX, double maxY) {
056: this .epsgCode = epsgCode;
057: this .minX = minX;
058: this .maxX = maxX;
059: this .minY = minY;
060: this .maxY = maxY;
061: }
062:
063: /**
064: * Returns the coordinate reference system for this envelope.
065: * Current implementation always return {@code null}, but it
066: * may change in a future version.
067: */
068: public CoordinateReferenceSystem getCoordinateReferenceSystem() {
069: return null;
070: }
071:
072: /**
073: * The CRS is bounding box's Coordinate Reference System
074: *
075: * @return the CRS/SRS value
076: */
077: public String getEPSGCode() {
078: return epsgCode;
079: }
080:
081: /**
082: * The CRS is bounding box's Coordinate Reference System
083: *
084: * @param epsgCode the new value for the CRS/SRS
085: */
086: public void setEPSGCode(String epsgCode) {
087: this .epsgCode = epsgCode;
088: }
089:
090: public int getDimension() {
091: return 2;
092: }
093:
094: public double getMinimum(int dimension) {
095: if (dimension == 0) {
096: return getMinX();
097: }
098:
099: return getMinY();
100: }
101:
102: public double getMaximum(int dimension) {
103: if (dimension == 0) {
104: return getMaxX();
105: }
106:
107: return getMaxY();
108: }
109:
110: public double getCenter(int dimension) {
111: double min, max;
112: if (dimension == 0) {
113: min = getMinX();
114: max = getMaxX();
115: } else {
116: min = getMinY();
117: max = getMaxY();
118: }
119: return min + (getLength(dimension) / 2);
120: }
121:
122: public double getLength(int dimension) {
123: double min, max;
124: if (dimension == 0) {
125: min = getMinX();
126: max = getMaxX();
127: } else {
128: min = getMinY();
129: max = getMaxY();
130: }
131:
132: return max - min;
133: }
134:
135: public DirectPosition getUpperCorner() {
136: return new GeneralDirectPosition(getMaxX(), getMaxY());
137: }
138:
139: public DirectPosition getLowerCorner() {
140: return new GeneralDirectPosition(getMinX(), getMinY());
141: }
142:
143: /**
144: * The maxX value is the higher X coordinate value
145: *
146: * @return the bounding box's maxX value
147: */
148: public double getMaxX() {
149: return maxX;
150: }
151:
152: /**
153: * The maxX value is the higher X coordinate value
154: *
155: * @param maxX the new value for maxX. Should be greater than minX.
156: */
157: public void setMaxX(double maxX) {
158: this .maxX = maxX;
159: }
160:
161: /**
162: * The maxY value is the higher Y coordinate value
163: *
164: * @return the bounding box's maxY value
165: */
166: public double getMaxY() {
167: return maxY;
168: }
169:
170: /**
171: * The maxY value is the higher Y coordinate value
172: *
173: * @param maxY the new value for maxY. Should be greater than minY.
174: */
175: public void setMaxY(double maxY) {
176: this .maxY = maxY;
177: }
178:
179: /**
180: * The minX value is the lower X coordinate value
181: *
182: * @return the bounding box's minX value
183: */
184: public double getMinX() {
185: return minX;
186: }
187:
188: /**
189: * The minX value is the lower X coordinate value
190: *
191: * @param minX the new value for minX. Should be less than maxX.
192: */
193: public void setMinX(double minX) {
194: this .minX = minX;
195: }
196:
197: /**
198: * The minY value is the lower Y coordinate value
199: *
200: * @return the bounding box's minY value
201: */
202: public double getMinY() {
203: return minY;
204: }
205:
206: /**
207: * The minY value is the lower Y coordinate value
208: *
209: * @param minY the new value for minY. Should be less than maxY.
210: */
211: public void setMinY(double minY) {
212: this .minY = minY;
213: }
214:
215: public String toString() {
216: return epsgCode.toString() + " [" + minX + "," + minY + " "
217: + maxX + "," + maxY + "]";
218: }
219:
220: }
|