Examples of CRSFactory


Examples of org.opengis.referencing.crs.CRSFactory

*/
void createCRSByHand2() throws Exception {
    System.out.println("------------------------------------------");
    System.out.println("Creating a CRS by hand:");
    // createCRSByHand2 start
    CRSFactory crsFactory = ReferencingFactoryFinder.getCRSFactory(null);
    DatumFactory datumFactory = ReferencingFactoryFinder.getDatumFactory(null);
    CSFactory csFactory = ReferencingFactoryFinder.getCSFactory(null);
   
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("name", "Clarke 1866");
   
    Ellipsoid clark1866ellipse = datumFactory.createFlattenedSphere(map, 6378206.4,
            294.978698213901, SI.METER);
   
    PrimeMeridian greenwichMeridian = org.geotools.referencing.datum.DefaultPrimeMeridian.GREENWICH;
   
    final BursaWolfParameters toWGS84 = new BursaWolfParameters(DefaultGeodeticDatum.WGS84);
    toWGS84.dx = -3.0;
    toWGS84.dy = 142;
    toWGS84.dz = 183;
   
    map.clear();
    map.put("name", "North American Datum 1927");
    map.put(DefaultGeodeticDatum.BURSA_WOLF_KEY, toWGS84);
   
    GeodeticDatum clark1866datum = datumFactory.createGeodeticDatum(map, clark1866ellipse,
            greenwichMeridian);
    System.out.println(clark1866datum.toWKT());
    // notice all of the lovely datum aliases (used to determine if two
    // datums are the same)
    System.out.println("Identified Datum object:");
    printIdentifierStuff(clark1866datum);
   
    map.clear();
    map.put("name", "<lat>, <long>");
    CoordinateSystemAxis latAxis = org.geotools.referencing.cs.DefaultCoordinateSystemAxis.GEODETIC_LATITUDE;
    CoordinateSystemAxis longAxis = org.geotools.referencing.cs.DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE;
    EllipsoidalCS ellipsCS = csFactory.createEllipsoidalCS(map, latAxis, longAxis);
   
    map.clear();
    map.put("name", "NAD 27");
    map.put("authority", "9999");
    // TODO add an authority code here (should be an identifier)
    GeographicCRS nad27CRS = crsFactory.createGeographicCRS(map, clark1866datum, ellipsCS);
    // createCRSByHand2 end
    System.out.println(nad27CRS.toWKT());
    System.out.println("Identified CRS object:");
    printIdentifierStuff(nad27CRS);
   
View Full Code Here

Examples of org.opengis.referencing.crs.CRSFactory

void createCRSByHand3() throws FactoryException {
    System.out.println("------------------------------------------");
    System.out.println("Creating two CRSs by hand:");
   
    // createCRSByHand3 start
    CRSFactory crsFactory = ReferencingFactoryFinder.getCRSFactory(null);
    DatumFactory datumFactory = ReferencingFactoryFinder.getDatumFactory(null);
    CSFactory csFactory = ReferencingFactoryFinder.getCSFactory(null);
    Map<String, Object> map = new HashMap<String, Object>();
   
    //
    // Create a datum used for each CRS
    //
    map.clear();
    map.put("name", "Greenwich Meridian");
    PrimeMeridian greenwichMeridian = datumFactory.createPrimeMeridian(map, 0, NonSI.DEGREE_ANGLE);
   
    map.clear();
    map.put("name", "WGS 84 Ellipsoid Datum");
    Ellipsoid wgs84Ellipsoid = datumFactory.createFlattenedSphere(map, 6378137, 298.257223563,
            SI.METER);
   
    map.clear();
    map.put("name", "WGS84 Height Datum");
    GeodeticDatum wgs84Datum = datumFactory.createGeodeticDatum(map, wgs84Ellipsoid,
            greenwichMeridian);
   
    //
    // Create a geocentric CRS
    //
    // Create a collection of axes for the coordinate system.
    map.clear();
    map.put("name", "Cartesian X axis");
    CoordinateSystemAxis xAxis = csFactory.createCoordinateSystemAxis(map, "X",
            AxisDirection.GEOCENTRIC_X, SI.METER);
   
    map.clear();
    map.put("name", "Cartesian Y axis");
    CoordinateSystemAxis yAxis = csFactory.createCoordinateSystemAxis(map, "Y",
            AxisDirection.GEOCENTRIC_Y, SI.METER);
   
    map.clear();
    map.put("name", "Cartesian Z axis");
    CoordinateSystemAxis zAxis = csFactory.createCoordinateSystemAxis(map, "Z",
            AxisDirection.GEOCENTRIC_Z, SI.METER);
   
    map.clear();
    map.put("name", "Rendered Cartesian CS");
    CartesianCS worldCS = csFactory.createCartesianCS(map, xAxis, yAxis, zAxis);
   
    // Now, the geocentric coordinate reference system that we'd use for output - eg to a 3D
    // renderer
    map.clear();
    map.put("name", "Output Cartesian CS");
    CoordinateReferenceSystem geocentricCRS = crsFactory.createGeocentricCRS(map, wgs84Datum,
            worldCS);
    System.out.println("Geocentric CRS: " + geocentricCRS.toWKT());
   
    //
    // Create a geograyhic CRS for the Airy 1830 ellipsoid
    // map.clear();
    // map.put("name", "Airy 1830");
    // Ellipsoid airyEllipse =
    // datumFactory.createFlattenedSphere(map, 6377563.396, 299.3249646, SI.METER);
   
    map.clear();
    map.put("name", "Geodetic North axis");
    CoordinateSystemAxis northAxis = csFactory.createCoordinateSystemAxis(map, "N",
            AxisDirection.NORTH, NonSI.DEGREE_ANGLE);
   
    map.clear();
    map.put("name", "Geodetic East axis");
    CoordinateSystemAxis eastAxis = csFactory.createCoordinateSystemAxis(map, "E",
            AxisDirection.EAST, NonSI.DEGREE_ANGLE);
   
    map.clear();
    map.put("name", "Geodetic Height axis");
    CoordinateSystemAxis heightAxis = csFactory.createCoordinateSystemAxis(map, "Up",
            AxisDirection.UP, SI.METER);
   
    map.clear();
    map.put("name", "<long>,<lat> Airy 1830 geodetic");
    EllipsoidalCS airyCS = csFactory.createEllipsoidalCS(map, eastAxis, northAxis, heightAxis);
   
    // finally create the source geographic CRS
    CoordinateReferenceSystem airyCRS = crsFactory.createGeographicCRS(map, wgs84Datum, airyCS);
   
    // createCRSByHand3 end
   
    // TODO crs.toWKT() throws exceptions here (.toString() works)
    System.out.println("Geographic CRS: " + airyCRS.toString());
View Full Code Here

Examples of org.opengis.referencing.crs.CRSFactory

                final String remarks = result.getString( 5);
                final String type    = getString(result, 6, code);
                // Note: Do not invoke 'generateProperties' now, even if we have all required
                //       informations, because the 'properties' map is going to overwritten
                //       by calls to 'createDatum', 'createCoordinateSystem', etc.
                final CRSFactory factory = factories.getCRSFactory();
                final CoordinateReferenceSystem crs;
                /* ----------------------------------------------------------------------
                 *   GEOGRAPHIC CRS
                 *
                 *   NOTE: 'generateProperties' MUST be invoked after any call to an other
                 *         'createFoo' method. Consequently, do not factor out.
                 * ---------------------------------------------------------------------- */
                if (type.equalsIgnoreCase("geographic 2D") ||
                    type.equalsIgnoreCase("geographic 3D"))
                {
                    final String csCode    = getString(result, 7, code);
                    final String dmCode    = result.getString( 8);
                    final EllipsoidalCS cs = createEllipsoidalCS(csCode);
                    final GeodeticDatum datum;
                    if (dmCode != null) {
                        datum = createGeodeticDatum(dmCode);
                    } else {
                        final String geoCode = getString(result, 9, code, 8);
                        result.close(); // Must be close before createGeographicCRS
                        result = null;
                        final GeographicCRS baseCRS = createGeographicCRS(geoCode);
                        datum = baseCRS.getDatum();
                    }
                    final Map<String,Object> properties = generateProperties(name, epsg, area, scope, remarks);
                    crs = factory.createGeographicCRS(properties, datum, cs);
                }
                /* ----------------------------------------------------------------------
                 *   PROJECTED CRS
                 *
                 *   NOTE: This method invokes itself indirectly, through createGeographicCRS.
                 *         Consequently, we can't use 'result' anymore. We must close it here.
                 * ---------------------------------------------------------------------- */
                else if (type.equalsIgnoreCase("projected")) {
                    final String csCode  = getString(result,  7, code);
                    final String geoCode = getString(result,  9, code);
                    final String opCode  = getString(result, 10, code);
                    result.close(); // Must be close before createGeographicCRS
                    result = null;
                    final CartesianCS         cs = createCartesianCS(csCode);
                    final GeographicCRS  baseCRS = createGeographicCRS(geoCode);
                    final CoordinateOperation op = createCoordinateOperation(opCode);
                    if (op instanceof Conversion) {
                        final Map<String,Object> properties = generateProperties(name, epsg, area, scope, remarks);
                        crs = factory.createProjectedCRS(properties, baseCRS, (Conversion)op, cs);
                    } else {
                         throw noSuchAuthorityCode(Projection.class, opCode);
                    }
                }
                /* ----------------------------------------------------------------------
                 *   VERTICAL CRS
                 * ---------------------------------------------------------------------- */
                else if (type.equalsIgnoreCase("vertical")) {
                    final String        csCode = getString(result, 7, code);
                    final String        dmCode = getString(result, 8, code);
                    final VerticalCS    cs     = createVerticalCS   (csCode);
                    final VerticalDatum datum  = createVerticalDatum(dmCode);
                    final Map<String,Object> properties = generateProperties(name, epsg, area, scope, remarks);
                    crs = factory.createVerticalCRS(properties, datum, cs);
                }
                /* ----------------------------------------------------------------------
                 *   COMPOUND CRS
                 *
                 *   NOTE: This method invokes itself recursively.
                 *         Consequently, we can't use 'result' anymore.
                 * ---------------------------------------------------------------------- */
                else if (type.equalsIgnoreCase("compound")) {
                    final String code1 = getString(result, 11, code);
                    final String code2 = getString(result, 12, code);
                    result.close();
                    result = null;
                    final CoordinateReferenceSystem crs1, crs2;
                    if (!safetyGuard.add(epsg)) {
                        throw recursiveCall(CompoundCRS.class, epsg);
                    } try {
                        crs1 = createCoordinateReferenceSystem(code1);
                        crs2 = createCoordinateReferenceSystem(code2);
                    } finally {
                        safetyGuard.remove(epsg);
                    }
                    // Note: Don't invoke 'generateProperties' sooner.
                    final Map<String,Object> properties = generateProperties(name, epsg, area, scope, remarks);
                    crs  = factory.createCompoundCRS(properties,
                           new CoordinateReferenceSystem[] {crs1, crs2});
                }
                /* ----------------------------------------------------------------------
                 *   GEOCENTRIC CRS
                 * ---------------------------------------------------------------------- */
                else if (type.equalsIgnoreCase("geocentric")) {
                    final String           csCode = getString(result, 7, code);
                    final String           dmCode = getString(result, 8, code);
                    final CoordinateSystem cs     = createCoordinateSystem(csCode);
                    final GeodeticDatum    datum  = createGeodeticDatum   (dmCode);
                    final Map<String,Object> properties = generateProperties(name, epsg, area, scope, remarks);
                    if (cs instanceof CartesianCS) {
                        crs = factory.createGeocentricCRS(properties, datum, (CartesianCS) cs);
                    } else if (cs instanceof SphericalCS) {
                        crs = factory.createGeocentricCRS(properties, datum, (SphericalCS) cs);
                    } else {
                        result.close();
                        throw new FactoryException(Errors.format(
                                ErrorKeys.ILLEGAL_COORDINATE_SYSTEM_FOR_CRS_$2,
                                cs.getClass(), GeocentricCRS.class));
                    }
                }
                /* ----------------------------------------------------------------------
                 *   ENGINEERING CRS
                 * ---------------------------------------------------------------------- */
                else if (type.equalsIgnoreCase("engineering")) {
                    final String           csCode = getString(result, 7, code);
                    final String           dmCode = getString(result, 8, code);
                    final CoordinateSystem cs     = createCoordinateSystem(csCode);
                    final EngineeringDatum datum  = createEngineeringDatum(dmCode);
                    final Map<String,Object> properties = generateProperties(name, epsg, area, scope, remarks);
                    crs = factory.createEngineeringCRS(properties, datum, cs);
                }
                /* ----------------------------------------------------------------------
                 *   UNKNOW CRS
                 * ---------------------------------------------------------------------- */
                else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.