Package org.geotools.feature

Examples of org.geotools.feature.DefaultFeatureCollection


        SimpleFeatureType type = tb.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        WKTReader reader = new WKTReader();

        DefaultFeatureCollection fc = new DefaultFeatureCollection();
        SimpleFeature feature;
       
        feature = buildFeature(builder, reader,
                "LINESTRING(10 0, 10 20)", "horizontal", (float)1.1);
        fc.add(feature);

        feature = buildFeature(builder, reader,
                "LINESTRING(0 10, 20 10)", "vertical", (float)2.2);
        fc.add(feature);

        feature = buildFeature(builder, reader,
                "LINESTRING(0 20,0 0,20 0,20 20,0 20)", "box", (float)3.3);
        fc.add(feature);
       
        return fc;
    }
View Full Code Here


        tb.add("shape", MultiPoint.class);
        tb.add("value", Double.class);

        SimpleFeatureType type = tb.buildFeatureType();
        SimpleFeatureBuilder fb = new SimpleFeatureBuilder(type);
        DefaultFeatureCollection fc = new DefaultFeatureCollection();

        GeometryFactory factory = new GeometryFactory(new PackedCoordinateSequenceFactory());

        for (Coordinate p : pts) {
            Geometry point = factory.createPoint(p);
            fb.add(point);
            fb.add(p.z);
            fc.add(fb.buildFeature(null));
        }

        return fc;
    }
View Full Code Here

        }
    }

    public SimpleFeatureCollection collection() throws IOException {
        try {
             DefaultFeatureCollection collection = new DefaultFeatureCollection(null,null);
            
             FeatureReader<SimpleFeatureType, SimpleFeature> reader = reader();
             try {
               while (reader.hasNext()) {
                 collection.add(reader.next());
               }
             } finally {
               reader.close();
             }
View Full Code Here

        tb.add("integer", Integer.class);

        GeometryFactory gf = new GeometryFactory();
        SimpleFeatureBuilder b = new SimpleFeatureBuilder(tb.buildFeatureType());

        DefaultFeatureCollection features = new DefaultFeatureCollection(null, b.getFeatureType());
        DefaultFeatureCollection secondFeatures = new DefaultFeatureCollection(null, b
                .getFeatureType());
        Polygon[] firstArrayGeometry = new Polygon[1];
        Polygon[] secondArrayGeometry = new Polygon[1];
        for (int numFeatures = 0; numFeatures < 1; numFeatures++) {
            Coordinate array[] = new Coordinate[5];
            array[0] = new Coordinate(0, 0);
            array[1] = new Coordinate(1, 0);
            array[2] = new Coordinate(1, 1);
            array[3] = new Coordinate(0, 1);
            array[4] = new Coordinate(0, 0);
            LinearRing shell = new LinearRing(array, new PrecisionModel(), 0);
            b.add(gf.createPolygon(shell, null));
            b.add(0);
            firstArrayGeometry[0] = gf.createPolygon(shell, null);
            features.add(b.buildFeature(numFeatures + ""));
        }
        for (int numFeatures = 0; numFeatures < 1; numFeatures++) {
            Coordinate array[] = new Coordinate[5];
            Coordinate centre = ((Polygon) features.features().next().getDefaultGeometry())
                    .getCentroid().getCoordinate();
            array[0] = new Coordinate(centre.x, centre.y);
            array[1] = new Coordinate(centre.x + 1, centre.y);
            array[2] = new Coordinate(centre.x + 1, centre.y + 1);
            array[3] = new Coordinate(centre.x, centre.y + 1);
            array[4] = new Coordinate(centre.x, centre.y);
            LinearRing shell = new LinearRing(array, new PrecisionModel(), 0);
            b.add(gf.createPolygon(shell, null));
            b.add(0);
            secondArrayGeometry[0] = gf.createPolygon(shell, null);
            secondFeatures.add(b.buildFeature(numFeatures + ""));
        }

        SimpleFeatureCollection output3 = process.execute(features,secondFeatures, null, null, null, false, false);

        assertTrue(output3.size()==1);
View Full Code Here

        tb.add("geom", Point.class, CRS.decode("EPSG:3857"));
        tb.add("name", String.class);
        tb.setName("xyz");
        SimpleFeatureType schema = tb.buildFeatureType();

        DefaultFeatureCollection fc = new DefaultFeatureCollection();

        SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema);
        fb.add(new WKTReader().read("POINT(20037508.34 20037508.34)"));
        fc.add(fb.buildFeature("xyz.1"));

        FeatureJSON fj = new FeatureJSON();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        fj.writeFeatureCollection(fc, os);
View Full Code Here

        Object crs = fjson.readCRS(reader(strip(crsText())));
        assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("epsg:4326"), crs));
    }

    public void testFeatureCollectionWithNullBoundsWrite() throws Exception {
        DefaultFeatureCollection features = new DefaultFeatureCollection() {
            @Override
            public ReferencedEnvelope getBounds() {
                return null;
            }
        };
        features.add(feature(0));

        String json = fjson.toString(features);

    }
