Package org.geotools.feature

Examples of org.geotools.feature.FeatureCollection


     * used to occur, see https://jira.codehaus.org/browse/GEOT-4284
     *
     * @throws Exception
     */
    public void testLineLabelingUom() throws Exception {
        FeatureCollection collection = createLineFeatureCollection();
        Style style = loadStyle("LineStyleUom.sld");
        assertNotNull(style);
        MapContext map = new DefaultMapContext(DefaultGeographicCRS.WGS84);
        map.addLayer(collection, style);

View Full Code Here


        SimpleFeatureType type = builder.buildFeatureType();
        return SimpleFeatureBuilder.build(type, new Object[]{line, name}, null);
  }
 
  public void testPolyLabeling() throws Exception{   
    FeatureCollection collection=createPolyFeatureCollection();
    Style style=loadStyle("PolyStyle.sld");
    assertNotNull(style);
    MapContext map = new DefaultMapContext(DefaultGeographicCRS.WGS84);
        map.addLayer(collection, style);
        StreamingRenderer renderer=new StreamingRenderer();
View Full Code Here

 
    public void testBboxFilter() throws Exception {
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        // should  match  "r2" and "r3"
        BBOX bbox = ff.bbox(aname("geom"), 2, 3, 4, 5, "EPSG:4326");
        FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(bbox);
        assertEquals(2, features.size());
    }
View Full Code Here

     
    public void testBboxFilterDefault() throws Exception {
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        // should  match  "r2" and "r3"
        BBOX bbox = ff.bbox("", 2, 3, 4, 5, "EPSG:4326");
        FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(bbox);
        assertEquals(2, features.size());
    }
View Full Code Here

        final CoordinateReferenceSystem sourceCrs;
        final NumberRange scaleRange = NumberRange.create(scaleDenominator,scaleDenominator);
        final ArrayList<LiteFeatureTypeStyle> lfts ;

        if ( featureSource != null ) {
            FeatureCollection features = null;
            final FeatureType schema = featureSource.getSchema();

            final GeometryDescriptor geometryAttribute = schema.getGeometryDescriptor();
            if(geometryAttribute != null && geometryAttribute.getType() != null) {
                sourceCrs = geometryAttribute.getType().getCoordinateReferenceSystem();
            } else {
                sourceCrs = null;
            }
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine("Processing " + style.featureTypeStyles().size() +
                        " stylers for " + featureSource.getSchema().getName());
            }

            lfts = createLiteFeatureTypeStyles(style.featureTypeStyles(), schema, graphics);
            if(lfts.isEmpty())
                return;
           
            // make sure all spatial filters in the feature source native SRS
            reprojectSpatialFilters(lfts, featureSource);
           
            // apply the uom and dpi rescale
            applyUnitRescale(lfts);
           
            // classify by transformation
            List<List<LiteFeatureTypeStyle>> txClassified = classifyByTransformation(lfts);
           
            // render groups by uniform transformation
            for (List<LiteFeatureTypeStyle> uniform : txClassified) {
                Expression transform = uniform.get(0).transformation;
               
                // ... assume we have to do the generalization, the query layer process will
                // turn down the flag if we don't
                inMemoryGeneralization = true;
                boolean hasTransformation = transform != null;
                Query styleQuery = getStyleQuery(featureSource, schema,
                        uniform, mapArea, destinationCrs, sourceCrs, screenSize,
                        geometryAttribute, at, hasTransformation);
                Query definitionQuery = getDefinitionQuery(currLayer, featureSource, sourceCrs);
                if(hasTransformation) {
                    // prepare the stage for the raster transformations
                    GridGeometry2D gridGeometry = getRasterGridGeometry(destinationCrs, sourceCrs);
                    // vector transformation wise, we have to account for two separate queries,
                    // the one attached to the layer and then one coming from SLD.
                    // The first source attributes, the latter talks tx output attributes
                    // so they have to be applied before and after the transformation respectively
                   
                    RenderingTransformationHelper helper = new RenderingTransformationHelper() {
                       
                        @Override
                        protected GridCoverage2D readCoverage(GridCoverage2DReader reader, Object params, GridGeometry2D readGG) throws IOException {
                            GeneralParameterValue[] readParams = (GeneralParameterValue[]) params;
                            Interpolation interpolation = getRenderingInterpolation();
                            GridCoverageReaderHelper helper;
                            try {
                                helper = new GridCoverageReaderHelper(reader,
                                        readGG.getGridRange2D(),
                                        ReferencedEnvelope.reference(readGG.getEnvelope2D()),
                                        interpolation);
                                return helper.readCoverage(readParams);
                            } catch (InvalidGridGeometryException | FactoryException e) {
                                throw new IOException("Failure reading the coverage", e);
                            }

                        }
                    };
                   
                    Object result = helper.applyRenderingTransformation(transform, featureSource, definitionQuery,
                            styleQuery, gridGeometry, sourceCrs, java2dHints);
                    if(result == null) {
                        return;
                    } else if (result instanceof FeatureCollection) {
                        features = (FeatureCollection) result;
                    } else if (result instanceof GridCoverage2D) {
                        GridCoverage2D coverage = (GridCoverage2D) result;
                        // we only avoid disposing if the input was a in memory GridCovereage2D
                        if((schema instanceof SimpleFeatureType && !FeatureUtilities.isWrappedCoverage((SimpleFeatureType) schema))) {
                            coverage = new DisposableGridCoverage(coverage);
                        }
                        features = FeatureUtilities.wrapGridCoverage(coverage);
                    } else if (result instanceof GridCoverage2DReader) {
                        features = FeatureUtilities.wrapGridCoverageReader(
                                (GridCoverage2DReader) result, null);
                    } else {
                        throw new IllegalArgumentException(
                                "Don't know how to handle the results of the transformation, "
                                        + "the supported result types are FeatureCollection, GridCoverage2D "
                                        + "and GridCoverage2DReader, but we got: "
                                        + result.getClass());
                    }                   
                } else {
                    Query mixed = DataUtilities.mixQueries(definitionQuery, styleQuery, null);
                    checkAttributeExistence(featureSource.getSchema(), mixed);
                    features = featureSource.getFeatures(mixed);
                    features = RendererUtilities.fixFeatureCollectionReferencing(features, sourceCrs);
                }

                // HACK HACK HACK
                // For complex features, we need the targetCrs and version in scenario where we have
                // a top level feature that does not contain a geometry(therefore no crs) and has a
                // nested feature that contains geometry as its property.Furthermore it is possible
                // for each nested feature to have different crs hence we need to reproject on each
                // feature accordingly.
                // This is a Hack, this information should not be passed through feature type
                // appschema will need to remove this information from the feature type again
                if (!(features instanceof SimpleFeatureCollection)) {
                    features.getSchema().getUserData().put("targetCrs", destinationCrs);
                    features.getSchema().getUserData().put("targetVersion", "wms:getmap");
                }

                // finally, perform rendering
                if(isOptimizedFTSRenderingEnabled() && lfts.size() > 1) {
                    drawOptimized(graphics, currLayer, at, destinationCrs, layerId, null, features,
View Full Code Here

        ((OracleDialect) dataStore.getSQLDialect()).setLooseBBOXEnabled(true);
       
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        // should match only "r2"
        BBOX bbox = ff.bbox(aname("geom"), 2, 3.5, 4, 4.5, "EPSG:4326");
        FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(bbox);
        checkSingleResult(features, "r2");
    }
View Full Code Here

            }
        }
       
        if(result == null && !isRasterData) {
            // it's a transformation starting from vector data, let's see if we can optimize the query
            FeatureCollection originalFeatures;
            Query optimizedQuery = null;
            if(transformation instanceof RenderingTransformation) {
                RenderingTransformation tx = (RenderingTransformation) transformation;
                optimizedQuery = tx.invertQuery(renderingQuery, gridGeometry);
            }
View Full Code Here

        BufferFeatureCollectionFactory factory = new BufferFeatureCollectionFactory();
        BufferFeatureCollectionProcess process = factory.create();
        Map<String, Object> output = process.execute(input, null);

        FeatureCollection buffered = (FeatureCollection) output
                .get(BufferFeatureCollectionFactory.RESULT.key);

        assertEquals(2, buffered.size());
        for (int i = 0; i < 2; i++) {
            Geometry expected = gf.createPoint(new Coordinate(i, i)).buffer(10d);
            FeatureCollection sub = buffered.subCollection(ff.equals(ff.property("integer"),
                    ff.literal(i)));
            assertEquals(1, sub.size());
            FeatureIterator iterator = sub.features();
            SimpleFeature sf = (SimpleFeature) iterator.next();
            assertTrue(expected.equals((Geometry) sf.getDefaultGeometry()));
            iterator.close();
        }
    }
View Full Code Here

    public void testFilterTranslation() throws Exception {
        //tests that the translation of the filter from GeoSciML to the xml datasorce works.
        Filter inputFilter = ff.equals(ff.property("gml:name"), ff
                .literal("Unit Name1233811724109 UC1233811724109 description name"));

        FeatureCollection features = getFeatures(Query.DEFAULT_MAX, inputFilter);
        assertEquals(1, DataUtilities.count(features));
       
        // check that it returns the right feature
        FeatureIterator iterator = features.features();
        Feature f = iterator.next();
        assertEquals(f.getIdentifier().toString(), "lithostratigraphic.unit.1679161041155866313");       
        iterator.close();    
    }
View Full Code Here

    }

    public void testFeatureCounting() throws Exception {
        Filter inputFilter = ff.like(ff.property("gml:name"), "*description name*");
       
        FeatureCollection features = getFeatures(Query.DEFAULT_MAX, inputFilter);
        assertEquals(3, DataUtilities.count(features));
       
        // check feature ids
        FeatureIterator iterator = features.features();
        Feature f = iterator.next();
        assertEquals(f.getIdentifier().toString(), "lithostratigraphic.unit.1679161021439131319");
        assertTrue(iterator.hasNext());
        f = iterator.next();           
        assertEquals(f.getIdentifier().toString(), "lithostratigraphic.unit.1679161041155866313")
        assertTrue(iterator.hasNext());
        f = iterator.next();     
        assertEquals(f.getIdentifier().toString(), "lithostratigraphic.unit.1679161021439938381");
       
        iterator.close();       
       
        // now with maxFeatures = 1, it should only return the first one
        features = getFeatures(MAX_FEATURES, inputFilter);
        assertEquals(MAX_FEATURES, DataUtilities.count(features));
       
        iterator = features.features();
        f = iterator.next();
        assertEquals(f.getIdentifier().toString(), "lithostratigraphic.unit.1679161021439131319");
       
        iterator.close();   
    }
View Full Code Here

TOP

Related Classes of org.geotools.feature.FeatureCollection

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.