Package org.geotools.feature

Examples of org.geotools.feature.DefaultFeatureCollection


            inputStream = new FileInputStream(kml);
        }
       
        PullParser parser = new PullParser(new KMLConfiguration(), inputStream, KML.Placemark);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
       
        int index = 0;
        SimpleFeature f;
        DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84;
        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName(kml.getName());
        b.setCRS(crs);
        b.add("name", String.class);
        b.add("the_geom", Geometry.class); //$NON-NLS-1$
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);

        while( (f = (SimpleFeature) parser.parse()) != null ) {
            Geometry geometry = (Geometry) f.getDefaultGeometry();
            Object nameAttribute = null;
            try {
                nameAttribute = f.getAttribute("name");
            } catch (Exception e){
                // ignore name attribute
            }
            builder.addAll(new Object[]{nameAttribute, geometry });
            SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + index++); //$NON-NLS-1$
            newCollection.add(feature);
        }

        return newCollection;
    }
View Full Code Here


       
        CoordinateReferenceSystem epsg4326 = DefaultGeographicCRS.WGS84;
        CoordinateReferenceSystem crs = featureCollection.getSchema().getCoordinateReferenceSystem();
        MathTransform mtrans = CRS.findMathTransform(crs, epsg4326, true);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        FeatureIterator<SimpleFeature> featuresIterator = featureCollection.features();
        while( featuresIterator.hasNext() ) {
            SimpleFeature f = featuresIterator.next();
            Geometry g = (Geometry) f.getDefaultGeometry();
            if (!mtrans.isIdentity()) {
                g = JTS.transform(g, mtrans);
            }
            f.setDefaultGeometry(g);
            newCollection.add(f);
        }

        OutputStream fos = null;
        try {
            if (kmlFile.getName().toLowerCase().endsWith(KMZ_FILE_EXTENSION)) {
View Full Code Here

   
    this.feature1 = new SimpleFeatureImpl( new ArrayList<Object>( Arrays.asList( NO_VALUE, NO_GEOMETRY ) ),
                                           featureType,
                                           new FeatureIdImpl( "one" ) );
   
    this.polygons = new DefaultFeatureCollection( "poly", featureType );
    this.polygons.add( feature1 );
  }
View Full Code Here

                typeBuilder.add(Constants.Style.Grid.ATT_Y_DISPLACEMENT, Double.class);
                typeBuilder.setName(Constants.Style.Grid.NAME);

                SimpleFeatureType featureType = typeBuilder.buildFeatureType();
                SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
                final DefaultFeatureCollection features;
                if (layerData.numberOfLines != null) {
                    features = createFeaturesFromNumberOfLines(mapContext, featureBuilder, layerData);
                } else {
                    features = createFeaturesFromSpacing(mapContext, featureBuilder, layerData);
                }
View Full Code Here

        String unit = bounds.getCoordinateReferenceSystem().getCoordinateSystem().getAxis(0).getUnit().toString();
        final AxisDirection direction = bounds.getCoordinateReferenceSystem().getCoordinateSystem().getAxis(0).getDirection();
        int numDimensions = bounds.getCoordinateReferenceSystem().getCoordinateSystem().getDimension();

        DefaultFeatureCollection features = new DefaultFeatureCollection();

        double pointSpacing = bounds.getSpan(1) / layerData.pointsInLine;
        int i = 0;
        for (double x = minX; x < bounds.getMaxX(); x += xSpace) {
            i++;
            final SimpleFeature feature = createFeature(mapContext, featureBuilder, geometryFactory, layerData,
                    unit, direction, numDimensions, pointSpacing, x, bounds.getMinimum(1), i, 1);
            features.add(feature);
        }

        pointSpacing = bounds.getSpan(0) / layerData.pointsInLine;
        int j = 0;
        for (double y = minY; y < bounds.getMaxY(); y += ySpace) {
            j++;
            final SimpleFeature feature = createFeature(mapContext, featureBuilder, geometryFactory, layerData,
                    unit, direction, numDimensions, pointSpacing, bounds.getMinimum(0), y, j, 0);
            features.add(feature);
        }

        return features;
    }
View Full Code Here

        typeBuilder.setName("overview-map");
        typeBuilder.setCRS(crs);
        typeBuilder.add("geom", Polygon.class);
        final SimpleFeatureType type = typeBuilder.buildFeatureType();

        DefaultFeatureCollection features = new DefaultFeatureCollection();
        features.add(SimpleFeatureBuilder.build(type, new Object[]{mapExtent}, null));

        return features;
    }
View Full Code Here

        final SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
        typeBuilder.setName("aoi");
        CoordinateReferenceSystem crs = mapAttributes.getMapBounds().getProjection();
        typeBuilder.add("geom", this.polygon.getClass(), crs);
        final SimpleFeature feature = SimpleFeatureBuilder.build(typeBuilder.buildFeatureType(), new Object[]{this.polygon}, "aoi");
        final DefaultFeatureCollection features = new DefaultFeatureCollection();
        features.add(feature);
        return features;
    }
View Full Code Here

    /**
     * Create a geotools feature collection from a list of isochrones in the OTPA internal format.
     * Once in a FeatureCollection, they can for example be exported as GeoJSON.
     */
    public static SimpleFeatureCollection makeContourFeatures(List<IsochroneData> isochrones) {
        DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(null,
                contourSchema);
        SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(contourSchema);
        for (IsochroneData isochrone : isochrones) {
            fbuilder.add(isochrone.geometry);
            fbuilder.add(isochrone.cutoffSec);
            featureCollection.add(fbuilder.buildFeature(null));
        }
        return featureCollection;
    }
View Full Code Here

    }

    private SimpleFeatureCollection makePointFeatures() throws Exception {
        Map<Vertex, Double> points = makePoints();
        /* Stage the point features in memory */
        DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(null, pointSchema);
        SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(pointSchema);
        GeometryFactory gf = new GeometryFactory();
        for (Map.Entry<Vertex, Double> entry : points.entrySet()) {
            Vertex vertex = entry.getKey();
            Double travelTime = entry.getValue();
            fbuilder.add(gf.createPoint(vertex.getCoordinate()));
            fbuilder.add(travelTime);
            featureCollection.add(fbuilder.buildFeature(null));
        }
        return featureCollection;
    }
View Full Code Here

    }

    private SimpleFeatureCollection makeContourFeatures() throws Exception {
        Map<Integer, Geometry> contours = makeContours();
        /* Stage the features in memory, in order from bottom to top, biggest to smallest */
        DefaultFeatureCollection featureCollection =
                new DefaultFeatureCollection(null, contourSchema);
        SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(contourSchema);
        List<Integer> thresholds = new ArrayList<Integer>(contours.keySet());
        Collections.sort(thresholds);
        //Collections.reverse(thresholds);
        for (Integer threshold : thresholds) {
            Geometry contour = contours.get(threshold);
            fbuilder.add(contour);
            fbuilder.add(threshold);
            featureCollection.add(fbuilder.buildFeature(null));
        }
        return featureCollection;
    }
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.