Search in sources :

Example 1 with FastByteArrayOutputStream

use of org.gridfour.io.FastByteArrayOutputStream in project gridfour by gwlucastrig.

the class PackageData method storeGeoreferencingInformation.

/**
 * Stores a GVRS tag (metadata) that gives coordinate/projection
 * data in the Well-Known Text (WKT) format used in many GIS systems. This
 * setting will allow applications to find out what kind of coordinate system
 * is stored in the GVRS file using an industry-standard text format.
 *
 * @param gvrs a valid GVRS file opened for writing
 * @throws IOException in the event of an unhandled I/O exception.
 */
void storeGeoreferencingInformation(GvrsFile gvrs) throws IOException {
    // Note:  At this time, the Well-Known Text (WKT) data for this
    // demo may not be complete. In particular, it does not include the
    // TOWGS84 node (the "to WGS 1984" node which specifies transformations
    // for the ellipsoid).  Because the products supported by this demonstration
    // are derived from multiple data sources, the included specifications
    // may be adequate for their intrinsic accuracy.  However, suggestions
    // from knowledgeable users are welcome.
    InputStream ins = PackageData.class.getResourceAsStream("GlobalMSL.prj");
    FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
    byte[] b = new byte[8196];
    int nBytesRead;
    while ((nBytesRead = ins.read(b)) > 0) {
        fbaos.write(b, 0, nBytesRead);
    }
    b = fbaos.toByteArray();
    String wkt = new String(b, StandardCharsets.UTF_8);
    GvrsMetadata metadataWKT = GvrsMnc.WKT.newInstance();
    metadataWKT.setDescription("Well-Known Text, geographic metadata");
    metadataWKT.setString(wkt);
    gvrs.writeMetadata(metadataWKT);
}
Also used : FastByteArrayOutputStream(org.gridfour.io.FastByteArrayOutputStream) InputStream(java.io.InputStream) GvrsMetadata(org.gridfour.gvrs.GvrsMetadata)

Aggregations

InputStream (java.io.InputStream)1 GvrsMetadata (org.gridfour.gvrs.GvrsMetadata)1 FastByteArrayOutputStream (org.gridfour.io.FastByteArrayOutputStream)1