SecuredSimpleFeatureCollection( FeatureCollection<SimpleFeatureType, SimpleFeature> delegate, WrapperPolicy policy) { super(delegate, policy); if (policy.getLimits() instanceof VectorAccessLimits) { List<PropertyName> properties = ((VectorAccessLimits) policy.getLimits()).getReadAttributes(); if (properties == null) { this.readSchema = getSchema(); } else { List<String> names = new ArrayList<String>(); for (PropertyName property : properties) { names.add(property.getPropertyName()); } String[] nameArray = (String[]) names.toArray(new String[names.size()]); try { this.readSchema = DataUtilities.createSubType(getSchema(), nameArray); } catch (SchemaException e) { // should just not happen throw new RuntimeException(e); } } } else { this.readSchema = getSchema(); } }
/** * @param schemaDef * @param crs * @return */ public static SimpleFeatureType createFeatureType( String schemaName, String schemaDef, CoordinateReferenceSystem crs) { SimpleFeatureType indexSchema = null; if (schemaDef == null) { throw new IllegalArgumentException( "Unable to create feature type from null definition!"); } schemaDef = schemaDef.trim(); // get the schema try { indexSchema = DataUtilities.createType(schemaName, schemaDef); indexSchema = DataUtilities.createSubType( indexSchema, DataUtilities.attributeNames(indexSchema), crs); } catch (Throwable e) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, e.getLocalizedMessage(), e); indexSchema = null; } return indexSchema; }
/** * Return a specific {@link FeatureTypeMapper} by parsing mapping properties contained within * the specified {@link Properties} object * * @param featureType * @return * @throws Exception */ protected FeatureTypeMapper getFeatureTypeMapper(final Properties props) throws Exception { SimpleFeatureType indexSchema; // Creating schema indexSchema = DataUtilities.createType(props.getProperty(NAME), props.getProperty(SCHEMA)); CoordinateReferenceSystem crs = CRS.parseWKT(props.getProperty(COORDINATE_REFERENCE_SYSTEM)); indexSchema = DataUtilities.createSubType( indexSchema, DataUtilities.attributeNames(indexSchema), crs); return getFeatureTypeMapper(indexSchema); }
SimpleFeatureType querySchema = DataUtilities.createSubType(fullSchema, attNames); return querySchema; } catch (SchemaException ex) {
subsetType = DataUtilities.createSubType((SimpleFeatureType) realType, properties); } catch (SchemaException e) { throw new DataSourceException(e);
if (propertyNames != null && propertyNames.length > 0) { try { queryType = DataUtilities.createSubType(queryType, propertyNames); } catch (SchemaException e) { throw new DataSourceException(e); try { queryType = DataUtilities.createSubType( queryType, propertyNames, coordinateSystemReproject); } catch (SchemaException e) {
/** * Create a derived FeatureType * * @param featureType Original feature type to derive from. * @param properties If null, every property of the featureType in input will be used * @param override Intended CoordinateReferenceSystem, if null original will be used * @return derived FeatureType * @throws SchemaException */ public static SimpleFeatureType createSubType( SimpleFeatureType featureType, String[] properties, CoordinateReferenceSystem override) throws SchemaException { URI namespaceURI = null; if (featureType.getName().getNamespaceURI() != null) { try { namespaceURI = new URI(featureType.getName().getNamespaceURI()); } catch (URISyntaxException e) { throw new RuntimeException(e); } } return createSubType( featureType, properties, override, featureType.getTypeName(), namespaceURI); } /**
if (featureType instanceof SimpleFeature) { simpleFeatureType = DataUtilities.createSubType((SimpleFeatureType) featureType, properties); } else { SimpleFeatureTypeBuilder build = new SimpleFeatureTypeBuilder();
public SimpleFeatureType getQueryType(Query query) throws IOException { final String typeName = query.getTypeName(); final String propertyNames[] = query.getPropertyNames(); final FeatureTypeInfo typeInfo = typeInfoCache.getFeatureTypeInfo(typeName); final SimpleFeatureType completeSchema = typeInfo.getFeatureType(); SimpleFeatureType featureType = completeSchema; if (!query.retrieveAllProperties() || query.getCoordinateSystem() != null) { try { featureType = DataUtilities.createSubType( featureType, propertyNames, query.getCoordinateSystem()); } catch (SchemaException e) { LOGGER.log(Level.FINEST, e.getMessage(), e); throw new DataSourceException("Could not create Feature Type for query", e); } } return featureType; }
} else { schema = DataUtilities.createSubType( featureSource.getSchema(), query.getPropertyNames()); DataUtilities.createSubType( originalType, query.getPropertyNames(),
DataUtilities.createSubType( origionalType, query.getPropertyNames(), cs, query.getTypeName(), null);
DataUtilities.createSubType( indexSchema, DataUtilities.attributeNames(indexSchema), actualCRS); if (actualCRS != null) {
public void testCreateSubTypeWithPropertyNotMatchingAnAttributeDescriptor() throws Exception { // creating a sub type with a property that doesn't map to an attribute descriptor SimpleFeatureType before = DataUtilities.createType("cities", "the_geom:Point:srid=4326,name:String"); SimpleFeatureType after = DataUtilities.createSubType( before, new String[] {"the_geom", "name", "not_existing"}); // the not_existing property should have been ignored assertEquals(2, after.getAttributeCount()); assertNotNull(after.getDescriptor("the_geom")); assertNotNull(after.getDescriptor("name")); }
public void testCreateSubType() throws Exception { SimpleFeatureType before = DataUtilities.createType("cities", "the_geom:Point:srid=4326,name:String"); SimpleFeatureType after = DataUtilities.createSubType(before, new String[] {"the_geom"}); assertEquals(1, after.getAttributeCount()); URI here = new URI("http://localhost/"); after = DataUtilities.createSubType( before, new String[] {"the_geom"}, DefaultGeographicCRS.WGS84, "now", here); assertEquals(here.toString(), after.getName().getNamespaceURI()); DataUtilities.createType( "cities", "the_geom:Point:srid=4326,name:String,population:Integer"); after = DataUtilities.createSubType(before, new String[] {"the_geom"}); assertEquals(before.getGeometryDescriptor(), after.getGeometryDescriptor()); DataUtilities.createType( "cities", "the_geom:Point:srid=4326,name:String,population:Integer"); after = DataUtilities.createSubType(before, new String[] {"the_geom"}); assertEquals(before.getGeometryDescriptor(), after.getGeometryDescriptor());
SimpleFeatureType before = tb.buildFeatureType(); SimpleFeatureType after = DataUtilities.createSubType( before, new String[] {"name", "the_geom1", "the_geom3"}); assertEquals(3, after.getAttributeCount()); DataUtilities.createSubType( before, new String[] {"name", "the_geom1", "the_geom3"}, DataUtilities.createSubType( before, new String[] {"name", "the_geom1", "the_geom2"}); assertEquals(3, after.getAttributeCount()); DataUtilities.createSubType( before, new String[] {"name", "the_geom1", "the_geom2"},
private SimpleFeatureType tryForceKnownCRS(SimpleFeatureType orig) { SimpleFeatureType override = orig; GeometryDescriptor geometryDescriptor = orig.getGeometryDescriptor(); CoordinateReferenceSystem crs = null; try { crs = findIdentifier(geometryDescriptor); override = DataUtilities.createSubType(orig, null, crs); } catch (Exception e) { LOG.warn("Error looking for known identifier for CRS " + crs, e); } return override; }
public @Test void testAddFeaturesSubType() throws Exception { FeatureCollection<SimpleFeatureType, SimpleFeature> collection; SimpleFeatureType subType = DataUtilities.createSubType(pointsType, new String[] { "ip" }); Feature newFeature = feature(subType, "subtype.1", new Integer(-1)); newFeature.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE); collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) newFeature)); List<FeatureId> addFeatures = points.addFeatures(collection); assertEquals(3, addFeatures.size()); assertEquals("subtype.1", addFeatures.get(2).getID()); }
public @Test void testAddFeaturesSubType() throws Exception { FeatureCollection<SimpleFeatureType, SimpleFeature> collection; SimpleFeatureType subType = DataUtilities.createSubType(pointsType, new String[] { "ip" }); Feature newFeature = feature(subType, "subtype.1", new Integer(-1)); newFeature.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE); collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) newFeature)); List<FeatureId> addFeatures = points.addFeatures(collection); assertEquals(3, addFeatures.size()); assertEquals("subtype.1", addFeatures.get(2).getID()); }
@Test public void testAdaptEmptySchema() throws Exception { CoordinateReferenceSystem crs = pointsType.getCoordinateReferenceSystem(); SimpleFeatureType emptySchema = DataUtilities.createSubType(pointsType, new String[0]); AutoCloseableIterator<NodeRef> nodes = AutoCloseableIterator.emptyIterator(); MaterializedIndexFeatureIterator iterator; iterator = MaterializedIndexFeatureIterator.create(emptySchema, nodes, geometryFactory, crs); NodeRef nodeRef = nodeRef((SimpleFeature) points1); SimpleFeature feature = iterator.adapt(nodeRef); assertNotNull(feature); assertEquals(emptySchema, feature.getFeatureType()); Envelope expectedBounds = nodeRef.bounds().get(); BoundingBox fbounds = feature.getBounds(); assertEquals(expectedBounds, fbounds); assertEquals(crs, fbounds.getCoordinateReferenceSystem()); }
@Test public void testAdaptEmptySchema() throws Exception { CoordinateReferenceSystem crs = pointsType.getCoordinateReferenceSystem(); SimpleFeatureType emptySchema = DataUtilities.createSubType(pointsType, new String[0]); AutoCloseableIterator<NodeRef> nodes = AutoCloseableIterator.emptyIterator(); MaterializedIndexFeatureIterator iterator; iterator = MaterializedIndexFeatureIterator.create(emptySchema, nodes, geometryFactory, crs); NodeRef nodeRef = nodeRef((SimpleFeature) points1); SimpleFeature feature = iterator.adapt(nodeRef); assertNotNull(feature); assertEquals(emptySchema, feature.getFeatureType()); Envelope expectedBounds = nodeRef.bounds().get(); BoundingBox fbounds = feature.getBounds(); assertEquals(expectedBounds, fbounds); assertEquals(crs, fbounds.getCoordinateReferenceSystem()); }