FeatureType featureType = featureSource.getSchema(); Name name = featureSource.getName(); if (name == null) { name = featureType.getName(); ftinfo.setNativeName(name.getLocalPart()); ftinfo.setName(name.getLocalPart()); CoordinateReferenceSystem crs = featureType.getCoordinateReferenceSystem(); if (crs == null && featureType.getGeometryDescriptor() != null) { crs = featureType.getGeometryDescriptor().getCoordinateReferenceSystem();
int limitedAttributeSize = mixed.getProperties() != null ? mixed.getProperties().size() : 0; final FeatureCollection<T, F> fc = delegate.getFeatures(mixed); if (fc == null) { return null; } else { if (limitedAttributeSize > 0 && fc.getSchema().getDescriptors().size() > limitedAttributeSize) { if (fc instanceof SimpleFeatureCollection) { SimpleFeatureType target = SimpleFeatureTypeBuilder.retype( sfc.getSchema(), mixed.getPropertyNames()); ReTypingFeatureCollection retyped = new ReTypingFeatureCollection(sfc, target); return (FeatureCollection) SecuredObjects.secure(retyped, policy);
if (info.getAttributes() == null || info.getAttributes().isEmpty()) { for (PropertyDescriptor pd : ft.getDescriptors()) { if (!(pd instanceof AttributeDescriptor)) { continue; PropertyDescriptor pd = ft.getDescriptor(attName); if (pd == null || !(pd instanceof AttributeDescriptor)) { throw new IOException(
@Test public void testMetadataFromFeatueSource() throws Exception { CatalogBuilder cb = new CatalogBuilder(getCatalog()); cb.setStore(cb.buildDataStore("fooStore")); FeatureType ft = createMock(FeatureType.class); expect(ft.getName()).andReturn(new NameImpl("foo")).anyTimes(); expect(ft.getCoordinateReferenceSystem()).andReturn(null).anyTimes(); expect(ft.getGeometryDescriptor()).andReturn(null).anyTimes(); replay(ft); ResourceInfo rInfo = createMock(ResourceInfo.class); expect(rInfo.getTitle()).andReturn("foo title"); expect(rInfo.getDescription()).andReturn("foo description"); expect(rInfo.getKeywords()) .andReturn(new LinkedHashSet<String>(Arrays.asList("foo", "bar", "baz", ""))) .anyTimes(); replay(rInfo); FeatureSource fs = createMock(FeatureSource.class); expect(fs.getSchema()).andReturn(ft).anyTimes(); expect(fs.getInfo()).andReturn(rInfo).anyTimes(); expect(fs.getName()).andReturn(ft.getName()).anyTimes(); replay(fs); FeatureTypeInfo ftInfo = cb.buildFeatureType(fs); assertEquals("foo title", ftInfo.getTitle()); assertEquals("foo description", ftInfo.getDescription()); assertTrue(ftInfo.getKeywords().contains(new Keyword("foo"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("bar"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("baz"))); }
@Test public void testForce() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.BASIC_POLYGONS.getLocalPart()); assertEquals("EPSG:4269", fti.getSRS()); assertEquals(ProjectionPolicy.FORCE_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4269"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); fi.close(); assertEquals(CRS.decode("EPSG:4269"), f.getType().getCoordinateReferenceSystem()); }
try { if (crs == null) { GeometryDescriptor gd = featureCollection.getSchema().getGeometryDescriptor(); if (gd != null) { crs = gd.getCoordinateReferenceSystem(); epsg4326 = CRS.decode("EPSG:4326"); } catch (Exception e) { throw new ProcessException("Unknown CRS code: EPSG:4326", e); MathTransform crsTransform = CRS.findMathTransform(crs, epsg4326); FeatureType targetFeatureType = createTargetFeatureType(featureCollection.getSchema()); Unit fromUnit = SI.METRE; Unit toUnit = USCustomary.MILE; double nearestDistance = 9e9; double nearestBearing = 0; FeatureIterator featureIterator = featureCollection.features(); try { while (featureIterator.hasNext()) { SimpleFeature f = (SimpleFeature) featureIterator.next(); if (f.getDefaultGeometryProperty().getValue() == null) continue; DistanceOp op = featureIterator.close();
/** * Create the modified feature type. * * @param sourceFeatureType the source feature type * @return the modified feature type * @throws ProcessException errror */ private SimpleFeatureType createTargetFeatureType(FeatureType sourceFeatureType) throws ProcessException { try { SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName(sourceFeatureType.getName().getLocalPart()); typeBuilder.setNamespaceURI(sourceFeatureType.getName().getNamespaceURI()); AttributeDescriptor geomAttbType = sourceFeatureType.getGeometryDescriptor(); for (PropertyDescriptor attbType : sourceFeatureType.getDescriptors()) { if (attbType.equals(geomAttbType)) { typeBuilder.add(geomAttbType.getLocalName(), Point.class); } else { typeBuilder.add((AttributeDescriptor) attbType); } } typeBuilder.setDefaultGeometry( sourceFeatureType.getGeometryDescriptor().getLocalName()); return typeBuilder.buildFeatureType(); } catch (Exception e) { LOGGER.warning("Error creating type: " + e); throw new ProcessException("Error creating type: " + e, e); } }
GeometryDescriptor gd = featureCollection.getSchema().getGeometryDescriptor(); if (gd != null) { crs = gd.getCoordinateReferenceSystem(); || featureCollection.getSchema().getDescriptor(fromMeasureAttb) == null) { throw new ProcessException( "The from_measure_attb parameter was not provided or not defined in schema"); || featureCollection.getSchema().getDescriptor(toMeasureAttb) == null) { throw new ProcessException("The to_measure_attb parameter was not provided"); epsg4326 = CRS.decode("EPSG:4326"); } catch (Exception e) { throw new ProcessException("Unknown CRS code: EPSG:4326", e); MathTransform crsTransform = CRS.findMathTransform(crs, epsg4326); while (featureIterator.hasNext()) { SimpleFeature f = (SimpleFeature) featureIterator.next(); if (f.getDefaultGeometryProperty().getValue() == null) continue; DistanceOp op = if (featureIterator != null) featureIterator.close();
DefaultFeatureCollection results = new DefaultFeatureCollection(); try { if (featureCollection == null || featureCollection.size() == 0) { LOGGER.info("No features provided in request"); return results; || featureCollection.getSchema().getDescriptor(fromMeasureAttb) == null) { throw new ProcessException( "The from_measure_attb parameter was not provided or not defined in schema"); || featureCollection.getSchema().getDescriptor(toMeasureAttb) == null) { throw new ProcessException("The to_measure_attb parameter was not provided"); try { featureIterator = featureCollection.features(); Feature feature = featureIterator.next(); Double featureFromMeasure = (Double) feature.getProperty(fromMeasureAttb).getValue(); Double featureToMeasure = (Double) feature.getProperty(toMeasureAttb).getValue(); LengthIndexedLine lengthIndexedLine = new LengthIndexedLine( (Geometry) feature.getDefaultGeometryProperty().getValue()); double featureLength = featureToMeasure - featureFromMeasure; double startOffset = measure - featureFromMeasure; results.add(createTargetFeature(feature, targetFeatureType, point)); } finally { if (featureIterator != null) featureIterator.close();
@Test public void testDefaultGeometry() throws IOException { FeatureTypeInfo featureType = getCatalog().getResourceByName("cdf", "Nulls", FeatureTypeInfo.class); GeometryDescriptor schemaDefaultGeometry = featureType.getFeatureType().getGeometryDescriptor(); FeatureIterator i = featureType.getFeatureSource(null, null).getFeatures().features(); GeometryDescriptor featureDefaultGeometry = i.next().getDefaultGeometryProperty().getDescriptor(); assertNotNull(schemaDefaultGeometry); assertNotNull(featureDefaultGeometry); assertEquals("pointProperty", schemaDefaultGeometry.getLocalName()); assertEquals(schemaDefaultGeometry, featureDefaultGeometry); } }
@Override public FeatureIterator getSortedFeatures(ReferencedEnvelope env, Connection cacheConn) throws Exception { FeatureSource fs = typeInfo.getFeatureSource(); // build the bbox filter GeometryDescriptor geom = fs.getSchema().getGeometryDescriptor(); CoordinateReferenceSystem nativeCrs = geom .getCoordinateReferenceSystem(); FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); if (!CRS.equalsIgnoreMetadata(WGS84, nativeCrs)) env = env.transform(nativeCrs, true); BBOX filter = ff.bbox(geom.getLocalName(), env.getMinX(), env.getMinY(), env.getMaxX(), env.getMaxY(), null); // build an optimized query (only the necessary attributes DefaultQuery q = new DefaultQuery(); q.setFilter(filter); // TODO: enable this when JTS learns how to compute centroids // without triggering the // generation of Coordinate[] out of the sequences... // q.setHints(new Hints(Hints.JTS_COORDINATE_SEQUENCE_FACTORY, // PackedCoordinateSequenceFactory.class)); q.setPropertyNames(new String[] { geom.getLocalName() }); // return the reader return fs.getFeatures(q).features(); }
LOGGER.fine("Querying layer " + schema.getName() + " with bbox: " + envelope); filter = createBBoxFilters(schema, attributes, envelopes); query = new Query(schema.getName().getLocalPart()); query.setFilter(filter); query.setProperties(attributes); processRuleForQuery(styleList, query); query = new Query(schema.getName().getLocalPart()); query.setProperties(attributes); Envelope bounds = source.getBounds(); if (bounds != null && envelope.intersects(bounds)) { LOGGER.log( QueryCapabilities qc = source.getQueryCapabilities(); if (qc != null && !qc.supportsSorting(sortBy)) { throw new IllegalArgumentException( Set<RenderingHints.Key> fsHints = source.getSupportedHints(); SingleCRS crs2D = crs == null ? null : CRS.getHorizontalCRS(crs); MathTransform mt = buildFullTransform(crs2D, mapCRS, worldToScreenTransform); double[] spans =
Query query = new Query(null, filter); query.setCoordinateSystemReproject(getMapContent().getCoordinateReferenceSystem()); FeatureSource featureSource = getLayer().getFeatureSource(); Collection<PropertyDescriptor> descriptors = featureSource.getSchema().getDescriptors(); FeatureCollection queryResult = featureSource.getFeatures(query); FeatureIterator iter = queryResult.features(); while (iter.hasNext()) { Feature f = iter.next(); result.newFeature(f.getIdentifier().getID()); for (PropertyDescriptor desc : descriptors) { Name name = desc.getName(); Object value = f.getProperty(name).getValue(); iter.close();
Query query = new Query(); if (reprojection != null) { if (sourceFeatures.getSchema().getGeometryDescriptor() != null && !this.isReprojectionCrsEqual( this.mappedSource.getSchema().getCoordinateReferenceSystem(), this.reprojection)) { query.setCoordinateSystemReproject(reprojection); query.setFilter(fidFilter); matchingFeatures = this.mappedSource.getFeatures(query); try (FeatureIterator<? extends Feature> iterator = matchingFeatures.features()) { while (iterator.hasNext()) { features.add(iterator.next());
public static Element AbstractFeatureType_encode( Object object, Document document, Element value) { Feature feature = (Feature) object; FeatureType featureType = feature.getType(); String namespace = featureType.getName().getNamespaceURI(); String typeName = featureType.getName().getLocalPart(); Element encoding = document.createElementNS(namespace, typeName); encoding.setAttributeNS(null, "fid", feature.getIdentifier().getID()); return encoding; }
/** * Returns the collection of all values of the dimension attribute, eventually sorted if the * native capabilities allow for it * * @param typeInfo * @param dimension * @throws IOException */ FeatureCollection getDimensionCollection(FeatureTypeInfo typeInfo, DimensionInfo dimension) throws IOException { FeatureSource source = getFeatureSource(typeInfo); // build query to grab the dimension values final Query dimQuery = new Query(source.getSchema().getName().getLocalPart()); dimQuery.setPropertyNames(Arrays.asList(dimension.getAttribute())); return source.getFeatures(dimQuery); }
crs = this.mappedSource.getSchema().getCoordinateReferenceSystem(); } catch (UnsupportedOperationException e) { if (uri != null) { try { target = CRS.decode(uri.toString()); } catch (Exception e) { String msg = "Unable to support srsName: " + uri; query.setMaxFeatures(dataMaxFeatures); sourceFeatures = mappedSource.getFeatures(query); if (reprojection != null) { xpathAttributeBuilder.setCRS(reprojection); if (sourceFeatures.getSchema().getGeometryDescriptor() == null || this.isReprojectionCrsEqual( this.mappedSource.getSchema().getCoordinateReferenceSystem(), this.reprojection)) { query.setCoordinateSystemReproject(null); this.sourceFeatureIterator = sourceFeatures.features();
throws IllegalFilterException, IOException, FactoryException { final FeatureType schema = source.getSchema(); Query query = new Query(schema.getName().getLocalPart()); query.setProperties(Query.ALL_PROPERTIES); String geomName = geometryAttribute.getLocalName(); Filter filter = reprojectSpatialFilter( FF.bbox(FF.property(geomName), queryArea)); query.setFilter(filter); simplifier.setFeatureType(source.getSchema()); Filter simplifiedFilter = (Filter) query.getFilter().accept(simplifier, null); query.setFilter(simplifiedFilter);
public void setQuery(Query query) { this.query = query; columns.clear(); features.clear(); FeatureType ft = layer.getFeatureSource().getSchema(); Collection<PropertyDescriptor> cols = ft.getDescriptors(); Iterator<PropertyDescriptor> ite = cols.iterator(); while (ite.hasNext()) { columns.add(ite.next()); } try { FeatureIterator<SimpleFeature> fi = (FeatureIterator<SimpleFeature>) layer.getFeatureSource().getFeatures(query.getFilter()).features(); while (fi.hasNext()) { features.add(fi.next()); } } catch (Exception ex) { ex.printStackTrace(); } }
final Query query = new Query(fs.getSchema().getName().getLocalPart()); query.setPropertyNames(Arrays.asList(di.getAttribute())); final PropertyName attribute = ff.property(di.getAttribute()); final PropertyIsBetween rangeFilter = ff.literal(range.getMinValue()), ff.literal(range.getMaxValue())); query.setFilter(rangeFilter); query.setMaxFeatures(maxItems); FeatureCollection collection = fs.getFeatures(query); collection.accepts(visitor, null); TreeSet<Object> result = new TreeSet<>(visitor.getUnique()); return result;