<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.sis.storage.gdal;

import javax.measure.Unit;
import javax.measure.quantity.Angle;
import org.opengis.util.FactoryException;
import org.opengis.parameter.ParameterValue;
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.referencing.IdentifiedObject;
import org.opengis.referencing.crs.GeodeticCRS;
import org.opengis.referencing.crs.ProjectedCRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.AxisDirection;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.CartesianCS;
import org.opengis.referencing.cs.EllipsoidalCS;
import org.opengis.referencing.datum.Ellipsoid;
import org.opengis.referencing.datum.GeodeticDatum;
import org.opengis.referencing.datum.PrimeMeridian;
import org.opengis.referencing.operation.CoordinateOperation;
import org.apache.sis.referencing.factory.UnavailableFactoryException;
import org.apache.sis.referencing.IdentifiedObjects;
import org.apache.sis.metadata.iso.citation.Citations;
import org.apache.sis.internal.metadata.AxisDirections;
import org.apache.sis.internal.system.Modules;
import org.apache.sis.internal.system.OS;
import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.Static;
import org.apache.sis.measure.Units;
import org.opengis.referencing.operation.Projection;


/**
 * Bindings to the {@literal Proj.4} library.
 *
 * @author  <NAME> (Geomatys)
 * @author  <NAME> (Geomatys)
 * @version 0.8
 * @since   0.8
 * @module
 */
public final class Proj4 extends Static {
    /**
     * Do not allow instantiation of this class.
     */
    private Proj4() {
    }

    /**
     * Returns the version number of the {@literal Proj.4} library.
     * Returns {@code null} if Proj.4 is not installed on the current system.
     *
     * <div class="note"><b>Example:</b> Rel. 4.9.3, 15 August 2016</div>
     *
     * @return the Proj.4 release string, or {@code null} if no installation has been found.
     */
    public static String version() {
        try {
            return PJ.getRelease();
        } catch (UnsatisfiedLinkError e) {
            // Thrown the first time that we try to use the library.
            Logging.unexpectedException(Logging.getLogger(Modules.GDAL), Proj4.class, "version", e);
        } catch (NoClassDefFoundError e) {
            // Thrown on all attempts after the first one.
            Logging.recoverableException(Logging.getLogger(Modules.GDAL), Proj4.class, "version", e);
        }
        return null;
    }

    /**
     * Infers a {@literal Proj.4} definition from the given projected, geographic or geocentric coordinate reference system.
     * This method does not need the Proj.4 native library; it can be used in a pure Java application.
     *
     * @param  crs  the coordinate reference system for which to create a Proj.4 definition.
     * @return the definition of the given CRS in a Proj.4 format.
     * @throws FactoryException if the Proj.4 definition string can not be created from the given CRS.
     */
    public static String definition(final CoordinateReferenceSystem crs) throws FactoryException {
        final String method;
        final GeodeticDatum datum;
        final ParameterValueGroup parameters;
        final CoordinateSystem cs = crs.getCoordinateSystem();
        if (crs instanceof GeodeticCRS) {
            if (cs instanceof EllipsoidalCS) {
                method = "latlon";
            } else if (cs instanceof CartesianCS) {<commit_msg>Returns the definition provided by Proj.4 itself if available.<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.sis.storage.gdal;

import javax.measure.Unit;
import javax.measure.quantity.Angle;
import org.opengis.metadata.Identifier;
import org.opengis.util.FactoryException;
import org.opengis.parameter.ParameterValue;
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.referencing.IdentifiedObject;
import org.opengis.referencing.crs.GeodeticCRS;
import org.opengis.referencing.crs.ProjectedCRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.AxisDirection;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.CartesianCS;
import org.opengis.referencing.cs.EllipsoidalCS;
import org.opengis.referencing.datum.Ellipsoid;
import org.opengis.referencing.datum.GeodeticDatum;
import org.opengis.referencing.datum.PrimeMeridian;
import org.opengis.referencing.operation.Projection;
import org.opengis.referencing.operation.CoordinateOperation;
import org.apache.sis.referencing.factory.UnavailableFactoryException;
import org.apache.sis.referencing.IdentifiedObjects;
import org.apache.sis.metadata.iso.citation.Citations;
import org.apache.sis.internal.metadata.AxisDirections;
import org.apache.sis.internal.system.Modules;
import org.apache.sis.internal.system.OS;
import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.Static;
import org.apache.sis.measure.Units;


/**
 * Bindings to the {@literal Proj.4} library as static convenience methods.
 * The methods in this class allow to:
 *
 * <ul>
 *   <li>{@linkplain #createCRS Create a Coordinate Reference System instance from a Proj.4 definition string}.</li>
 *   <li>Conversely, {@link #definition get a Proj.4 definition string from a Coordinate Reference System}.</li>
 *   <li>{@linkplain #createOperation Create a coordinate operation backed by Proj.4 between two arbitrary CRS}.</li>
 * </ul>
 *
 * Most methods in this class delegate to {@link Proj4Factory}.
 *
 * @author  <NAME> (Geomatys)
 * @author  <NAME> (Geomatys)
 * @version 0.8
 * @since   0.8
 * @module
 */
public final class Proj4 extends Static {
    /**
     * Do not allow instantiation of this class.
     */
    private Proj4() {
    }

    /**
     * Returns the version number of the {@literal Proj.4} library.
     * Returns {@code null} if Proj.4 is not installed on the current system.
     *
     * <div class="note"><b>Example:</b> Rel. 4.9.3, 15 August 2016</div>
     *
     * @return the Proj.4 release string, or {@code null} if no installation has been found.
     */
    public static String version() {
        try {
            return PJ.getRelease();
        } catch (UnsatisfiedLinkError e) {
            // Thrown the first time that we try to use the library.
            Logging.unexpectedException(Logging.getLogger(Modules.GDAL), Proj4.class, "version", e);
        } catch (NoClassDefFoundError e) {
            // Thrown on all attempts after the first one.
            Logging.recoverableException(Logging.getLogger(Modules.GDAL), Proj4.class, "version", e);
        }
        return null;
    }

    /**
     * Infers a {@literal Proj.4} definition from the given projected, geographic or geocentric coordinate reference system.
     * This method does not need the Proj.4 native library; it can be used in a pure Java application.
     *
     * @param  crs  the coordinate reference system for which to create a Proj.4 definition.
     * @return the definition of the given CRS in a Proj.4 format.
     * @throws FactoryException if the Proj.4 definition string can not be created from the given CRS.
     */
    public static String definition(final CoordinateReferenceSystem crs) throws FactoryException {
        ArgumentChecks.ensureNonNull("crs", crs);
        for (final Identifier id : crs.getIdentifiers()) {
            if (id instanceof PJ) {
                return ((PJ) id).getCode();
            }
        }
        final String method;
        final GeodeticDatum datum;
        final ParameterValueGroup parameters;
        final CoordinateSystem cs = crs.getCoordinateSystem();
        if (crs instanceof GeodeticCRS) {
            if (cs instanceof EllipsoidalCS) {
                method = "latlon";
            } else if (cs instanceof CartesianCS) {
{'fraction_non_alphanumeric': 0.09122662831312923, 'fraction_numerical': 0.006677624820217793, 'mean_word_length': 3.4986136783733826, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4941171', 'n_tokens_mistral': 2810, 'n_tokens_neox': 2766, 'n_words': 883}