当前位置: 首页>>代码示例>>Java>>正文


Java ListFeatureCollection类代码示例

本文整理汇总了Java中org.geotools.data.collection.ListFeatureCollection的典型用法代码示例。如果您正苦于以下问题:Java ListFeatureCollection类的具体用法?Java ListFeatureCollection怎么用?Java ListFeatureCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ListFeatureCollection类属于org.geotools.data.collection包,在下文中一共展示了ListFeatureCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCorrectFeatureCollection

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
private SimpleFeatureCollection createCorrectFeatureCollection(FeatureCollection<?, ?> fc) {

        List<SimpleFeature> simpleFeatureList = new ArrayList<SimpleFeature>();
        SimpleFeatureType featureType = null;
        FeatureIterator<?> iterator = fc.features();
        String uuid = UUID.randomUUID().toString();
        int i = 0;
        while (iterator.hasNext()) {
            SimpleFeature feature = (SimpleFeature) iterator.next();

            //if (i == 0) {
                featureType = gtHelper.createFeatureType(feature.getProperties(), (Geometry) feature.getDefaultGeometry(), uuid, feature.getFeatureType().getCoordinateReferenceSystem());
                QName qname = gtHelper.createGML3SchemaForFeatureType(featureType);
                SchemaRepository.registerSchemaLocation(qname.getNamespaceURI(), qname.getLocalPart());
            //}
            SimpleFeature resultFeature = gtHelper.createFeature("ID" + i, (Geometry) feature.getDefaultGeometry(), featureType, feature.getProperties());

            simpleFeatureList.add(resultFeature);
            i++;
        }
        iterator.close();

        ListFeatureCollection resultFeatureCollection = new ListFeatureCollection(featureType, simpleFeatureList);
        return resultFeatureCollection;

    }
 
开发者ID:52North,项目名称:javaps-geotools-backend,代码行数:27,代码来源:GML3BasicGenerator.java

示例2: OSMInfo

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
public OSMInfo(final URL url, final long modificationStamp) {
	super(modificationStamp);
	CoordinateReferenceSystem crs = null;
	ReferencedEnvelope env2 = new ReferencedEnvelope();

	int number = 0;
	try {
		final File f = new File(url.toURI());
		final GamaOsmFile osmfile = new GamaOsmFile(null, f.getAbsolutePath());
		attributes.putAll(osmfile.getOSMAttributes(GAMA.getRuntimeScope()));

		final SimpleFeatureType TYPE = DataUtilities.createType("geometries", "geom:LineString");
		final ArrayList<SimpleFeature> list = new ArrayList<SimpleFeature>();
		for (final IShape shape : osmfile.iterable(null)) {
			list.add(SimpleFeatureBuilder.build(TYPE, new Object[] { shape.getInnerGeometry() }, null));
		}
		final SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, list);
		final SimpleFeatureSource featureSource = DataUtilities.source(collection);

		env2 = featureSource.getBounds();
		number = osmfile.nbObjects;
		crs = osmfile.getOwnCRS(null);
	} catch (final Exception e) {
		System.out.println("Error in reading metadata of " + url);
		hasFailed = true;

	} finally {

		// approximation of the width and height in meters.
		width = env2 != null ? env2.getWidth() * (FastMath.PI / 180) * 6378137 : 0;
		height = env2 != null ? env2.getHeight() * (FastMath.PI / 180) * 6378137 : 0;
		itemNumber = number;
		this.crs = crs;
	}

}
 
开发者ID:gama-platform,项目名称:gama,代码行数:37,代码来源:GamaOsmFile.java

