org.geotools.process.raster
Class RasterToVectorProcess

java.lang.Object
  extended by org.geotools.process.impl.AbstractProcess
      extended by org.geotools.process.raster.RasterToVectorProcess
All Implemented Interfaces:
Process

public class RasterToVectorProcess
extends AbstractProcess

Vectorizes discrete regions of uniform value in the specified band of a GridCoverage2D object. Data are treated as double values regardless of the data type of the input grid coverage.

Example of use via the GeoTools process API


 GridCoverage2D cov = ...

 final Map<String, Object> params = new HashMap<String, Object>();
 params.put(RasterToVectorFactory.RASTER.key, cov);
 params.put(RasterToVectorFactory.BAND.key, Integer.valueOf(0));
 params.put(RasterToVectorFactory.BOUNDS.key, env);
 params.put(RasterToVectorFactory.OUTSIDE.key, Collections.singleton(0.0d));
 params.put(RasterToVectorFactory.INSIDE_EDGES.key, Boolean.TRUE);

 final Process r2v = Processors.createProcess(new NameImpl(ProcessFactory.GT_NAMESPACE, "RasterToVectorProcess"));

 // run the process on a thread other than the event-dispatch thread
 // (here we use SwingWorker to accomplish this)
 SwingWorker worker = new SwingWorker<Map<String, Object>, Void>() {
     protected Map<String, Object> doInBackground() throws Exception {
         ProgressWindow pw = new ProgressWindow(null);
         pw.setTitle("Vectorizing coverage");
         return r2v.execute(params, pw);
     }

     protected void done() {
         Map<String, Object> vectorizingResults = null;
         try {
             vectorizingResults = get();
         } catch (Exception ignore) {}

         if (vectorizingResults != null) {
             FeatureCollection<SimpleFeatureType, SimpleFeature> fc =
                 (FeatureCollection<SimpleFeatureType, SimpleFeature>) vectorizingResults.get(
                         RasterToVectorFactory.RESULT_FEATURES.key);

             // do something with features...
         }
     }
 };

 worker.execute();
 
Example of "manual" use with the static helper method:

 GridCoverage2D cov = ...
 int band = ...
 Envelope bounds = ...
 List<Double> outsideValues = ...
 boolean insideEdges = ...

 FeatureCollection<SimpleFeatureType,SimpleFeature> features =
     RasterToVectorProcess.process(cov, band, bounds, outsideValues, insideEdges, null);
 

Since:
2.6
Version:
$Id: RasterToVectorProcess.java 35533 2010-05-21 11:25:14Z mbedward $
Author:
Jody Garnett, Michael Bedward

Field Summary
 
Fields inherited from class org.geotools.process.impl.AbstractProcess
factory
 
Method Summary
 java.util.Map<java.lang.String,java.lang.Object> execute(java.util.Map<java.lang.String,java.lang.Object> input, org.opengis.util.ProgressListener monitor)
          Run the raster to vector process.
static FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> process(GridCoverage2D cov, int band, org.opengis.geometry.Envelope bounds, java.util.Collection<java.lang.Double> outsideValues, boolean insideEdges, org.opengis.util.ProgressListener monitor)
          A static helper method that can be called directy to run the process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

execute

public java.util.Map<java.lang.String,java.lang.Object> execute(java.util.Map<java.lang.String,java.lang.Object> input,
                                                                org.opengis.util.ProgressListener monitor)
                                                         throws ProcessException
Run the raster to vector process. The returned Map will contain a single object: the FeatureCollection of vector polygons which can be retrieved as follows

 FeatureCollection<SimpleFeatureType, SimpleFeature> features =
     (FeatureCollection<SimpleFeatureType, SimpleFeature>) resultsMap.get(
         RasterToVectorFactory.RESULT_FEATURES.key);
 

Parameters:
input - a map of input parameters (see RasterToVectorFactory for details)
monitor - an optional ProgressListener (may be null)
Returns:
a Map containing the vectorized features
Throws:
ProcessException

process

public static FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> process(GridCoverage2D cov,
                                                                                                                               int band,
                                                                                                                               org.opengis.geometry.Envelope bounds,
                                                                                                                               java.util.Collection<java.lang.Double> outsideValues,
                                                                                                                               boolean insideEdges,
                                                                                                                               org.opengis.util.ProgressListener monitor)
                                                                                                                        throws ProcessException
A static helper method that can be called directy to run the process.

The process interface is useful for advertising functionality to dynamic applications, but for 'hands on' coding this method is much more convenient than working via Process.execute(java.util.Map, org.opengis.util.ProgressListener).

Parameters:
cov - the input coverage
band - the index of the band to be vectorized
bounds - bounds of the area (in world coordinates) to vectorize; if null the whole coverage
outside - a collection of one or more values which represent 'outside' or no data (may be null or empty)
insideEdges - whether to vectorize inside edges (those separating grid regions with non-outside values)
monitor - an optional ProgressListener (may be null)
Returns:
a FeatureCollection containing simple polygon features
Throws:
ProcessException


Copyright © 1996-2010 Geotools. All Rights Reserved.