Permalink
Browse files

Moved VectorToRaster process to vector category.

  • Loading branch information...
1 parent 040f46b commit baea5cc72ee3e42e1dd20bf3bece71ba22642855 jdeolive committed Aug 21, 2012
@@ -63,7 +63,8 @@ public VectorProcessFactory() {
TransformProcess.class,
LRSGeocodeProcess.class,
LRSMeasureProcess.class,
- LRSSegmentProcess.class);
+ LRSSegmentProcess.class,
+ VectorToRasterProcess.class);
}
}
@@ -24,7 +24,7 @@
*/
-package org.geotools.process.raster;
+package org.geotools.process.vector;
import org.geotools.process.ProcessException;
@@ -23,7 +23,7 @@
* of any kind is given regarding the work.
*/
-package org.geotools.process.raster;
+package org.geotools.process.vector;
import java.awt.AlphaComposite;
import java.awt.Color;
@@ -55,17 +55,23 @@
import org.geotools.coverage.grid.GridCoverageFactory;
import org.geotools.coverage.grid.GridEnvelope2D;
import org.geotools.coverage.grid.GridGeometry2D;
+import org.geotools.data.Parameter;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
+import org.geotools.feature.FeatureCollection;
import org.geotools.filter.text.cql2.CQLException;
import org.geotools.filter.text.ecql.ECQL;
import org.geotools.geometry.DirectPosition2D;
import org.geotools.geometry.jts.Geometries;
import org.geotools.geometry.jts.JTS;
import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.process.factory.DescribeParameter;
+import org.geotools.process.factory.DescribeProcess;
+import org.geotools.process.factory.DescribeResult;
import org.geotools.process.feature.AbstractFeatureCollectionProcess;
import org.geotools.process.feature.AbstractFeatureCollectionProcessFactory;
import org.geotools.referencing.CRS;
+import org.geotools.text.Text;
import org.geotools.util.NullProgressListener;
import org.geotools.util.SimpleInternationalString;
import org.opengis.feature.simple.SimpleFeature;
@@ -94,8 +100,11 @@
*
* @source $URL$
* @version $Id$
+ *
+ *
*/
-public class VectorToRasterProcess extends AbstractFeatureCollectionProcess {
+@DescribeProcess(title = "Transform", description = "Converts some or all of a feature collection to a raster grid, using an attribute to specify cell values.")
+public class VectorToRasterProcess {
private static final int COORD_GRID_CHUNK_SIZE = 1000;
@@ -130,14 +139,6 @@
TiledImage image;
Graphics2D graphics;
- /**
- * Constructor
- *
- * @param factory
- */
- public VectorToRasterProcess(VectorToRasterFactory factory) {
- super(factory);
- }
/**
* A static helper method that can be called directy to run the process.
@@ -175,61 +176,80 @@ public static GridCoverage2D process(
String covName,
ProgressListener monitor) throws VectorToRasterException {
- VectorToRasterFactory factory = new VectorToRasterFactory();
- VectorToRasterProcess process = factory.create();
-
+ VectorToRasterProcess process = new VectorToRasterProcess();
return process.convert(features, attribute, gridDim, bounds, covName, monitor);
}
- /**
- * Retrieves the input parameters from the supplied Map, conducts some basic checking,
- * and then carries out the vector to raster conversion.
- *
- * @param input
- * input parameters from those defined in {@linkplain VectorToRasterFactory}
- *
- * @param monitor
- * a ProgressListener object, or null if monitoring is not required
- *
- * @return a Map of result objects
- *
- * @throws org.geotools.process.raster.VectorToRasterException if unable to
- * rasterize the features as requested
- *
- * @see VectorToRasterFactory#getResultInfo(java.util.Map)
- */
- @Override
- public Map<String, Object> execute( Map<String, Object> input, ProgressListener monitor )
- throws VectorToRasterException {
-
- SimpleFeatureCollection features = (SimpleFeatureCollection)
- input.get(AbstractFeatureCollectionProcessFactory.FEATURES.key);
-
- String attributeStr = (String) input.get(VectorToRasterFactory.ATTRIBUTE.key);
- Expression attribute = null;
+ @DescribeResult(name = "result", description = "Rasterized grid")
+ public GridCoverage2D execute(
+ @DescribeParameter(name = "features", description = "Features to process", min = 1, max = 1) SimpleFeatureCollection features,
+ @DescribeParameter(name = "rasterWidth", description = "Width of the output grid in pixels", min = 1, max = 1) Integer rasterWidth,
+ @DescribeParameter(name = "rasterHeight", description = "Height of the output grid in pixels", min = 1, max = 1) Integer rasterHeight,
+ @DescribeParameter(name = "title", description = "Title to use for the output grid", min = 0, max = 1, defaultValue = "raster" ) String title,
+ @DescribeParameter(name = "attribute", description = "Attribute name to use for the raster cell values", min = 1, max = 1) String attribute,
+ @DescribeParameter(name = "bounds", description = "Bounding box of the area to rasterize", min = 0, max = 1) Envelope bounds,
+ ProgressListener progressListener) {
+
+ Expression attributeExpr = null;
try {
- attribute = ECQL.toExpression(attributeStr);
+ attributeExpr = ECQL.toExpression(attribute);
} catch(CQLException e) {
- throw new VectorToRasterException(e);
+ throw new VectorToRasterException(e);
}
-
- int w = (Integer) input.get(VectorToRasterFactory.RASTER_WIDTH.key);
- int h = (Integer) input.get(VectorToRasterFactory.RASTER_HEIGHT.key);
- Dimension gridDim = new Dimension(w, h);
-
- ReferencedEnvelope env = (ReferencedEnvelope) input.get(VectorToRasterFactory.BOUNDS.key);
-
- String title = (String) input.get(VectorToRasterFactory.TITLE.key);
- if(title == null) {
- title = "raster";
- }
-
- GridCoverage2D cov = convert(features, attribute, gridDim, env, title, monitor);
-
- Map<String, Object> results = new HashMap<String, Object>();
- results.put(VectorToRasterFactory.RESULT.key, cov);
- return results;
+ return convert(features, attributeExpr, new Dimension(rasterWidth, rasterHeight), bounds,
+ title, progressListener);
}
+
+
+// /**
+// * Retrieves the input parameters from the supplied Map, conducts some basic checking,
+// * and then carries out the vector to raster conversion.
+// *
+// * @param input
+// * input parameters from those defined in {@linkplain VectorToRasterFactory}
+// *
+// * @param monitor
+// * a ProgressListener object, or null if monitoring is not required
+// *
+// * @return a Map of result objects
+// *
+// * @throws org.geotools.process.raster.VectorToRasterException if unable to
+// * rasterize the features as requested
+// *
+// * @see VectorToRasterFactory#getResultInfo(java.util.Map)
+// */
+// @Override
+// public Map<String, Object> execute( Map<String, Object> input, ProgressListener monitor )
+// throws VectorToRasterException {
+//
+// SimpleFeatureCollection features = (SimpleFeatureCollection)
+// input.get(AbstractFeatureCollectionProcessFactory.FEATURES.key);
+//
+// String attributeStr = (String) input.get(VectorToRasterFactory.ATTRIBUTE.key);
+// Expression attribute = null;
+// try {
+// attribute = ECQL.toExpression(attributeStr);
+// } catch(CQLException e) {
+// throw new VectorToRasterException(e);
+// }
+//
+// int w = (Integer) input.get(VectorToRasterFactory.RASTER_WIDTH.key);
+// int h = (Integer) input.get(VectorToRasterFactory.RASTER_HEIGHT.key);
+// Dimension gridDim = new Dimension(w, h);
+//
+// ReferencedEnvelope env = (ReferencedEnvelope) input.get(VectorToRasterFactory.BOUNDS.key);
+//
+// String title = (String) input.get(VectorToRasterFactory.TITLE.key);
+// if(title == null) {
+// title = "raster";
+// }
+//
+// GridCoverage2D cov = convert(features, attribute, gridDim, env, title, monitor);
+//
+// Map<String, Object> results = new HashMap<String, Object>();
+// results.put(VectorToRasterFactory.RESULT.key, cov);
+// return results;
+// }
/**
* This method is called by {@linkplain #execute} to rasterize an individual feature.
@@ -242,10 +262,8 @@ public static GridCoverage2D process(
*
* @throws java.lang.Exception
*/
- @Override
- protected void processFeature(SimpleFeature feature, Map<String, Object> input) throws Exception {
+ protected void processFeature(SimpleFeature feature, Object attribute) throws Exception {
- Object attribute = input.get(VectorToRasterFactory.ATTRIBUTE.key);
Geometry geometry = (Geometry) feature.getDefaultGeometry();
if (geometry.intersects(extentGeometry)) {
@@ -327,9 +345,6 @@ private GridCoverage2D convert(
initialize( features, bounds, attribute, gridDim );
- Map<String, Object> params = new HashMap<String, Object>();
- params.put(VectorToRasterFactory.ATTRIBUTE.key, attribute);
-
monitor.setTask(new SimpleInternationalString("Rasterizing features..."));
float scale = 100.0f / features.size();
@@ -340,7 +355,7 @@ private GridCoverage2D convert(
int counter = 0;
while( fi.hasNext() ) {
try {
- processFeature(fi.next(), params);
+ processFeature(fi.next(), attribute);
}
catch( Exception e ) {
monitor.exceptionOccurred( e );
@@ -482,7 +497,7 @@ private void setBounds( SimpleFeatureCollection features, Envelope bounds)
// features to the output CRS prior to rasterizing them.
CoordinateReferenceSystem featuresCRS = featureBounds.getCoordinateReferenceSystem();
- CoordinateReferenceSystem boundsCRS = bounds.getCoordinateReferenceSystem();
+ CoordinateReferenceSystem boundsCRS = extent.getCoordinateReferenceSystem();
transformFeatures = false;
if (featuresCRS != null
@@ -14,7 +14,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
-package org.geotools.process.raster;
+package org.geotools.process.vector;
import java.awt.Dimension;
import java.awt.Point;
@@ -75,16 +75,12 @@
@Test
public void testCreateProcess() throws Exception {
- System.out.println(" create process");
- Process p = Processors.createProcess(new NameImpl("gt", "VectorToRaster"));
+ Process p = Processors.createProcess(new NameImpl("vec", "VectorToRaster"));
assertNotNull(p);
- assertTrue(p instanceof VectorToRasterProcess);
}
@Test
public void rasterizePolygons() throws Exception {
- System.out.println(" rasterize polygons");
-
SimpleFeatureCollection features = createPolys();
ReferencedEnvelope bounds = features.getBounds();
@@ -137,8 +133,6 @@ public void rasterizePolygons() throws Exception {
@Test
public void rasterizePoints() throws Exception {
- System.out.println(" rasterize points");
-
ReferencedEnvelope bounds = new ReferencedEnvelope(-10, 10, -20, 20, DefaultEngineeringCRS.GENERIC_2D);
Dimension gridDim = new Dimension(100, 100);
@@ -174,7 +168,7 @@ public void rasterizePoints() throws Exception {
@Test
public void executeProcessWithFloat() throws Exception {
System.out.println(" execute process using float values");
- Process p = Processors.createProcess(new NameImpl("gt", "VectorToRaster"));
+ Process p = Processors.createProcess(new NameImpl("vec", "VectorToRaster"));
assertNotNull(p);
SimpleFeatureCollection features = createFloatLines();
@@ -188,13 +182,13 @@ public void executeProcessWithFloat() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put(AbstractFeatureCollectionProcessFactory.FEATURES.key, features);
- map.put(VectorToRasterFactory.ATTRIBUTE.key, "value");
- map.put(VectorToRasterFactory.RASTER_WIDTH.key, gridDim.width);
- map.put(VectorToRasterFactory.RASTER_HEIGHT.key, gridDim.height);
- map.put(VectorToRasterFactory.BOUNDS.key, bounds);
+ map.put("attribute", "value");
+ map.put("rasterWidth", gridDim.width);
+ map.put("rasterHeight", gridDim.height);
+ map.put("bounds", bounds);
Map<String, Object> result = p.execute(map, monitor);
- GridCoverage2D cov = (GridCoverage2D) result.get(VectorToRasterFactory.RESULT.key);
+ GridCoverage2D cov = (GridCoverage2D) result.get("result");
//textPrintFloat(cov);
@@ -224,8 +218,7 @@ public void executeProcessWithFloat() throws Exception {
*/
@Test
public void executeProcessWithString() throws Exception {
- System.out.println(" execute process using String values");
- Process p = Processors.createProcess(new NameImpl("gt", "VectorToRaster"));
+ Process p = Processors.createProcess(new NameImpl("vec", "VectorToRaster"));
assertNotNull(p);
SimpleFeatureCollection features = createStringLines();
@@ -239,13 +232,13 @@ public void executeProcessWithString() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put(AbstractFeatureCollectionProcessFactory.FEATURES.key, features);
- map.put(VectorToRasterFactory.ATTRIBUTE.key, "value");
- map.put(VectorToRasterFactory.RASTER_WIDTH.key, gridDim.width);
- map.put(VectorToRasterFactory.RASTER_HEIGHT.key, gridDim.height);
- map.put(VectorToRasterFactory.BOUNDS.key, bounds);
+ map.put("attribute", "value");
+ map.put("rasterWidth", gridDim.width);
+ map.put("rasterHeight", gridDim.height);
+ map.put("bounds", bounds);
Map<String, Object> result = p.execute(map, monitor);
- GridCoverage2D cov = (GridCoverage2D) result.get(VectorToRasterFactory.RESULT.key);
+ GridCoverage2D cov = (GridCoverage2D) result.get("result");
//textPrint(cov);
Oops, something went wrong.

0 comments on commit baea5cc

Please sign in to comment.