Example usage for org.apache.commons.lang3 Range getMinimum

List of usage examples for org.apache.commons.lang3 Range getMinimum

Introduction

In this page you can find the example usage for org.apache.commons.lang3 Range getMinimum.

Prototype

public T getMinimum() 

Source Link

Document

Gets the minimum value in this range.

Usage

From source file:org.kalypso.gml.ui.internal.coverage.CoverageColormapHandler.java

public void guessInitialColormap(final Shell shell, final ICoverage[] coverages) {
    final RasterSymbolizer symb = getRasterSymbolizer();
    if (symb == null)
        return;//from www . ja  v  a 2s. c  o  m

    final SortedMap<Double, ColorMapEntry> colorMap = symb.getColorMap();
    if (!colorMap.isEmpty())
        return;

    try {
        /* In order to show anything to the user, create a default color map, if no colors have been defined yet */
        final Range<Double> minMax = ElevationUtilities.calculateRange(coverages);
        final Double min = minMax.getMinimum();
        final Double max = minMax.getMaximum();

        // TODO: check for infinity
        if (Doubles.isNullOrInfinite(min, max))
            return;

        // TODO: find better step...
        final BigDecimal stepWidth = new BigDecimal("0.1"); //$NON-NLS-1$
        final Color fromColor = new Color(0, 255, 0, 200);
        final Color toColor = new Color(255, 0, 0, 200);

        // TODO: scale?! -> get max scale from all coverages
        final BigDecimal minDecimal = new BigDecimal(min);
        final BigDecimal maxDecimal = new BigDecimal(max);

        final ColorMapEntry[] colors = SldHelper.createColorMap(fromColor, toColor, stepWidth, minDecimal,
                maxDecimal, 250);
        updateRasterSymbolizer(shell, colors);
    } catch (final CoreException e) {
        // will not happen, as we do not define a class limit in createColorMap
    }
}

From source file:org.kalypso.gml.ui.internal.coverage.CoverageColorRangeAction.java

@Override
public void runWithEvent(final Event event) {
    final IKalypsoFeatureTheme selectedTheme = m_widget.getSelectedTheme();
    final ICoverage[] coverages = m_widget.getCoverages();
    if (selectedTheme == null || coverages == null) {
        // no message, should not happen because action is disabled in this case
        return;//w w w  . ja  v  a  2s  .  c o  m
    }

    final IKalypsoFeatureTheme[] allCoverageThemes = m_widget.findThemesForCombo();

    final CoverageColormapHandler colormapHandler = new CoverageColormapHandler(selectedTheme,
            allCoverageThemes);

    final RasterSymbolizer symb = colormapHandler.getRasterSymbolizer();
    if (symb == null) {
        MessageDialog.openWarning(event.display.getActiveShell(),
                Messages.getString("org.kalypso.gml.ui.map.CoverageManagementWidget.4"), //$NON-NLS-1$
                Messages.getString("org.kalypso.gml.ui.map.CoverageManagementWidget.6")); //$NON-NLS-1$
        return;
    }

    final SortedMap<Double, ColorMapEntry> input = symb.getColorMap();

    if (input == null)
        return;

    // convert map into an array
    final Collection<ColorMapEntry> values = input.values();
    final ColorMapEntry[] entries = values.toArray(new ColorMapEntry[values.size()]);

    final Range<Double> minMax = ElevationUtilities.calculateRange(coverages);

    final BigDecimal min = asBigDecimal(minMax.getMinimum());
    final BigDecimal max = asBigDecimal(minMax.getMaximum());

    // open dialog
    final GridStyleDialog dialog = new GridStyleDialog(event.display.getActiveShell(), entries, min, max);
    if (dialog.open() == Window.OK) {
        colormapHandler.updateRasterSymbolizer(event.display.getActiveShell(), dialog.getColorMap());

        m_widget.updateStylePanel();
    }
}

From source file:org.kalypso.model.flood.ui.map.EventManagementWidget.java

