@Override public boolean processAlgorithm() throws GeoAlgorithmExecutionException { final IVectorLayer layerIn = m_Parameters.getParameterValueAsVectorLayer(LAYER); final double dTolerance = m_Parameters.getParameterValueAsDouble(TOLERANCE); m_bPreserve = m_Parameters.getParameterValueAsBoolean(PRESERVE); if (!m_bIsAutoExtent) { layerIn.addFilter(new BoundingBoxFilter(m_AnalysisExtent)); } final IVectorLayer output = getNewVectorLayer( RESULT, Sextante.getText("Generalized_lines"), IVectorLayer.SHAPE_TYPE_LINE, layerIn.getFieldTypes(), layerIn.getFieldNames()); final IFeatureIterator iter = layerIn.iterator(); int i = 0; final int iCount = layerIn.getShapesCount(); while (iter.hasNext() && setProgress(i, iCount)) { final IFeature feature = iter.next(); final Geometry simpleGeom = getSimpleLine(feature.getGeometry(), dTolerance); output.addFeature(simpleGeom, feature.getRecord().getValues()); i++; } return !m_Task.isCanceled(); }
private void extractPoints() throws GeoAlgorithmExecutionException { double dWeight; m_Demand = new ArrayList(); m_Offer = new ArrayList(); m_Candidates = new ArrayList(); IFeatureIterator iter = m_DemandLayer.iterator(); while (iter.hasNext()) { final IFeature feature = iter.next(); final Coordinate coord = feature.getGeometry().getCoordinate(); try { dWeight = Double.parseDouble(feature.getRecord().getValue(m_iDemandField).toString()); } catch (final Exception e) { dWeight = 1; } m_Demand.add(new DemandPoint(coord.x, coord.y, dWeight)); } iter.close(); iter = m_CandidatesLayer.iterator(); while (iter.hasNext()) { final IFeature feature = iter.next(); final Coordinate coord = feature.getGeometry().getCoordinate(); m_Candidates.add(coord); } iter.close(); if (m_OfferLayer != null) { iter = m_OfferLayer.iterator(); while (iter.hasNext()) { final IFeature feature = iter.next(); final Coordinate coord = feature.getGeometry().getCoordinate(); m_Offer.add(coord); } iter.close(); } if ((m_Candidates.size() < m_iNewLocations) || (m_Demand.size() == 0)) { throw new GeoAlgorithmExecutionException(Sextante.getText("Invalid_or_insufficient_data")); } }