[udig-devel] Save programatically created layer

Jesse Eichar jeichar at refractions.net
Fri Feb 22 09:06:16 PST 2008


I'm a little curious about why the editor isn't showing dirty for you  
since the layer is a temporary layer.  I will try to look into the  
problem.  But if you find out before me please let me know.

With regards to FIDS,  you are out of luck because the Datastore API  
give the datastores control over the FIDS.  The end user has not  
choice.  The only option is to have an Attribute on the feature that  
is your fid essentially.


Le 20-Feb-08 à 11:16 AM, ragga doll a écrit :

> Hello,
>
> I try to open the map before adding a layer with  
> "ApplicationGIS.openMap(map, true) ;" but the menu entries aren't  
> still enable and it takes about 10s to add 8 little features to the  
> layer ...
>
> By the way, I've tried an other solution : add the feature after  
> creating the layer, menu entries are enable but there are still  
> problems :
>
> _ about 10s to do the job
> _ the feature id is changed when :  
> resource.resolve( FeatureStore.class,  
> progressmonitor ).addFeatures(afeatCollection) ; and i don't want  
> to, because i want to manage FID (actually the features are some  
> kind of clone)
>
> How can I add feature without changed their FID ?
>
> Code :
>
> //menu entries are not enable and takes 10s to interact with the layer
>
> public static Layer CreateNewLayer(Vector<Feature> vf, Map map,  
> String name, java.awt.Color color, IProgressMonitor progressmonitor)  
> throws Exception
> {
>     Layer result = null ;
>     FeatureType schema = vf.get(0).getFeatureType();
>     IGeoResource resource =  
> CatalogPlugin 
> .getDefault().getLocalCatalog().createTemporaryResource(schema);
>     resource.resolve( FeatureStore.class,  
> progressmonitor ).removeFeatures(Filter.NONE);
>     FeatureCollection afeatCollection =  
> FeatureCollections.newCollection() ;
>     afeatCollection.addAll(vf) ;
>     resource.resolve( FeatureStore.class,  
> progressmonitor ).addFeatures(afeatCollection) ;//changes FID (new0,  
> new1, ...) and i don't want, just leave the original FID, a flag for  
> exemple ?
>     ApplicationGIS.openMap(map, true) ;//nothing appends, at any  
> place in the code
>     List<? extends ILayer> layers =  
> ApplicationGIS 
> .addLayersToMap(map,Collections.singletonList(resource), -1,  
> map.getProject(), true);
>     result = (Layer) layers.get(0);//to the point, fast
>
>     result.setName(name);//takes 10s to set but the layer are  
> already rended
>
>     return result ;
> }
>
> *** a solution ***
>
> //menu entries are enable but takes 10s adding the features and the  
> FID are changed
>
> {
>     Layer result = null ;
>     FeatureType schema = vf.get(0).getFeatureType();
>     IGeoResource resource =  
> CatalogPlugin 
> .getDefault().getLocalCatalog().createTemporaryResource(schema);
>
>     resource.resolve( FeatureStore.class,  
> progressmonitor ).removeFeatures(Filter.NONE);
>     ApplicationGIS.openMap(map, true) ;//nothing appends, at any  
> place in the code
>     List<? extends ILayer> layers =  
> ApplicationGIS 
> .addLayersToMap(map,Collections.singletonList(resource), -1,  
> map.getProject(), true);
>     result = (Layer) layers.get(0);//to the point, fast
>
>     //adding feature after creating the layer, makes the menu  
> entries enable
>     FeatureCollection afeatCollection =  
> FeatureCollections.newCollection() ;
>     afeatCollection.addAll(vf) ;
>     result.getGeoResource().resolve( FeatureStore.class,  
> progressmonitor ).addFeatures(afeatCollection) ; //but takes 10s  
> probably map async command, and changes FID
>     // if i use : resource.resolve( FeatureStore.class,  
> progressmonitor ).addFeatures(afeatCollection) ; // feature are  
> rended but menu entries are not enable ...
>     result.setName(name);//no more delay
>
>     return result ;
> }
>
>
> *** old code where menu entries are not enable but fast and the FID  
> don't changed ***
>
> {
>     FeatureType schema = vf.get(0).getFeatureType();
>     IGeoResource resource =  
> CatalogPlugin 
> .getDefault().getLocalCatalog().createTemporaryResource(schema );
>     Layer l = map.getLayerFactory().createLayer(resource);//create  
> an empty layer, fast
>
>     ICatalog catalog = CatalogPlugin.getDefault().getLocalCatalog();
>     List services = catalog.find(new URL("http://localhost/ 
> scratch"), progressmonitor);
>     IService service = (IService) services.get(0);
>     MemoryDataStore ds = service.resolve(MemoryDataStore.class,  
> progressmonitor);
>     ds.getSchema(schema.getTypeName());
>     ds.addFeatures(vf);//add feature without changed FID
>
>     ApplicationGIS.openMap(map, true) ;
>     map.getLayersInternal().add(l);
>     // OR map.sendCommandASync(new AddLayerCommand(l) );
>     l.setName(name);
>     return l ;//fast but menu entries are not enable ...
> }
>
> Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers  
> Yahoo! Mail _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.refractions.net/pipermail/udig-devel/attachments/20080222/66dcb5df/attachment.html


More information about the udig-devel mailing list