@Test public void test() throws Exception { SimpleFeatureSource source = dataStore.getFeatureSource("polygon"); assertTrue(source.getCount(Query.ALL) > 0); Map<String, Object> input = new HashMap<String, Object>(); input.put(AreaProcessFactory.inputFeatures.key, source.getFeatures()); org.geotools.process.Process process = new AreaProcess(null); Map<String, Object> resultMap = process.execute(input, null); Object result = resultMap.get(AreaProcessFactory.RESULT.key); assertNotNull("result area = ", result); AreaProcessFactory factory = new AreaProcessFactory(); process = factory.create(); resultMap = process.execute(input, null); result = resultMap.get(AreaProcessFactory.RESULT.key); assertNotNull("result area = ", result); }
@Override @SuppressWarnings("unchecked") public Map<String, Object> execute(Map<String, Object> input, ProgressListener monitor) throws ProcessException { SimpleFeatureCollection features = (SimpleFeatureCollection) Params.getValue(input, AreaProcessFactory.inputFeatures, null); Filter filter = (Filter) Params.getValue(input, AreaProcessFactory.filter, Filter.INCLUDE); AreaUnit targetUnit = (AreaUnit) Params.getValue(input, AreaProcessFactory.areaUnit, AreaUnit.Default); if (features == null) { throw new NullPointerException("inputFeatures parameters required"); } CoordinateReferenceSystem sourceCRS = features.getSchema().getCoordinateReferenceSystem(); filter = filter == null ? Filter.INCLUDE : filter; targetUnit = targetUnit == null ? AreaUnit.Default : targetUnit; double dArea = 0d; if (sourceCRS == null || targetUnit == AreaUnit.Default) { dArea = sumArea(features.subCollection(filter)); } else { CoordinateReferenceSystem horCRS = CRS.getHorizontalCRS(sourceCRS); Unit<Area> sourceUnit = SI.SQUARE_METRE; if (horCRS instanceof GeographicCRS) { try { Coordinate p = features.getBounds().centre(); CoordinateReferenceSystem autoCRS = CRS.decode("AUTO:42001," + p.x + "," + p.y); dArea = sumArea(new ReprojectFeatureCollection(features.subCollection(filter), autoCRS)); } catch (NoSuchAuthorityCodeException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } catch (FactoryException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } } else { Unit<?> distUnit = horCRS.getCoordinateSystem().getAxis(0).getUnit(); sourceUnit = (Unit<Area>) distUnit.multiply(distUnit); dArea = sumArea(features.subCollection(filter)); } dArea = UnitConverter.convertArea(new Measure(dArea, sourceUnit), targetUnit); } Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put(AreaProcessFactory.RESULT.key, new Double(dArea)); return resultMap; }
AreaProcess extends AbstractStatisticsProcess { @Override @SuppressWarnings("unchecked") public Map<String, Object> execute(Map<String, Object> input, ProgressListener monitor) throws ProcessException { SimpleFeatureCollection features = (SimpleFeatureCollection) Params.getValue(input, AreaProcessFactory.inputFeatures, null); Filter filter = (Filter) Params.getValue(input, AreaProcessFactory.filter, Filter.INCLUDE); AreaUnit targetUnit = (AreaUnit) Params.getValue(input, AreaProcessFactory.areaUnit, AreaUnit.Default); if (features == null) { throw new NullPointerException("inputFeatures parameters required"); } CoordinateReferenceSystem sourceCRS = features.getSchema().getCoordinateReferenceSystem(); filter = filter == null ? Filter.INCLUDE : filter; targetUnit = targetUnit == null ? AreaUnit.Default : targetUnit; double dArea = 0d; if (sourceCRS == null || targetUnit == AreaUnit.Default) { dArea = sumArea(features.subCollection(filter)); } else { CoordinateReferenceSystem horCRS = CRS.getHorizontalCRS(sourceCRS); Unit<Area> sourceUnit = SI.SQUARE_METRE; if (horCRS instanceof GeographicCRS) { try { Coordinate p = features.getBounds().centre(); CoordinateReferenceSystem autoCRS = CRS.decode("AUTO:42001," + p.x + "," + p.y); dArea = sumArea(new ReprojectFeatureCollection(features.subCollection(filter), autoCRS)); } catch (NoSuchAuthorityCodeException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } catch (FactoryException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } } else { Unit<?> distUnit = horCRS.getCoordinateSystem().getAxis(0).getUnit(); sourceUnit = (Unit<Area>) distUnit.multiply(distUnit); dArea = sumArea(features.subCollection(filter)); } dArea = UnitConverter.convertArea(new Measure(dArea, sourceUnit), targetUnit); } Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put(AreaProcessFactory.RESULT.key, new Double(dArea)); return resultMap; } }
AreaProcess extends AbstractStatisticsProcess { @Override @SuppressWarnings("unchecked") public Map<String, Object> execute(Map<String, Object> input, ProgressListener monitor) throws ProcessException { SimpleFeatureCollection features = (SimpleFeatureCollection) Params.getValue(input, AreaProcessFactory.inputFeatures, null); Filter filter = (Filter) Params.getValue(input, AreaProcessFactory.filter, Filter.INCLUDE); AreaUnit targetUnit = (AreaUnit) Params.getValue(input, AreaProcessFactory.areaUnit, AreaUnit.Default); if (features == null) { throw new NullPointerException("inputFeatures parameters required"); } CoordinateReferenceSystem sourceCRS = features.getSchema().getCoordinateReferenceSystem(); filter = filter == null ? Filter.INCLUDE : filter; targetUnit = targetUnit == null ? AreaUnit.Default : targetUnit; double dArea = 0d; if (sourceCRS == null || targetUnit == AreaUnit.Default) { dArea = sumArea(features.subCollection(filter)); } else { CoordinateReferenceSystem horCRS = CRS.getHorizontalCRS(sourceCRS); Unit<Area> sourceUnit = SI.SQUARE_METRE; if (horCRS instanceof GeographicCRS) { try { Coordinate p = features.getBounds().centre(); CoordinateReferenceSystem autoCRS = CRS.decode("AUTO:42001," + p.x + "," + p.y); dArea = sumArea(new ReprojectFeatureCollection(features.subCollection(filter), autoCRS)); } catch (NoSuchAuthorityCodeException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } catch (FactoryException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } } else { Unit<?> distUnit = horCRS.getCoordinateSystem().getAxis(0).getUnit(); sourceUnit = (Unit<Area>) distUnit.multiply(distUnit); dArea = sumArea(features.subCollection(filter)); } dArea = UnitConverter.convertArea(new Measure(dArea, sourceUnit), targetUnit); } Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put(AreaProcessFactory.RESULT.key, new Double(dArea)); return resultMap; } AreaProcess(ProcessFactory factory); }
AreaProcess extends AbstractStatisticsProcess { @Override @SuppressWarnings("unchecked") public Map<String, Object> execute(Map<String, Object> input, ProgressListener monitor) throws ProcessException { SimpleFeatureCollection features = (SimpleFeatureCollection) Params.getValue(input, AreaProcessFactory.inputFeatures, null); Filter filter = (Filter) Params.getValue(input, AreaProcessFactory.filter, Filter.INCLUDE); AreaUnit targetUnit = (AreaUnit) Params.getValue(input, AreaProcessFactory.areaUnit, AreaUnit.Default); if (features == null) { throw new NullPointerException("inputFeatures parameters required"); } CoordinateReferenceSystem sourceCRS = features.getSchema().getCoordinateReferenceSystem(); filter = filter == null ? Filter.INCLUDE : filter; targetUnit = targetUnit == null ? AreaUnit.Default : targetUnit; double dArea = 0d; if (sourceCRS == null || targetUnit == AreaUnit.Default) { dArea = sumArea(features.subCollection(filter)); } else { CoordinateReferenceSystem horCRS = CRS.getHorizontalCRS(sourceCRS); Unit<Area> sourceUnit = SI.SQUARE_METRE; if (horCRS instanceof GeographicCRS) { try { Coordinate p = features.getBounds().centre(); CoordinateReferenceSystem autoCRS = CRS.decode("AUTO:42001," + p.x + "," + p.y); dArea = sumArea(new ReprojectFeatureCollection(features.subCollection(filter), autoCRS)); } catch (NoSuchAuthorityCodeException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } catch (FactoryException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } } else { Unit<?> distUnit = horCRS.getCoordinateSystem().getAxis(0).getUnit(); sourceUnit = (Unit<Area>) distUnit.multiply(distUnit); dArea = sumArea(features.subCollection(filter)); } dArea = UnitConverter.convertArea(new Measure(dArea, sourceUnit), targetUnit); } Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put(AreaProcessFactory.RESULT.key, new Double(dArea)); return resultMap; } AreaProcess(ProcessFactory factory); ProcessFactory getFactory(); static Double process(SimpleFeatureCollection inputFeatures, Filter filter,
            ProgressListener monitor); static Double process(SimpleFeatureCollection inputFeatures, Filter filter,
            AreaUnit areaUnit, ProgressListener monitor); @Override @SuppressWarnings("unchecked") Map<String, Object> execute(Map<String, Object> input, ProgressListener monitor); }
