Example usage for org.apache.pdfbox.cos COSDictionary asUnmodifiableDictionary

List of usage examples for org.apache.pdfbox.cos COSDictionary asUnmodifiableDictionary

Introduction

In this page you can find the example usage for org.apache.pdfbox.cos COSDictionary asUnmodifiableDictionary.

Prototype

public COSDictionary asUnmodifiableDictionary() 

Source Link

Document

Returns an unmodifiable view of this dictionary.

Usage

From source file:com.esri.geoportal.commons.pdf.PdfUtils.java

License:Apache License

/**
 * Generates the projection Well-Known Text (WKT) for reprojecting the geospatial points
 * //  w w w .j  a v  a 2  s.com
 * @see <a href="http://www.geoapi.org/2.0/javadoc/org/opengis/referencing/doc-files/WKT.html">The WKT specification</a>, specifically the "Coordinate System WKT".
 * @see <a href="https://www.loc.gov/preservation/digital/formats/fdd/fdd000312.shtml">The GeoPDF specification</a> for the projection dictionary properties/parameters.
 * 
 * @param projectionDictionary the PDF Carousel Object Structure (COS) dictionary for the GeoPDF
 * @param projectionType the projection algorithm to use
 * 
 * @returns the WKT for the projection
 */
private static String getProjectionWKT(COSDictionary projectionDictionary, String projectionType)
        throws IOException {
    Map<String, String> tokens = new HashMap<>();

    tokens.put("name", projectionType);

    // Different projection algorithms require different parameters 
    if ("LE".equalsIgnoreCase(projectionType)) {
        tokens.put("projection", "PROJECTION[\"Lambert_Conformal_Conic\"]");

        // Set up the projection parameters
        String paramsString = generateWKTParameters(projectionDictionary);
        tokens.put("parameters", paramsString);

        tokens.put("linear_unit", "UNIT[\"Meter\",1.0]");

        tokens.put("geo_cs", datumTranslation(projectionDictionary.getDictionaryObject("Datum")));

        // Set the parameters
        tokens.put("parameters", generateWKTParameters(projectionDictionary));

        StringSubstitutor subber = new StringSubstitutor(tokens);
        return subber.replace(PROJ_WKT_TEMPLATE);
    } else if ("MC".equalsIgnoreCase(projectionType)) {
        tokens.put("projection", "PROJECTION[\"Mercator\"]");

        // Get the datum
        COSBase datumObj = projectionDictionary.getDictionaryObject("Datum");
        tokens.put("geo_cs", datumTranslation(datumObj));

        // Set the parameters
        tokens.put("parameters", generateWKTParameters(projectionDictionary.asUnmodifiableDictionary()));

        tokens.put("linear_unit", "UNIT[\"Meter\",1.0]");

        StringSubstitutor subber = new StringSubstitutor(tokens);
        return subber.replace(PROJ_WKT_TEMPLATE);
    }

    // Returning null bypasses projection
    return null;
}