001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2004, Institut de Recherche pour le D�veloppement
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: * This package contains documentation from OpenGIS specifications.
018: * OpenGIS consortium's work is fully acknowledged here.
019: */
020: package org.geotools.referencing.factory;
021:
022: // J2SE dependencies and extensions
023: import java.text.ParseException;
024: import java.util.Date;
025: import java.util.Map;
026: import javax.units.Unit;
027:
028: // OpenGIS dependencies
029: import org.opengis.metadata.citation.Citation;
030: import org.opengis.parameter.GeneralParameterValue;
031: import org.opengis.parameter.ParameterValue;
032: import org.opengis.parameter.ParameterValueGroup;
033: import org.opengis.referencing.*;
034: import org.opengis.referencing.cs.*;
035: import org.opengis.referencing.crs.*;
036: import org.opengis.referencing.datum.*;
037: import org.opengis.referencing.operation.*;
038: import org.opengis.util.InternationalString;
039:
040: // Geotools dependencies
041: import org.geotools.factory.Hints;
042: import org.geotools.factory.BufferedFactory;
043: import org.geotools.referencing.ReferencingFactoryFinder;
044: import org.geotools.referencing.wkt.Parser;
045: import org.geotools.referencing.wkt.Symbols;
046: import org.geotools.referencing.cs.*;
047: import org.geotools.referencing.crs.*;
048: import org.geotools.referencing.datum.*;
049: import org.geotools.referencing.operation.DefaultOperationMethod;
050: import org.geotools.util.CanonicalSet;
051:
052: /**
053: * Builds Geotools implementations of {@linkplain CoordinateReferenceSystem CRS},
054: * {@linkplain CoordinateSystem CS} and {@linkplain Datum datum} objects. Most factory methods
055: * expect properties given through a {@link Map} argument. The content of this map is described
056: * in the {@link ObjectFactory} interface.
057: *
058: * @since 2.4
059: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/factory/ReferencingObjectFactory.java $
060: * @version $Id: ReferencingObjectFactory.java 28031 2007-11-23 21:24:22Z desruisseaux $
061: * @author Martin Desruisseaux
062: */
063: public class ReferencingObjectFactory extends ReferencingFactory
064: implements CSFactory, DatumFactory, CRSFactory, BufferedFactory {
065: /**
066: * The object to use for parsing <cite>Well-Known Text</cite> (WKT) strings.
067: * Will be created only when first needed.
068: */
069: private transient Parser parser;
070:
071: /**
072: * Set of weak references to existing objects (identifiers, CRS, Datum, whatever).
073: * This set is used in order to return a pre-existing object instead of creating a
074: * new one.
075: */
076: private final CanonicalSet pool = new CanonicalSet();
077:
078: /**
079: * Constructs a default factory. This method is public in order to allows instantiations
080: * from a {@linkplain javax.imageio.spi.ServiceRegistry service registry}. Users should
081: * not instantiate this factory directly, but use one of the following lines instead:
082: *
083: * <blockquote><pre>
084: * {@linkplain DatumFactory} factory = FactoryFinder.{@linkplain ReferencingFactoryFinder#getDatumFactory getDatumFactory(null)};
085: * {@linkplain CSFactory} factory = FactoryFinder.{@linkplain ReferencingFactoryFinder#getCSFactory getCSFactory(null)};
086: * {@linkplain CRSFactory} factory = FactoryFinder.{@linkplain ReferencingFactoryFinder#getCRSFactory getCRSFactory(null)};
087: * </pre></blockquote>
088: */
089: public ReferencingObjectFactory() {
090: }
091:
092: /////////////////////////////////////////////////////////////////////////////////////////
093: //////// ////////
094: //////// D A T U M F A C T O R Y ////////
095: //////// ////////
096: /////////////////////////////////////////////////////////////////////////////////////////
097:
098: /**
099: * Creates an ellipsoid from radius values.
100: *
101: * @param properties Name and other properties to give to the new object.
102: * @param semiMajorAxis Equatorial radius in supplied linear units.
103: * @param semiMinorAxis Polar radius in supplied linear units.
104: * @param unit Linear units of ellipsoid axes.
105: * @throws FactoryException if the object creation failed.
106: */
107: public Ellipsoid createEllipsoid(Map properties,
108: double semiMajorAxis, double semiMinorAxis, Unit unit)
109: throws FactoryException {
110: Ellipsoid ellipsoid;
111: try {
112: ellipsoid = DefaultEllipsoid.createEllipsoid(properties,
113: semiMajorAxis, semiMinorAxis, unit);
114: } catch (IllegalArgumentException exception) {
115: throw new FactoryException(exception);
116: }
117: ellipsoid = (Ellipsoid) pool.unique(ellipsoid);
118: return ellipsoid;
119: }
120:
121: /**
122: * Creates an ellipsoid from an major radius, and inverse flattening.
123: *
124: * @param properties Name and other properties to give to the new object.
125: * @param semiMajorAxis Equatorial radius in supplied linear units.
126: * @param inverseFlattening Eccentricity of ellipsoid.
127: * @param unit Linear units of major axis.
128: * @throws FactoryException if the object creation failed.
129: */
130: public Ellipsoid createFlattenedSphere(Map properties,
131: double semiMajorAxis, double inverseFlattening, Unit unit)
132: throws FactoryException {
133: Ellipsoid ellipsoid;
134: try {
135: ellipsoid = DefaultEllipsoid.createFlattenedSphere(
136: properties, semiMajorAxis, inverseFlattening, unit);
137: } catch (IllegalArgumentException exception) {
138: throw new FactoryException(exception);
139: }
140: ellipsoid = (Ellipsoid) pool.unique(ellipsoid);
141: return ellipsoid;
142: }
143:
144: /**
145: * Creates a prime meridian, relative to Greenwich.
146: *
147: * @param properties Name and other properties to give to the new object.
148: * @param longitude Longitude of prime meridian in supplied angular units East of Greenwich.
149: * @param angularUnit Angular units of longitude.
150: * @throws FactoryException if the object creation failed.
151: */
152: public PrimeMeridian createPrimeMeridian(Map properties,
153: double longitude, Unit angularUnit) throws FactoryException {
154: PrimeMeridian meridian;
155: try {
156: meridian = new DefaultPrimeMeridian(properties, longitude,
157: angularUnit);
158: } catch (IllegalArgumentException exception) {
159: throw new FactoryException(exception);
160: }
161: meridian = (PrimeMeridian) pool.unique(meridian);
162: return meridian;
163: }
164:
165: /**
166: * Creates geodetic datum from ellipsoid and (optionaly) Bursa-Wolf parameters.
167: *
168: * @param properties Name and other properties to give to the new object.
169: * @param ellipsoid Ellipsoid to use in new geodetic datum.
170: * @param primeMeridian Prime meridian to use in new geodetic datum.
171: * @throws FactoryException if the object creation failed.
172: */
173: public GeodeticDatum createGeodeticDatum(Map properties,
174: Ellipsoid ellipsoid, PrimeMeridian primeMeridian)
175: throws FactoryException {
176: GeodeticDatum datum;
177: try {
178: datum = new DefaultGeodeticDatum(properties, ellipsoid,
179: primeMeridian);
180: } catch (IllegalArgumentException exception) {
181: throw new FactoryException(exception);
182: }
183: datum = (GeodeticDatum) pool.unique(datum);
184: return datum;
185: }
186:
187: /**
188: * Creates a vertical datum from an enumerated type value.
189: *
190: * @param properties Name and other properties to give to the new object.
191: * @param type The type of this vertical datum (often geoidal).
192: * @throws FactoryException if the object creation failed.
193: */
194: public VerticalDatum createVerticalDatum(Map properties,
195: VerticalDatumType type) throws FactoryException {
196: VerticalDatum datum;
197: try {
198: datum = new DefaultVerticalDatum(properties, type);
199: } catch (IllegalArgumentException exception) {
200: throw new FactoryException(exception);
201: }
202: datum = (VerticalDatum) pool.unique(datum);
203: return datum;
204: }
205:
206: /**
207: * Creates a temporal datum from an enumerated type value.
208: *
209: * @param properties Name and other properties to give to the new object.
210: * @param origin The date and time origin of this temporal datum.
211: * @throws FactoryException if the object creation failed.
212: */
213: public TemporalDatum createTemporalDatum(Map properties, Date origin)
214: throws FactoryException {
215: TemporalDatum datum;
216: try {
217: datum = new DefaultTemporalDatum(properties, origin);
218: } catch (IllegalArgumentException exception) {
219: throw new FactoryException(exception);
220: }
221: datum = (TemporalDatum) pool.unique(datum);
222: return datum;
223: }
224:
225: /**
226: * Creates an engineering datum.
227: *
228: * @param properties Name and other properties to give to the new object.
229: * @throws FactoryException if the object creation failed.
230: */
231: public EngineeringDatum createEngineeringDatum(Map properties)
232: throws FactoryException {
233: EngineeringDatum datum;
234: try {
235: datum = new DefaultEngineeringDatum(properties);
236: } catch (IllegalArgumentException exception) {
237: throw new FactoryException(exception);
238: }
239: datum = (EngineeringDatum) pool.unique(datum);
240: return datum;
241: }
242:
243: /**
244: * Creates an image datum.
245: *
246: * @param properties Name and other properties to give to the new object.
247: * @param pixelInCell Specification of the way the image grid is associated
248: * with the image data attributes.
249: * @throws FactoryException if the object creation failed.
250: */
251: public ImageDatum createImageDatum(Map properties,
252: PixelInCell pixelInCell) throws FactoryException {
253: ImageDatum datum;
254: try {
255: datum = new DefaultImageDatum(properties, pixelInCell);
256: } catch (IllegalArgumentException exception) {
257: throw new FactoryException(exception);
258: }
259: datum = (ImageDatum) pool.unique(datum);
260: return datum;
261: }
262:
263: /////////////////////////////////////////////////////////////////////////////////////////
264: //////// ////////
265: //////// C O O R D I N A T E S Y S T E M F A C T O R Y ////////
266: //////// ////////
267: /////////////////////////////////////////////////////////////////////////////////////////
268:
269: /**
270: * Creates a coordinate system axis from an abbreviation and a unit.
271: *
272: * @param properties Name and other properties to give to the new object.
273: * @param abbreviation The coordinate axis abbreviation.
274: * @param direction The axis direction.
275: * @param unit The coordinate axis unit.
276: * @throws FactoryException if the object creation failed.
277: */
278: public CoordinateSystemAxis createCoordinateSystemAxis(
279: Map properties, String abbreviation,
280: AxisDirection direction, Unit unit) throws FactoryException {
281: CoordinateSystemAxis axis;
282: try {
283: axis = new DefaultCoordinateSystemAxis(properties,
284: abbreviation, direction, unit);
285: } catch (IllegalArgumentException exception) {
286: throw new FactoryException(exception);
287: }
288: axis = (CoordinateSystemAxis) pool.unique(axis);
289: return axis;
290: }
291:
292: /**
293: * Creates a two dimensional cartesian coordinate system from the given pair of axis.
294: *
295: * @param properties Name and other properties to give to the new object.
296: * @param axis0 The first axis.
297: * @param axis1 The second axis.
298: * @throws FactoryException if the object creation failed.
299: */
300: public CartesianCS createCartesianCS(Map properties,
301: CoordinateSystemAxis axis0, CoordinateSystemAxis axis1)
302: throws FactoryException {
303: CartesianCS cs;
304: try {
305: cs = new DefaultCartesianCS(properties, axis0, axis1);
306: } catch (IllegalArgumentException exception) {
307: throw new FactoryException(exception);
308: }
309: cs = (CartesianCS) pool.unique(cs);
310: return cs;
311: }
312:
313: /**
314: * Creates a three dimensional cartesian coordinate system from the given set of axis.
315: *
316: * @param properties Name and other properties to give to the new object.
317: * @param axis0 The first axis.
318: * @param axis1 The second axis.
319: * @param axis2 The third axis.
320: * @throws FactoryException if the object creation failed.
321: */
322: public CartesianCS createCartesianCS(Map properties,
323: CoordinateSystemAxis axis0, CoordinateSystemAxis axis1,
324: CoordinateSystemAxis axis2) throws FactoryException {
325: CartesianCS cs;
326: try {
327: cs = new DefaultCartesianCS(properties, axis0, axis1, axis2);
328: } catch (IllegalArgumentException exception) {
329: throw new FactoryException(exception);
330: }
331: cs = (CartesianCS) pool.unique(cs);
332: return cs;
333: }
334:
335: /**
336: * Creates a two dimensional coordinate system from the given pair of axis.
337: *
338: * @param properties Name and other properties to give to the new object.
339: * @param axis0 The first axis.
340: * @param axis1 The second axis.
341: * @throws FactoryException if the object creation failed.
342: */
343: public AffineCS createAffineCS(Map properties,
344: CoordinateSystemAxis axis0, CoordinateSystemAxis axis1)
345: throws FactoryException {
346: AffineCS cs;
347: try {
348: cs = new DefaultAffineCS(properties, axis0, axis1);
349: } catch (IllegalArgumentException exception) {
350: throw new FactoryException(exception);
351: }
352: cs = (AffineCS) pool.unique(cs);
353: return cs;
354: }
355:
356: /**
357: * Creates a three dimensional coordinate system from the given set of axis.
358: *
359: * @param properties Name and other properties to give to the new object.
360: * @param axis0 The first axis.
361: * @param axis1 The second axis.
362: * @param axis2 The third axis.
363: * @throws FactoryException if the object creation failed.
364: */
365: public AffineCS createAffineCS(Map properties,
366: CoordinateSystemAxis axis0, CoordinateSystemAxis axis1,
367: CoordinateSystemAxis axis2) throws FactoryException {
368: AffineCS cs;
369: try {
370: cs = new DefaultAffineCS(properties, axis0, axis1, axis2);
371: } catch (IllegalArgumentException exception) {
372: throw new FactoryException(exception);
373: }
374: cs = (AffineCS) pool.unique(cs);
375: return cs;
376: }
377:
378: /**
379: * Creates a polar coordinate system from the given pair of axis.
380: *
381: * @param properties Name and other properties to give to the new object.
382: * @param axis0 The first axis.
383: * @param axis1 The second axis.
384: * @throws FactoryException if the object creation failed.
385: */
386: public PolarCS createPolarCS(Map properties,
387: CoordinateSystemAxis axis0, CoordinateSystemAxis axis1)
388: throws FactoryException {
389: PolarCS cs;
390: try {
391: cs = new DefaultPolarCS(properties, axis0, axis1);
392: } catch (IllegalArgumentException exception) {
393: throw new FactoryException(exception);
394: }
395: cs = (PolarCS) pool.unique(cs);
396: return cs;
397: }
398:
399: /**
400: * Creates a cylindrical coordinate system from the given set of axis.
401: *
402: * @param properties Name and other properties to give to the new object.
403: * @param axis0 The first axis.
404: * @param axis1 The second axis.
405: * @param axis2 The third axis.
406: * @throws FactoryException if the object creation failed.
407: */
408: public CylindricalCS createCylindricalCS(Map properties,
409: CoordinateSystemAxis axis0, CoordinateSystemAxis axis1,
410: CoordinateSystemAxis axis2) throws FactoryException {
411: CylindricalCS cs;
412: try {
413: cs = new DefaultCylindricalCS(properties, axis0, axis1,
414: axis2);
415: } catch (IllegalArgumentException exception) {
416: throw new FactoryException(exception);
417: }
418: cs = (CylindricalCS) pool.unique(cs);
419: return cs;
420: }
421:
422: /**
423: * Creates a spherical coordinate system from the given set of axis.
424: *
425: * @param properties Name and other properties to give to the new object.
426: * @param axis0 The first axis.
427: * @param axis1 The second axis.
428: * @param axis2 The third axis.
429: * @throws FactoryException if the object creation failed.
430: */
431: public SphericalCS createSphericalCS(Map properties,
432: CoordinateSystemAxis axis0, CoordinateSystemAxis axis1,
433: CoordinateSystemAxis axis2) throws FactoryException {
434: SphericalCS cs;
435: try {
436: cs = new DefaultSphericalCS(properties, axis0, axis1, axis2);
437: } catch (IllegalArgumentException exception) {
438: throw new FactoryException(exception);
439: }
440: cs = (SphericalCS) pool.unique(cs);
441: return cs;
442: }
443:
444: /**
445: * Creates an ellipsoidal coordinate system without ellipsoidal height.
446: *
447: * @param properties Name and other properties to give to the new object.
448: * @param axis0 The first axis.
449: * @param axis1 The second axis.
450: * @throws FactoryException if the object creation failed.
451: */
452: public EllipsoidalCS createEllipsoidalCS(Map properties,
453: CoordinateSystemAxis axis0, CoordinateSystemAxis axis1)
454: throws FactoryException {
455: EllipsoidalCS cs;
456: try {
457: cs = new DefaultEllipsoidalCS(properties, axis0, axis1);
458: } catch (IllegalArgumentException exception) {
459: throw new FactoryException(exception);
460: }
461: cs = (EllipsoidalCS) pool.unique(cs);
462: return cs;
463: }
464:
465: /**
466: * Creates an ellipsoidal coordinate system with ellipsoidal height.
467: *
468: * @param properties Name and other properties to give to the new object.
469: * @param axis0 The first axis.
470: * @param axis1 The second axis.
471: * @param axis2 The third axis.
472: * @throws FactoryException if the object creation failed.
473: */
474: public EllipsoidalCS createEllipsoidalCS(Map properties,
475: CoordinateSystemAxis axis0, CoordinateSystemAxis axis1,
476: CoordinateSystemAxis axis2) throws FactoryException {
477: EllipsoidalCS cs;
478: try {
479: cs = new DefaultEllipsoidalCS(properties, axis0, axis1,
480: axis2);
481: } catch (IllegalArgumentException exception) {
482: throw new FactoryException(exception);
483: }
484: cs = (EllipsoidalCS) pool.unique(cs);
485: return cs;
486: }
487:
488: /**
489: * Creates a vertical coordinate system.
490: *
491: * @param properties Name and other properties to give to the new object.
492: * @param axis The axis.
493: * @throws FactoryException if the object creation failed.
494: */
495: public VerticalCS createVerticalCS(Map properties,
496: CoordinateSystemAxis axis) throws FactoryException {
497: VerticalCS cs;
498: try {
499: cs = new DefaultVerticalCS(properties, axis);
500: } catch (IllegalArgumentException exception) {
501: throw new FactoryException(exception);
502: }
503: cs = (VerticalCS) pool.unique(cs);
504: return cs;
505: }
506:
507: /**
508: * Creates a temporal coordinate system.
509: *
510: * @param properties Name and other properties to give to the new object.
511: * @param axis The axis.
512: * @throws FactoryException if the object creation failed.
513: */
514: public TimeCS createTimeCS(Map properties, CoordinateSystemAxis axis)
515: throws FactoryException {
516: TimeCS cs;
517: try {
518: cs = new DefaultTimeCS(properties, axis);
519: } catch (IllegalArgumentException exception) {
520: throw new FactoryException(exception);
521: }
522: cs = (TimeCS) pool.unique(cs);
523: return cs;
524: }
525:
526: /**
527: * Creates a linear coordinate system.
528: *
529: * @param properties Name and other properties to give to the new object.
530: * @param axis The axis.
531: * @throws FactoryException if the object creation failed.
532: */
533: public LinearCS createLinearCS(Map properties,
534: CoordinateSystemAxis axis) throws FactoryException {
535: LinearCS cs;
536: try {
537: cs = new DefaultLinearCS(properties, axis);
538: } catch (IllegalArgumentException exception) {
539: throw new FactoryException(exception);
540: }
541: cs = (LinearCS) pool.unique(cs);
542: return cs;
543: }
544:
545: /**
546: * Creates a two dimensional user defined coordinate system from the given pair of axis.
547: *
548: * @param properties Name and other properties to give to the new object.
549: * @param axis0 The first axis.
550: * @param axis1 The second axis.
551: * @throws FactoryException if the object creation failed.
552: */
553: public UserDefinedCS createUserDefinedCS(Map properties,
554: CoordinateSystemAxis axis0, CoordinateSystemAxis axis1)
555: throws FactoryException {
556: UserDefinedCS cs;
557: try {
558: cs = new DefaultUserDefinedCS(properties, axis0, axis1);
559: } catch (IllegalArgumentException exception) {
560: throw new FactoryException(exception);
561: }
562: cs = (UserDefinedCS) pool.unique(cs);
563: return cs;
564: }
565:
566: /**
567: * Creates a three dimensional user defined coordinate system from the given set of axis.
568: *
569: * @param properties Name and other properties to give to the new object.
570: * @param axis0 The first axis.
571: * @param axis1 The second axis.
572: * @param axis2 The third axis.
573: * @throws FactoryException if the object creation failed.
574: */
575: public UserDefinedCS createUserDefinedCS(Map properties,
576: CoordinateSystemAxis axis0, CoordinateSystemAxis axis1,
577: CoordinateSystemAxis axis2) throws FactoryException {
578: UserDefinedCS cs;
579: try {
580: cs = new DefaultUserDefinedCS(properties, axis0, axis1,
581: axis2);
582: } catch (IllegalArgumentException exception) {
583: throw new FactoryException(exception);
584: }
585: cs = (UserDefinedCS) pool.unique(cs);
586: return cs;
587: }
588:
589: /////////////////////////////////////////////////////////////////////////////////////////
590: //////// ////////
591: //////// C O O R D I N A T E R E F E R E N C E S Y S T E M F A C T O R Y ////////
592: //////// ////////
593: /////////////////////////////////////////////////////////////////////////////////////////
594:
595: /**
596: * Creates a compound coordinate reference system from an ordered
597: * list of {@code CoordinateReferenceSystem} objects.
598: *
599: * @param properties Name and other properties to give to the new object.
600: * @param elements ordered array of {@code CoordinateReferenceSystem} objects.
601: * @throws FactoryException if the object creation failed.
602: */
603: public CompoundCRS createCompoundCRS(Map properties,
604: CoordinateReferenceSystem[] elements)
605: throws FactoryException {
606: CompoundCRS crs;
607: try {
608: crs = new DefaultCompoundCRS(properties, elements);
609: } catch (IllegalArgumentException exception) {
610: throw new FactoryException(exception);
611: }
612: crs = (CompoundCRS) pool.unique(crs);
613: return crs;
614: }
615:
616: /**
617: * Creates a engineering coordinate reference system.
618: *
619: * @param properties Name and other properties to give to the new object.
620: * @param datum Engineering datum to use in created CRS.
621: * @param cs The coordinate system for the created CRS.
622: * @throws FactoryException if the object creation failed.
623: */
624: public EngineeringCRS createEngineeringCRS(Map properties,
625: EngineeringDatum datum, CoordinateSystem cs)
626: throws FactoryException {
627: EngineeringCRS crs;
628: try {
629: crs = new DefaultEngineeringCRS(properties, datum, cs);
630: } catch (IllegalArgumentException exception) {
631: throw new FactoryException(exception);
632: }
633: crs = (EngineeringCRS) pool.unique(crs);
634: return crs;
635: }
636:
637: /**
638: * Creates an image coordinate reference system.
639: *
640: * @param properties Name and other properties to give to the new object.
641: * @param datum Image datum to use in created CRS.
642: * @param cs The Cartesian or Oblique Cartesian coordinate system for the created CRS.
643: * @throws FactoryException if the object creation failed.
644: */
645: public ImageCRS createImageCRS(Map properties, ImageDatum datum,
646: AffineCS cs) throws FactoryException {
647: ImageCRS crs;
648: try {
649: crs = new DefaultImageCRS(properties, datum, cs);
650: } catch (IllegalArgumentException exception) {
651: throw new FactoryException(exception);
652: }
653: crs = (ImageCRS) pool.unique(crs);
654: return crs;
655: }
656:
657: /**
658: * Creates a temporal coordinate reference system.
659: *
660: * @param properties Name and other properties to give to the new object.
661: * @param datum Temporal datum to use in created CRS.
662: * @param cs The Temporal coordinate system for the created CRS.
663: * @throws FactoryException if the object creation failed.
664: */
665: public TemporalCRS createTemporalCRS(Map properties,
666: TemporalDatum datum, TimeCS cs) throws FactoryException {
667: TemporalCRS crs;
668: try {
669: crs = new DefaultTemporalCRS(properties, datum, cs);
670: } catch (IllegalArgumentException exception) {
671: throw new FactoryException(exception);
672: }
673: crs = (TemporalCRS) pool.unique(crs);
674: return crs;
675: }
676:
677: /**
678: * Creates a vertical coordinate reference system.
679: *
680: * @param properties Name and other properties to give to the new object.
681: * @param datum Vertical datum to use in created CRS.
682: * @param cs The Vertical coordinate system for the created CRS.
683: * @throws FactoryException if the object creation failed.
684: */
685: public VerticalCRS createVerticalCRS(Map properties,
686: VerticalDatum datum, VerticalCS cs) throws FactoryException {
687: VerticalCRS crs;
688: try {
689: crs = new DefaultVerticalCRS(properties, datum, cs);
690: } catch (IllegalArgumentException exception) {
691: throw new FactoryException(exception);
692: }
693: crs = (VerticalCRS) pool.unique(crs);
694: return crs;
695: }
696:
697: /**
698: * Creates a geocentric coordinate reference system from a {@linkplain CartesianCS
699: * cartesian coordinate system}.
700: *
701: * @param properties Name and other properties to give to the new object.
702: * @param datum Geodetic datum to use in created CRS.
703: * @param cs The cartesian coordinate system for the created CRS.
704: * @throws FactoryException if the object creation failed.
705: */
706: public GeocentricCRS createGeocentricCRS(Map properties,
707: GeodeticDatum datum, CartesianCS cs)
708: throws FactoryException {
709: GeocentricCRS crs;
710: try {
711: crs = new DefaultGeocentricCRS(properties, datum, cs);
712: } catch (IllegalArgumentException exception) {
713: throw new FactoryException(exception);
714: }
715: crs = (GeocentricCRS) pool.unique(crs);
716: return crs;
717: }
718:
719: /**
720: * Creates a geocentric coordinate reference system from a {@linkplain SphericalCS
721: * spherical coordinate system}.
722: *
723: * @param properties Name and other properties to give to the new object.
724: * @param datum Geodetic datum to use in created CRS.
725: * @param cs The spherical coordinate system for the created CRS.
726: * @throws FactoryException if the object creation failed.
727: */
728: public GeocentricCRS createGeocentricCRS(Map properties,
729: GeodeticDatum datum, SphericalCS cs)
730: throws FactoryException {
731: GeocentricCRS crs;
732: try {
733: crs = new DefaultGeocentricCRS(properties, datum, cs);
734: } catch (IllegalArgumentException exception) {
735: throw new FactoryException(exception);
736: }
737: crs = (GeocentricCRS) pool.unique(crs);
738: return crs;
739: }
740:
741: /**
742: * Creates a geographic coordinate reference system.
743: * It could be <var>Latitude</var>/<var>Longitude</var> or
744: * <var>Longitude</var>/<var>Latitude</var>.
745: *
746: * @param properties Name and other properties to give to the new object.
747: * @param datum Geodetic datum to use in created CRS.
748: * @param cs The ellipsoidal coordinate system for the created CRS.
749: * @throws FactoryException if the object creation failed.
750: */
751: public GeographicCRS createGeographicCRS(Map properties,
752: GeodeticDatum datum, EllipsoidalCS cs)
753: throws FactoryException {
754: GeographicCRS crs;
755: try {
756: crs = new DefaultGeographicCRS(properties, datum, cs);
757: } catch (IllegalArgumentException exception) {
758: throw new FactoryException(exception);
759: }
760: crs = (GeographicCRS) pool.unique(crs);
761: return crs;
762: }
763:
764: /**
765: * Creates a derived coordinate reference system. If the transformation is an affine
766: * map performing a rotation, then any mixed axes must have identical units.
767: * For example, a (<var>lat_deg</var>, <var>lon_deg</var>, <var>height_feet</var>)
768: * system can be rotated in the (<var>lat</var>, <var>lon</var>) plane, since both
769: * affected axes are in decimal degrees. But you should not rotate this coordinate
770: * system in any other plane.
771: * <p>
772: * <strong>NOTE:</strong>
773: * It is the user's responsability to ensure that the {@code baseToDerived} transform performs
774: * all required steps, including {@linkplain AbstractCS#swapAndScaleAxis unit conversions and
775: * change of axis order}, if needed. The {@link ReferencingFactoryContainer} class provides
776: * conveniences methods for this task.
777: *
778: * @param properties Name and other properties to give to the new object.
779: * @param method A description of the {@linkplain Conversion#getMethod method for the
780: * conversion}.
781: * @param base Coordinate reference system to base the derived CRS on.
782: * @param baseToDerived The transform from the base CRS to returned CRS.
783: * @param derivedCS The coordinate system for the derived CRS.
784: * @throws FactoryException if the object creation failed.
785: */
786: public DerivedCRS createDerivedCRS(Map properties,
787: OperationMethod method, CoordinateReferenceSystem base,
788: MathTransform baseToDerived, CoordinateSystem derivedCS)
789: throws FactoryException {
790: DerivedCRS crs;
791: try {
792: crs = new DefaultDerivedCRS(properties, method, base,
793: baseToDerived, derivedCS);
794: } catch (IllegalArgumentException exception) {
795: throw new FactoryException(exception);
796: }
797: crs = (DerivedCRS) pool.unique(crs);
798: return crs;
799: }
800:
801: /**
802: * Not yet implemented in GeoTools 2.4. This is implemented in GeoTools 2.5.
803: */
804: public DerivedCRS createDerivedCRS(Map properties,
805: CoordinateReferenceSystem baseCRS,
806: Conversion conversionFromBase, CoordinateSystem derivedCS)
807: throws FactoryException {
808: throw new FactoryException("Not yet implemented.");
809: }
810:
811: /**
812: * Creates a projected coordinate reference system from a transform.
813: * <p>
814: * <strong>NOTE:</strong>
815: * It is the user's responsability to ensure that the {@code baseToDerived} transform performs
816: * all required steps, including {@linkplain AbstractCS#swapAndScaleAxis unit conversions and
817: * change of axis order}, if needed. The {@link ReferencingFactoryContainer} class provides
818: * conveniences methods for this task.
819: *
820: * @param properties Name and other properties to give to the new object.
821: * @param method A description of the {@linkplain Conversion#getMethod method for the
822: * projection}.
823: * @param base Geographic coordinate reference system to base projection on.
824: * @param baseToDerived The transform from the geographic to the projected CRS.
825: * @param derivedCS The coordinate system for the projected CRS.
826: * @throws FactoryException if the object creation failed.
827: */
828: public ProjectedCRS createProjectedCRS(Map properties,
829: OperationMethod method, GeographicCRS base,
830: MathTransform baseToDerived, CartesianCS derivedCS)
831: throws FactoryException {
832: ProjectedCRS crs;
833: try {
834: crs = new DefaultProjectedCRS(properties, method, base,
835: baseToDerived, derivedCS);
836: } catch (IllegalArgumentException exception) {
837: throw new FactoryException(exception);
838: }
839: crs = (ProjectedCRS) pool.unique(crs);
840: return crs;
841: }
842:
843: /**
844: * Not yet implemented in GeoTools 2.4. This is implemented in GeoTools 2.5.
845: */
846: public ProjectedCRS createProjectedCRS(Map properties,
847: GeographicCRS baseCRS, Conversion conversionFromBase,
848: CartesianCS derivedCS) throws FactoryException {
849: throw new FactoryException("Not yet implemented.");
850: }
851:
852: /**
853: * Creates a coordinate reference system object from a XML string.
854: *
855: * @param xml Coordinate reference system encoded in XML format.
856: * @throws FactoryException if the object creation failed.
857: *
858: * @todo Not yet implemented.
859: */
860: public CoordinateReferenceSystem createFromXML(String xml)
861: throws FactoryException {
862: throw new FactoryException("Not yet implemented");
863: }
864:
865: /**
866: * Creates a coordinate reference system object from a string.
867: * The <A HREF="../doc-files/WKT.html">definition for WKT</A>
868: * is shown using Extended Backus Naur Form (EBNF).
869: *
870: * @param wkt Coordinate system encoded in Well-Known Text format.
871: * @throws FactoryException if the object creation failed.
872: */
873: public synchronized CoordinateReferenceSystem createFromWKT(
874: final String wkt) throws FactoryException {
875: // Note: while this factory is thread safe, the WKT parser is not.
876: // Since we share a single instance of this parser, we must
877: // synchronize.
878: if (parser == null) {
879: final Hints hints = new Hints(getImplementationHints());
880: parser = new Parser(Symbols.DEFAULT,
881: ReferencingFactoryFinder.getDatumFactory(hints),
882: this , this , ReferencingFactoryFinder
883: .getMathTransformFactory(hints));
884: }
885: try {
886: return parser.parseCoordinateReferenceSystem(wkt);
887: } catch (ParseException exception) {
888: final Throwable cause = exception.getCause();
889: if (cause instanceof FactoryException) {
890: throw (FactoryException) cause;
891: }
892: throw new FactoryException(exception);
893: }
894: }
895: }
|