Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [udig-devel] Re: How can we create new layer from given features?

Hello,

This won't help you with map graphics and it uses a deprecated method
  myFeatureSource.addFeatures()
which we will both have to find out how to update but the method works
to add a Layer of Features to uDig:

********************************************************************
////// STEP 5: Turn the Geotools Feature into a uDig Layer
            
    List<IGeoResource> geoResourceList2 = null, myGRList = null;
    
   // Use the CatalogPlugin convenience method:
   //   1) get an IGeoResource through the convenience method
   //   2) resolve the IGeoResource to get a FeatureStore of some kind.
   //   3) get an iterator on a List of features to add
   //   4) use the deprecated!? addFeatures with a FeatureReader
   //   5) create the Layer


IGeoResource newIGR = CatalogPlugin.getDefault().getLocalCatalog().
                              createTemporaryResource( myBufferFT );

FeatureStore newFS = null;
if (newIGR.canResolve(FeatureStore.class)) {
   	try {
   			
   		newFS = newIGR.resolve(FeatureStore.class, monitor);;
   			
   	} catch (Exception e) {
   		System.err.println(
   		   "Resolving the IGeoResource failed with exception " + e);
   		// TODO: re-emit the exception, bail from the operation.
   	}
}

final Iterator<Feature> iter = Arrays.asList(myBufferF).iterator();

newFS.addFeatures( (FeatureReader) new FeatureReader(){
  public boolean hasNext(){  return iter.hasNext(); }
  public Feature next() { return iter.next(); }
  // TODO: what should this be?
  public void close() { ; }
  public void remove() {throw new UnsupportedOperationException();}
  public FeatureType getFeatureType(){return this.getFeatureType();}
  }
);
    
// WHY? Creating the Layer is what adds it to the catalog!?
LayerFactoryImpl myLF = LayerFactoryImpl.create();
myLF.createLayer(newIGR);

//Make a List <IGeoResource>
myGRList = new ArrayList<IGeoResource> ();
myGRList.add(newIGR);


// TODO:Cleanup - remove.
System.out.println("Got to create the layer.");

****************************************************************

--adrian

On Fri, 2007-04-06 at 20:49 +0300, Sergiy Doroshenko wrote:
> About map graphic - I found extension point mapgraphic and interface MapGraphic.
> 
> But I still confused how to create new layer from selected features.
> I found method LayerFactory.createLayer( IGeoResource resource )
> But how to make IGeoResource from selected features?
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel



Back to the top