private void createInitialColorMap(final IRunoffEvent runoffEvent, final ITinReference[] newTinRefs) {
    if (ArrayUtils.isEmpty(newTinRefs))
        return;/*from ww w  .  java  2  s .  c  om*/

    final IKalypsoFeatureTheme eventTheme = findThemeForEvent(runoffEvent);
    final PolygonColorMap colorMap = findColorMap(eventTheme);

    if (colorMap == null)
        return;

    /* In order to show anything to the user, create a default color map, if no colors have been defined yet */
    final Range<BigDecimal> minMax = GenerateColorMapAction.computeTinRange(newTinRefs);
    final BigDecimal min = minMax.getMinimum();
    final BigDecimal max = minMax.getMaximum();
    final BigDecimal stepWidth = new BigDecimal(0.1);
    final Color fromColor = new Color(0, 255, 255, 200);
    final Color toColor = new Color(0, 0, 255, 200);

    final PolygonColorMapEntry fromEntry = StyleFactory.createPolygonColorMapEntry(fromColor, fromColor, min,
            min);
    final PolygonColorMapEntry toEntry = StyleFactory.createPolygonColorMapEntry(toColor, toColor, max, max);

    final List<PolygonColorMapEntry> entries = PolygonSymbolizerUtils.createColorMap(fromEntry, toEntry,
            stepWidth, min, max, false);
    colorMap.replaceColorMap(entries);

    handleColormapChanged(eventTheme);
}

From source file:org.kalypso.model.flood.ui.map.GenerateColorMapAction.java

@Override
public void runWithEvent(final Event event) {
    final Shell shell = event.display.getActiveShell();

    final IRunoffEvent runoffEvent = m_widget.getSelectedEvent();
    if (runoffEvent == null) {
        MessageDialog.openInformation(shell, getText(), Messages.getString("GenerateColorMapAction.0")); //$NON-NLS-1$
        return;/*from  ww  w .  j  av  a  2  s .  c om*/
    }

    final IKalypsoFeatureTheme runoffEventTheme = m_widget.findThemeForEvent(runoffEvent);

    final PolygonColorMap colorMap = m_widget.findColorMap(runoffEventTheme);
    if (colorMap == null)
        return;

    final IFeatureBindingCollection<ITinReference> tins = runoffEvent.getTins();
    if (tins.size() == 0 && colorMap.getColorMap().length == 0) {
        MessageDialog.openInformation(shell, getText(), Messages.getString("GenerateColorMapAction.1")); //$NON-NLS-1$
        return;
    }

    final Range<BigDecimal> range = computeTinRange(tins.toArray(new ITinReference[tins.size()]));
    final BigDecimal minimum = range.getMinimum();
    final BigDecimal maximum = range.getMaximum();

    final EventStyleDialog dialog = new EventStyleDialog(shell, colorMap, decimalOrNull(minimum),
            decimalOrNull(maximum));
    if (dialog.open() == Window.OK)
        m_widget.handleColormapChanged(runoffEventTheme);
}

From source file:org.kalypso.model.wspm.core.profil.impl.RangeSelection.java

@Override
public void setRange(final Range<Double> selection) {
    if (Objects.equal(m_selection, selection))
        return;//from   w w w .  jav a2s  .co  m

    m_selection = selection;

    int selectionCount = 0;
    for (final IProfileRecord record : m_profile.getPoints()) {
        final boolean isSelected = selection.contains(record.getBreite());
        ((ProfileRecord) record).setSelected(isSelected);

        if (isSelected)
            selectionCount++;
    }

    if (selection.getMinimum() == selection.getMaximum() && selectionCount == 0) {
        final IProfileRecord previous = m_profile.findPreviousPoint(selection.getMinimum());
        if (previous != null)
            ((ProfileRecord) previous).setSelected(!selection.contains(previous.getBreite()));
    }

    final ProfileChangeHint hint = new ProfileChangeHint(
            ProfileChangeHint.SELECTION_CHANGED | ProfileChangeHint.ACTIVE_POINTS_CHANGED);
    m_profile.fireProfilChanged(hint);
}

From source file:org.kalypso.model.wspm.pdb.internal.waterlevel2d.ProjectedWaterlevels.java

private LineString extractLine(final IProfileObject simplifiedWaterlevel,
        final Range<Double> profileWidthRange) {
    final CoordinateList waterlevelLocations = new CoordinateList();

    /* extract waterlevel locations */
    final IProfileObjectRecords records = simplifiedWaterlevel.getRecords();
    for (int i = 0; i < records.size(); i++) {
        final IProfileObjectRecord record = records.getRecord(i);
        final Coordinate widthHeight = record.getWidthHeightLocation();
        waterlevelLocations.add(widthHeight, false);
    }//from   ww w  . j  ava  2  s .  c  om

    /* sort locations by x */
    sortCoordinatesByX(waterlevelLocations);

    /* deny empty waterlevels */
    if (waterlevelLocations.isEmpty())
        return null;

    /* extend waterlevel to left and right to make sure that it covers the whole profile */
    final Coordinate leftBorder = waterlevelLocations.getCoordinate(0);
    final double leftExtendX = Math.min(leftBorder.x, profileWidthRange.getMinimum());
    final Coordinate leftExtend = new Coordinate(leftExtendX, leftBorder.y);

    final Coordinate rightBorder = waterlevelLocations.getCoordinate(waterlevelLocations.size() - 1);
    final double rightExtendX = Math.min(rightBorder.x, profileWidthRange.getMaximum());
    final Coordinate rightExtend = new Coordinate(rightExtendX, leftBorder.y);

    waterlevelLocations.add(0, leftExtend, false);
    waterlevelLocations.add(rightExtend, false);

    /* create the waterlevel line */
    final Coordinate[] waterlevelcoordinates = waterlevelLocations.toCoordinateArray();
    return m_profileLine.getFactory().createLineString(waterlevelcoordinates);
}

