/** @see net.refractions.udig.project.internal.command.MapCommand#run() */ @SuppressWarnings("deprecation") public void run(IProgressMonitor monitor) throws Exception { monitor.beginTask(Messages.WriteFeatureChangesCommand_runTask, 3); SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 1); editFeature = featureProvider.get(subProgressMonitor); subProgressMonitor.done(); store = storeProvider.get(subProgressMonitor); if (editFeature == null || store == null) { noChange = true; return; } FeatureType featureType = editFeature.getFeatureType(); FilterFactory factory = FilterFactoryFinder.createFilterFactory(); subProgressMonitor = new SubProgressMonitor(monitor, 1); subProgressMonitor.done(); filter = factory.createFidFilter(editFeature.getID()); FeatureCollection results = store.getFeatures(filter); FeatureIterator reader = results.features(); try { if (reader.hasNext()) { try { store.modifyFeatures( featureType.getAttributeTypes(), editFeature.getAttributes(new Object[featureType.getAttributeCount()]), filter); } catch (Exception e) { ProjectPlugin.log("", e); // $NON-NLS-1$ noChange = true; } } else { added = true; store.addFeatures( new StaticFeatureCollection(Collections.singleton(editFeature), featureType)); } } finally { if (reader != null) reader.close(); } }
/** * Create a {@link Filter} that selects features from the test table whose description contains * the text specified in the argument (case-insensitive). * * @param descriptionContainsText text that description column must contain * @return filter to select features containing text in their description */ private Filter buildFilter(String descriptionContainsText) { FilterFactory filterFactory = new RegfuncFilterFactoryImpl(); // Programmatically build a filter like this fragment from an OGC WFS 1.1.0 Query: // // <ogc:Filter> // <ogc:PropertyIsEqualTo> // <ogc:Function name="contains_text"> // <ogc:PropertyName> // gsml:specification/gsml:GeologicUnit/gml:description // </ogc:PropertyName> // <ogc:Literal>basalt</ogc:Literal> // </ogc:Function> // <ogc:Literal>1</ogc:Literal> // </ogc:PropertyIsEqualTo> // </ogc:Filter> // // Now step by step: // // Build <ogc:PropertyName> Expression property = filterFactory.property(DESCRIPTION_COLUMN_NAME); // Build <ogc:Literal>basalt</ogc:Literal> equivalent Expression string = filterFactory.createLiteralExpression(descriptionContainsText); // Build <ogc:Function name="contains_text"> equivalent and set its arguments Expression function = filterFactory.function(TEST_FUNCTION_NAME, property, string); // Sanity check assertEquals(RegisteredFunction.class, function.getClass()); // Build <ogc:Literal>1</ogc:Literal> Expression one = filterFactory.createLiteralExpression(TEST_FUNCTION_RETURN_TRUE); // Build <ogc:PropertyIsEqualTo>, set its arguments, and return it return filterFactory.equals(function, one); }
/** * reads the completechain dataset * * @throws Exception */ public void getrows() throws Exception { // SELECT ... FROM ... WHERE // (statel=state and countyl=county) OR (stater=state and countyr=county ) FilterFactory ff = FilterFactory.createFilterFactory(); CompareFilter cf1 = ff.createCompareFilter(FilterType.COMPARE_EQUALS); cf1.addLeftValue(ff.createAttributeExpression(null, "statel")); cf1.addRightValue(ff.createLiteralExpression(state)); CompareFilter cf2 = ff.createCompareFilter(FilterType.COMPARE_EQUALS); cf2.addLeftValue(ff.createAttributeExpression(null, "countyl")); cf2.addRightValue(ff.createLiteralExpression(county)); LogicFilter and1 = ff.createLogicFilter(cf1, cf2, Filter.LOGIC_AND); CompareFilter cf3 = ff.createCompareFilter(FilterType.COMPARE_EQUALS); cf3.addLeftValue(ff.createAttributeExpression(null, "stater")); cf3.addRightValue(ff.createLiteralExpression(state)); CompareFilter cf4 = ff.createCompareFilter(FilterType.COMPARE_EQUALS); cf4.addLeftValue(ff.createAttributeExpression(null, "countyr")); cf4.addRightValue(ff.createLiteralExpression(county)); LogicFilter and2 = ff.createLogicFilter(cf3, cf4, Filter.LOGIC_AND); LogicFilter or = ff.createLogicFilter(and1, and2, Filter.LOGIC_OR); String[] ps = new String[] {"wkb_geometry", "statel", "countyl", "stater", "countyr"}; Query q = new DefaultQuery("county_boundary", or, ps); FeatureReader fr = ds.getFeatureReader(q, new DefaultTransaction()); while (fr.hasNext()) { Feature f = fr.next(); if (!alreadyThere(f.getDefaultGeometry())) lines.add(f.getDefaultGeometry()); } fr.close(); }