View Full Code Here

       
        return text;
    }

    FeatureCollection collection() {
        DefaultFeatureCollection collection = new DefaultFeatureCollection(null, featureType);
        for (int i = 0; i < 3; i++) {
            collection.add(feature(i));
        }
        return collection;
    }
View Full Code Here

            @DescribeParameter(name = "from_measure_attb", description = "Attribute providing start measure of feature") String fromMeasureAttb,
            @DescribeParameter(name = "to_measure_attb", description = "Attribute providing end measure of feature") String toMeasureAttb,
            @DescribeParameter(name = "point", description = "Point whose location to measure") Point point,
            @DescribeParameter(name = "crs", min = 0, description = "Coordinate reference system to use for input (default is the input collection CRS)") CoordinateReferenceSystem crs)
            throws ProcessException {
        DefaultFeatureCollection results = new DefaultFeatureCollection();
        try {
            if (featureCollection == null || featureCollection.size() == 0) {
                LOGGER.info("No features provided in request");
                return results;
            }
            if (crs == null) {
                GeometryDescriptor gd = featureCollection.getSchema().getGeometryDescriptor();
                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) {
View Full Code Here

        DataStore store = DataStoreFinder.getDataStore(params);

        final SimpleFeatureType type = store.getSchema("locations");
        final FeatureWriter<SimpleFeatureType, SimpleFeature> writer;
        SimpleFeature f;
        DefaultFeatureCollection collection = new DefaultFeatureCollection();
       
        // 45.52, -122.681944, Portland, 800, 2014
        GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();
        Point portland = gf.createPoint(new Coordinate( 45.52, -122.681944));
        f = SimpleFeatureBuilder.build(type, new Object[] { portland, "Portland", 800, 2014 }, "locations.1");
        collection.add(f);

        writer = store.getFeatureWriter("locations", Transaction.AUTO_COMMIT);
        try {
            // remove all features
            while (writer.hasNext()) {
                writer.next();
                writer.remove();
            }
            // copy new features in
            SimpleFeatureIterator iterator = collection.features();
            while (iterator.hasNext()) {
                SimpleFeature feature = iterator.next();
                SimpleFeature newFeature = writer.next(); // new blank feature
                newFeature.setAttributes(feature.getAttributes());
                writer.write();
View Full Code Here

    @Test
    public void testAdd() throws FileNotFoundException, IOException {
        DataStore csv = this.getDataStore();
        SimpleFeatureStore rows = (SimpleFeatureStore) csv.getFeatureSource(TYPE_NAME);
        SimpleFeatureType featureType = csv.getSchema(TYPE_NAME);
        DefaultFeatureCollection toAdd = new DefaultFeatureCollection("test", featureType);
        SimpleFeature newFeature = new SimpleFeatureImpl(new Object[] {this.newPoint(new Coordinate(12, 34)), "Manhattan Beach", 444}, featureType, new FeatureIdImpl("test"), false);
        toAdd.add(newFeature);
        rows.addFeatures(toAdd);

        // re-open
        csv = this.getDataStore();
        rows = (SimpleFeatureStore) csv.getFeatureSource( TYPE_NAME );
View Full Code Here

TOP

Related Classes of org.geotools.feature.DefaultFeatureCollection

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.