org.geotools.data.simple.SimpleFeatureCollection Java Examples

The following examples show how to use org.geotools.data.simple.SimpleFeatureCollection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LasInfoController.java    From hortonmachine with GNU General Public License v3.0 7 votes vote down vote up
private void createOverviewAction( File saveFile ) {
    String outputFilePath = saveFile.getAbsolutePath();

    ILasHeader header = lasReader.getHeader();
    long recordsCount = header.getRecordsCount();
    int work = (int) (recordsCount / 1000);

    new ExecutorProgressGui(work * 2){
        @Override
        public void backGroundWork() throws Exception {
            constraints.applyConstraints(lasReader, true, this);

            publish(new ProgressUpdate("Getting bounds...", work + work / 2));
            Envelope filteredEnvelope = constraints.getFilteredEnvelope();
            Polygon polygon = GeometryUtilities.createPolygonFromEnvelope(filteredEnvelope);
            polygon.setUserData("Overview for " + lasReader.getLasFile().getName());
            SimpleFeatureCollection fc = FeatureUtilities.featureCollectionFromGeometry(header.getCrs(), polygon);
            String f = outputFilePath;
            if (!f.toLowerCase().endsWith(".shp"))
                f = f + ".shp";
            OmsVectorWriter.writeVector(f, fc);
            done();
        }
    }.execute();
}
 
Example #2
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGetFeaturesWithORLogicFilter() throws Exception {
    init();
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyIsEqualTo property1 = ff.equals(ff.property("vendor_s"), ff.literal("D-Link"));
    PropertyIsEqualTo property2 = ff.equals(ff.property("vendor_s"), ff.literal("Linksys"));
    Or filter = ff.or(property1, property2);
    SimpleFeatureCollection features = featureSource.getFeatures(filter);
    assertEquals(6, features.size());
    SimpleFeatureIterator iterator = features.features();
    while (iterator.hasNext()) {
        SimpleFeature f = iterator.next();
        assertTrue(f.getAttribute("vendor_s").equals("D-Link")
                || f.getAttribute("vendor_s").equals("Linksys"));
    }
}
 
