Package org.geotools.process.function

Source Code of org.geotools.process.function.ProcessFunctionTest

package org.geotools.process.function;

import static org.junit.Assert.assertEquals;

import java.net.URL;

import org.geotools.TestData;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
import org.geotools.process.feature.BufferFeatureCollectionFactory;
import org.junit.Test;
import org.opengis.feature.type.GeometryDescriptor;
import org.opengis.filter.FilterFactory;
import org.opengis.filter.capability.FunctionName;
import org.opengis.filter.expression.Function;

import com.vividsolutions.jts.geom.MultiPolygon;

/**
*
*
* @source $URL$
*/
public class ProcessFunctionTest {

    FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);

    @Test
    public void testBuffer() throws Exception {
        URL url = TestData.getResource(TestData.class, "shapes/archsites.shp");
        ShapefileDataStore store = new ShapefileDataStore(url);
        SimpleFeatureCollection features = store.getFeatureSource().getFeatures();

        // first param, the context feature collection
        Function featuresParam = ff.function("parameter", ff
                .literal(BufferFeatureCollectionFactory.FEATURES.key));
        // second param, the buffer size
        Function bufferParam = ff.function("parameter", ff
                .literal(BufferFeatureCollectionFactory.BUFFER.key), ff.literal(1000));
        // build the function and call it
        Function buffer = ff.function("gt:BufferFeatureCollection", featuresParam, bufferParam);
       
        // check the metadata
        FunctionName fn = buffer.getFunctionName();
        assertEquals("gt:BufferFeatureCollection", fn.getName());
        assertEquals(2, fn.getArgumentCount());
        assertEquals(FeatureCollection.class, fn.getReturn().getType());
       
        // run and check results
        SimpleFeatureCollection buffered = (SimpleFeatureCollection) buffer.evaluate(features);
        assertEquals(features.size(), buffered.size());
        GeometryDescriptor gd = buffered.getSchema().getGeometryDescriptor();
        // is it actually a buffer?
        assertEquals(MultiPolygon.class, gd.getType().getBinding());
    }
   
}
TOP

Related Classes of org.geotools.process.function.ProcessFunctionTest

TOP
Copyright © 2018 www.massapi.com. 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.