AreaProcess extends AbstractStatisticsProcess { @Override @SuppressWarnings("unchecked") public Map<String, Object> execute(Map<String, Object> input, ProgressListener monitor) throws ProcessException { SimpleFeatureCollection features = (SimpleFeatureCollection) Params.getValue(input, AreaProcessFactory.inputFeatures, null); Filter filter = (Filter) Params.getValue(input, AreaProcessFactory.filter, Filter.INCLUDE); AreaUnit targetUnit = (AreaUnit) Params.getValue(input, AreaProcessFactory.areaUnit, AreaUnit.Default); if (features == null) { throw new NullPointerException("inputFeatures parameters required"); } CoordinateReferenceSystem sourceCRS = features.getSchema().getCoordinateReferenceSystem(); filter = filter == null ? Filter.INCLUDE : filter; targetUnit = targetUnit == null ? AreaUnit.Default : targetUnit; double dArea = 0d; if (sourceCRS == null || targetUnit == AreaUnit.Default) { dArea = sumArea(features.subCollection(filter)); } else { CoordinateReferenceSystem horCRS = CRS.getHorizontalCRS(sourceCRS); Unit<Area> sourceUnit = SI.SQUARE_METRE; if (horCRS instanceof GeographicCRS) { try { Coordinate p = features.getBounds().centre(); CoordinateReferenceSystem autoCRS = CRS.decode("AUTO:42001," + p.x + "," + p.y); dArea = sumArea(new ReprojectFeatureCollection(features.subCollection(filter), autoCRS)); } catch (NoSuchAuthorityCodeException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } catch (FactoryException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } } else { Unit<?> distUnit = horCRS.getCoordinateSystem().getAxis(0).getUnit(); sourceUnit = (Unit<Area>) distUnit.multiply(distUnit); dArea = sumArea(features.subCollection(filter)); } dArea = UnitConverter.convertArea(new Measure(dArea, sourceUnit), targetUnit); } Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put(AreaProcessFactory.RESULT.key, new Double(dArea)); return resultMap; } AreaProcess(ProcessFactory factory); ProcessFactory getFactory(); static Double process(SimpleFeatureCollection inputFeatures, Filter filter,
            ProgressListener monitor); static Double process(SimpleFeatureCollection inputFeatures, Filter filter,
            AreaUnit areaUnit, ProgressListener monitor); @Override @SuppressWarnings("unchecked") Map<String, Object> execute(Map<String, Object> input, ProgressListener monitor);  }