@Test public void testGetHorizontalCrs() { assertEquals( DefaultEngineeringCRS.GENERIC_2D, CRS.getHorizontalCRS(DefaultEngineeringCRS.GENERIC_2D)); }
public static SingleCRS getHorizontalCRS(final CoordinateReferenceSystem crs) { if (crs instanceof SingleCRS) { final CoordinateSystem cs = crs.getCoordinateSystem(); final int dimension = cs.getDimension(); if (dimension == 2) { CoordinateReferenceSystem base = crs; while (base instanceof GeneralDerivedCRS) { base = ((GeneralDerivedCRS) base).getBaseCRS(); } if (base instanceof GeographicCRS) { return (SingleCRS) crs; } if (base.getCoordinateSystem() instanceof CartesianCS) { return (SingleCRS) crs; } } else if (dimension >= 3 && crs instanceof GeographicCRS) { CoordinateSystemAxis axis0 = null, axis1 = null; int count = 0; for (int i=0; i<dimension; i++) { final CoordinateSystemAxis axis = cs.getAxis(i); search: if (DefaultCoordinateSystemAxis.isCompassDirection(axis.getDirection())) { switch (count++) { case 0: axis0 = axis; break; case 1: axis1 = axis; break; default: break search; } } } if (count == 2) { final GeodeticDatum datum = ((GeographicCRS) crs).getDatum(); Map<String,?> properties = CRSUtilities.changeDimensionInName(cs, "3D", "2D"); EllipsoidalCS horizontalCS; try { horizontalCS = ReferencingFactoryFinder.getCSFactory(null). createEllipsoidalCS(properties, axis0, axis1); } catch (FactoryException e) { Logging.recoverableException(CRS.class, "getHorizontalCRS", e); horizontalCS = new DefaultEllipsoidalCS(properties, axis0, axis1); } properties = CRSUtilities.changeDimensionInName(crs, "3D", "2D"); GeographicCRS horizontalCRS; try { horizontalCRS = ReferencingFactoryFinder.getCRSFactory(null). createGeographicCRS(properties, datum, horizontalCS); } catch (FactoryException e) { Logging.recoverableException(CRS.class, "getHorizontalCRS", e); horizontalCRS = new DefaultGeographicCRS(properties, datum, horizontalCS); } return horizontalCRS; } } } if (crs instanceof CompoundCRS) { final CompoundCRS cp = (CompoundCRS) crs; for (final CoordinateReferenceSystem c : cp.getCoordinateReferenceSystems()) { final SingleCRS candidate = getHorizontalCRS(c); if (candidate != null) { return candidate; } } } return null; }
CRS { public static SingleCRS getHorizontalCRS(final CoordinateReferenceSystem crs) { if (crs instanceof SingleCRS) { final CoordinateSystem cs = crs.getCoordinateSystem(); final int dimension = cs.getDimension(); if (dimension == 2) { CoordinateReferenceSystem base = crs; while (base instanceof GeneralDerivedCRS) { base = ((GeneralDerivedCRS) base).getBaseCRS(); } if (base instanceof GeographicCRS) { return (SingleCRS) crs; } if (base.getCoordinateSystem() instanceof CartesianCS) { return (SingleCRS) crs; } } else if (dimension >= 3 && crs instanceof GeographicCRS) { CoordinateSystemAxis axis0 = null, axis1 = null; int count = 0; for (int i=0; i<dimension; i++) { final CoordinateSystemAxis axis = cs.getAxis(i); search: if (DefaultCoordinateSystemAxis.isCompassDirection(axis.getDirection())) { switch (count++) { case 0: axis0 = axis; break; case 1: axis1 = axis; break; default: break search; } } } if (count == 2) { final GeodeticDatum datum = ((GeographicCRS) crs).getDatum(); Map<String,?> properties = CRSUtilities.changeDimensionInName(cs, "3D", "2D"); EllipsoidalCS horizontalCS; try { horizontalCS = ReferencingFactoryFinder.getCSFactory(null). createEllipsoidalCS(properties, axis0, axis1); } catch (FactoryException e) { Logging.recoverableException(CRS.class, "getHorizontalCRS", e); horizontalCS = new DefaultEllipsoidalCS(properties, axis0, axis1); } properties = CRSUtilities.changeDimensionInName(crs, "3D", "2D"); GeographicCRS horizontalCRS; try { horizontalCRS = ReferencingFactoryFinder.getCRSFactory(null). createGeographicCRS(properties, datum, horizontalCS); } catch (FactoryException e) { Logging.recoverableException(CRS.class, "getHorizontalCRS", e); horizontalCRS = new DefaultGeographicCRS(properties, datum, horizontalCS); } return horizontalCRS; } } } if (crs instanceof CompoundCRS) { final CompoundCRS cp = (CompoundCRS) crs; for (final CoordinateReferenceSystem c : cp.getCoordinateReferenceSystems()) { final SingleCRS candidate = getHorizontalCRS(c); if (candidate != null) { return candidate; } } } return null; } }
CRS { public static SingleCRS getHorizontalCRS(final CoordinateReferenceSystem crs) { if (crs instanceof SingleCRS) { final CoordinateSystem cs = crs.getCoordinateSystem(); final int dimension = cs.getDimension(); if (dimension == 2) { CoordinateReferenceSystem base = crs; while (base instanceof GeneralDerivedCRS) { base = ((GeneralDerivedCRS) base).getBaseCRS(); } if (base instanceof GeographicCRS) { return (SingleCRS) crs; } if (base.getCoordinateSystem() instanceof CartesianCS) { return (SingleCRS) crs; } } else if (dimension >= 3 && crs instanceof GeographicCRS) { CoordinateSystemAxis axis0 = null, axis1 = null; int count = 0; for (int i=0; i<dimension; i++) { final CoordinateSystemAxis axis = cs.getAxis(i); search: if (DefaultCoordinateSystemAxis.isCompassDirection(axis.getDirection())) { switch (count++) { case 0: axis0 = axis; break; case 1: axis1 = axis; break; default: break search; } } } if (count == 2) { final GeodeticDatum datum = ((GeographicCRS) crs).getDatum(); Map<String,?> properties = CRSUtilities.changeDimensionInName(cs, "3D", "2D"); EllipsoidalCS horizontalCS; try { horizontalCS = ReferencingFactoryFinder.getCSFactory(null). createEllipsoidalCS(properties, axis0, axis1); } catch (FactoryException e) { Logging.recoverableException(CRS.class, "getHorizontalCRS", e); horizontalCS = new DefaultEllipsoidalCS(properties, axis0, axis1); } properties = CRSUtilities.changeDimensionInName(crs, "3D", "2D"); GeographicCRS horizontalCRS; try { horizontalCRS = ReferencingFactoryFinder.getCRSFactory(null). createGeographicCRS(properties, datum, horizontalCS); } catch (FactoryException e) { Logging.recoverableException(CRS.class, "getHorizontalCRS", e); horizontalCRS = new DefaultGeographicCRS(properties, datum, horizontalCS); } return horizontalCRS; } } } if (crs instanceof CompoundCRS) { final CompoundCRS cp = (CompoundCRS) crs; for (final CoordinateReferenceSystem c : cp.getCoordinateReferenceSystems()) { final SingleCRS candidate = getHorizontalCRS(c); if (candidate != null) { return candidate; } } } return null; } private  CRS(); }
CRS { public static SingleCRS getHorizontalCRS(final CoordinateReferenceSystem crs) { if (crs instanceof SingleCRS) { final CoordinateSystem cs = crs.getCoordinateSystem(); final int dimension = cs.getDimension(); if (dimension == 2) { CoordinateReferenceSystem base = crs; while (base instanceof GeneralDerivedCRS) { base = ((GeneralDerivedCRS) base).getBaseCRS(); } if (base instanceof GeographicCRS) { return (SingleCRS) crs; } if (base.getCoordinateSystem() instanceof CartesianCS) { return (SingleCRS) crs; } } else if (dimension >= 3 && crs instanceof GeographicCRS) { CoordinateSystemAxis axis0 = null, axis1 = null; int count = 0; for (int i=0; i<dimension; i++) { final CoordinateSystemAxis axis = cs.getAxis(i); search: if (DefaultCoordinateSystemAxis.isCompassDirection(axis.getDirection())) { switch (count++) { case 0: axis0 = axis; break; case 1: axis1 = axis; break; default: break search; } } } if (count == 2) { final GeodeticDatum datum = ((GeographicCRS) crs).getDatum(); Map<String,?> properties = CRSUtilities.changeDimensionInName(cs, "3D", "2D"); EllipsoidalCS horizontalCS; try { horizontalCS = ReferencingFactoryFinder.getCSFactory(null). createEllipsoidalCS(properties, axis0, axis1); } catch (FactoryException e) { Logging.recoverableException(CRS.class, "getHorizontalCRS", e); horizontalCS = new DefaultEllipsoidalCS(properties, axis0, axis1); } properties = CRSUtilities.changeDimensionInName(crs, "3D", "2D"); GeographicCRS horizontalCRS; try { horizontalCRS = ReferencingFactoryFinder.getCRSFactory(null). createGeographicCRS(properties, datum, horizontalCS); } catch (FactoryException e) { Logging.recoverableException(CRS.class, "getHorizontalCRS", e); horizontalCRS = new DefaultGeographicCRS(properties, datum, horizontalCS); } return horizontalCRS; } } } if (crs instanceof CompoundCRS) { final CompoundCRS cp = (CompoundCRS) crs; for (final CoordinateReferenceSystem c : cp.getCoordinateReferenceSystems()) { final SingleCRS candidate = getHorizontalCRS(c); if (candidate != null) { return candidate; } } } return null; } private  CRS(); static synchronized CRSAuthorityFactory getAuthorityFactory(final boolean longitudeFirst); static synchronized CoordinateOperationFactory getCoordinateOperationFactory(final boolean lenient); static Version getVersion(final String authority); static Set<String> getSupportedCodes(final String authority); static Set<String> getSupportedAuthorities(final boolean returnAliases); static CoordinateReferenceSystem decode(final String code); static CoordinateReferenceSystem decode(String code, final boolean longitudeFirst); static CoordinateReferenceSystem parseWKT(final String wkt); static Envelope getEnvelope(final CoordinateReferenceSystem crs); static GeographicBoundingBox getGeographicBoundingBox(final CoordinateReferenceSystem crs); static SingleCRS getHorizontalCRS(final CoordinateReferenceSystem crs); static ProjectedCRS getProjectedCRS(final CoordinateReferenceSystem crs); static MapProjection getMapProjection(final CoordinateReferenceSystem crs); static VerticalCRS getVerticalCRS(final CoordinateReferenceSystem crs); static TemporalCRS getTemporalCRS(final CoordinateReferenceSystem crs); static Ellipsoid getEllipsoid(final CoordinateReferenceSystem crs); static boolean equalsIgnoreMetadata(final Object object1, final Object object2); static String toSRS(final CoordinateReferenceSystem crs); static String toSRS(final CoordinateReferenceSystem crs, boolean simple); static String lookupIdentifier(final IdentifiedObject object, final boolean fullScan); static String lookupIdentifier(final Citation authority,
            final CoordinateReferenceSystem crs, final boolean fullScan); static Integer lookupEpsgCode(final CoordinateReferenceSystem crs, final boolean fullScan); static MathTransform findMathTransform(final CoordinateReferenceSystem sourceCRS,
                                                  final CoordinateReferenceSystem targetCRS); static MathTransform findMathTransform(final CoordinateReferenceSystem sourceCRS,
                                                  final CoordinateReferenceSystem targetCRS,
                                                  boolean lenient); static Envelope transform(Envelope envelope, final CoordinateReferenceSystem targetCRS); static GeneralEnvelope transform(final MathTransform transform, final Envelope envelope); static GeneralEnvelope transform(final CoordinateOperation operation, final Envelope envelope); static Rectangle2D transform(final MathTransform2D transform,
                                        final Rectangle2D     envelope,
                                              Rectangle2D     destination); static Rectangle2D transform(final CoordinateOperation operation,
                                        final Rectangle2D         envelope,
                                              Rectangle2D         destination); static void reset(final String aspects); static void cleanupThreadLocals(); static AxisOrder getAxisOrder(CoordinateReferenceSystem crs); static AxisOrder getAxisOrder(CoordinateReferenceSystem crs, boolean useBaseGeoCRS); static void main(final String[] args); }
