Search in sources :

Example 1 with DESegment

use of nitf.DESegment in project imageio-ext by geosolutions-it.

the class NITFImageWriter method getShapeData.

/**
 * @param record
 * @param shape
 * @return
 * @throws NITFException
 * @throws IOException
 */
private byte[] getShapeData(Record record, ShapeFileWrapper shape) throws NITFException, IOException {
    final DESegment des = record.newDESegment();
    byte[] fullData = null;
    TRE csshpa = new TRE("CSSHPA");
    TRE tre = des.getSubheader().setSubheaderFields(csshpa);
    final byte[] bshp = shape.getShp();
    final byte[] bshx = shape.getShx();
    final byte[] bdbf = shape.getDbf();
    final int shp = shape.getShpLength();
    final int shx = shape.getShxLength();
    final int dbf = shape.getDbfLength();
    if (bshp == null || bshx == null || bdbf == null) {
        throw new NITFException("Unable to write CSSHPA ShapeFile");
    }
    fullData = new byte[shp + shx + dbf];
    System.arraycopy(bshp, 0, fullData, 0, shp);
    System.arraycopy(bshx, 0, fullData, shp, shx);
    System.arraycopy(bdbf, 0, fullData, shp + shx, dbf);
    tre.setField("SHAPE_USE", "IMAGE_SHAPE              ");
    NITFUtilities.setTREField(tre, "SHAPE_CLASS", "POLYGON   ", false);
    NITFUtilities.setTREField(tre, "SHAPE1_NAME", "SHP", false);
    NITFUtilities.setTREField(tre, "SHAPE1_START", NITFUtilities.Consts.ZERO, false);
    NITFUtilities.setTREField(tre, "SHAPE2_NAME", "SHX", false);
    NITFUtilities.setTREField(tre, "SHAPE2_START", String.valueOf(shp), false);
    NITFUtilities.setTREField(tre, "SHAPE3_NAME", "DBF", false);
    NITFUtilities.setTREField(tre, "SHAPE3_START", String.valueOf(shx + shp), false);
    NITFUtilities.setField("DE", des.getSubheader().getFilePartType(), "DE");
    NITFUtilities.setField("DESID", des.getSubheader().getTypeID(), "CSSHPA DES");
    NITFUtilities.setField("DESVER", des.getSubheader().getVersion(), "01");
    NITFUtilities.setField("DECLAS", des.getSubheader().getSecurityClass(), "U");
    NITFUtilities.setField("DESCLSY", des.getSubheader().getSecurityGroup().getClassificationSystem(), "US");
    return fullData;
}
Also used : TRE(nitf.TRE) NITFException(nitf.NITFException) DESegment(nitf.DESegment)

Aggregations

DESegment (nitf.DESegment)1 NITFException (nitf.NITFException)1 TRE (nitf.TRE)1