本文整理汇总了Java中org.geotools.feature.DefaultFeatureCollection类的典型用法代码示例。如果您正苦于以下问题:Java DefaultFeatureCollection类的具体用法?Java DefaultFeatureCollection怎么用?Java DefaultFeatureCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultFeatureCollection类属于org.geotools.feature包,在下文中一共展示了DefaultFeatureCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: correctFeatures
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
public static SimpleFeatureCollection correctFeatures(SimpleFeatureCollection fc){
SimpleFeatureIterator iterator=fc.features();
DefaultFeatureCollection outVector = new DefaultFeatureCollection();
while(iterator.hasNext()){
SimpleFeature sf=iterator.next();
Geometry gm=(Geometry)sf.getDefaultGeometry();
if(!gm.isValid()){
gm=JTSUtil.repair(gm);
System.out.println(gm.isValid());
}
sf.setDefaultGeometry(gm);
outVector.add(sf);
}
return fc;
}
示例2: process
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
@Execute
public void process() {
// create a geometry list of the input polygons
List<Geometry> inInundationGeomsList = FeatureUtilities.featureCollectionToGeometriesList(inInundationArea, false, null);
// make the union and merge of the polygons
Geometry union = CascadedPolygonUnion.union(inInundationGeomsList);
List<Geometry> removedHoles = removeHoles(union);
// store the results in the output feature collection
outInundationArea = new DefaultFeatureCollection();
SimpleFeatureCollection outMergedAreaFC = FeatureUtilities.featureCollectionFromGeometry(inInundationArea.getBounds()
.getCoordinateReferenceSystem(), removedHoles.toArray(GeometryUtilities.TYPE_POLYGON));
((DefaultFeatureCollection) outInundationArea).addAll(outMergedAreaFC);
}
示例3: addDeleteNewFeature
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
public static void addDeleteNewFeature(SimpleFeatureType sft, FeatureStore producerFS)
throws InterruptedException, IOException {
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(sft);
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
final Random random = new Random();
String id = "1000";
builder.add("Antoninus"); // name
builder.add((int) Math.round(random.nextDouble()*110)); // age
builder.add(new Date()); // dtg
builder.add(WKTUtils$.MODULE$.read("POINT(-1 -1)")); // geom
SimpleFeature feature = builder.buildFeature(id);
featureCollection.add(feature);
producerFS.addFeatures(featureCollection);
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Filter idFilter = ff.id(ff.featureId(id));
producerFS.removeFeatures(idFilter);
}
示例4: createFeatureLayerFromMapObject
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
/**
* Creates a feature layer based on a map object.
*/
public static Layer createFeatureLayerFromMapObject( InternalMapObject mapObject )
{
Style style = mapObject.getStyle();
SimpleFeatureType featureType = mapObject.getFeatureType();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder( featureType );
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
featureBuilder.add( mapObject.getGeometry() );
SimpleFeature feature = featureBuilder.buildFeature( null );
featureCollection.add( feature );
return new FeatureLayer( featureCollection, style );
}
示例5: storeStatements
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
@Override
public void storeStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
// create a feature collection
final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
for (final RyaStatement ryaStatement : ryaStatements) {
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
// if the predicate list is empty, accept all predicates.
// Otherwise, make sure the predicate is on the "valid" list
final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
if (isValidPredicate && (statement.getObject() instanceof Literal)) {
try {
final SimpleFeature feature = createFeature(featureType, statement);
featureCollection.add(feature);
} catch (final ParseException e) {
logger.warn("Error getting geo from statement: " + statement.toString(), e);
}
}
}
// write this feature collection to the store
if (!featureCollection.isEmpty()) {
featureStore.addFeatures(featureCollection);
}
}
示例6: createAggregationFeatures
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
public static SimpleFeatureCollection createAggregationFeatures(List<Map<String,Object>> data) {
final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName( "testType" );
builder.add("_aggregation", HashMap.class );
builder.add("aString", String.class );
final SimpleFeatureType featureType = builder.buildFeatureType();
final DefaultFeatureCollection collection = new DefaultFeatureCollection();
final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
data.stream().forEach(item -> {
item.keySet().stream().forEach(key -> {
featureBuilder.set(key, item.get(key));
});
collection.add(featureBuilder.buildFeature(null));
});
return collection;
}
示例7: createExtraFeatures
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
private static Layer createExtraFeatures() {
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName("Location");
b.setCRS(DefaultGeographicCRS.WGS84);
// picture location
b.add("geom", Point.class);
final SimpleFeatureType TYPE = b.buildFeatureType();
GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();
Point point = gf.createPoint(new Coordinate(CANBERRA_LONG, CANBERRA_LAT));
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(TYPE);
builder.add(point);
SimpleFeature feature = builder.buildFeature("Canberra");
DefaultFeatureCollection features = new DefaultFeatureCollection(null, null);
features.add(feature);
Style style = SLD.createPointStyle("Star", Color.BLUE, Color.BLUE, 0.3f, 10);
return new FeatureLayer(features, style);
}
示例8: createPolygons
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
private void createPolygons( CoordinateReferenceSystem crs, GeometryFactory gf, List<Geometry> polygons ) {
outMap = new DefaultFeatureCollection();
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName(POLYGON);
b.setCRS(crs);
b.add("the_geom", Polygon.class);
b.add("id", Long.class);
SimpleFeatureType type = b.buildFeatureType();
SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(type);
long index = 0;
int numGeometries = polygons.size();
for( int i = 0; i < numGeometries; i++ ) {
Geometry geometry = polygons.get(i);
Object[] values = new Object[]{geometry, index++};
fbuilder.addAll(values);
SimpleFeature feature = fbuilder.buildFeature(null);
((DefaultFeatureCollection) outMap).add(feature);
}
}
示例9: createPoints
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
private void createPoints( CoordinateReferenceSystem crs, GeometryFactory gf, List<LineString> verticals,
List<LineString> horizontals ) {
outMap = new DefaultFeatureCollection();
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName(POINT);
b.setCRS(crs);
b.add("the_geom", Point.class);
b.add("id", Long.class);
SimpleFeatureType type = b.buildFeatureType();
SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(type);
Geometry gVer = gf.createMultiLineString(verticals.toArray(new LineString[0]));
Geometry gHor = gf.createMultiLineString(horizontals.toArray(new LineString[0]));
Geometry intersection = gHor.intersection(gVer);
long index = 0;
int numGeometries = intersection.getNumGeometries();
for( int i = 0; i < numGeometries; i++ ) {
Geometry geometry = intersection.getGeometryN(i);
Object[] values = new Object[]{geometry, index++};
fbuilder.addAll(values);
SimpleFeature feature = fbuilder.buildFeature(null);
((DefaultFeatureCollection) outMap).add(feature);
}
}
示例10: createBboxGeometry
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
private void createBboxGeometry( CoordinateReferenceSystem crs, File lasFile, SimpleFeatureCollection outGeodata )
throws IOException {
final ReferencedEnvelope3D envelope = lasReader.getHeader().getDataEnvelope();
ReferencedEnvelope env2d = new ReferencedEnvelope(envelope);
final Polygon polygon = FeatureUtilities.envelopeToPolygon(new Envelope2D(env2d));
final SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName("lasdataenvelope");
b.setCRS(crs);
b.add("the_geom", Polygon.class);
b.add("id", String.class);
final SimpleFeatureType type = b.buildFeatureType();
final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
final Object[] values = new Object[]{polygon, lasFile.getName()};
builder.addAll(values);
final SimpleFeature feature = builder.buildFeature(null);
((DefaultFeatureCollection) outGeodata).add(feature);
OmsVectorWriter.writeVector(outFile, outGeodata);
}
示例11: doCollection
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
private SimpleFeatureCollection doCollection() {
CoordinateReferenceSystem crs = HMTestMaps.getCrs();
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName("typename");
b.setCRS(crs);
b.add("the_geom", LineString.class);
SimpleFeatureType type = b.buildFeatureType();
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
Coordinate one = new Coordinate(westNorth.x + ep.getXres() / 2, centerCoord.y + ep.getYres() / 2);
Coordinate two = new Coordinate(eastSouth.x - ep.getXres() / 2, centerCoord.y + ep.getYres() / 2);
LineString lineString = GeometryUtilities.gf().createLineString(new Coordinate[]{one, two});
Object[] values = new Object[]{lineString};
builder.addAll(values);
SimpleFeature feature = builder.buildFeature(null);
DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
newCollection.add(feature);
return newCollection;
}
示例12: doCollection
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
private SimpleFeatureCollection doCollection( RegionMap envelopeParams ) {
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName("typename");
b.setCRS(crs);
b.add("the_geom", Polygon.class);
b.add("cat", Double.class);
SimpleFeatureType type = b.buildFeatureType();
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
Object[] values = new Object[]{polygon, 1.0};
builder.addAll(values);
SimpleFeature feature = builder.buildFeature(null);
DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
newCollection.add(feature);
return newCollection;
}
示例13: addFeature
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
/**
* Add a feature to the store.
*
* @param feature the feature to add.
*/
default public void addFeature( SimpleFeature feature) {
FeatureStoreInfo featureStoreInfo = getFeatureStoreInfo();
SimpleFeatureStore featureStore = featureStoreInfo.getFeatureStore();
if (featureStore != null) {
Transaction transaction = new DefaultTransaction("add");
featureStore.setTransaction(transaction);
try {
DefaultFeatureCollection fc = new DefaultFeatureCollection();
fc.add(feature);
featureStore.addFeatures(fc);
transaction.commit();
} catch (Exception eek) {
try {
transaction.rollback();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
示例14: viewSpatialQueryResult
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
public boolean viewSpatialQueryResult( String title, String sqlText, IHMProgressMonitor pm ) {
boolean hasError = false;
if (sqlText.trim().length() == 0) {
return false;
}
try {
pm.beginTask("Run query: " + sqlText, IHMProgressMonitor.UNKNOWN);
DefaultFeatureCollection fc = DbsHelper.runRawSqlToFeatureCollection(title, currentConnectedDatabase, sqlText, null);
ReprojectingFeatureCollection rfc = new ReprojectingFeatureCollection(fc, NwwUtilities.GPS_CRS);
showInMapFrame(true, rfc);
addQueryToHistoryCombo(sqlText);
} catch (Exception e1) {
String localizedMessage = e1.getLocalizedMessage();
hasError = true;
pm.errorMessage("An error occurred: " + localizedMessage);
} finally {
pm.done();
}
return hasError;
}
示例15: runQueryToShapefile
import org.geotools.feature.DefaultFeatureCollection; //导入依赖的package包/类
protected boolean runQueryToShapefile( String sqlText, File selectedFile, IHMProgressMonitor pm ) {
boolean hasError = false;
if (sqlText.trim().length() == 0) {
return false;
}
if (currentConnectedDatabase instanceof GTSpatialiteThreadsafeDb) {
try {
pm.beginTask("Run query: " + sqlText + "\ninto shapefile: " + selectedFile, IHMProgressMonitor.UNKNOWN);
DefaultFeatureCollection fc = DbsHelper.runRawSqlToFeatureCollection(null, currentConnectedDatabase, sqlText,
null);
OmsVectorWriter.writeVector(selectedFile.getAbsolutePath(), fc);
addQueryToHistoryCombo(sqlText);
} catch (Exception e1) {
String localizedMessage = e1.getLocalizedMessage();
hasError = true;
pm.errorMessage("An error occurred: " + localizedMessage);
} finally {
pm.done();
}
} else {
guiBridge.messageDialog("WARNING", "This operation is not yet supported for this database type.",
JOptionPane.WARNING_MESSAGE);
}
return hasError;
}