CRS { public static SingleCRS getHorizontalCRS(final CoordinateReferenceSystem crs) { if (crs instanceof SingleCRS) { final CoordinateSystem cs = crs.getCoordinateSystem(); final int dimension = cs.getDimension(); if (dimension == 2) { CoordinateReferenceSystem base = crs; while (base instanceof GeneralDerivedCRS) { base = ((GeneralDerivedCRS) base).getBaseCRS(); } if (base instanceof GeographicCRS) { return (SingleCRS) crs; } if (base.getCoordinateSystem() instanceof CartesianCS) { return (SingleCRS) crs; } } else if (dimension >= 3 && crs instanceof GeographicCRS) { CoordinateSystemAxis axis0 = null, axis1 = null; int count = 0; for (int i=0; i<dimension; i++) { final CoordinateSystemAxis axis = cs.getAxis(i); search: if (DefaultCoordinateSystemAxis.isCompassDirection(axis.getDirection())) { switch (count++) { case 0: axis0 = axis; break; case 1: axis1 = axis; break; default: break search; } } } if (count == 2) { final GeodeticDatum datum = ((GeographicCRS) crs).getDatum(); Map<String,?> properties = CRSUtilities.changeDimensionInName(cs, "3D", "2D"); EllipsoidalCS horizontalCS; try { horizontalCS = ReferencingFactoryFinder.getCSFactory(null). createEllipsoidalCS(properties, axis0, axis1); } catch (FactoryException e) { Logging.recoverableException(CRS.class, "getHorizontalCRS", e); horizontalCS = new DefaultEllipsoidalCS(properties, axis0, axis1); } properties = CRSUtilities.changeDimensionInName(crs, "3D", "2D"); GeographicCRS horizontalCRS; try { horizontalCRS = ReferencingFactoryFinder.getCRSFactory(null). createGeographicCRS(properties, datum, horizontalCS); } catch (FactoryException e) { Logging.recoverableException(CRS.class, "getHorizontalCRS", e); horizontalCRS = new DefaultGeographicCRS(properties, datum, horizontalCS); } return horizontalCRS; } } } if (crs instanceof CompoundCRS) { final CompoundCRS cp = (CompoundCRS) crs; for (final CoordinateReferenceSystem c : cp.getCoordinateReferenceSystems()) { final SingleCRS candidate = getHorizontalCRS(c); if (candidate != null) { return candidate; } } } return null; } private  CRS(); static synchronized CRSAuthorityFactory getAuthorityFactory(final boolean longitudeFirst); static synchronized CoordinateOperationFactory getCoordinateOperationFactory(final boolean lenient); static Version getVersion(final String authority); static Set<String> getSupportedCodes(final String authority); static Set<String> getSupportedAuthorities(final boolean returnAliases); static CoordinateReferenceSystem decode(final String code); static CoordinateReferenceSystem decode(String code, final boolean longitudeFirst); static CoordinateReferenceSystem parseWKT(final String wkt); static Envelope getEnvelope(final CoordinateReferenceSystem crs); static GeographicBoundingBox getGeographicBoundingBox(final CoordinateReferenceSystem crs); static SingleCRS getHorizontalCRS(final CoordinateReferenceSystem crs); static ProjectedCRS getProjectedCRS(final CoordinateReferenceSystem crs); static MapProjection getMapProjection(final CoordinateReferenceSystem crs); static VerticalCRS getVerticalCRS(final CoordinateReferenceSystem crs); static TemporalCRS getTemporalCRS(final CoordinateReferenceSystem crs); static Ellipsoid getEllipsoid(final CoordinateReferenceSystem crs); static boolean equalsIgnoreMetadata(final Object object1, final Object object2); static String toSRS(final CoordinateReferenceSystem crs); static String toSRS(final CoordinateReferenceSystem crs, boolean simple); static String lookupIdentifier(final IdentifiedObject object, final boolean fullScan); static String lookupIdentifier(final Citation authority,
            final CoordinateReferenceSystem crs, final boolean fullScan); static Integer lookupEpsgCode(final CoordinateReferenceSystem crs, final boolean fullScan); static MathTransform findMathTransform(final CoordinateReferenceSystem sourceCRS,
                                                  final CoordinateReferenceSystem targetCRS); static MathTransform findMathTransform(final CoordinateReferenceSystem sourceCRS,
                                                  final CoordinateReferenceSystem targetCRS,
                                                  boolean lenient); static Envelope transform(Envelope envelope, final CoordinateReferenceSystem targetCRS); static GeneralEnvelope transform(final MathTransform transform, final Envelope envelope); static GeneralEnvelope transform(final CoordinateOperation operation, final Envelope envelope); static Rectangle2D transform(final MathTransform2D transform,
                                        final Rectangle2D     envelope,
                                              Rectangle2D     destination); static Rectangle2D transform(final CoordinateOperation operation,
                                        final Rectangle2D         envelope,
                                              Rectangle2D         destination); static void reset(final String aspects); static void cleanupThreadLocals(); static AxisOrder getAxisOrder(CoordinateReferenceSystem crs); static AxisOrder getAxisOrder(CoordinateReferenceSystem crs, boolean useBaseGeoCRS); static void main(final String[] args);  }