[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: R: [udig-devel] Modify Attributes and geometry
|
I made a test case and found a problem I recently introduced and that
might have caused some problems for you if you are running against head
and not against 1.0.0.
I've attached a unit test that modifies an attribute in a features and
commits it.
Let me know if you still have problems. Oh if you are running against
head I'd recommend updating.
Jesse
On Tue, 2005-28-06 at 08:36 -0700, Jesse Eichar wrote:
> Could you tell me what you are trying to do? As I understand it (and
> I've done so) you should be able to ask the layer for its feature store
> and use that store to modify the attributes and the geometry. If you
> want to commit, send the commit command to the map.
>
> I will send you an example in 10 minutes or so.
>
> Jesse
>
> On Tue, 2005-28-06 at 11:18 +0200, d.venturini wrote:
> > Thank you very much Jody for your interest. I'm removing the statement
> >
> > transaction and I'm using map's transaction to commit changes but UDig
> >
> > doesn't work as expected too...
> >
> > I cannot create another FeatureSource because when I changes
> > attributes in
> >
> > new FeatureSource must be matched with the first one diplayed in
> > current
> >
> > layer of Map...
> >
> >
> >
> > Thank's for any other suggestions...
> >
> >
> >
> > Davide.
> >
> >
> > _______________________________________________
> > User-friendly Desktop Internet GIS (uDig)
> > http://udig.refractions.net
> > http://lists.refractions.net/mailman/listinfo/udig-devel
>
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel
package net.refractions.udig.project.internal.impl;
import java.net.URL;
import java.util.ArrayList;
import junit.framework.TestCase;
import net.refractions.udig.catalog.CatalogPlugin;
import net.refractions.udig.catalog.IService;
import net.refractions.udig.catalog.memory.MemoryService;
import net.refractions.udig.catalog.memory.internal.MemoryServiceExtensionImpl;
import net.refractions.udig.project.command.EditCommandFactory;
import net.refractions.udig.project.internal.Layer;
import net.refractions.udig.project.internal.Map;
import net.refractions.udig.project.internal.ProjectFactory;
import net.refractions.udig.project.internal.ProjectPlugin;
import org.geotools.data.DataUtilities;
import org.geotools.data.FeatureSource;
import org.geotools.data.FeatureStore;
import org.geotools.data.memory.MemoryDataStore;
import org.geotools.feature.Feature;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.FeatureType;
import org.geotools.filter.FilterFactory;
public class EditFeatureTest extends TestCase {
private static final Object MODIFIED_VALUE = "modifiedValue";
private static final Object ORIGINAL_VALUE = "secondFeature";
MemoryDataStore ds;
private IService service;
private Map map;
@SuppressWarnings("deprecation")
protected void setUp() throws Exception {
FeatureType ft=DataUtilities.createType("testType", "*geom:Geometry,name:String");
Feature[] features=new Feature[4];
features[0]=ft.create(new Object[]{null, "firstFeature"}, "1");
features[1]=ft.create(new Object[]{null, ORIGINAL_VALUE}, "2");
features[2]=ft.create(new Object[]{null, "thirdFeature"}, "3");
features[3]=ft.create(new Object[]{null, "fourthFeature"}, "4");
URL url=MemoryService.URL;
service=new MemoryServiceExtensionImpl().createService(url, new MemoryServiceExtensionImpl().createParams(url));
CatalogPlugin.getDefault().getLocalCatalog().add(service);
map=ProjectFactory.eINSTANCE.createMap(ProjectPlugin.getPlugin().getProjectRegistry().getDefaultProject(),
"testMap", new ArrayList<Layer>());
ds=service.resolve(MemoryDataStore.class, null);
ds.addFeatures(features);
map.getLayersInternal().add(map.getLayerFactory().createLayer( service.members(null).get(0)));
}
@Override
protected void tearDown() throws Exception {
CatalogPlugin.getDefault().getLocalCatalog().remove(service);
}
public void testSetFeatureAttribute() throws Exception{
FeatureStore store=map.getLayersInternal().get(0).getResource(FeatureStore.class, null);
FilterFactory factory=FilterFactory.createFilterFactory();
FeatureCollection collection=store.getFeatures(factory.createFidFilter("2"));
FeatureIterator iter = collection.features();
assertEquals(ORIGINAL_VALUE, iter.next().getAttribute(1));
collection.close(iter);
store.modifyFeatures(store.getSchema().getAttributeType(1), MODIFIED_VALUE, factory.createFidFilter("2") );
//not committed so other featurestores should not get modified value
FeatureSource dsSource= ds.getFeatureSource("testType");
collection=dsSource.getFeatures(factory.createFidFilter("2"));
iter = collection.features();
assertEquals(ORIGINAL_VALUE, iter.next().getAttribute(1));
collection.close(iter);
//layer featureStore has transactions so should have new value
collection=store.getFeatures(factory.createFidFilter("2"));
iter = collection.features();
assertEquals(MODIFIED_VALUE, iter.next().getAttribute(1));
collection.close(iter);
//Create and send a commit command
map.sendCommandASync(EditCommandFactory.getInstance().createCommitCommand());
//Now is committed so all FeatureSources should have the new value
collection=dsSource.getFeatures(factory.createFidFilter("2"));
iter = collection.features();
assertEquals(MODIFIED_VALUE, iter.next().getAttribute(1));
collection.close(iter);
}
}