org.geotools.data.simple.SimpleFeatureIterator Java Examples
The following examples show how to use
org.geotools.data.simple.SimpleFeatureIterator.
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: TxtParser.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
public void write(SimpleFeatureCollection obj, OutputStream output) throws IOException { SimpleFeatureIterator it = obj.features(); PrintStream printStream = new PrintStream(output); while (it.hasNext()) { SimpleFeature ft = it.next(); printStream.print(ft.getID() + " ["); boolean first = true; for (AttributeDescriptor ad : ft.getType().getAttributeDescriptors()) { if (!first) { printStream.print(", "); } printStream.print(ad.getLocalName() + ": " + ft.getAttribute(ad.getName())); first = false; } printStream.println("]"); } }
Example #2
Source File: ElasticViewParametersFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testNativeAggregation() throws Exception { init(); Map<String, String> vparams = new HashMap<>(); 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")); }
Example #3
Source File: ElasticViewParametersFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testNativeBooleanQuery() throws Exception { init(); Map<String, String> vparams = new HashMap<>(); Map<String,Object> query = ImmutableMap.of("bool", ImmutableMap.of("must", ImmutableMap.of("term", ImmutableMap.of("security_ss", "WPA")), "must_not", ImmutableMap.of("term", ImmutableMap.of("modem_b", true)))); vparams.put("q", mapper.writeValueAsString(query)); 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(2, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getAttribute("modem_b"), false); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getAttribute("modem_b"), false); }
Example #4
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@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"); }
Example #5
Source File: ElasticViewParametersFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testEncodedNativeTermQuery() throws Exception { init("not-active"); Map<String, String> vparams = new HashMap<>(); 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"); }
Example #6
Source File: ElasticViewParametersFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testNativeTermQuery() throws Exception { init("not-active"); Map<String, String> vparams = new HashMap<>(); Map<String,Object> query = ImmutableMap.of("term", ImmutableMap.of("security_ss", "WPA")); vparams.put("q", mapper.writeValueAsString(query)); 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"); }
Example #7
Source File: InLineFeatureModel.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * 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; }
Example #8
Source File: GeoHashGrid.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
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; }
Example #9
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@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, "m"); 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"); }
Example #10
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@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"); }
Example #11
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@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 #12
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testGeoPointAsArray() throws Exception { init("active","geo5"); 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("geo5"), ff.literal(ls), 3, "m"); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(2, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); SimpleFeature feature = fsi.next(); assertEquals(feature.getID(), "active.01"); assertNotNull(feature.getDefaultGeometry()); assertTrue(fsi.hasNext()); feature = fsi.next(); assertEquals(feature.getID(), "active.10"); assertNotNull(feature.getDefaultGeometry()); }
Example #13
Source File: ElasticGeometryFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@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 #14
Source File: ElasticTemporalFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@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(); }
Example #15
Source File: ElasticTemporalFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@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(); }
Example #16
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@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 #17
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testGetFeaturesWithQuery() throws Exception { init(); FilterFactory ff = dataStore.getFilterFactory(); PropertyIsEqualTo filter = ff.equals(ff.property("modem_b"), ff.literal(true)); Query query = new Query(); query.setPropertyNames(new String[] { "standard_ss", "security_ss" }); query.setFilter(filter); SimpleFeatureCollection features = featureSource.getFeatures(query); assertEquals(8, features.size()); try (SimpleFeatureIterator iterator = features.features()) { assertTrue(iterator.hasNext()); SimpleFeature feature = iterator.next(); assertEquals(2, feature.getAttributeCount()); String st = (String) feature.getAttribute("standard_ss"); // changed from "IEEE 802.11b" in SolrFeatureSourceTest assertTrue(st.contains("IEEE 802.11b")); } }
Example #18
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@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 #19
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testGetFeaturesWithOffsetLimit() throws Exception { init(); Query q = new Query(featureSource.getSchema().getTypeName()); // no sorting, let's see if the database can use native one q.setStartIndex(1); q.setMaxFeatures(1); SimpleFeatureCollection features = featureSource.getFeatures(q); // check size assertEquals(1, features.size()); // check actual iteration try (SimpleFeatureIterator it = features.features()) { assertTrue(it.hasNext()); SimpleFeature f = it.next(); assertEquals(2, Integer.parseInt((String) f.getAttribute("id"))); assertFalse(it.hasNext()); } }
Example #20
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testOnlyStoredFields() throws Exception { init(); Name name = new NameImpl("active"); for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){ if (!attribute.isStored()) { attribute.setUse(false); } } assertEquals(11, featureSource.getCount(Query.ALL)); SimpleFeatureIterator features = featureSource.getFeatures().features(); for (int i=0; i<11; i++) { assertTrue(features.hasNext()); features.next(); } }
Example #21
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testOnlySourceFields() throws Exception { init(); Name name = new NameImpl("active"); for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){ if (attribute.isStored()) { attribute.setUse(false); } } featureSource = (ElasticFeatureSource) dataStore.getFeatureSource(TYPE_NAME); assertEquals(11, featureSource.getCount(Query.ALL)); SimpleFeatureIterator features = featureSource.getFeatures().features(); for (int i=0; i<11; i++) { assertTrue(features.hasNext()); features.next(); } }
Example #22
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testOnlyStoredFieldsWithSourceFiltering() throws Exception { init(); dataStore.setSourceFilteringEnabled(true); Name name = new NameImpl("active"); for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){ if (!attribute.isStored()) { attribute.setUse(false); } } assertEquals(11, featureSource.getCount(Query.ALL)); SimpleFeatureIterator features = featureSource.getFeatures().features(); for (int i=0; i<11; i++) { assertTrue(features.hasNext()); features.next(); } }
Example #23
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testOnlySourceFieldsWithSourceFiltering() throws Exception { init(); dataStore.setSourceFilteringEnabled(true); Name name = new NameImpl("active"); for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){ if (attribute.isStored()) { attribute.setUse(false); } } featureSource = (ElasticFeatureSource) dataStore.getFeatureSource(TYPE_NAME); assertEquals(11, featureSource.getCount(Query.ALL)); SimpleFeatureIterator features = featureSource.getFeatures().features(); for (int i=0; i<11; i++) { assertTrue(features.hasNext()); features.next(); } }
Example #24
Source File: FeatureUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Extracts features from a {@link FeatureCollection} into an {@link STRtree}. * * @param collection the feature collection. * @return the tree containing the features. */ public static STRtree featureCollectionToSTRtree( SimpleFeatureCollection collection ) { STRtree tree = new STRtree(); SimpleFeatureIterator featureIterator = collection.features(); while( featureIterator.hasNext() ) { SimpleFeature feature = featureIterator.next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); tree.insert(geometry.getEnvelopeInternal(), feature); } featureIterator.close(); return tree; }
Example #25
Source File: FeatureCollectionLinesLayer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void run() { try { removeAllRenderables(); SimpleFeatureIterator featureIterator = getfeatureCollection().features(); while( featureIterator.hasNext() ) { SimpleFeature lineFeature = featureIterator.next(); boolean doExtrude = false; if (mApplyExtrusion && (mHeightFieldName != null || mHasConstantHeight)) { doExtrude = true; } addLine(lineFeature, doExtrude); } featureIterator.close(); } catch (Exception e) { e.printStackTrace(); } }
Example #26
Source File: ExportGeometryActionTest.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private void doExportImport(ArrayList<SimpleFeature> features, Class<? extends Geometry> geomType) throws IOException { File tempFile = File.createTempFile("pins", null, tempDir); try { ExportGeometryAction.writeEsriShapefile(geomType, features, tempFile); assertTrue(tempFile.exists()); VectorDataNode vectorDataNode = readIn(new File(String.format("%s_%s.shp", tempFile.getAbsolutePath(), geomType.getSimpleName())), product); assertEquals(1, vectorDataNode.getFeatureCollection().getCount()); try (SimpleFeatureIterator readFeatures = vectorDataNode.getFeatureCollection().features()) { while (readFeatures.hasNext()) { SimpleFeature next = readFeatures.next(); assertNotNull(next.getDefaultGeometry()); } } } catch (Throwable t) { t.printStackTrace(); fail(String.format("Throwable '%s: %s' not expected", t.getClass().getSimpleName(), t.getMessage())); } finally { boolean deleted = tempFile.delete(); if (!deleted) { tempFile.deleteOnExit(); } } }
Example #27
Source File: TestUtils.java From geowave with Apache License 2.0 | 6 votes |
public static SimpleFeature resourceToFeature(final URL filterResource) throws IOException { final Map<String, Object> map = new HashMap<>(); DataStore dataStore = null; map.put("url", filterResource); final SimpleFeature savedFilter; SimpleFeatureIterator sfi = null; try { dataStore = DataStoreFinder.getDataStore(map); if (dataStore == null) { LOGGER.error("Could not get dataStore instance, getDataStore returned null"); throw new IOException("Could not get dataStore instance, getDataStore returned null"); } // just grab the first feature and use it as a filter sfi = dataStore.getFeatureSource(dataStore.getNames().get(0)).getFeatures().features(); savedFilter = sfi.next(); } finally { if (sfi != null) { sfi.close(); } if (dataStore != null) { dataStore.dispose(); } } return savedFilter; }
Example #28
Source File: MultiPolygons.java From amodeus with GNU General Public License v2.0 | 6 votes |
private static Set<MultiPolygon> initializeFrom(File shapeFile) throws IOException { URL shapeFileURL = shapeFile.toURI().toURL(); Map<String, URL> inputMap = new HashMap<>(); inputMap.put("url", shapeFileURL); DataStore dataStore = DataStoreFinder.getDataStore(inputMap); SimpleFeatureSource featureSource = dataStore.getFeatureSource(dataStore.getTypeNames()[0]); SimpleFeatureCollection collection = DataUtilities.collection(featureSource.getFeatures()); dataStore.dispose(); Set<MultiPolygon> polygons = new HashSet<>(); SimpleFeatureIterator iterator = collection.features(); while (iterator.hasNext()) polygons.add((MultiPolygon) iterator.next().getDefaultGeometry()); return polygons; }
Example #29
Source File: TestVectorReprojector.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorReprojector() throws Exception { SimpleFeatureCollection testFC = HMTestMaps.getTestFC(); OmsVectorReprojector reprojector = new OmsVectorReprojector(); reprojector.inVector = testFC; reprojector.pCode = "EPSG:4326"; reprojector.pm = pm; reprojector.process(); CoordinateReferenceSystem sourceCRS = HMTestMaps.getCrs(); CoordinateReferenceSystem targetCRS = CrsUtilities.getCrsFromSrid(4326); MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS); SimpleFeatureCollection outFC = reprojector.outVector; FeatureIterator<SimpleFeature> featureIterator = outFC.features(); SimpleFeatureIterator originalFeatureIterator = testFC.features(); while( featureIterator.hasNext() ) { SimpleFeature feature = featureIterator.next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); Coordinate coordinate = geometry.getCoordinate(); SimpleFeature originalFeature = originalFeatureIterator.next(); Coordinate origCoord = ((Geometry) originalFeature.getDefaultGeometry()).getCoordinate(); Coordinate reprojected = JTS.transform(origCoord, null, transform); assertEquals(reprojected.x, coordinate.x, delta); assertEquals(reprojected.y, coordinate.y, delta); } featureIterator.close(); }
Example #30
Source File: OmsVectorMerger.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
@Execute public void process() throws Exception { checkNull(inVectors); SimpleFeatureType firstType = null; FeatureExtender fEx = null; pm.beginTask("Merging features...", inVectors.size()); try { outVector = new DefaultFeatureCollection(); for( SimpleFeatureCollection featureCollection : inVectors ) { if (firstType == null) { firstType = featureCollection.getSchema(); fEx = new FeatureExtender(firstType, new String[0], new Class< ? >[0]); } else { SimpleFeatureType schema = featureCollection.getSchema(); int compare = DataUtilities.compare(firstType, schema); if (compare != 0) { throw new ModelsIllegalargumentException("Merging is done only on same feature types.", this, pm); } } SimpleFeatureIterator featureIterator = featureCollection.features(); while( featureIterator.hasNext() ) { SimpleFeature f = featureIterator.next(); SimpleFeature extendFeature = fEx.extendFeature(f, new Object[0]); ((DefaultFeatureCollection) outVector).add(extendFeature); } pm.worked(1); } } finally { pm.done(); } }