本文整理汇总了Java中org.geotools.data.simple.SimpleFeatureIterator类的典型用法代码示例。如果您正苦于以下问题:Java SimpleFeatureIterator类的具体用法?Java SimpleFeatureIterator怎么用?Java SimpleFeatureIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleFeatureIterator类属于org.geotools.data.simple包,在下文中一共展示了SimpleFeatureIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: correctFeatures
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的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: testEncodedNativeTermQuery
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
@Test
public void testEncodedNativeTermQuery() throws Exception {
init("not-active");
Map<String, String> vparams = new HashMap<String, String>();
Map<String,Object> query = ImmutableMap.of("term", ImmutableMap.of("security_ss", "WPA"));
vparams.put("q", URLEncoder.encode(mapper.writeValueAsString(query), "UTF-8"));
Hints hints = new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, vparams);
Query q = new Query(featureSource.getSchema().getTypeName());
q.setHints(hints);
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter = ff.equals(ff.property("speed_is"), ff.literal("300"));
q.setFilter(filter);
ContentFeatureCollection features = featureSource.getFeatures(q);
assertEquals(1, features.size());
SimpleFeatureIterator fsi = features.features();
assertTrue(fsi.hasNext());
assertEquals(fsi.next().getID(), "active.12");
}
示例3: CommunityAreas
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
public CommunityAreas() {
communities = new HashMap<>();
try {
File f = new File(shapeFilePath);
ShapefileDataStore shapefile = new ShapefileDataStore(f.toURI().toURL());
SimpleFeatureIterator features = shapefile.getFeatureSource().getFeatures().features();
SimpleFeature shp;
while (features.hasNext()) {
shp = features.next();
int id = Integer.parseInt((String) shp.getAttribute("AREA_NUMBE"));
String name = (String) shp.getAttribute("COMMUNITY");
MultiPolygon boundary = (MultiPolygon) shp.getDefaultGeometry();
CommunityArea ca = new CommunityArea(id, name, boundary);
communities.put(id, ca);
}
features.close();
shapefile.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: Tracts
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
public Tracts() {
tracts = new HashMap<>();
try {
SimpleFeatureIterator features = getShapeFileFeatures();
SimpleFeature shp;
while (features.hasNext()) {
shp = features.next();
int id = Integer.parseInt((String) shp.getAttribute("tractce10"));
MultiPolygon boundary = (MultiPolygon) shp.getDefaultGeometry();
Tract t = new Tract(id, boundary);
tracts.put(id, t);
}
features.close();
shapefile.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: testAllShapesArePolygon
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
public void testAllShapesArePolygon() {
try {
SimpleFeatureIterator features = Tracts.getShapeFileFeatures();
SimpleFeature shp = features.next();
int fieldSize = shp.getType().getTypes().size();
assertEquals(fieldSize, 10);
assertEquals(shp.getType().getType(3).getName().getLocalPart(), "tractce10");
assertEquals(shp.getType().getType(0).getName().getLocalPart(), "MultiPolygon");
for (int i = 0; i < fieldSize; i++){
System.out.println(shp.getType().getType(i).getName().getLocalPart());
}
int cnt = 1;
while (features.hasNext()) {
shp = features.next();
MultiPolygon g = (MultiPolygon) shp.getDefaultGeometry();
cnt ++;
}
assertEquals(cnt, 801);
features.close();
Tracts.shapefile.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
示例6: getFeature
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
/**
* Gets the feature.
*
* @param row the row
* @return the feature
*/
private SimpleFeature getFeature(int row) {
if (featureCollection != null) {
if (row != lastRow) {
SimpleFeatureIterator iterator = featureCollection.features();
SimpleFeature feature = iterator.next();
int index = 0;
while (iterator.hasNext() && (index < row)) {
feature = iterator.next();
index++;
}
lastRow = row;
cachedFeature = feature;
}
return cachedFeature;
}
return null;
}
示例7: getOutcomeTest
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
@Test(enabled = true, groups = { "suitability", "integration" })
public void getOutcomeTest() throws Exception {
String areaAnalyzed = WifKeys.POLYGON_TEST;
String crsArea = WifKeys.CRS_TEST;
SimpleFeatureCollection suitabilityAnalysis = suitabilityScenarioService
.getOutcome(WifKeys.TEST_SUITABILITY_SCENARIO_ID, areaAnalyzed, crsArea);
SimpleFeatureIterator it = suitabilityAnalysis.features();
LOGGER.debug("results feature size: " + suitabilityAnalysis.size());
Assert.assertEquals(suitabilityAnalysis.size(), (8));
Double score = 0.0;
try {
while (it.hasNext()) {
SimpleFeature uazFeature = it.next();
score += (Double) uazFeature.getAttribute("SCORE_1");
}
} finally {
it.close();
}
LOGGER.debug("Score = " + score);
Assert.assertNotEquals(score, new Double(0));
// FIXME This was before, please check
// Assert.assertEquals(score, new Double(90000));
}
示例8: readFeatures
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
private List<Map<String, Object>> readFeatures(SimpleFeatureCollection features) {
final ObjectMapper mapper = new ObjectMapper();
final List<Map<String, Object>> buckets = new ArrayList<>();
try (SimpleFeatureIterator iterator = features.features()) {
while (iterator.hasNext()) {
final SimpleFeature feature = iterator.next();
if (feature.getAttribute("_aggregation") != null) {
final byte[] data = (byte[]) feature.getAttribute("_aggregation");
try {
final Map<String,Object> aggregation = mapper.readValue(data, new TypeReference<Map<String,Object>>() {});
buckets.add(aggregation);
} catch (IOException e) {
LOGGER.fine("Failed to parse aggregation value: " + e);
}
}
}
}
return buckets;
}
示例9: testNativeAggregation
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
@Test
public void testNativeAggregation() throws Exception {
init();
Map<String, String> vparams = new HashMap<String, String>();
Map<String,Object> query = ImmutableMap.of("agg", ImmutableMap.of("geohash_grid",
ImmutableMap.of("field", "geo", "precision", 3)));
vparams.put("a", mapper.writeValueAsString(query));
Hints hints = new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, vparams);
Query q = new Query(featureSource.getSchema().getTypeName());
q.setHints(hints);
ContentFeatureCollection features = featureSource.getFeatures(q);
assertFalse(features.isEmpty());
SimpleFeatureIterator fsi = features.features();
assertTrue(fsi.hasNext());
assertNotNull(fsi.next().getAttribute("_aggregation"));
}
示例10: testDisjointFilter
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
@Test
public void testDisjointFilter() throws Exception {
init("not-active","geo3");
FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
GeometryFactory gf = new GeometryFactory();
PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2));
Disjoint f = ff.disjoint(ff.property("geo3"), ff.literal(ls));
SimpleFeatureCollection features = featureSource.getFeatures(f);
assertEquals(2, features.size());
SimpleFeatureIterator fsi = features.features();
assertTrue(fsi.hasNext());
assertEquals(fsi.next().getID(), "active.12");
assertTrue(fsi.hasNext());
assertEquals(fsi.next().getID(), "active.13");
}
示例11: testDWithinFilter
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
@Test
public void testDWithinFilter() throws Exception {
init();
FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
GeometryFactory gf = new GeometryFactory();
PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2));
DWithin f = ff.dwithin(ff.property("geo"), ff.literal(ls), 3, SI.METRE.getSymbol());
SimpleFeatureCollection features = featureSource.getFeatures(f);
assertEquals(2, features.size());
SimpleFeatureIterator fsi = features.features();
assertTrue(fsi.hasNext());
assertEquals(fsi.next().getID(), "active.01");
assertTrue(fsi.hasNext());
assertEquals(fsi.next().getID(), "active.10");
}
示例12: testAlternateGeometry
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
@Test
public void testAlternateGeometry() throws Exception {
init("active", "geo2");
SimpleFeatureType schema = featureSource.getSchema();
GeometryDescriptor gd = schema.getGeometryDescriptor();
assertNotNull(gd);
assertEquals("geo2", gd.getLocalName());
FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
BBOX bbox = ff.bbox("geo2", 6.5, 23.5, 7.5, 24.5, "EPSG:4326");
SimpleFeatureCollection features = featureSource.getFeatures(bbox);
assertEquals(1, features.size());
SimpleFeatureIterator fsi = features.features();
assertTrue(fsi.hasNext());
assertEquals(fsi.next().getID(), "active.09");
}
示例13: testOgrStyleGeoPoint
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
@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());
}
示例14: testLessDateFilterLong
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
@Test
public void testLessDateFilterLong() throws Exception {
init();
Date testDate = new Date(1005912798000l);
FilterFactory ff = dataStore.getFilterFactory();
Filter f = ff.lessOrEqual(ff.property("installed_td"), ff.literal(testDate.getTime()));
SimpleFeatureCollection features = featureSource.getFeatures(f);
assertEquals(4, features.size());
SimpleFeatureIterator it = features.features();
while (it.hasNext()) {
SimpleFeature next = it.next();
Date date = (Date) next.getAttribute("installed_td");
assertTrue(date.before(testDate) || date.equals(testDate));
}
it.close();
}
示例15: testGreaterDateFilterLong
import org.geotools.data.simple.SimpleFeatureIterator; //导入依赖的package包/类
@Test
public void testGreaterDateFilterLong() throws Exception {
init();
Date testDate = new Date(1005912798000l);
FilterFactory ff = dataStore.getFilterFactory();
Filter f = ff.greaterOrEqual(ff.property("installed_td"), ff.literal(testDate.getTime()));
SimpleFeatureCollection features = featureSource.getFeatures(f);
assertEquals(7, features.size());
SimpleFeatureIterator it = features.features();
while (it.hasNext()) {
SimpleFeature next = it.next();
Date date = (Date) next.getAttribute("installed_td");
assertTrue(date.after(testDate) || date.equals(testDate));
}
it.close();
}