Package org.geotools.process

Examples of org.geotools.process.ProcessException


            }
            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


                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");
            }

            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);

            DefaultFeatureCollection results = new DefaultFeatureCollection();
            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;
            double nearestBearing = 0;
            double[] nearestPoint = new double[2];
            FeatureIterator featureIterator = featureCollection.features();
            try {
                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();
                    nearestBearing = calcBearing(co);
                    nearestPoint[0] = geo1[0];
                    nearestPoint[1] = geo1[1];
                }
            } finally {
                featureIterator.close();
            }
            if (nearestFeature != null) {
                nearestDistance = unitConvert.convert(nearestDistance);
                results.add(createTargetFeature(nearestFeature,
                        (SimpleFeatureType) targetFeatureType, nearestPoint, nearestDistance,
                        nearestBearing));
            }
            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

        }

        try {
            return source.getFeatures();
        } catch (IOException e) {
            throw new ProcessException("Unexpected exception while grabbing features", e);
        }
    }
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 (measure == null) {
                throw new ProcessException("The measure parameter was not provided");
            }
            SimpleFeatureType targetFeatureType = createTargetFeatureType(featureCollection
                    .getSchema());

            FeatureIterator<Feature> featureIterator = null;
            try {
                featureIterator = featureCollection.features();
                Feature feature = featureIterator.next();
                Double featureFromMeasure = (Double) feature.getProperty(fromMeasureAttb)
                        .getValue();
                Double featureToMeasure = (Double) feature.getProperty(toMeasureAttb).getValue();
                LengthIndexedLine lengthIndexedLine = new LengthIndexedLine((Geometry) feature
                        .getDefaultGeometryProperty().getValue());
                double featureLength = featureToMeasure - featureFromMeasure;
                double startOffset = measure - featureFromMeasure;
                double calcLength = ((Geometry) feature.getDefaultGeometryProperty().getValue())
                        .getLength();
                if (calcLength == 0) {
                    LOGGER.info("Edge feature has zero length");
                    return results;
                }
                if (featureLength == 0) {
                    LOGGER.info("Requested feature has zero length");
                    return results;
                }
                Coordinate point = lengthIndexedLine.extractPoint(startOffset * calcLength
                        / featureLength);
                results.add(createTargetFeature(feature, targetFeatureType, point));
            } 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

            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

        MathTransform invTransform = null;
        try {
            crsTransform = CRS.findMathTransform(srcCRS, dstCRS);
            invTransform = crsTransform.inverse();
        } catch (FactoryException e) {
            throw new ProcessException(e);
        }
       
        boolean normalize = false;
        if(argNormalize!=null){
            normalize = argNormalize;
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");
            }

            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);

            DefaultFeatureCollection results = new DefaultFeatureCollection();
            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;
            double nearestBearing = 0;
            FeatureIterator featureIterator = featureCollection.features();
            try {
                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();
                    nearestBearing = calcBearing(co);
                }
            } finally {
                featureIterator.close();
            }
            if (nearestFeature != null) {
                nearestDistance = unitConvert.convert(nearestDistance);
                results.add(createTargetFeature(nearestFeature,
                        (SimpleFeatureType) targetFeatureType, nearestDistance, nearestBearing));
            }
            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.