示例3: addFeaturesExample

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
private void addFeaturesExample() throws Exception {
    // addExample start
    SimpleFeatureStore store = (SimpleFeatureStore) dataStore.getFeatureSource( typeName );
    
    SimpleFeatureType featureType = store.getSchema();
    
    SimpleFeatureBuilder build = new SimpleFeatureBuilder(featureType);
    GeometryBuilder geom = new GeometryBuilder();
    
    List<SimpleFeature> list = new ArrayList<SimpleFeature>();
    list.add( build.buildFeature("fid1", new Object[]{ geom.point(1,1), "hello" } ) );
    list.add( build.buildFeature("fid2", new Object[]{ geom.point(2,3), "martin" } ) );
    SimpleFeatureCollection collection = new ListFeatureCollection(featureType, list);

    Transaction transaction = new DefaultTransaction("Add Example");
    store.setTransaction( transaction );
    try {
        store.addFeatures( collection );
        transaction.commit(); // actually writes out the features in one go
    }
    catch( Exception eek){
        transaction.rollback();
    }
    // addExample end
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:26,代码来源:SimpleFeatureStoreExamples.java

示例4: write

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
public static <T> void write(File file,
        Consumer<SimpleFeatureTypeBuilder> fun1,
        BiConsumer<SimpleFeatureBuilder, T> fun2,
        List<T> geometries) {
    try {
        SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
        typeBuilder.setName("MyFeatureType");
        typeBuilder.setCRS(DefaultGeographicCRS.WGS84);
        fun1.accept(typeBuilder);
        SimpleFeatureType type = typeBuilder.buildFeatureType();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type);
        AtomicInteger id = new AtomicInteger(0);
        List<SimpleFeature> geoms = geometries.stream().map(g -> {
            fun2.accept(featureBuilder, g);
            return featureBuilder.buildFeature(String.valueOf(id.getAndIncrement()));
        }).collect(toList());
        ShapefileDataStoreFactory datastoreFactory = new ShapefileDataStoreFactory();
        Map<String, Serializable> params = newHashMap();
        params.put("url", file.toURI().toURL());
        params.put("create spatial index", Boolean.TRUE);
        ShapefileDataStore datastore = (ShapefileDataStore) datastoreFactory.createNewDataStore(params);
        datastore.createSchema(type);
        Transaction transaction = new DefaultTransaction("create");
        String typeName = datastore.getTypeNames()[0];
        SimpleFeatureSource featureSource = datastore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        SimpleFeatureCollection collection = new ListFeatureCollection(type, geoms);
        featureStore.setTransaction(transaction);
        featureStore.addFeatures(collection);
        transaction.commit();
        transaction.close();
        datastore.dispose();
    }
    catch (IOException e) {
        throw propagate(e);
    }
}
 
开发者ID:Mappy,项目名称:fpm,代码行数:38,代码来源:ShapefileWriter.java

示例5: write

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
@Override
public void write(Gpx gpx, String filename, GpxFile metadata) {
	if (metadata == null) {
		LOGGER.warn("Skipped because of missing metadata: " + filename);
	} else {
		for (int i = 0; i < gpx.getTrk().size(); i++) {
			Trk trk = gpx.getTrk().get(i);
			if (filter.check(trk)) {

				List<SimpleFeature> featureList = gpxToFeatureList(trk, metadata.getId(), i);
				SimpleFeatureCollection collection = new ListFeatureCollection(featureStore.getSchema(),
						featureList);
				/*
				 * Write the featurecollection to the shapefile
				 */
				try {

					featureStore.addFeatures(collection);

					// save features to file
					// transaction.commit();
				} catch (IOException e) {
					LOGGER.error("Error while writing to shapefile. Last transaction is beeing rolled back.");
					try {
						transaction.rollback();
					} catch (IOException e1) {
						LOGGER.error("Could not roll back transaction.");
						e1.printStackTrace();
					}
					e.printStackTrace();
				}
			}
		}
	}
}
 
开发者ID:GIScience,项目名称:osmgpxfilter,代码行数:36,代码来源:ShapeFileWriter.java

示例6: readTrack

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
static FeatureCollection<SimpleFeatureType, SimpleFeature> readTrack(Reader reader, GeoCoding geoCoding) throws IOException {
    CsvReader csvReader = new CsvReader(reader, new char[]{'\t', ' '}, true, "#");
    SimpleFeatureType trackFeatureType = createTrackFeatureType(geoCoding);
    ListFeatureCollection featureCollection = new ListFeatureCollection(trackFeatureType);
    double[] record;
    int pointIndex = 0;
    while ((record = csvReader.readDoubleRecord()) != null) {
        if (record.length < 3) {
            throw new IOException("Illegal track file format.\n" +
                                          "Expecting tab-separated lines containing 3 values: lat, lon, data.");
        }

        float lat = (float) record[0];
        float lon = (float) record[1];
        double data = record[2];

        final SimpleFeature feature = createFeature(trackFeatureType, geoCoding, pointIndex, lat, lon, data);
        if (feature != null) {
            featureCollection.add(feature);
        }

        pointIndex++;
    }

    if (featureCollection.isEmpty()) {
        throw new IOException("No track point found or all of them are located outside the scene boundaries.");
    }

    final CoordinateReferenceSystem mapCRS = geoCoding.getMapCRS();
    if (!mapCRS.equals(DefaultGeographicCRS.WGS84)) {
        try {
            transformFeatureCollection(featureCollection, mapCRS);
        } catch (TransformException e) {
            throw new IOException("Cannot transform the ship track onto CRS '" + mapCRS.toWKT() + "'.", e);
        }
    }

    return featureCollection;
}
 
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:40,代码来源:ImportTrackAction.java

