Package org.geotools.feature

Examples of org.geotools.feature.DefaultFeatureCollection


        if (isGeometryCollection(diffSource.getSchema().getGeometryDescriptor())) {
            MessageDialog.openError(display.getActiveShell(), Messages.differenceOp_inputError, fromLayer.getName() + Messages.differenceOp_multiGeoms);
            return;
        }
       
        final DefaultFeatureCollection diffFeatures = new DefaultFeatureCollection();
        diffFeatures.addAll(diffSource.getFeatures());
       
        FeatureStore<SimpleFeatureType, SimpleFeature> destStore = (FeatureStore<SimpleFeatureType, SimpleFeature>)ds.getFeatureSource("diff"); //$NON-NLS-1$
       
        // TODO: figure out whatever this FeatureReader is doing; and make it a feature collection instead
        destStore.addFeatures(DataUtilities.collection(new FeatureReader<SimpleFeatureType, SimpleFeature>(){
        // TODO this needs an undo
//        ((FeatureStore<SimpleFeatureType, SimpleFeature>)fromSource).setFeatures(new FeatureReader() {
          FeatureCollection<SimpleFeatureType, SimpleFeature> coll = fromSource.getFeatures();
            FeatureIterator<SimpleFeature> iter = coll.features();
            FeatureIterator<SimpleFeature> peek = coll.features();
            boolean hasNextCalled = false;
           
            public SimpleFeatureType getFeatureType() {
                return newSchema;
            }
           
            private Geometry diff(SimpleFeature f) {
                Geometry geom = (Geometry) f.getDefaultGeometry();
                FeatureIterator<SimpleFeature> i = diffFeatures.features();
                try {
                    while (i.hasNext()) {
                        SimpleFeature diff = i.next();
                        Geometry g = geom.difference((Geometry) diff.getDefaultGeometry());
                        if (g.isEmpty()) {
View Full Code Here


            b.add(fieldName, String.class);
        }
        SimpleFeatureType featureType = b.buildFeatureType();
        MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mapCrs);
        pm.beginTask("Import notes...", IProgressMonitor.UNKNOWN);
        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();

        Statement statement = null;
        try {
            statement = connection.createStatement();
            statement.setQueryTimeout(30); // set timeout to 30 sec.

            ResultSet rs = statement.executeQuery("select lat, lon, altim, ts, text from notes");
            int i = 0;
            while( rs.next() ) {

                double lat = rs.getDouble("lat");
                double lon = rs.getDouble("lon");
                double altim = rs.getDouble("altim");
                String dateTimeString = rs.getString("ts");
                String text = rs.getString("text");

                if (lat == 0 || lon == 0) {
                    continue;
                }

                // and then create the features
                Coordinate c = new Coordinate(lon, lat);
                Point point = gF.createPoint(c);
                Geometry reprojectPoint = JTS.transform(point, transform);

                SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
                Object[] values = new Object[]{reprojectPoint, text, dateTimeString, String.valueOf(altim)};
                builder.addAll(values);
                SimpleFeature feature = builder.buildFeature(featureType.getTypeName() + "." + i++);
                newCollection.add(feature);
                pm.worked(1);
            }
        } finally {
            pm.done();
            if (statement != null)
View Full Code Here

        SimpleFeatureType featureType = b.buildFeatureType();

        try {
            MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mapCrs);
            pm.beginTask("Import gps to lines...", logsList.size());
            DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
            int index = 0;
            for( GpsLog log : logsList ) {
                List<GpsPoint> points = log.points;

                List<Coordinate> coordList = new ArrayList<Coordinate>();
                String startDate = log.startTime;
                String endDate = log.endTime;
                for( GpsPoint gpsPoint : points ) {
                    Coordinate c = new Coordinate(gpsPoint.lon, gpsPoint.lat);
                    coordList.add(c);
                }
                Coordinate[] coordArray = (Coordinate[]) coordList.toArray(new Coordinate[coordList.size()]);
                if (coordArray.length < 2) {
                    continue;
                }
                LineString lineString = gF.createLineString(coordArray);
                LineString reprojectLineString = (LineString) JTS.transform(lineString, transform);
                MultiLineString multiLineString = gF.createMultiLineString(new LineString[]{reprojectLineString});

                SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
                Object[] values = new Object[]{multiLineString, startDate, endDate, log.text};
                builder.addAll(values);
                SimpleFeature feature = builder.buildFeature(featureType.getTypeName() + "." + index++);

                newCollection.add(feature);
                pm.worked(1);
            }
            pm.done();

            ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
            Map<String, Serializable> params = new HashMap<String, Serializable>();
            params.put("url", outputLinesShapeFile.toURI().toURL());
            params.put("create spatial index", Boolean.TRUE);
            ShapefileDataStore dStore = (ShapefileDataStore) factory.createNewDataStore(params);
            dStore.createSchema(featureType);
            dStore.forceSchemaCRS(mapCrs);

            JGrassToolsPlugin.getDefault().writeToShapefile(dStore, newCollection);

            JGrassToolsPlugin.getDefault().addServiceToCatalogAndMap(outputLinesShapeFile.getAbsolutePath(), true, true,
                    new NullProgressMonitor());

        } catch (Exception e1) {
            JGrassToolsPlugin.log(e1.getLocalizedMessage(), e1);
            e1.printStackTrace();
        }
        /*
         * create the points shapefile
         */

        File outputPointsShapeFile = new File(outputFolderFile, "gpspoints.shp");

        b = new SimpleFeatureTypeBuilder();
        b.setName("geopaparazzinotes");
        b.setCRS(mapCrs);
        b.add("the_geom", Point.class);
        b.add("ALTIMETRY", String.class);
        b.add("DATE", String.class);
        featureType = b.buildFeatureType();

        try {
            MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mapCrs);

            pm.beginTask("Import gps to points...", logsList.size());
            DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
            int index = 0;
            for( GpsLog log : logsList ) {
                List<GpsPoint> gpsPointList = log.points;
                for( GpsPoint gpsPoint : gpsPointList ) {
                    Coordinate c = new Coordinate(gpsPoint.lon, gpsPoint.lat);
                    Point point = gF.createPoint(c);

                    Point reprojectPoint = (Point) JTS.transform(point, transform);
                    Object[] values = new Object[]{reprojectPoint, String.valueOf(gpsPoint.altim), gpsPoint.utctime};

                    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
                    builder.addAll(values);
                    SimpleFeature feature = builder.buildFeature(featureType.getTypeName() + "." + index++);
                    newCollection.add(feature);
                }
                pm.worked(1);
            }
            pm.done();

View Full Code Here

            b.add("IMAGE", String.class);
            SimpleFeatureType featureType = b.buildFeatureType();

            MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mapCrs);

            DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
            for( File imageFile : listFiles ) {
                String name = imageFile.getName();
                if (name.endsWith("jpg") || imageFile.getName().endsWith("JPG") || imageFile.getName().endsWith("png")
                        || imageFile.getName().endsWith("PNG") || imageFile.getName().endsWith("3gp")) {

                    String[] nameSplit = name.split("[_\\|.]"); //$NON-NLS-1$
                    String dateString = nameSplit[1];
                    String timeString = nameSplit[2];

                    Properties locationProperties = new Properties();
                    String mediaPath = imageFile.getAbsolutePath();
                    int lastDot = mediaPath.lastIndexOf("."); //$NON-NLS-1$
                    String nameNoExt = mediaPath.substring(0, lastDot);
                    String infoPath = nameNoExt + ".properties"; //$NON-NLS-1$
                    File infoFile = new File(infoPath);
                    if (!infoFile.exists()) {
                        nonTakenFilesList.add(mediaPath);
                        continue;
                    }
                    locationProperties.load(new FileInputStream(infoFile));
                    String azimuthString = locationProperties.getProperty("azimuth"); //$NON-NLS-1$
                    String latString = locationProperties.getProperty("latitude"); //$NON-NLS-1$
                    String lonString = locationProperties.getProperty("longitude"); //$NON-NLS-1$
                    String altimString = locationProperties.getProperty("altim"); //$NON-NLS-1$

                    Double azimuth = -9999.0;
                    if (azimuthString != null)
                        azimuth = Double.parseDouble(azimuthString);
                    double lat = 0.0;
                    double lon = 0.0;
                    if (latString.contains("/")) {
                        // this is an exif string
                        lat = exifFormat2degreeDecimal(latString);
                        lon = exifFormat2degreeDecimal(lonString);
                    } else {
                        lat = Double.parseDouble(latString);
                        lon = Double.parseDouble(lonString);
                    }
                    double altim = Double.parseDouble(altimString);

                    Coordinate c = new Coordinate(lon, lat);
                    Point point = gF.createPoint(c);

                    String imageRelativePath = imageFolderName + "/" + imageFile.getName();
                    File newImageFile = new File(outputFolderFile, imageRelativePath);
                    FileUtils.copyFile(imageFile, newImageFile);

                    Point reprojectPoint = (Point) JTS.transform(point, transform);
                    String dateTime = dateString + timeString;
                    Object[] values = new Object[]{reprojectPoint, String.valueOf(altim), dateTime, azimuth, imageRelativePath};

                    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
                    builder.addAll(values);
                    SimpleFeature feature = builder.buildFeature(null);
                    newCollection.add(feature);
                }
                pm.worked(1);
            }

            ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
View Full Code Here

    /**
     * Removes the selected features (the features selected by the owning {@link FeatureTableControl}).
     * @return returns a collection of the deleted features
     */
    public FeatureCollection<SimpleFeatureType, SimpleFeature> deleteSelection() {
        final DefaultFeatureCollection deletedFeatures = new DefaultFeatureCollection();
        Runnable updateTable = new Runnable(){
            @SuppressWarnings("unchecked")
            public void run() {
                Collection<String> selectionFids = owningFeatureTableControl.getSelectionProvider().getSelectionFids();
               
                for( Iterator<SimpleFeature> iter = features.iterator(); iter.hasNext(); ) {
                    SimpleFeature feature =  iter.next();
                    if( selectionFids.contains(feature.getID()) ){
                        deletedFeatures.add(feature);
                        iter.remove();
                        lookup.remove(feature.getID());
                    }
                }
               
View Full Code Here

        b.setName( "Test" );
        b.add( "location", Polygon.class );
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeature donutFeature = SimpleFeatureBuilder.build(type, new Object[]{donut}, "fid.1");
        SimpleFeature holeFeature = SimpleFeatureBuilder.build(type, new Object[]{hole}, "fid.2");
        DefaultFeatureCollection fc = new DefaultFeatureCollection();
        fc.add(donutFeature);
        fc.add(holeFeature);
       
        //create iterator for collection
        FeatureIterator<SimpleFeature> iterator = fc.features();
       
        //create List<Geometry> for the simulated "drawn" shape
        Polygon userDrawnPoly = (Polygon) reader.read("POLYGON ((114 90, 130 90, 130 130, 114 130, 114 90))");
        List<Geometry> geoms = new ArrayList<Geometry>();
        geoms.add(userDrawnPoly);
View Full Code Here

        InputStream in = url.openConnection().getInputStream();
       
        InputStreamReader filereader=new InputStreamReader(in);
       
        InputSource input = new InputSource(filereader);
        DefaultFeatureCollection collection = new DefaultFeatureCollection();
        GMLReceiver receiver=new GMLReceiver(collection);
        GMLFilterFeature filterFeature = new GMLFilterFeature(receiver);
        GMLFilterGeometry filterGeometry = new GMLFilterGeometry(filterFeature);
        GMLFilterDocument filterDocument = new GMLFilterDocument(filterGeometry);
        try {
            // parse xml
            XMLReader reader = XMLReaderFactory.createXMLReader();
            reader.setContentHandler(filterDocument);
            reader.parse(input);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        SimpleFeature feature=collection.features().next();
        ReferencedEnvelope bounds = new ReferencedEnvelope(feature.getBounds());
        bounds=new ReferencedEnvelope( bounds.getMinX()-(bounds.getWidth()/8),
                bounds.getMaxX()+(bounds.getWidth()/8),
                bounds.getMinY()-(bounds.getHeight()/4),
                bounds.getMaxY()+(bounds.getHeight()/4), DefaultGeographicCRS.WGS84 );
View Full Code Here

                                b.setCRS(DefaultGeographicCRS.WGS84);
                                b.add("the_geom", MultiPoint.class);
                                b.add("name", String.class);
                                SimpleFeatureType type = b.buildFeatureType();

                                DefaultFeatureCollection newCollection = new DefaultFeatureCollection();

                                int size = keySet.size();

                                pm.beginTask("Converting geometries of places...", size);
                                int id = 0;
                                for( String name : keySet ) {
                                    Coordinate coordinate = placesMap.get(name);
                                    MultiPoint point = gF.createMultiPoint(new Coordinate[]{coordinate});
                                    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
                                    Object[] values = new Object[]{point, name};
                                    builder.addAll(values);
                                    SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + id);
                                    id++;
                                    newCollection.add(feature);
                                    pm.worked(1);
                                }
                                pm.done();

                                IGeoResource resource = CatalogPlugin.getDefault().getLocalCatalog()
View Full Code Here

                b.add(fieldName, class1);
            }
        }
        SimpleFeatureType featureType = b.buildFeatureType();

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        Collection<Integer> orderedTypeIndexes = fieldsAndTypesIndex.values();
        Integer[] orderedTypeIndexesArray = (Integer[]) orderedTypeIndexes.toArray(new Integer[orderedTypeIndexes.size()]);

        BufferedReader bR = null;
        try {
            bR = new BufferedReader(new FileReader(csvFile));
            String line = null;
            int featureId = 0;
            pm.beginTask("Importing raw data", -1);
            while( (line = bR.readLine()) != null ) {
                pm.worked(1);
                line = line.trim();
                if (line.length() == 0) {
                    continue;
                }
                if (line.startsWith("#")) {
                    continue;
                }

                SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
                Object[] values = new Object[fieldNames.size() - 1];

                String[] lineSplit = line.split(separator);
                double x = Double.parseDouble(lineSplit[xIndex]);
                double y = Double.parseDouble(lineSplit[yIndex]);
                Point point = gf.createPoint(new Coordinate(x, y));
                values[0] = point;

                int objIndex = 1;
                for( int i = 0; i < lineSplit.length; i++ ) {
                    if (i == xIndex || i == yIndex) {
                        continue;
                    }

                    String value = lineSplit[i];
                    int typeIndex = orderedTypeIndexesArray[i];
                    String typeName = typesArray[typeIndex];
                    if (typeName.equals(typesArray[3])) {
                        values[objIndex] = value;
                    } else if (typeName.equals(typesArray[4])) {
                        values[objIndex] = new Double(value);
                    } else if (typeName.equals(typesArray[5])) {
                        values[objIndex] = new Integer(value);
                    } else {
                        throw new IllegalArgumentException("An undefined value type was found");
                    }
                    objIndex++;
                }
                builder.addAll(values);

                SimpleFeature feature = builder.buildFeature(featureType.getTypeName() + "." + featureId);
                featureId++;
                newCollection.add(feature);
            }
        } finally {
            if (bR != null)
                bR.close();
            pm.done();
View Full Code Here

            if (isAbstractGeometryType(schema)) {
                // possibly multiple geometry types
                String geomName = schema.getGeometryDescriptor().getName().getLocalPart();

                DefaultFeatureCollection pointCollection = new DefaultFeatureCollection();
                DefaultFeatureCollection lineCollection = new DefaultFeatureCollection();
                DefaultFeatureCollection polygonCollection = new DefaultFeatureCollection();

                SimpleFeatureCollection featureCollection = fs.getFeatures();
                FeatureIterator<SimpleFeature> featureIterator = featureCollection.features();
                while( featureIterator.hasNext() ) {
                    SimpleFeature feature = featureIterator.next();
                    String geometryType = ((Geometry) feature.getDefaultGeometry())
                            .getGeometryType();

                    if (geometryType.endsWith("Point")) {
                        pointCollection.add(feature);
                    } else if (geometryType.endsWith("LineString")) {
                        lineCollection.add(feature);
                    } else if (geometryType.endsWith("Polygon")) {
                        polygonCollection.add(feature);
                    }
                }

                if (polygonCollection.size() > 0) {
                    exportPolygonFeatures(data, monitor, file, polygonCollection, schema, geomName,
                            mt);
                }
                if (pointCollection.size() > 0) {
                    exportPointFeatures(data, monitor, file, pointCollection, schema, geomName, mt);
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.