Package org.geotools.process

Examples of org.geotools.process.ProcessException


        //
        // initial checks
        //
        if (coverage == null) {
            throw new ProcessException("Invalid input, source grid coverage should be not null");
        }

        if (band == null) {
            band = 0;
        } else if (band < 0 || band >= coverage.getNumSampleDimensions()) {
            throw new ProcessException("Invalid input, invalid band number:" + band);
        }

        // do we have classification ranges?
        boolean hasClassificationRanges = classificationRanges != null && classificationRanges.size() > 0;
View Full Code Here


        CoordinateReferenceSystem dstCRS = outputEnv.getCoordinateReferenceSystem();
        MathTransform trans = null;
        try {
            trans = CRS.findMathTransform(srcCRS, dstCRS);
        } catch (FactoryException e) {
            throw new ProcessException(e);
        }
        /**---------------------------------------------
         * Convert distance parameters to units of the destination CRS.
         * ---------------------------------------------
         */
        double distanceConversionFactor = distanceConversionFactor(srcCRS, dstCRS);
        double dstLengthScale = lengthScale * distanceConversionFactor;
        double dstMaxObsDistance = maxObsDistance * distanceConversionFactor;

        /**---------------------------------------------
         * Extract the input observation points
         * ---------------------------------------------
         */
        Coordinate[] pts = null;
        try {
            pts = extractPoints(obsFeatures, valueAttr, trans, dataLimit);
        } catch (CQLException e) {
            throw new ProcessException(e);
        }

        /**---------------------------------------------
         * Do the processing
         * ---------------------------------------------
 
View Full Code Here

                    builder.add(stats.getAverage());
                    builder.add(stats.getStandardDeviation());
                }
                return builder.buildFeature(zone.getID());
            } catch (Exception e) {
                throw new ProcessException("Failed to compute statistics on feature " + zone, e);
            }
        }
View Full Code Here

                break;
            }
        }

        if (attIndex == -1) {
            throw new ProcessException("Could not find attribute " +
                "[" + aggAttribute + "] "
                    + " the valid values are " + attNames(atts));
        }
        if (functions == null ){
            throw new NullPointerException("Aggregate function to call is required");
        }
        List<AggregationFunction> functionList = new ArrayList<AggregationFunction>(functions);
        List<FeatureCalc> visitors = new ArrayList<FeatureCalc>();

        for (AggregationFunction function : functionList) {
            FeatureCalc calc;
            if (function == AggregationFunction.Average) {
                calc = new AverageVisitor(attIndex, features.getSchema());
            } else if (function == AggregationFunction.Count) {
                calc = new CountVisitor();
            } else if (function == AggregationFunction.Max) {
                calc = new MaxVisitor(attIndex, features.getSchema());
            } else if (function == AggregationFunction.Median) {
                calc = new MedianVisitor(attIndex, features.getSchema());
            } else if (function == AggregationFunction.Min) {
                calc = new MinVisitor(attIndex, features.getSchema());
            } else if (function == AggregationFunction.StdDev) {
                calc = new StandardDeviationVisitor(CommonFactoryFinder.getFilterFactory(null).property(aggAttribute));
            } else if (function == AggregationFunction.Sum) {
                calc = new SumVisitor(attIndex, features.getSchema());
            } else {
                throw new ProcessException("Uknown method " + function);
            }
            visitors.add(calc);
        }

        EnumMap<AggregationFunction, Number> results = new EnumMap<AggregationFunction, Number>(AggregationFunction.class);
View Full Code Here

                && !CRS.equalsIgnoreMetadata(featuresCRS, clip.getCoordinateReferenceSystem())) {
            boolean lenient = true;
            try {
                clip = clip.transform(featuresCRS, lenient);
            } catch (TransformException e) {
                throw new ProcessException(e);
            } catch (FactoryException e) {
                throw new ProcessException(e);
            }
        }
        return new ClipProcess().execute(features, JTS.toGeometry(clip), preserveZ);
    }
View Full Code Here

                if (gd != null) {
                    crs = gd.getCoordinateReferenceSystem();
                }
            }
            if (crs == null) {
                throw new ProcessException(
                        "The CRS parameter was not provided and the feature collection does not have a default one either");
            }
            if (fromMeasureAttb == null
                    || featureCollection.getSchema().getDescriptor(fromMeasureAttb) == null) {
                throw new ProcessException(
                        "The from_measure_attb parameter was not provided or not defined in schema");
            }
            if (toMeasureAttb == null
                    || featureCollection.getSchema().getDescriptor(toMeasureAttb) == null) {
                throw new ProcessException("The to_measure_attb parameter was not provided");
            }
            if (point == null) {
                throw new ProcessException("The point parameter was not provided");
            }

            CoordinateReferenceSystem epsg4326;
            try {
                epsg4326 = CRS.decode("EPSG:4326");
            } catch (Exception e) {
                throw new ProcessException("Unknown CRS code: EPSG:4326", e);
            }
            MathTransform crsTransform = CRS.findMathTransform(crs, epsg4326);

            FeatureType targetFeatureType = createTargetFeatureType(featureCollection.getSchema());
            Unit fromUnit = SI.METER;
            Unit toUnit = Unit.valueOf("mi");
            UnitConverter unitConvert = fromUnit.getConverterTo(toUnit);
            Feature nearestFeature = null;
            double nearestDistance = 9e9;
            Coordinate[] nearestCoords = null;
            FeatureIterator<Feature> featureIterator = null;
            try {
                featureIterator = featureCollection.features();
                while (featureIterator.hasNext()) {
                    SimpleFeature f = (SimpleFeature) featureIterator.next();
                    if (f.getDefaultGeometryProperty().getValue() == null)
                        continue;
                    DistanceOp op = new DistanceOp(point, (Geometry) f.getDefaultGeometryProperty()
                            .getValue());
                    Coordinate[] co = op.closestPoints();
                    double[] co0 = new double[] { co[0].x, co[0].y, };
                    double[] co1 = new double[] { co[1].x, co[1].y, };
                    double[] geo0 = new double[2];
                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
                    crsTransform.transform(co1, 0, geo1, 0, 1);

                    // get distance
                    Measure m = DefaultGeographicCRS.WGS84.distance(geo0, geo1);
                    if (m.doubleValue() > nearestDistance)
                        continue;
                    nearestFeature = f;
                    nearestDistance = m.doubleValue();
                    nearestCoords = co;
                }
            } finally {
                if (featureIterator != null)
                    featureIterator.close();
            }
            if (nearestFeature != null) {
                LengthIndexedLine lengthIndexedLine = new LengthIndexedLine(
                        (Geometry) nearestFeature.getDefaultGeometryProperty().getValue());
                double lineIndex = lengthIndexedLine.indexOf(nearestCoords[1]);
                double lineLength = ((Geometry) nearestFeature.getDefaultGeometryProperty()
                        .getValue()).getLength();
                Double featureFromMeasure = (Double) nearestFeature.getProperty(fromMeasureAttb)
                        .getValue();
                Double featureToMeasure = (Double) nearestFeature.getProperty(toMeasureAttb)
                        .getValue();
                double lrsMeasure = featureFromMeasure + (featureToMeasure - featureFromMeasure)
                        * lineIndex / lineLength;
                nearestFeature.getDefaultGeometryProperty().setValue(
                        geometryFactory.createPoint(new Coordinate(nearestCoords[1].x,
                                nearestCoords[1].y)));
                results.add(createTargetFeature(nearestFeature,
                        (SimpleFeatureType) targetFeatureType, lrsMeasure));
                return results;
            }
            return results;
        } catch (ProcessException e) {
            throw e;
        } catch (Throwable e) {
            LOGGER.warning("Error executing method: " + e);
            throw new ProcessException("Error executing method: " + e, e);
        }
    }
View Full Code Here

            typeBuilder
                    .setDefaultGeometry(sourceFeatureType.getGeometryDescriptor().getLocalName());
            return typeBuilder.buildFeatureType();
        } catch (Exception e) {
            LOGGER.warning("Error creating type: " + e);
            throw new ProcessException("Error creating type: " + e, e);
        }
    }
View Full Code Here

            }
            return SimpleFeatureBuilder.build(targetFeatureType, attributes, feature
                    .getIdentifier().getID());
        } catch (Exception e) {
            LOGGER.warning("Error creating feature: " + e);
            throw new ProcessException("Error creating feature: " + e, e);
        }
    }
View Full Code Here

            @DescribeParameter(name = "features", description = "Input feature collection") SimpleFeatureCollection features,
            @DescribeParameter(name = "distance", description = "Simplification distance tolerance") double distance,
            @DescribeParameter(name = "preserveTopology", description = "If True, ensures that simplified features are topologically valid",  defaultValue = "false") boolean preserveTopology)
            throws ProcessException {
        if (distance < 0) {
            throw new ProcessException("Invalid distance, it should be a positive number");
        }

        return new SimplifyingFeatureCollection(features, distance, preserveTopology);
    }
View Full Code Here

                LOGGER.info("No features provided in request");
                return results;
            }
            if (fromMeasureAttb == null
                    || featureCollection.getSchema().getDescriptor(fromMeasureAttb) == null) {
                throw new ProcessException(
                        "The from_measure_attb parameter was not provided or not defined in schema");
            }
            if (toMeasureAttb == null
                    || featureCollection.getSchema().getDescriptor(toMeasureAttb) == null) {
                throw new ProcessException("The to_measure_attb parameter was not provided");
            }
            if (fromMeasure == null) {
                throw new ProcessException("The from_measure parameter was not provided");
            }
            if (toMeasure == null) {
                throw new ProcessException("The to_measure parameter was not provided");
            }
            if (fromMeasure.doubleValue() == toMeasure.doubleValue()) {
                LOGGER.info("Zero length segment requested");
                return results;
            }

            FeatureIterator<Feature> featureIterator = null;
            Feature firstFeature = null;
            try {
                LineMerger lineMerger = new LineMerger();
                if (toMeasure.doubleValue() > fromMeasure.doubleValue()) {
                    featureIterator = featureCollection.features();
                    while (featureIterator.hasNext()) {
                        Feature feature = featureIterator.next();
                        if (firstFeature == null)
                            firstFeature = feature;
                        Double featureFromMeasure = (Double) feature.getProperty(fromMeasureAttb)
                                .getValue();
                        Double featureToMeasure = (Double) feature.getProperty(toMeasureAttb)
                                .getValue();

                        if (fromMeasure < featureToMeasure && toMeasure > featureFromMeasure) {
                            try {
                                if (fromMeasure <= featureFromMeasure
                                        && toMeasure >= featureToMeasure) {
                                    lineMerger.add((Geometry) feature.getDefaultGeometryProperty()
                                            .getValue());
                                } else if (fromMeasure > featureFromMeasure
                                        && toMeasure < featureToMeasure) {
                                    LengthIndexedLine lengthIndexedLine = new LengthIndexedLine(
                                            (Geometry) feature.getDefaultGeometryProperty()
                                                    .getValue());
                                    double featureLength = featureToMeasure - featureFromMeasure;
                                    double startOffset = fromMeasure - featureFromMeasure;
                                    double stopOffset = toMeasure - featureFromMeasure;
                                    double calcLength = ((Geometry) feature
                                            .getDefaultGeometryProperty().getValue()).getLength();
                                    if (calcLength == 0 || featureLength == 0)
                                        continue;
                                    Geometry extracted = lengthIndexedLine.extractLine(startOffset
                                            * calcLength / featureLength, stopOffset * calcLength
                                            / featureLength);
                                    if (!extracted.isEmpty())
                                        lineMerger.add(extracted);
                                } else if (fromMeasure > featureFromMeasure) {
                                    LengthIndexedLine lengthIndexedLine = new LengthIndexedLine(
                                            (Geometry) feature.getDefaultGeometryProperty()
                                                    .getValue());
                                    double featureLength = featureToMeasure - featureFromMeasure;
                                    double startOffset = fromMeasure - featureFromMeasure;
                                    double calcLength = ((Geometry) feature
                                            .getDefaultGeometryProperty().getValue()).getLength();
                                    if (calcLength == 0 || featureLength == 0)
                                        continue;
                                    Geometry extracted = lengthIndexedLine.extractLine(startOffset
                                            * calcLength / featureLength, calcLength);
                                    if (!extracted.isEmpty())
                                        lineMerger.add(extracted);
                                } else {
                                    LengthIndexedLine lengthIndexedLine = new LengthIndexedLine(
                                            (Geometry) feature.getDefaultGeometryProperty()
                                                    .getValue());
                                    double featureLength = featureToMeasure - featureFromMeasure;
                                    double stopOffset = toMeasure - featureFromMeasure;
                                    double calcLength = ((Geometry) feature
                                            .getDefaultGeometryProperty().getValue()).getLength();
                                    if (calcLength == 0 || featureLength == 0)
                                        continue;
                                    Geometry extracted = lengthIndexedLine.extractLine(0,
                                            stopOffset * calcLength / featureLength);
                                    if (extracted.isEmpty() || extracted.getLength() == 0.0) {
                                        LOGGER.info("Empty segment: featureFromMeasure="
                                                + featureFromMeasure + " featureToMeasure:"
                                                + featureToMeasure + " toMeasure:" + toMeasure
                                                + " fromMeasure:" + fromMeasure);
                                    } else {
                                        lineMerger.add(extracted);
                                    }
                                }
                            } catch (Exception e) {
                                LOGGER.warning("Error merging line strings: " + e
                                        + " featureFromMeasure=" + featureFromMeasure
                                        + " featureToMeasure:" + featureToMeasure + " toMeasure:"
                                        + toMeasure + " fromMeasure:" + fromMeasure);
                            }
                        }
                    }
                    results.add(createTargetFeature(firstFeature, (SimpleFeatureType) firstFeature
                            .getType(), new MultiLineString((LineString[]) lineMerger
                            .getMergedLineStrings().toArray(new LineString[0]), geometryFactory)));
                }
            } finally {
                if (featureIterator != null)
                    featureIterator.close();
            }
            return results;
        } catch (ProcessException e) {
            throw e;
        } catch (Throwable e) {
            LOGGER.warning("Error executing method: " + e);
            throw new ProcessException("Error executing method: " + e, e);
        }
    }
View Full Code Here

TOP

Related Classes of org.geotools.process.ProcessException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.