use of org.geotoolkit.filter.FilterFactory2 in project geotoolkit by Geomatys.
the class PatternSymbolizerTest method testXml.
/**
* Test Jaxb xml support.
*/
@Test
public void testXml() throws JAXBException, IOException {
final MutableStyleFactory SF = GO2Utilities.STYLE_FACTORY;
final FilterFactory2 FF = GO2Utilities.FILTER_FACTORY;
final Map<Expression, List<Symbolizer>> ranges = new LinkedHashMap<>();
ranges.put(FF.literal(-1000), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.BLUE), null)));
ranges.put(FF.literal(-500), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.RED), null)));
ranges.put(FF.literal(-100), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.GREEN), null)));
ranges.put(FF.literal(100), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.YELLOW), null)));
ranges.put(FF.literal(1000), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.GRAY), null)));
final PatternSymbolizer ps = new PatternSymbolizer(FF.literal(0), ranges, ThreshholdsBelongTo.PRECEDING);
final MutableStyle style = GO2Utilities.STYLE_FACTORY.style(ps);
final Path path = Files.createTempFile("xml", ".xml");
IOUtilities.deleteOnExit(path);
new StyleXmlIO().writeStyle(path, style, Specification.StyledLayerDescriptor.V_1_1_0);
}
use of org.geotoolkit.filter.FilterFactory2 in project geotoolkit by Geomatys.
the class FilterConverterTest method buildResultFilter.
private Filter buildResultFilter() throws FactoryException {
FilterFactory2 ff = FilterUtilities.FF;
final Filter filter1 = ff.equal(ff.property(NamesExt.create("name")), ff.literal("Smith"));
final Filter filter2 = ff.equal(ff.property(NamesExt.create("age")), ff.literal(30));
return ff.and(filter1, filter2);
}
use of org.geotoolkit.filter.FilterFactory2 in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method testFidFilter.
@Test
public void testFidFilter() throws Exception {
File shpFile = copyShapefiles(STATE_POP);
URL url = shpFile.toURI().toURL();
IndexedShapefileFeatureStore ds = new IndexedShapefileFeatureStore(url.toURI(), true, true, IndexType.NONE, null);
FeatureCollection features = ds.createSession(true).getFeatureCollection(new Query(ds.getName()));
FeatureIterator indexIter = features.iterator();
Set<String> expectedFids = new HashSet<>();
final Filter fidFilter;
try {
FilterFactory2 ff = FilterUtilities.FF;
Set<Filter<Object>> fids = new HashSet<>();
while (indexIter.hasNext()) {
Feature newFeature = indexIter.next();
String id = FeatureExt.getId(newFeature).getIdentifier();
expectedFids.add(id);
fids.add(ff.resourceId(id));
}
switch(fids.size()) {
case 0:
fidFilter = Filter.exclude();
break;
case 1:
fidFilter = fids.iterator().next();
break;
default:
fidFilter = ff.or(fids);
break;
}
} finally {
indexIter.close();
}
Set<String> actualFids = new HashSet<>();
{
indexIter = ds.getFeatureReader(Query.filtered(ds.getName().toString(), fidFilter));
while (indexIter.hasNext()) {
Feature next = indexIter.next();
String id = FeatureExt.getId(next).getIdentifier();
actualFids.add(id);
}
indexIter.close();
}
TreeSet<String> lackingFids = new TreeSet<>(expectedFids);
lackingFids.removeAll(actualFids);
TreeSet<String> unexpectedFids = new TreeSet<>(actualFids);
unexpectedFids.removeAll(expectedFids);
String lacking = String.valueOf(lackingFids);
String unexpected = String.valueOf(unexpectedFids);
String failureMsg = "lacking fids: " + lacking + ". Unexpected ones: " + unexpected;
assertEquals(failureMsg, expectedFids.size(), actualFids.size());
assertEquals(failureMsg, expectedFids, actualFids);
}
use of org.geotoolkit.filter.FilterFactory2 in project geotoolkit by Geomatys.
the class RegroupFeatureCollection method filter.
private Query filter(final Object attributeValue) throws FactoryException, MismatchedDimensionException, TransformException {
final FilterFactory2 ff = FilterUtilities.FF;
final Filter filter = ff.equal(ff.property(regroupAttribute), ff.literal(attributeValue));
return Query.filtered("filter", filter);
}
use of org.geotoolkit.filter.FilterFactory2 in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method testWipesOutInvalidFidsFromFilters.
/**
* Issueing a request, whether its a query, update or delete, with a fid filter where feature
* ids match the {@code <typeName>.<number>} structure but the {@code <typeName>} part does not
* match the actual typeName, shoud ensure the invalid fids are ignored
*
* @throws java.lang.Exception
*/
@Test
public void testWipesOutInvalidFidsFromFilters() throws Exception {
final IndexedShapefileFeatureStore ds = createDataStore();
final Session session = ds.createSession(true);
final String validFid1, validFid2, invalidFid1, invalidFid2;
try (FeatureIterator features = ds.getFeatureReader(new Query(ds.getName()))) {
validFid1 = FeatureExt.getId(features.next()).getIdentifier();
validFid2 = FeatureExt.getId(features.next()).getIdentifier();
invalidFid1 = "_" + FeatureExt.getId(features.next()).getIdentifier();
invalidFid2 = FeatureExt.getId(features.next()).getIdentifier() + "abc";
}
FilterFactory2 ff = FilterUtilities.FF;
Set<Filter<Object>> ids = new HashSet<>();
ids.add(ff.resourceId(validFid1));
ids.add(ff.resourceId(validFid2));
ids.add(ff.resourceId(invalidFid1));
ids.add(ff.resourceId(invalidFid2));
Filter fidFilter = ff.or(ids);
final FeatureType schema = ds.getFeatureType();
final String typeName = schema.getName().tip().toString();
// get a property of type String to update its value by the given filter
assertEquals(2, count(ds, typeName, fidFilter));
session.updateFeatures(ds.getName().toString(), fidFilter, Collections.singletonMap("f", "modified"));
session.commit();
Filter modifiedFilter = ff.equal(ff.property("f"), ff.literal("modified"));
assertEquals(2, count(ds, typeName, modifiedFilter));
final long initialCount = ds.getCount(new Query(ds.getName()));
session.removeFeatures(ds.getName().toString(), fidFilter);
session.commit();
final long afterCount = ds.getCount(new Query(ds.getName()));
assertEquals(initialCount - 2, afterCount);
}
Aggregations