示例7: writeEsriShapefile

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
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");
    }
}
 
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:40,代码来源:ExportGeometryAction.java

示例8: createVectorDataNode

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
private static VectorDataNode createVectorDataNode(FeatureStatisticsWriter featureStatisticsWriter,
                                                   VectorDataNode originalVDN) {
    final SimpleFeatureType updatedFeatureType = featureStatisticsWriter.getUpdatedFeatureType();
    final List<SimpleFeature> features = featureStatisticsWriter.getFeatures();
    final ListFeatureCollection featureCollection = new ListFeatureCollection(updatedFeatureType, features);
    final PlacemarkDescriptor placemarkDescriptor = originalVDN.getPlacemarkDescriptor();
    final VectorDataNode vectorDataNode = new VectorDataNode(originalVDN.getName(), featureCollection, placemarkDescriptor);
    vectorDataNode.setPermanent(originalVDN.isPermanent());
    vectorDataNode.setModified(true);
    vectorDataNode.setDescription(originalVDN.getDescription());
    return vectorDataNode;
}
 
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:13,代码来源:PutStatisticsIntoVectorDataAction.java

示例9: createTissotLayer

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
/**
 * A method to create Tissot Indicatrices based on Whuber's answer to
 * http://gis
 * .stackexchange.com/questions/5068/how-to-create-an-accurate-tissot
 * -indicatrix
 *
 * @param style
 *          - the style to draw the circles with
 * @param gridBounds
 *          - the bounds of the map (may be increased in the method)
 * @return a layer of Tissot Indicatrices (scaled for visibility).
 */
