@Override public IStatus execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException { final SubMonitor progress = SubMonitor.convert( monitor, Messages.getString("org.kalypso.model.flood.ui.map.operations.ImportTinOperation.0"), 100); //$NON-NLS-1$ /* Add sources as new tin references */ progress.subTask( Messages.getString( "org.kalypso.model.flood.ui.map.operations.ImportTinOperation.1")); //$NON-NLS-1$ m_tinRefs = new ITinReference[m_sources.length]; final Feature[] changedFeatures = new Feature[m_sources.length]; for (int i = 0; i < m_sources.length; i++) { final IGmlSource source = m_sources[i]; final ITinReference tinRef = m_tins.addNew(-1, ITinReference.QNAME, ITinReference.class); tinRef.setName(source.getName()); tinRef.setDescription(source.getDescription()); tinRef.setSourceLocation(source.getLocation()); tinRef.setSourceFeaturePath(source.getPath()); tinRef.setSourceType(typeForSource(source)); m_tinRefs[i] = tinRef; changedFeatures[i] = tinRef; } ProgressUtilities.worked(progress, 20); /* post command for events stuff... */ final Feature parentFeature = m_tins.getParentFeature(); final GMLWorkspace workspace = parentFeature.getWorkspace(); final ModellEvent modelEvent = new FeatureStructureChangeModellEvent( workspace, parentFeature, changedFeatures, FeatureStructureChangeModellEvent.STRUCTURE_CHANGE_ADD); workspace.fireModellEvent(modelEvent); /* Save data model */ // progress.subTask( "speichere Datenmodell" ); // m_provider.saveModel( IFloodModel.class, progress.newChild( 20 ) ); /* update tins */ progress.subTask( Messages.getString( "org.kalypso.model.flood.ui.map.operations.ImportTinOperation.2")); //$NON-NLS-1$ final UpdateTinsOperation updateOp = new UpdateTinsOperation(m_tinRefs, m_provider); updateOp.execute(progress.newChild(60)); /* Jump to imported tins */ final GM_Envelope envelope = FeatureHelper.getEnvelope(changedFeatures); final GM_Envelope scaledBox = envelope == null ? null : GeometryUtilities.scaleEnvelope(envelope, 1.05); if (m_mapPanel != null && scaledBox != null) m_mapPanel.setBoundingBox(scaledBox); return Status.OK_STATUS; }
/** Not in waterbody, as we create a TuhhReach */ public static TuhhReach createNewReachForWaterBody(final WspmWaterBody waterBody) throws GMLSchemaException { final TuhhReach tuhhReach = (TuhhReach) FeatureHelper.addFeature( waterBody, WspmWaterBody.MEMBER_REACH, new QName(NS_WSPM_TUHH, "ReachWspmTuhhSteadyState")); // $NON-NLS-1$ tuhhReach.setWaterBody(waterBody); return tuhhReach; }
private String getFilename(final ProfilesSelection profileSelection, final ISelection selection) { final String fileName = ExportShapeUtils.guessExportFileName(selection); if (!StringUtils.isEmpty(fileName)) return fileName; // if no theme, we should use the container. final Feature container = profileSelection.getContainer(); if (container != null) return FeatureHelper.getAnnotationValue(container, IAnnotation.ANNO_LABEL); final IProfileFeature[] profiles = profileSelection.getProfiles(); if (!ArrayUtils.isEmpty(profiles)) return profiles[0].getName(); return null; }
@Override public IObservation[] createRainfall( final Feature[] catchmentFeatures, final IStringResolver variables, final ILog log, IProgressMonitor monitor) throws CoreException { /* Monitor. */ if (monitor == null) monitor = new NullProgressMonitor(); /* Monitor. */ monitor.beginTask( Messages.getString("InverseDistanceRainfallGenerator_7"), 1000); // $NON-NLS-1$ monitor.subTask(Messages.getString("InverseDistanceRainfallGenerator_8")); // $NON-NLS-1$ /* Update the log. */ LogUtilities.logQuietly( log, new Status( IStatus.INFO, KalypsoModelRcmActivator.PLUGIN_ID, Messages.getString("InverseDistanceRainfallGenerator_9"), null)); //$NON-NLS-1$ /* Get the needed properties. */ final Feature ombrometerCollection = getProperty(MEMBER_ombrometerCollection, Feature.class); final String collectionPath = getProperty(PROPERTY_ombrometerFeaturePath, String.class); final String linkPath = getProperty(PROPERTY_timeseriesLinkPath, String.class); final String stationLocationPath = getProperty(PROPERTY_stationLocationPath, String.class); final BigInteger numberOmbrometers = getProperty(PROPERTY_numberOmbrometers, BigInteger.class); final String catchmentAreaPath = getProperty(PROPERTY_catchmentAreaPath, String.class); /* Create the paths. */ final GMLXPath collectionXPath = new GMLXPath(collectionPath, getWorkspace().getNamespaceContext()); final GMLXPath linkXPath = new GMLXPath(linkPath, getWorkspace().getNamespaceContext()); final GMLXPath stationLocationXPath = new GMLXPath(stationLocationPath, getWorkspace().getNamespaceContext()); final GMLXPath catchmentAreaXPath = new GMLXPath(catchmentAreaPath, getWorkspace().getNamespaceContext()); /* Monitor. */ monitor.worked(100); monitor.subTask(Messages.getString("InverseDistanceRainfallGenerator_10")); // $NON-NLS-1$ try { /* Get the ombrometers. */ final FeatureList ombrometerList = (FeatureList) GMLXPathUtilities.query(collectionXPath, ombrometerCollection); /* Convert to an array. */ final List<Feature> featureList = new ArrayList<>(ombrometerList.size()); final GMLWorkspace workspace = ombrometerList.getOwner().getWorkspace(); for (final Object object : ombrometerList) { final Feature feature = FeatureHelper.getFeature(workspace, object); if (feature != null) { // TODO Should be in the generator gml (rcm) ... final Boolean active = (Boolean) feature.getProperty(IOmbrometer.QNAME_PROP_ISUSED); if (active != null && active.booleanValue() == true) featureList.add(feature); } } /* Convert to an array. */ final Feature[] ombrometerFeatures = featureList.toArray(new Feature[featureList.size()]); /* Monitor. */ monitor.worked(100); monitor.subTask(Messages.getString("InverseDistanceRainfallGenerator_11")); // $NON-NLS-1$ /* Convert to zml observations . */ final IZmlFilter[] filters = getFilters().toArray(new IZmlFilter[] {}); final DateRange range = getPeriod(variables); final IObservation[] ombrometerObservations = RainfallGeneratorUtilities.readObservations( ombrometerFeatures, linkXPath, filters, range); /* Monitor. */ monitor.worked(100); monitor.subTask(Messages.getString("InverseDistanceRainfallGenerator_12")); // $NON-NLS-1$ /* Get the station locations. */ final GM_Point[] ombrometerStations = FeatureHelper.getProperties( ombrometerFeatures, stationLocationXPath, new GM_Point[ombrometerFeatures.length]); /* Convert to JTS geometries. */ final Point[] ombrometerPoints = new Point[ombrometerStations.length]; final IGeoTransformer transformer = GeoTransformerFactory.getGeoTransformer( KalypsoDeegreePlugin.getDefault().getCoordinateSystem()); for (int i = 0; i < ombrometerStations.length; i++) { final GM_Point ombrometerPoint = ombrometerStations[i]; final GM_Object ombrometerTransformed = transformer.transform(ombrometerPoint); ombrometerPoints[i] = (Point) JTSAdapter.export(ombrometerTransformed); /* Monitor. */ monitor.worked(200 / ombrometerStations.length); } /* Monitor. */ monitor.subTask(Messages.getString("InverseDistanceRainfallGenerator_13")); // $NON-NLS-1$ /* Get all catchment areas. */ final GM_MultiSurface[] areas = RainfallGeneratorUtilities.findCatchmentAreas(catchmentFeatures, catchmentAreaXPath); /* Monitor. */ monitor.worked(100); monitor.subTask(Messages.getString("InverseDistanceRainfallGenerator_14")); // $NON-NLS-1$ /* Iterate through all catchments. */ final IObservation[] result = new IObservation[areas.length]; for (int i = 0; i < areas.length; i++) { /* Monitor. */ monitor.subTask( String.format( Messages.getString("InverseDistanceRainfallGenerator_15"), i + 1, areas.length)); // $NON-NLS-1$ /* Get the catchment. */ final GM_MultiSurface area = areas[i]; if (area == null) { monitor.worked(400 / areas.length); continue; } /* Convert to a JTS geometry. */ final Geometry areaGeometry = JTSAdapter.export(area); /* Get the weights. */ final double[] weights = InverseDistanceUtilities.getWeights( areaGeometry, ombrometerPoints, numberOmbrometers.intValue()); /* Combine the observations. */ result[i] = RainfallGeneratorUtilities.combineObses( ombrometerObservations, weights, "ombrometer://inverse.distance"); // $NON-NLS-1$ /* Monitor. */ monitor.worked(400 / areas.length); } /* Update the log. */ LogUtilities.logQuietly( log, new Status( IStatus.OK, KalypsoModelRcmActivator.PLUGIN_ID, Messages.getString("InverseDistanceRainfallGenerator_17"), null)); //$NON-NLS-1$ return result; } catch (final GM_Exception e) { /* Update the log. */ LogUtilities.logQuietly( log, new Status( IStatus.ERROR, KalypsoModelRcmActivator.PLUGIN_ID, String.format( Messages.getString("InverseDistanceRainfallGenerator_18"), e.getLocalizedMessage()), e)); //$NON-NLS-1$ throw new CoreException( new Status( IStatus.ERROR, KalypsoModelRcmActivator.PLUGIN_ID, "Failed to convert Geometrie: " + e.toString(), e)); //$NON-NLS-1$ } catch (final SensorException e) { /* Update the log. */ LogUtilities.logQuietly( log, new Status( IStatus.ERROR, KalypsoModelRcmActivator.PLUGIN_ID, String.format( Messages.getString("InverseDistanceRainfallGenerator_20"), e.getLocalizedMessage()), e)); //$NON-NLS-1$ throw new CoreException( new Status( IStatus.ERROR, KalypsoModelRcmActivator.PLUGIN_ID, "Failed to combine Observations: " + e.toString(), e)); //$NON-NLS-1$ } catch (final Exception e) { /* Update the log. */ LogUtilities.logQuietly( log, new Status( IStatus.ERROR, KalypsoModelRcmActivator.PLUGIN_ID, String.format( Messages.getString("InverseDistanceRainfallGenerator_22"), e.getLocalizedMessage()), e)); //$NON-NLS-1$ throw new CoreException( new Status( IStatus.ERROR, KalypsoModelRcmActivator.PLUGIN_ID, Messages.getString("InverseDistanceRainfallGenerator_23") + e.toString(), e)); //$NON-NLS-1$ } finally { /* Update the log. */ LogUtilities.logQuietly( log, new Status( IStatus.INFO, KalypsoModelRcmActivator.PLUGIN_ID, Messages.getString("InverseDistanceRainfallGenerator_24"), null)); //$NON-NLS-1$ /* Monitor. */ monitor.done(); } }
public TuhhCalculation createReibConstCalculation() throws GMLSchemaException { return (TuhhCalculation) FeatureHelper.addFeature( this, QNAME_PROP_CALC_MEMBER, TuhhCalculation.QN_TUHH_CALC_REIB_CONST, -1); }