SimpleFeatureTypeBuilder.retype( sfc.getSchema(), mixed.getPropertyNames()); ReTypingFeatureCollection retyped = new ReTypingFeatureCollection(sfc, target);
/** * * Takes into account eventual joins * * @param query * @return */ public SimpleFeatureType getFeatureType(Query query) { SimpleFeatureType result; if (query.getPropertyNames() != Query.ALL_NAMES) { result = SimpleFeatureTypeBuilder.retype(featureType, query.getPropertyNames()); } else { result = featureType; } // add back the joined features in case of join if (!query.getJoins().isEmpty()) { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(result); for (Join join : query.getJoins()) { String joinedFeatureAttribute = join.getAlias(); if (joinedFeatureAttribute == null) { joinedFeatureAttribute = join.getTypeName(); } tb.add(joinedFeatureAttribute, SimpleFeature.class); } result = tb.buildFeatureType(); } return result; }
/** * Create a SimpleFeatureType containing just the descriptors indicated. * * @param original SimpleFeatureType * @param types name of types to include in result * @return SimpleFeatureType containing just the types indicated by name */ public static SimpleFeatureType retype(SimpleFeatureType original, String[] types) { return retype(original, Arrays.asList(types)); }
/** * Creates a sub-schema with only the selected attributes * * @param schema * @param query * @return */ static SimpleFeatureType retypeSchema(SimpleFeatureType schema, Query query) { if (query.getPropertyNames() == Query.ALL_NAMES) { return schema; } else { return SimpleFeatureTypeBuilder.retype(schema, query.getPropertyNames()); } }
SimpleFeatureType[] buildQueryAndReturnFeatureTypes( SimpleFeatureType featureType, String[] propertyNames, Filter filter) { SimpleFeatureType[] types = null; if (propertyNames == Query.ALL_NAMES) { return new SimpleFeatureType[] {featureType, featureType}; } else { SimpleFeatureType returnedSchema = SimpleFeatureTypeBuilder.retype(featureType, propertyNames); SimpleFeatureType querySchema = returnedSchema; if (filter != null && !filter.equals(Filter.INCLUDE)) { FilterAttributeExtractor extractor = new FilterAttributeExtractor(featureType); filter.accept(extractor, null); String[] extraAttributes = extractor.getAttributeNames(); if (extraAttributes != null && extraAttributes.length > 0) { List<String> allAttributes = new ArrayList<String>(Arrays.asList(propertyNames)); for (String extraAttribute : extraAttributes) { if (!allAttributes.contains(extraAttribute)) allAttributes.add(extraAttribute); } String[] allAttributeArray = allAttributes.toArray(new String[allAttributes.size()]); querySchema = SimpleFeatureTypeBuilder.retype(getSchema(), allAttributeArray); } } types = new SimpleFeatureType[] {querySchema, returnedSchema}; } return types; }
@Override protected FeatureReader<SimpleFeatureType, SimpleFeature> getReaderInternal(Query query) throws IOException { List<Filter> postFilterList = new ArrayList<Filter>(); List<String> postFilterAttributes = new ArrayList<String>(); DBCursor cursor = toCursor(query, postFilterList, postFilterAttributes); FeatureReader<SimpleFeatureType, SimpleFeature> r = new MongoFeatureReader(cursor, this); if (!postFilterList.isEmpty() && !isAll(postFilterList.get(0))) { r = new FilteringFeatureReader<SimpleFeatureType, SimpleFeature>( r, postFilterList.get(0)); // check whether attributes not present in the original query have been // added to the set of retrieved attributes for the sake of // post-filters; if so, wrap the FeatureReader in a ReTypeFeatureReader if (!postFilterAttributes.isEmpty()) { // build the feature type returned by this query SimpleFeatureType returnedSchema = SimpleFeatureTypeBuilder.retype(getSchema(), query.getPropertyNames()); r = new ReTypeFeatureReader(r, returnedSchema); } } return r; }
SimpleFeatureType getReadSchema(Query q) { if (q.getPropertyNames() == Query.ALL_NAMES) { return getSchema(); } // Step 1: start with requested property names LinkedHashSet<String> attributes = new LinkedHashSet<String>(); attributes.addAll(Arrays.asList(q.getPropertyNames())); Filter filter = q.getFilter(); if (filter != null && !Filter.INCLUDE.equals(filter)) { // Step 2: Add query attributes (if needed) // Step 3: Fill empty XPath with appropriate property names FilterAttributeExtractor fat = new AbsoluteAttributeExtractor(getSchema()); filter.accept(fat, null); attributes.addAll(fat.getAttributeNameSet()); } return SimpleFeatureTypeBuilder.retype(getSchema(), new ArrayList<String>(attributes)); }
private SimpleFeatureCollection getFeatureCollection(Query query, Envelope bounds) throws IOException { try { SimpleFeatureType base = wrapped.getSchema(); SimpleFeatureType alternate = base; if (query.getPropertyNames() != Query.ALL_NAMES) { alternate = SimpleFeatureTypeBuilder.retype(base, query.getPropertyNames()); if (alternate.equals(base)) alternate = base; } return new CachingFeatureCollection(bounds, base, alternate, query); } catch (Exception e) { throw new DataSourceException( "Error occurred extracting features from the spatial index", e); } }
/** * Returns the feature type or the schema of the feature source. * * <p>This method delegates to {@link #buildFeatureType()}, which must be implemented by * subclasses. The result is cached in {@link ContentState#getFeatureType()}. */ public final SimpleFeatureType getSchema() { // check schema override if (schema != null) { return schema; } SimpleFeatureType featureType = getAbsoluteSchema(); // this may be a view if (query != null && query.getPropertyNames() != Query.ALL_NAMES) { synchronized (this) { if (schema == null) { schema = SimpleFeatureTypeBuilder.retype(featureType, query.getPropertyNames()); } } return schema; } return featureType; }
SimpleFeatureType getResultSchema(Query q) { if (q.getPropertyNames() == null) { return getSchema(); } else { return SimpleFeatureTypeBuilder.retype(getSchema(), q.getPropertyNames()); } }
SimpleFeatureType ft = SimpleFeatureTypeBuilder.retype(features.getSchema(), names); if (!(ft.equals(features.getSchema()))) { features = new ReTypingFeatureCollection(features, ft);
@Override public SimpleFeatureCollection getGranules(Query q) throws IOException { Query renamed = renameQuery(q); SimpleFeatureCollection granules = delegate.getGranules(renamed); SimpleFeatureType targetSchema = this.schema; if (q.getPropertyNames() != Query.ALL_NAMES) { targetSchema = SimpleFeatureTypeBuilder.retype(schema, q.getPropertyNames()); } return new ReTypingFeatureCollection(granules, targetSchema); }
/** * Configure expected * * @param origional * @param query * @return */ public static SimpleFeatureType retype(SimpleFeatureType origional, Query query) { CoordinateReferenceSystem crs = null; if (query.getCoordinateSystem() != null) { crs = query.getCoordinateSystem(); } if (query.getCoordinateSystemReproject() != null) { crs = query.getCoordinateSystemReproject(); } return retype(origional, query.getPropertyNames(), crs); }
protected void setUp() throws Exception { super.setUp(); data = new MemoryDataStore(); data.addFeatures(roadFeatures); // Override river to use CRS riverType = SimpleFeatureTypeBuilder.retype(super.riverType, CRS.decode("EPSG:4326")); riverBounds = new ReferencedEnvelope(super.riverBounds, CRS.decode("EPSG:4326")); riverFeatures = new SimpleFeature[super.riverFeatures.length]; for (int i = 0; i < riverFeatures.length; i++) { riverFeatures[i] = SimpleFeatureBuilder.retype(super.riverFeatures[i], riverType); } data.addFeatures(riverFeatures); }
protected void setUp() throws Exception { super.setUp(); data = new MemoryDataStore(); data.addFeatures(roadFeatures); // Override river to use CRS riverType = SimpleFeatureTypeBuilder.retype(super.riverType, CRS.decode("EPSG:4326")); riverBounds = new ReferencedEnvelope(super.riverBounds, CRS.decode("EPSG:4326")); riverFeatures = new SimpleFeature[super.riverFeatures.length]; for (int i = 0; i < riverFeatures.length; i++) { riverFeatures[i] = SimpleFeatureBuilder.retype(super.riverFeatures[i], riverType); } data.addFeatures(riverFeatures); decorator = new MyDecoratingDataStore(data); }
protected void setUp() throws Exception { super.setUp(); data = new MemoryDataStore(); data.addFeatures(roadFeatures); SimpleFeatureType riverTypeWithCrs = SimpleFeatureTypeBuilder.retype(riverType, CRS.decode("EPSG:4326")); data.addFeature(SimpleFeatureBuilder.retype(riverFeatures[0], riverTypeWithCrs)); riverBounds = new ReferencedEnvelope(riverFeatures[0].getBounds()); }
@Override public boolean endObject() throws ParseException, IOException { super.endObject(); if (delegate instanceof FeatureHandler) { feature = ((FeatureHandler) delegate).getValue(); if (feature != null) { // check for a null builder, if it is null set it with the feature type // from this feature if (builder == null) { SimpleFeatureType featureType = feature.getFeatureType(); if (featureType.getCoordinateReferenceSystem() == null && crs != null) { // retype with a crs featureType = SimpleFeatureTypeBuilder.retype(featureType, crs); } builder = new SimpleFeatureBuilder(featureType); } ((FeatureHandler) delegate).init(); // we want to pause at this point return false; } } else if (delegate instanceof CRSHandler) { crs = ((CRSHandler) delegate).getValue(); if (crs != null) { delegate = NULL; } } return true; }
public void testMaintainDefaultGeometryOnRetype() { builder.setName("testGeometries"); builder.add("geo1", Point.class, DefaultGeographicCRS.WGS84); builder.add("geo2", Polygon.class, DefaultGeographicCRS.WGS84); builder.setDefaultGeometry("geo1"); SimpleFeatureType type = builder.buildFeatureType(); // performing an attribute selection, even changing order, should not change // the default geometry, that had a special meaning in the original source SimpleFeatureType retyped = SimpleFeatureTypeBuilder.retype(type, new String[] {"geo2", "geo1"}); assertEquals("geo1", retyped.getGeometryDescriptor().getLocalName()); }
public void testRetypeGeometryless() { builder.setName("testGeometryless"); builder.add("geo1", Point.class, DefaultGeographicCRS.WGS84); builder.add("integer", Integer.class); builder.setDefaultGeometry("geo1"); SimpleFeatureType type = builder.buildFeatureType(); // performing an attribute selection, even changing order, should not change // the default geometry, that had a special meaning in the original source SimpleFeatureType retyped = SimpleFeatureTypeBuilder.retype(type, new String[] {"integer"}); assertNotNull(retyped); assertNull(retyped.getGeometryDescriptor()); assertEquals(1, retyped.getAttributeCount()); assertEquals("integer", retyped.getAttributeDescriptors().get(0).getLocalName()); }
@Override protected void connect() throws Exception { super.connect(); // we need to use the type builder because the pk has min occurs = 1 on Oracle AttributeTypeBuilder atb = new AttributeTypeBuilder(); atb.setMinOccurs(isPkNillable() ? 0 : 1); atb.setMaxOccurs(1); atb.setNillable(isPkNillable()); atb.setName(FID); atb.setBinding(Integer.class); AttributeDescriptor fidDescriptor = atb.buildDescriptor(FID); SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setNamespaceURI(dataStore.getNamespaceURI()); tb.setName(LAKESVIEW); tb.add(fidDescriptor); tb.add(ID, Integer.class); tb.add(GEOM, Polygon.class, (CoordinateReferenceSystem) null); tb.add(NAME, String.class); lakeViewSchema = tb.buildFeatureType(); lakeViewPkSchema = tb.retype(lakeViewSchema, new String[] {ID, GEOM, NAME}); }