private Layer createTissotLayer(Style style, ReferencedEnvelope gridBounds) {
	FeatureType type = createFeatureType(null,
			gridBounds.getCoordinateReferenceSystem());
	SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(
			(SimpleFeatureType) type);
	double step = 20.0;
	GeometryFactory geomFac = new GeometryFactory();
	double width = gridBounds.getWidth();
	double height = gridBounds.getHeight();
	int id = 0;
	final ListFeatureCollection fc = new ListFeatureCollection(
			(SimpleFeatureType) type);
	double y = gridBounds.getMinY();

	for (int iy = 0; iy < (height / step); iy++) {
		double x = gridBounds.getMinX();
		for (int ix = 0; ix < (width / step); ix++) {
			Point p = geomFac.createPoint(new Coordinate(x, y));

			sfb.set("the_geom", p);
			SimpleFeature f = sfb.buildFeature("tissot2" + id);
			fc.add(f);
			x += step;
		}
		y += step;
	}

	Layer layer = new FeatureLayer(fc, style);
	return layer;
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:43,代码来源:Tissot.java

示例10: main

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
public static void main(String[] args) {
	File file;
	if (args.length > 0) {
		file = new File(args[0]);
	} else {
		file = new File("ian.shp");
	}
	// create some random features and write them out;
	List<SimpleFeature> feats = new ArrayList<SimpleFeature>();
	SimpleFeatureType schema = null;
	try {
		schema = DataUtilities.createType("", "Location",
				"locations:Point:srid=4326," + // <- the geometry attribute:
						// Point type
						"name:String," + // <- a String attribute
						"number:Integer" // a number attribute
				);
	} catch (SchemaException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return;
	}
	for (int i = 0; i < 10; i++) {
		SimpleFeature f = createSimpleFeature(schema);
		feats.add(f);
	}
	WriteShapefile writer = new WriteShapefile(file);

	FeatureCollection<SimpleFeatureType, SimpleFeature> features = new ListFeatureCollection(
			schema, feats);
	writer.writeFeatures(features);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:33,代码来源:WriteShapefile.java

示例11: addNewColumn

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
/**
 * Adds the new column.
 */
public void addNewColumn() {
    if (featureCollection != null) {
        String attributeName = getUniqueAttributeName();

        columnList.add(attributeName);

        // Populate field names
        SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
        featureTypeBuilder.init(featureCollection.getSchema());
        featureTypeBuilder.add(attributeName, String.class);

        SimpleFeatureType newFeatureType = featureTypeBuilder.buildFeatureType();

        String typeName = userLayer.getInlineFeatureType().getTypeName();
        try {
            SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore()
                    .getFeatureSource(typeName);

            SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);

            ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();

            SimpleFeatureIterator it = featureSource.getFeatures().features();
            try {
                while (it.hasNext()) {
                    SimpleFeature sf = it.next();
                    sfb.addAll(sf.getAttributes());
                    sfb.add(new String(""));
                    featureList.add(sfb.buildFeature(null));
                }
            } finally {
                it.close();
            }

            SimpleFeatureCollection collection = new ListFeatureCollection(newFeatureType,
                    featureList);

            featureCollection = collection;
            cachedFeature = null;
            lastRow = -1;
            DataStore dataStore = DataUtilities.dataStore(collection);
            userLayer.setInlineFeatureDatastore(dataStore);
            userLayer.setInlineFeatureType(newFeatureType);

        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }

        this.fireTableStructureChanged();
        this.fireTableDataChanged();

        if (parentObj != null) {
            parentObj.inlineFeatureUpdated();
        }
    }
}
 
开发者ID:robward-scisys,项目名称:sldeditor,代码行数:60,代码来源:InLineFeatureModel.java

示例12: removeColumn

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
/**
 * Removes the column.
 *
 * @param columnName the column name
 */
public void removeColumn(String columnName) {
    if (featureCollection != null) {
        if (columnList.contains(columnName)) {
            columnList.remove(columnName);

            // Find field name to remote
            SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
            featureTypeBuilder.init(featureCollection.getSchema());
            featureTypeBuilder.remove(columnName);

            SimpleFeatureType newFeatureType = featureTypeBuilder.buildFeatureType();

            int attributeToRemoveIndex = 0;
            for (AttributeDescriptor descriptor : newFeatureType.getAttributeDescriptors()) {
                if (descriptor.getLocalName().compareTo(columnName) == 0) {
                    break;
                }
                attributeToRemoveIndex++;
            }

            String typeName = userLayer.getInlineFeatureType().getTypeName();
            try {
                SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore()
                        .getFeatureSource(typeName);

                SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);

                ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();

                SimpleFeatureIterator it = featureSource.getFeatures().features();
                try {
                    while (it.hasNext()) {
                        SimpleFeature sf = it.next();
                        List<Object> attributes = sf.getAttributes();
                        attributes.remove(attributeToRemoveIndex);

                        sfb.addAll(attributes);
                        featureList.add(sfb.buildFeature(null));
                    }
                } finally {
                    it.close();
                }

                SimpleFeatureCollection collection = new ListFeatureCollection(newFeatureType,
                        featureList);

                featureCollection = collection;
                cachedFeature = null;
                lastRow = -1;
                DataStore dataStore = DataUtilities.dataStore(collection);
                userLayer.setInlineFeatureDatastore(dataStore);
                userLayer.setInlineFeatureType(newFeatureType);

            } catch (IOException e) {
                ConsoleManager.getInstance().exception(this, e);
            }

            this.fireTableStructureChanged();
            this.fireTableDataChanged();

            if (parentObj != null) {
                parentObj.inlineFeatureUpdated();
            }
        }
    }
}
 
开发者ID:robward-scisys,项目名称:sldeditor,代码行数:72,代码来源:InLineFeatureModel.java

示例13: updateCRS

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
/**
 * Update CRS.
 *
 * @param selectedValue the selected value
 */
