/**
  * Returns a beautiful String representation for the provided {@link Unit}
  *
  * @param crs
  * @param uom
  * @return
  */
 public String extractUoM(CoordinateReferenceSystem crs, Unit<?> uom) {
   // special handling for Degrees
   if (crs instanceof GeographicCRS) {
     return "Deg";
   }
   return UnitFormat.getInstance().format(uom);
 }
    /**
     * Encodes the RangeType as per the GML spec of the provided {@link GridCoverage2D}
     *
     * <p>e.g.:
     *
     * <pre>{@code
     * <gmlcov:rangeType>
     *    <swe:DataRecord>
     *        <swe:field name="singleBand">
     *           <swe:Quantity definition="http://www.opengis.net/def/property/OGC/0/Radiance">
     *               <gml:description>Panchromatic Channel</gml:description>
     *               <gml:name>single band</gml:name>
     *               <swe:uom code="W/cm2"/>
     *               <swe:constraint>
     *                   <swe:AllowedValues>
     *                       <swe:interval>0 255</swe:interval>
     *                       <swe:significantFigures>3</swe:significantFigures>
     *                   </swe:AllowedValues>
     *               </swe:constraint>
     *           </swe:Quantity>
     *        </swe:field>
     *    </swe:DataRecord>
     * </gmlcov:rangeType>
     * }</pre>
     *
     * @param gc2d the {@link GridCoverage2D} for which to encode the RangeType.
     */
    public void handleRangeType(GridCoverage2D gc2d) {
      start("gml:rangeType");
      start("swe:DataRecord");

      // get bands
      final SampleDimension[] bands = gc2d.getSampleDimensions();

      // handle bands
      for (SampleDimension sd : bands) {
        final AttributesImpl fieldAttr = new AttributesImpl();
        fieldAttr.addAttribute(
            "",
            "name",
            "name",
            "",
            sd.getDescription().toString()); // TODO NCNAME? TODO Use Band[i] convention?
        start("swe:field", fieldAttr);

        start("swe:Quantity");

        // Description
        start("swe:description");
        chars(sd.getDescription().toString()); // TODO can we make up something better??
        end("swe:description");

        // UoM
        final AttributesImpl uomAttr = new AttributesImpl();
        final Unit<?> uom = sd.getUnits();
        uomAttr.addAttribute(
            "",
            "code",
            "code",
            "",
            uom == null ? "W.m-2.Sr-1" : UnitFormat.getInstance().format(uom));
        start("swe:uom", uomAttr);
        end("swe:uom");

        // constraint on values
        start("swe:constraint");
        start("swe:AllowedValues");
        handleSampleDimensionRange(sd); // TODO make this generic
        end("swe:AllowedValues");
        end("swe:constraint");

        // nil values
        handleSampleDimensionNilValues(gc2d, sd.getNoDataValues());

        end("swe:Quantity");
        end("swe:field");
      }

      end("swe:DataRecord");
      end("gml:rangeType");
    }
Пример #3
0
  public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException {

    // make sure we're at the appropriate start tag
    UnmarshallingContext ctx = (UnmarshallingContext) ictx;
    if (!ctx.isAt(this.uri, this.name)) {
      ctx.throwStartTagNameError(this.uri, this.name);
    }

    String unitString = ctx.attributeText(null, "unit");
    Unit<?> unit = null;
    try {
      unit = (Unit<?>) (UnitFormat.getInstance().parseObject(unitString));
    } catch (ParseException ex) {
      throw new JiBXException("Unable to parse unit element", ex);
    }
    // unit.asType(Length.class);
    ctx.parsePastStartTag(this.uri, this.name);
    String value = ctx.parseContentText();
    ctx.parsePastEndTag(this.uri, this.name);
    return KnittingMeasure.valueOf(value, unit);
  }