Example #3
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGeoShapeAsWkt() throws Exception {
    if (client.getVersion() < 6.2) {
        // wkt unsupported prior to v6.2
        return;
    }
    init("not-active","geo6");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    LineString ls = gf.createLineString(sf.create(new double[] { 0, 0, 2, 2 }, 2));
    Crosses f = ff.crosses(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.12");

    sf = new PackedCoordinateSequenceFactory();
    ls = gf.createLineString(sf.create(new double[] { 0, 0, 1, 1 }, 2));
    f = ff.crosses(ff.property("geo5"), ff.literal(ls));
    features = featureSource.getFeatures(f);
    assertEquals(0, features.size());
}
 
Example #4
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testOgrStyleGeoPoint() throws Exception {
    init("not-active","geo4.coordinates");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    BBOX bbox = ff.bbox("geo4.coordinates", 0, 0, 5, 5, "EPSG:4326");
    assertNotNull(featureSource.getSchema().getDescriptor("geo4.coordinates"));
    assertNull(featureSource.getSchema().getDescriptor("geo4.type"));

    SimpleFeatureCollection features = featureSource.getFeatures(bbox);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    SimpleFeature feature = fsi.next();
    assertEquals(feature.getID(), "active.13");
    assertNotNull(feature.getDefaultGeometry());
}
 
Example #5
Source File: StyleGenerator.java    From constellation with Apache License 2.0 6 votes vote down vote up
public static Style createStyle(final SimpleFeatureCollection features) {
    if (features.size() == 0) {
        LOGGER.warning("No features available to generate style");
        return null;
    }

    final Class<?> geometryType = features.getSchema().getGeometryDescriptor().getType().getBinding();
    if (Polygon.class.isAssignableFrom(geometryType)
            || MultiPolygon.class.isAssignableFrom(geometryType)) {
        return createPolygonStyle();
    } else if (LineString.class.isAssignableFrom(geometryType)) {
        return createLineStyle();
    } else if (Point.class.isAssignableFrom(geometryType)) {
        return createPointStyle();
    } else {
        LOGGER.log(Level.WARNING, "Style cannot be generated from type: {0}", geometryType);
        return null;
    }
}
 
Example #6
Source File: TestVectorReshaper.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public void testBuffer() throws Exception {
    String cql = "the_geom=buffer(the_geom, 20.0)";

    SimpleFeatureCollection testFC = HMTestMaps.getTestFC();
    OmsVectorReshaper reshaper = new OmsVectorReshaper();
    reshaper.inVector = testFC;
    reshaper.pCql = cql;
    reshaper.process();
    SimpleFeatureCollection outFC = reshaper.outVector;
    FeatureIterator<SimpleFeature> featureIterator = outFC.features();
    SimpleFeature feature = featureIterator.next();
    Geometry geometry = (Geometry) feature.getDefaultGeometry();
    String geometryType = geometry.getGeometryType();
    assertTrue(geometryType.toUpperCase().equals("POLYGON"));
    featureIterator.close();
}
 
Example #7
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testReadStringArrayWithCsvStrategy() throws Exception {
    init();
    dataStore.setArrayEncoding(ArrayEncoding.CSV);
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyIsEqualTo filter = ff.equals(ff.property("modem_b"), ff.literal(true));

    SimpleFeatureCollection features = featureSource.getFeatures(filter);
    assertEquals(8, features.size());

    try (SimpleFeatureIterator iterator = features.features()) {
        assertTrue(iterator.hasNext());
        SimpleFeature feature = iterator.next();
        String st = (String) feature.getAttribute("standard_ss");
        // changed from "IEEE 802.11b" in SolrFeatureSourceTest
        assertTrue(URLDecoder.decode(st, StandardCharsets.UTF_8.toString()).startsWith("IEEE 802.11"));
    }
}
 
Example #8
Source File: TestVectorReshaper.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("nls")
public void testFeatureReshaper() throws Exception {

    SimpleFeatureCollection testFC = HMTestMaps.getTestFC();

    OmsVectorReshaper reshaper = new OmsVectorReshaper();
    reshaper.inVector = testFC;
    reshaper.pCql = "newcat=cat*2 \n newcat2=cat*4";
    reshaper.process();
    SimpleFeatureCollection outFC = reshaper.outVector;

    FeatureIterator<SimpleFeature> featureIterator = outFC.features();
    SimpleFeature feature = featureIterator.next();
    assertNotNull(feature);

    Integer attribute = (Integer) feature.getAttribute("cat");
    Double newAttribute = (Double) feature.getAttribute("newcat");
    Double newAttribute2 = (Double) feature.getAttribute("newcat2");
    assertEquals(attribute.intValue() * 2, newAttribute.intValue());
    assertEquals(attribute.intValue() * 4, newAttribute2.intValue());
    featureIterator.close();

}
 
Example #9
Source File: DwgReader.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public Map<String, SimpleFeatureCollection> getFeatureCollectionsMap() throws IOException {
    Map<String, SimpleFeatureCollection> map = new HashMap<>();
    if (!textFeatures.isEmpty()) {
        map.put("text", textFeatures);
    }
    if (!attributesFeatures.isEmpty()) {
        map.put("text", attributesFeatures);
    }
    if (!multiLineFeatures.isEmpty()) {
        map.put(LINES, multiLineFeatures);
    }
    if (!contourFeatures.isEmpty()) {
        map.put(LINES, contourFeatures);
    }
    if (!multiPointFeatures.isEmpty()) {
        map.put("points", multiPointFeatures);
    }
    if (!multiPolygonFeatures.isEmpty()) {
        map.put("polygons", multiPolygonFeatures);
    }
    return map;
}
 
Example #10
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testWithinFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Polygon ls = gf.createPolygon(sf.create(new double[] { 0, 0, 0, 6, 6, 6, 6, 0, 0, 0 }, 2));
    Within f = ff.within(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.12");
}
 
Example #11
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetFeaturesWithNOTLogicFilter() throws Exception {
    init();
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyIsEqualTo property1 = ff.equals(ff.property("vendor_s"), ff.literal("D-Link"));
    Not filter = ff.not(property1);
    SimpleFeatureCollection features = featureSource.getFeatures(filter);
    assertEquals(7, features.size());
    SimpleFeatureIterator iterator = features.features();
    while (iterator.hasNext()) {
        SimpleFeature f = iterator.next();
        assertTrue(!f.getAttribute("vendor_s").equals("D-Link"));
    }
}
 
Example #12
Source File: NwwUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the geometry type from a featurecollection.
 * 
 * @param featureCollection
 *            the collection.
 * @return the {@link GEOMTYPE}.
 */
public static GEOMTYPE getGeometryType( SimpleFeatureCollection featureCollection ) {
    GeometryDescriptor geometryDescriptor = featureCollection.getSchema().getGeometryDescriptor();
    if (EGeometryType.isPolygon(geometryDescriptor)) {
        return GEOMTYPE.POLYGON;
    } else if (EGeometryType.isLine(geometryDescriptor)) {
        return GEOMTYPE.LINE;
    } else if (EGeometryType.isPoint(geometryDescriptor)) {
        return GEOMTYPE.POINT;
    } else {
        return GEOMTYPE.UNKNOWN;
    }
}
 
Example #13
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetFeaturesWithIsBetweenFilterOnNestedType() throws Exception {
    init();
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyIsBetween f = ff.between(ff.property("nested.hej"), ff.literal(5), ff.literal(15));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(10, features.size());
}
 
Example #14
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetFeaturesWithIsGreaterThanOrEqualToFilter() throws Exception {
    init();
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyIsGreaterThanOrEqualTo f = ff.greaterOrEqual(ff.property("speed_is"),
            ff.literal(300));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(5, features.size());
}
 
Example #15
Source File: TestVectorTableJoiner.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void testVectorTableJoiner() throws Exception {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("test");
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", Point.class);
        b.add("id", Integer.class);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Point point = GeometryUtilities.gf().createPoint(new Coordinate(0, 0));
        Object[] values = new Object[]{point, 1};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0");
        newCollection.add(feature);

        HashMap<String, List<Object>> tabledata = new HashMap<String, List<Object>>();
        List<Object> id = Arrays.asList(new Object[]{1});
        tabledata.put("id", id);
        List<Object> area = Arrays.asList(new Object[]{123.45});
        tabledata.put("area", area);
        List<Object> area2 = Arrays.asList(new Object[]{67.89});
        tabledata.put("area2", area2);

        OmsVectorTableJoiner joiner = new OmsVectorTableJoiner();
        joiner.inVector = newCollection;
        joiner.tabledata = tabledata;
        joiner.fCommon = "id";
        joiner.pFields = "area";
        joiner.process();
        SimpleFeatureCollection outFeatures = joiner.outVector;

        SimpleFeature f = FeatureUtilities.featureCollectionToList(outFeatures).get(0);
        String areaStr = f.getAttribute("area").toString();

        assertTrue(areaStr.equals("123.45"));
    }
 
Example #16
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetFeaturesWithIsLikeFilter() throws Exception {
    init();
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyIsLike f = ff.like(ff.property("standard_ss"), "IEEE 802.11?");
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(11, features.size());
}
 
Example #17
Source File: TestVectorFieldRounder.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void testVectorFieldRounder() throws Exception {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("test");
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", Point.class);
        b.add("area", Double.class);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Point point = GeometryUtilities.gf().createPoint(new Coordinate(0, 0));
        Object[] values = new Object[]{point, 123.456789};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0");
        newCollection.add(feature);

        OmsVectorFieldRounder rounder = new OmsVectorFieldRounder();
        rounder.inVector = newCollection;
        rounder.fRound = "area";
        rounder.pPattern = ".##";
        rounder.process();
        SimpleFeatureCollection outFeatures = rounder.outVector;

        SimpleFeature f = FeatureUtilities.featureCollectionToList(outFeatures).get(0);
        String areaStr = f.getAttribute("area").toString();

        assertTrue(areaStr.equals("123.46"));
    }
 
Example #18
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetFeaturesWithIsNullFilter() throws Exception {
    init();
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyIsNull f = ff.isNull(ff.property("security_ss"));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
}
 
Example #19
Source File: TestLineSmootherJaitools.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void testVectorReader() throws Exception {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("test");
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", LineString.class);
        b.add("id", Integer.class);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        SimpleFeatureType type = b.buildFeatureType();

        Geometry line = new WKTReader().read("LINESTRING (0 0, 1 1, 2 0)");//2 2, 3 3, 4 4, 5 3, 6 2, 7 1, 8 0)");
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Object[] values = new Object[]{line, 0};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0");
        newCollection.add(feature);

        OmsLineSmootherJaitools smoother = new OmsLineSmootherJaitools();
        smoother.inVector = newCollection;
        smoother.pAlpha = 1;
        smoother.process();
        SimpleFeatureCollection outFeatures = smoother.outVector;

        List<Geometry> geomList = FeatureUtilities.featureCollectionToGeometriesList(outFeatures, false, null);
        Geometry geometry = geomList.get(0);
        
        int newLength = geometry.getCoordinates().length;

        Geometry densifiedline = new WKTReader()
                .read("LINESTRING (0 0, 0.0342935528120713 0.0342935528120713, 0.1262002743484225 0.1262002743484225, 0.2592592592592592 0.2592592592592592, 0.4170096021947873 0.4170096021947873, 0.5829903978052127 0.5829903978052127, 0.7407407407407407 0.7407407407407407, 0.8737997256515775 0.8737997256515775, 0.9657064471879286 0.9657064471879286, 1 1, 1.0342935528120714 0.9657064471879288, 1.1262002743484225 0.8737997256515775, 1.2592592592592593 0.7407407407407408, 1.4170096021947873 0.5829903978052127, 1.5829903978052127 0.4170096021947874, 1.7407407407407407 0.2592592592592593, 1.8737997256515775 0.1262002743484225, 1.9657064471879289 0.0342935528120714, 2 0)");
        int expectedLength = densifiedline.getCoordinates().length;

        assertEquals(expectedLength, newLength);

    }
 
Example #20
Source File: ElasticTemporalFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAfterInterval() throws Exception {
    init();
    Period period = period("2011-21-05 00:00:00", "2011-15-09 00:00:00");
    FilterFactory ff = dataStore.getFilterFactory();
    Filter f = ff.after(ff.property("installed_tdt"), ff.literal(period));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(4, features.size());
}
 
Example #21
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBBOXCoveringDateline() throws Exception {
    init("not-active","geo");
    FilterFactory ff = dataStore.getFilterFactory();
    BBOX bbox = ff.bbox("geo", 178, -90, 182, 90, "EPSG:" + SOURCE_SRID);
    SimpleFeatureCollection features = featureSource.getFeatures(bbox);
    assertEquals(2, features.size());
}
 
Example #22
Source File: InternalDistributedRenderProcess.java    From geowave with Apache License 2.0 5 votes vote down vote up
@DescribeResult(
    name = "result",
    description = "This is just a pass-through, the key is to provide enough information within invertQuery to perform a map to screen transform")
public GridCoverage2D execute(
    @DescribeParameter(
        name = "data",
        description = "Feature collection containing the rendered image") final SimpleFeatureCollection features)
    throws ProcessException {
  // vector-to-raster render transform that take a single feature that
  // wraps a distributed render result and converts it to a GridCoverage2D
  if (features != null) {
    final SimpleFeatureIterator it = features.features();
    if (it.hasNext()) {
      final SimpleFeature resultFeature = features.features().next();
      final DistributedRenderResult actualResult =
          (DistributedRenderResult) resultFeature.getAttribute(0);
      final DistributedRenderOptions renderOptions =
          (DistributedRenderOptions) resultFeature.getAttribute(1);
      // convert to the GridCoverage2D required for output
      final GridCoverageFactory gcf =
          CoverageFactoryFinder.getGridCoverageFactory(GeoTools.getDefaultHints());
      final BufferedImage result = actualResult.renderComposite(renderOptions);
      final GridCoverage2D gridCov =
          gcf.create("Process Results", result, renderOptions.getEnvelope());
      return gridCov;
    }
  }
  return null;
}
 
Example #23
Source File: OmsShapefileFeatureReader.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fast read access mode. 
 * 
 * @param path the shapefile path.
 * @return the read {@link FeatureCollection}.
 * @throws IOException
 */
public static SimpleFeatureCollection readShapefile( String path ) throws IOException {

    OmsShapefileFeatureReader reader = new OmsShapefileFeatureReader();
    reader.file = path;
    reader.readFeatureCollection();

    return reader.geodata;
}
 
Example #24
Source File: OmsKriging.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extract the coordinate of a FeatureCollection in a HashMap with an ID as
 * a key.
 * 
 * @param nStaz
 * @param collection
 * @throws Exception
 *             if a fiel of elevation isn't the same of the collection
 */
private LinkedHashMap<Integer, Coordinate> getCoordinate( int nStaz, SimpleFeatureCollection collection, String idField )
        throws Exception {
    LinkedHashMap<Integer, Coordinate> id2CoordinatesMap = new LinkedHashMap<Integer, Coordinate>();
    FeatureIterator<SimpleFeature> iterator = collection.features();
    Coordinate coordinate = null;
    try {
        while( iterator.hasNext() ) {
            SimpleFeature feature = iterator.next();
            int name = ((Number) feature.getAttribute(idField)).intValue();
            coordinate = ((Geometry) feature.getDefaultGeometry()).getCentroid().getCoordinate();
            double z = 0;
            if (fPointZ != null) {
                try {
                    z = ((Number) feature.getAttribute(fPointZ)).doubleValue();
                } catch (NullPointerException e) {
                    pm.errorMessage(msg.message("kriging.noPointZ"));
                    throw new Exception(msg.message("kriging.noPointZ"));
                }
            }
            coordinate.z = z;
            id2CoordinatesMap.put(name, coordinate);
        }
    } finally {
        iterator.close();
    }

    return id2CoordinatesMap;
}
 
Example #25
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testContainsFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Polygon ls = gf.createPolygon(sf.create(new double[] { 2, 2, 3, 2, 3, 3, 2, 3, 2, 2 }, 2));
    Contains f = ff.contains(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.12");
}
 
Example #26
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetFeaturesWithIsGreaterThanFilterOnNestedType() throws Exception {
    init();
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyIsGreaterThan f = ff.greater(ff.property("nested.hej"), ff.literal(10));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(8, features.size());
}
 
Example #27
Source File: ExportGeometryAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
static void writeEsriShapefile(Class<?> geomType, List<SimpleFeature> features, File file) throws IOException {
    String geomName = geomType.getSimpleName();
    String basename = file.getName();
    if (basename.endsWith(FILE_EXTENSION_SHAPEFILE)) {
        basename = basename.substring(0, basename.length() - 4);
    }
    File file1 = new File(file.getParentFile(), basename + "_" + geomName + FILE_EXTENSION_SHAPEFILE);

    SimpleFeature simpleFeature = features.get(0);
    SimpleFeatureType simpleFeatureType = changeGeometryType(simpleFeature.getType(), geomType);

    ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
    Map<String, Serializable> map = Collections.singletonMap("url", file1.toURI().toURL());
    ShapefileDataStore dataStore = (ShapefileDataStore) factory.createNewDataStore(map);
    dataStore.createSchema(simpleFeatureType);
    String typeName = dataStore.getTypeNames()[0];
    SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
    DefaultTransaction transaction = new DefaultTransaction("X");
    if (featureSource instanceof SimpleFeatureStore) {
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        SimpleFeatureCollection collection = new ListFeatureCollection(simpleFeatureType, features);
        featureStore.setTransaction(transaction);
        // I'm not sure why the next line is necessary (mp/20170627)
        // Without it is not working, the wrong feature type is used for writing
        // But it is not mentioned in the tutorials
        dataStore.getEntry(featureSource.getName()).getState(transaction).setFeatureType(simpleFeatureType);
        try {
            featureStore.addFeatures(collection);
            transaction.commit();
        } catch (Exception problem) {
            transaction.rollback();
            throw new IOException(problem);
        } finally {
            transaction.close();
        }
    } else {
        throw new IOException(typeName + " does not support read/write access");
    }
}
 
Example #28
Source File: TestVectorizer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void testVectorizer1() throws Exception {

        double[][] inData = HMTestMaps.extractNet0Data;
        HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams();
        CoordinateReferenceSystem crs = HMTestMaps.getCrs();
        GridCoverage2D inCoverage = CoverageUtilities.buildCoverage("data", inData, envelopeParams, crs, true);

        OmsVectorizer vectorizer = new OmsVectorizer();
        vectorizer.pm = pm;
        vectorizer.inRaster = inCoverage;
        vectorizer.pValue = 2.0;
        vectorizer.pThres = 1;
        vectorizer.fDefault = "rast";
        vectorizer.process();

        SimpleFeatureCollection outGeodata = vectorizer.outVector;
        assertEquals(2, outGeodata.size());

        List<SimpleFeature> features = FeatureUtilities.featureCollectionToList(outGeodata);
        SimpleFeature f1 = features.get(0);
        SimpleFeature f2 = features.get(1);
        Geometry g1 = (Geometry) f1.getDefaultGeometry();
        Geometry g2 = (Geometry) f2.getDefaultGeometry();

        // SimpleFeature nvFeature = f1;
        SimpleFeature valuesFeature = f2;
        if (g1.getArea() < g2.getArea()) {
            // nvFeature = f2;
            valuesFeature = f1;
        }

        double value = ((Number) valuesFeature.getAttribute("rast")).doubleValue();
        assertEquals(2.0, value, 0.0000001);
        Geometry geometry = (Geometry) valuesFeature.getDefaultGeometry();
        double area = geometry.getArea();
        assertEquals(6300.0, area, 0.0000001);
    }
 
Example #29
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testNotCrossesFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    LineString ls = gf.createLineString(sf.create(new double[] { 0, 0, 1, 1 }, 2));
    Crosses f = ff.crosses(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(0, features.size());
}
 
Example #30
Source File: OmsNmeaFeatureReader.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fast read access mode. 
 * 
 * @param path the NMEA file path.
 * @return the read {@link FeatureCollection}.
 * @throws IOException
 */
public static SimpleFeatureCollection readNMEAfile( String path ) throws IOException {

    OmsNmeaFeatureReader reader = new OmsNmeaFeatureReader();
    reader.file = path;
    reader.readFeatureCollection();

    return reader.geodata;
}