/** Returns a collection containing only the factories of the specified authority. */
 private static Collection<CRSAuthorityFactory> filter(
     final Collection<? extends CRSAuthorityFactory> factories, final String authority) {
   final List<CRSAuthorityFactory> filtered = new ArrayList<CRSAuthorityFactory>();
   for (final CRSAuthorityFactory factory : factories) {
     if (Citations.identifierMatches(factory.getAuthority(), authority)) {
       filtered.add(factory);
     }
   }
   return filtered;
 }
Esempio n. 2
0
  static List<SRS> buildCodeList() {
    long t = System.currentTimeMillis();
    Set<String> codes = CRS.getSupportedCodes("EPSG");

    try {
      codes.addAll(customFactory.getAuthorityCodes(CoordinateReferenceSystem.class));
    } catch (FactoryException e) {
      LOGGER.log(Level.WARNING, "Error occurred while trying to gather custom CRS codes", e);
    }

    // make a set with each code
    Set<SRS> idSet = new HashSet<SRS>();
    for (String code : codes) {
      // make sure we're using just the non prefix part
      String id = code.substring(code.indexOf(':') + 1);
      // avoid WGS84DD and eventual friends, as we're still not able to handle them,
      // if they are chosen exceptions arises everywhere
      if (NUMERIC.matcher(id).matches()) {
        idSet.add(new SRS(id));
      }
    }

    List<SRS> srsList = new ArrayList<SRS>(idSet);
    Collections.sort(srsList, new CodeComparator()); // sort to get them in order
    return srsList;
  }
  public static CoordinateReferenceSystem getCRS(MapProjection projection, Datum datum) {
    CoordinateReferenceSystem result = WGS84;

    try {
      final MapTransform mapTransform = projection.getMapTransform();
      if (mapTransform.getDescriptor() instanceof IdentityTransformDescriptor) {
        // 1. Identity map projection
        if (Datum.ITRF_97.equals(datum)) {
          result = ITRF97;
        } else if (Datum.WGS_72.equals(datum)) {
          result = WGS72;
        }
      } else if (projection instanceof UTMProjection && !Datum.ITRF_97.equals(datum)) {
        // 2. UTM map projections
        final UTMProjection utmProjection = (UTMProjection) projection;
        final int zone = utmProjection.getZone();

        if (zone >= 1 && zone <= 60) {
          final CRSAuthorityFactory factory =
              ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", null);
          if (utmProjection.isNorth()) {
            if (Datum.WGS_72.equals(datum)) {
              final int WGS72_UTM_zone_N_BASE = 32200;
              result = factory.createProjectedCRS("EPSG:" + (WGS72_UTM_zone_N_BASE + zone));
            } else if (Datum.WGS_84.equals(datum)) {
              final int WGS84_UTM_zone_N_BASE = 32600;
              result = factory.createProjectedCRS("EPSG:" + (WGS84_UTM_zone_N_BASE + zone));
            }
          } else {
            if (Datum.WGS_72.equals(datum)) {
              final int WGS72_UTM_zone_S_BASE = 32300;
              result = factory.createProjectedCRS("EPSG:" + (WGS72_UTM_zone_S_BASE + zone));
            } else if (Datum.WGS_84.equals(datum)) {
              final int WGS84_UTM_zone_S_BASE = 32700;
              result = factory.createProjectedCRS("EPSG:" + (WGS84_UTM_zone_S_BASE + zone));
            }
          }
        }
      } else if (Datum.ITRF_97.equals(datum)) {
        // 3. Other map projections
        final String crsName = "ITRF 97 / " + mapTransform.getDescriptor().getName();
        final MathTransform mathTransform = getMathTransform(mapTransform);
        if (mathTransform != null) {
          result =
              new DefaultProjectedCRS(crsName, ITRF97, mathTransform, DefaultCartesianCS.PROJECTED);
        }
      } else if (Datum.WGS_72.equals(datum)) {
        final String crsName = "WGS 72 / " + mapTransform.getDescriptor().getName();
        final MathTransform mathTransform = getMathTransform(mapTransform);
        if (mathTransform != null) {
          result =
              new DefaultProjectedCRS(crsName, WGS72, mathTransform, DefaultCartesianCS.PROJECTED);
        }
      } else if (Datum.WGS_84.equals(datum)) {
        final String crsName = "WGS 84 / " + mapTransform.getDescriptor().getName();
        final MathTransform mathTransform = getMathTransform(mapTransform);
        if (mathTransform != null) {
          result =
              new DefaultProjectedCRS(crsName, WGS84, mathTransform, DefaultCartesianCS.PROJECTED);
        }
      }
    } catch (FactoryException e) {
      // ignore
    }

    return result;
  }