public void updateCRS(ValueComboBoxData selectedValue) {
    if (selectedValue != null) {
        String crsCode = selectedValue.getKey();

        CoordinateReferenceSystem newCRS = CoordManager.getInstance().getCRS(crsCode);

        SimpleFeatureType newFeatureType = SimpleFeatureTypeBuilder
                .retype(featureCollection.getSchema(), newCRS);

        String typeName = userLayer.getInlineFeatureType().getTypeName();
        try {
            SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore()
                    .getFeatureSource(typeName);

            SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);

            ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();

            SimpleFeatureIterator it = featureSource.getFeatures().features();
            try {
                while (it.hasNext()) {
                    SimpleFeature sf = it.next();
                    List<Object> attributeValueList = sf.getAttributes();
                    sfb.addAll(attributeValueList);
                    featureList.add(sfb.buildFeature(null));
                }
            } finally {
                it.close();
            }

            SimpleFeatureCollection collection = new ListFeatureCollection(newFeatureType,
                    featureList);

            featureCollection = collection;
            cachedFeature = null;
            lastRow = -1;
            DataStore dataStore = DataUtilities.dataStore(collection);
            userLayer.setInlineFeatureDatastore(dataStore);
            userLayer.setInlineFeatureType(newFeatureType);

        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }

        this.fireTableStructureChanged();
        this.fireTableDataChanged();

        if (parentObj != null) {
            parentObj.inlineFeatureUpdated();
        }
    }
}
 
开发者ID:robward-scisys,项目名称:sldeditor,代码行数:58,代码来源:InLineFeatureModel.java

示例14: addNewFeature

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
/**
 * Adds the new feature.
 */
public void addNewFeature() {
    SimpleFeatureType featureType = userLayer.getInlineFeatureType();

    String typeName = userLayer.getInlineFeatureType().getTypeName();
    try {
        SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore()
                .getFeatureSource(typeName);

        SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(featureType);

        ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();

        SimpleFeatureIterator it = featureSource.getFeatures().features();
        try {
            while (it.hasNext()) {
                SimpleFeature sf = it.next();
                List<Object> attributeValueList = sf.getAttributes();
                sfb.addAll(attributeValueList);
                featureList.add(sfb.buildFeature(null));
            }
            // Add new feature
            String wktString = "wkt://POINT(0 0)";
            Geometry geometry = WKTConversion.convertToGeometry(wktString,
                    getSelectedCRSCode());
            sfb.add(geometry);
            featureList.add(sfb.buildFeature(null));
        } finally {
            it.close();
        }

        SimpleFeatureCollection collection = new ListFeatureCollection(featureType,
                featureList);

        featureCollection = collection;
        cachedFeature = null;
        lastRow = -1;
        DataStore dataStore = DataUtilities.dataStore(collection);
        userLayer.setInlineFeatureDatastore(dataStore);

    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }

    this.fireTableStructureChanged();
    this.fireTableDataChanged();

    if (parentObj != null) {
        parentObj.inlineFeatureUpdated();
    }
}
 
开发者ID:robward-scisys,项目名称:sldeditor,代码行数:54,代码来源:InLineFeatureModel.java

示例15: removeFeature

import org.geotools.data.collection.ListFeatureCollection; //导入依赖的package包/类
/**
 * Removes the feature.
 *
 * @param selectedRow the selected row
 */
public void removeFeature(int selectedRow) {
    if ((selectedRow < 0) || (selectedRow >= getRowCount())) {
        return;
    }

    SimpleFeatureType featureType = userLayer.getInlineFeatureType();

    String typeName = userLayer.getInlineFeatureType().getTypeName();
    try {
        SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore()
                .getFeatureSource(typeName);

        SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(featureType);

        ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();

        SimpleFeatureIterator it = featureSource.getFeatures().features();
        try {
            int index = 0;
            while (it.hasNext()) {
                SimpleFeature sf = it.next();

                if (index != selectedRow) {
                    List<Object> attributeValueList = sf.getAttributes();
                    sfb.addAll(attributeValueList);
                    featureList.add(sfb.buildFeature(null));
                }
                index++;
            }
        } finally {
            it.close();
        }

        SimpleFeatureCollection collection = new ListFeatureCollection(featureType,
                featureList);

        featureCollection = collection;
        cachedFeature = null;
        lastRow = -1;
        DataStore dataStore = DataUtilities.dataStore(collection);
        userLayer.setInlineFeatureDatastore(dataStore);

    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }

    this.fireTableStructureChanged();
    this.fireTableDataChanged();

    if (parentObj != null) {
        parentObj.inlineFeatureUpdated();
    }
}
 
开发者ID:robward-scisys,项目名称:sldeditor,代码行数:59,代码来源:InLineFeatureModel.java


注:本文中的org.geotools.data.collection.ListFeatureCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。