Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [udig-devel] Pattern for updating features based on attribute change

Hi Miles,

On Fri, Aug 13, 2010 at 9:47 PM, Miles Parker <milesparker@xxxxxxxxx> wrote:
> Hi,
> I hope this is the appropriate place to ask this question -- not sure if it
> is a geotools issue or if that even matters.
> I got the map viewer (IViewPart implementation) working well, and I was able
> to get styles to update dynamically, so I think I more or less have the
> basic patterns worked out. But I'm having trouble figuring out the recipe
> for my key use case:
> "Change feature attributes dynamically and have those changes reflected on
> the map."

I will try to stop here at first and point you to this:
http://udig.refractions.net/confluence/display/DEV/4+Edit+Commands
which is part of:
http://udig.refractions.net/confluence/display/DEV/04+Commands

It shows how to delete a feature but I remember there is also a create
feature and set attribute/geometry. Just look into the Type Hierarchy
and you will have them.

Hope that helps, else let me know,
Ciao
Andrea




> I have the first part, in that I figured out how that the ShapeFileDataStore
> was read only. So I created a MemoryDataStore for that. I gather that that
> is slow, but I couldn't see a better way of making the shape file
> modifiable. Now, I can get the attributes to change to new values. As I
> mentioned, I can also get a map to update regularly. But I can't get the
> values to hook up with the map.
> First, I load in the shape file like so:
>             URL resourceId = new URL(
>             "file:///blah/blah/shapefiles/blah/foo.shp");
>             ICatalog localCatalog =
> CatalogPlugin.getDefault().getLocalCatalog();
>             List<IService> services =
> CatalogPlugin.getDefault().getServiceFactory().createService(resourceId);
>             for (IService service : services) {
>                 localCatalog.add(service);
>                 for (IGeoResource resource : service.resources(null)) {
>                     FeatureSource<SimpleFeatureType, SimpleFeature>
> featureSource = resource
>                     .resolve(FeatureSource.class, null);
>
>
>
> Then, I copy the feature into the memory store (I think..)
>                         FeatureCollection<SimpleFeatureType, SimpleFeature>
> shapeFeatures = featureSource.getFeatures();
>                         features = DataUtilities.collection(shapeFeatures);
>                         MemoryDataStore mds = new MemoryDataStore(features);
>                         mdsStore =
> mds.getFeatureSource(featureSource.getName());
>
> Now, I can add the original resource into the map..and as I say form that it
> displays properly, I can modify styles, etc..
>                         Layer createLayer =
> getMap().getLayerFactory().createLayer(resource);
>                         getMap().getLayersInternal().add(createLayer);
>                         createLayer.getStyleBlackboard().put(SLDContent.ID,
> style);
> Here's where I'm stuck, but perhaps there is a better approach altogether..
> I can't actually figure out how to get an IGeoResource for the MapDataStore
> to add it into the set of layers. I mean, this has to be straightforward
> but..?
> thanks for any hints,
> Miles
>
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel
>
>


Back to the top