From source file:org.kalypso.model.wspm.tuhh.schema.simulation.BreakLinesWriter.java

private void init() throws GMLSchemaException, GM_Exception {
    if (m_triangleWorkspace != null || m_breaklinesWorkspace != null)
        return;// www.j a va  2  s .c  om

    final Map<Double, Double> wspMap = BreakLinesHelper.createWspMap(m_result, m_componentStation,
            m_componentWaterlevel);
    if (m_segments.length == 0)
        return;

    m_triangleWorkspace = FeatureFactory
            .createGMLWorkspace(new QName(NS_WSPMCOMMONS, "TriangulatedSurfaceFeature"), null, null); //$NON-NLS-1$
    final String defaultCrs = KalypsoDeegreePlugin.getDefault().getCoordinateSystem();
    final GM_TriangulatedSurface surface = org.kalypsodeegree_impl.model.geometry.GeometryFactory
            .createGM_TriangulatedSurface(defaultCrs);
    final Feature triangleFeature = m_triangleWorkspace.getRootFeature();
    triangleFeature.setProperty(new QName(NS_WSPMCOMMONS, "triangulatedSurfaceMember"), surface); //$NON-NLS-1$
    // TODO: set tin name
    NamedFeatureHelper.setDescription(triangleFeature, Messages.getString("BreakLinesHelper.0")); //$NON-NLS-1$
    NamedFeatureHelper.setName(triangleFeature, Messages.getString("BreakLinesHelper.1")); //$NON-NLS-1$
    triangleFeature.setProperty(new QName(NS_WSPMCOMMONS, "unit"), "NN+m"); //$NON-NLS-1$ //$NON-NLS-2$
    triangleFeature.setProperty(new QName(NS_WSPMCOMMONS, "parameter"), "h"); //$NON-NLS-1$ //$NON-NLS-2$
    triangleFeature.setProperty(new QName(NS_WSPMCOMMONS, "date"), //$NON-NLS-1$
            DateUtilities.toXMLGregorianCalendar(new Date()));

    m_breaklinesWorkspace = FeatureFactory
            .createGMLWorkspace(new QName(NS_WSPM_BREAKLINE, "BreaklineCollection"), null, null); //$NON-NLS-1$
    final Feature rootFeature = m_breaklinesWorkspace.getRootFeature();

    final String gmlVersion = rootFeature.getFeatureType().getGMLSchema().getGMLVersion();

    // debug
    GM_Curve lastProfile = null;
    Range<Double> range = null;
    for (final TuhhReachProfileSegment reach : m_segments) {
        final GM_Curve geometry = reach.getGeometry();
        final BigDecimal station = reach.getStation();
        if (geometry == null) // ignore profiles without geometry
            continue;

        final Double wsp = wspMap.get(station.doubleValue());

        final GM_Curve thinProfile = thinnedOutClone(geometry, m_epsThinning, gmlVersion);
        if (wsp != null) {
            if (range == null)
                range = Range.is(wsp);
            else
                range = Range.between(Math.min(wsp, range.getMinimum()), Math.max(wsp, range.getMaximum()));

            // ignore profiles without result (no value in length section). This can occur if the
            // simulation does not cover the whole reach.
            final GM_Curve newProfile = GeometryUtilities.setValueZ(thinProfile.getAsLineString(), wsp);

            /* Triangulate two adjacent profiles */
            if (lastProfile != null) {
                final GM_Position[] polygonPosesClosed = GeometryUtilities.getPolygonfromCurves(lastProfile,
                        newProfile);

                // Write the curve as breakline into breakline file
                final GM_Curve polygoneRing = GeometryFactory.createGM_Curve(polygonPosesClosed, defaultCrs);
                final Feature ringFeature = FeatureHelper.addFeature(rootFeature,
                        new QName(NS_WSPM_BREAKLINE, "breaklineMember"), //$NON-NLS-1$
                        new QName(NS_WSPM_BREAKLINE, "Breakline")); //$NON-NLS-1$
                ringFeature.setProperty(new QName(NS_WSPM_BREAKLINE, "geometry"), polygoneRing); //$NON-NLS-1$
                ringFeature.setProperty(new QName(NS_WSPM_BREAKLINE, "station"), station); //$NON-NLS-1$
                ringFeature.setProperty(new QName(NS_WSPM_BREAKLINE, "wsp"), wsp); //$NON-NLS-1$

                // Interpolate triangles between two adjacent curves and add them to the triangulated surface
                final GM_Position[] polygonPosesOpen = ArrayUtils.remove(polygonPosesClosed,
                        polygonPosesClosed.length - 1);
                final GM_Position[][] triangles = GeometryUtilities.triangulateRing(polygonPosesOpen);
                for (final GM_Position[] triangle : triangles) {
                    final GM_Triangle gmTriangle = GeometryFactory.createGM_Triangle(triangle, defaultCrs);
                    surface.add(gmTriangle);
                }
            }

            lastProfile = newProfile;
        }
    }

    m_range = range;
}

From source file:org.kalypso.model.wspm.tuhh.schema.simulation.ResultLSTinSldFile.java

/**
 * @see org.kalypso.model.wspm.tuhh.schema.simulation.AbstractResultLSFile#doWrite(java.io.File)
 *///from   w w  w  . j  a va  2 s .c  o  m
@Override
protected void doWrite(final File outputFile)
        throws IOException, XMLParsingException, SAXException, GMLSchemaException, GM_Exception {
    final Range<Double> range = m_breakLines.getRange();
    if (range == null)
        return;

    /* Fetch template polygon symbolizer */
    final URL wspSldLocation = getClass().getResource("resources/WspTin.sld"); //$NON-NLS-1$
    final FeatureTypeStyle wspStyle = SLDFactory.createFeatureTypeStyle(null, wspSldLocation);
    final Rule[] rules = wspStyle.getRules();
    final SurfacePolygonSymbolizer polySymb = (SurfacePolygonSymbolizer) rules[0].getSymbolizers()[0];
    final PolygonColorMap colorMap = polySymb.getColorMap();

    final BigDecimal stepWidth = new BigDecimal("0.01"); //$NON-NLS-1$
    final BigDecimal minValue = new BigDecimal(range.getMinimum());
    final BigDecimal maxValue = new BigDecimal(range.getMaximum());

    final Color minFill = new Color(0, 255, 0, 128);
    final Color maxFill = new Color(255, 0, 0, 128);
    final Color minStroke = ColorUtilities.createTransparent(minFill, 255);
    final Color maxStroke = ColorUtilities.createTransparent(maxFill, 255);
    final PolygonColorMapEntry fromEntry = StyleFactory.createPolygonColorMapEntry(minFill, minStroke, minValue,
            minValue.add(stepWidth));
    final PolygonColorMapEntry toEntry = StyleFactory.createPolygonColorMapEntry(maxFill, maxStroke,
            maxValue.subtract(stepWidth), maxValue);

    /* Create and replace new color map */
    final List<PolygonColorMapEntry> colorMapEntries = PolygonSymbolizerUtils.createColorMap(fromEntry, toEntry,
            stepWidth, minValue, maxValue, true);
    colorMap.replaceColorMap(colorMapEntries);

    /* Save as tin-sld */
    final String styleAsString = wspStyle.exportAsXML();
    FileUtils.writeStringToFile(outputFile, styleAsString, "UTF-8"); //$NON-NLS-1$
}

From source file:org.kalypso.model.wspm.ui.action.base.ProfilePainter.java

private static Geometry toGeometry(final IProfileFeature profile, final IRangeSelection selection)
        throws Exception {
    final Range<Double> range = selection.getRange();
    final Double minimum = range.getMinimum();
    final Double maximum = range.getMaximum();

    if (Objects.equal(minimum, maximum)) {
        final Coordinate coorinate = Profiles.getJtsPosition(profile.getProfile(), minimum);
        return JTSConverter.toPoint(coorinate);
    } else {//from  www .  ja va  2  s  . c  o  m
        final Coordinate c1 = Profiles.getJtsPosition(profile.getProfile(), minimum);
        final Coordinate c2 = Profiles.getJtsPosition(profile.getProfile(), maximum);

        return JTSUtilities.createLineString(profile.getJtsLine(), JTSConverter.toPoint(c1),
                JTSConverter.toPoint(c2));
    }
}