public void testExecuteBuffer() throws Exception {
    org.geotools.process.Process buffer = factory.create(new NameImpl("JTS", "Buffer"));

    // try less than the required params
    Map<String, Object> inputs = new HashMap<String, Object>();
    try {
      buffer.execute(inputs, null);
      fail("What!!! Should have failed big time!");
    } catch (ProcessException e) {
      // fine
    }

    // try out only the required params
    Geometry geom = new WKTReader().read("POINT(0 0)");
    inputs.put("geom", geom);
    inputs.put("distance", 1d);
    Map<String, Object> result = buffer.execute(inputs, null);

    assertEquals(1, result.size());
    Geometry buffered = (Geometry) result.get("result");
    assertNotNull(buffered);
    assertTrue(buffered.equals(geom.buffer(1d)));

    // pass in all params
    inputs.put("quadrantSegments", 12);
    inputs.put("capStyle", GeometryFunctions.BufferCapStyle.Square);
    result = buffer.execute(inputs, null);

    assertEquals(1, result.size());
    buffered = (Geometry) result.get("result");
    assertNotNull(buffered);
    assertTrue(buffered.equals(geom.buffer(1d, 12, BufferParameters.CAP_SQUARE)));
  }
  public void testExecuteUnion() throws Exception {
    org.geotools.process.Process union = factory.create(new NameImpl("JTS", "union"));

    // try less than the required params
    Map<String, Object> inputs = new HashMap<String, Object>();
    try {
      union.execute(inputs, null);
      fail("What!!! Should have failed big time!");
    } catch (ProcessException e) {
      // fine
    }

    // try again with less
    Geometry geom1 = new WKTReader().read("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))");
    Geometry geom2 = new WKTReader().read("POLYGON((0 1, 0 2, 1 2, 1 1, 0 1))");
    List<Geometry> geometries = new ArrayList<Geometry>();
    geometries.add(geom1);
    inputs.put("geom", geometries);
    try {
      union.execute(inputs, null);
      fail("What!!! Should have failed big time!");
    } catch (ProcessException e) {
      // fine
    }

    // now with just enough
    geometries.add(geom2);
    Map<String, Object> result = union.execute(inputs, null);

    assertEquals(1, result.size());
    Geometry united = (Geometry) result.get("result");
    assertNotNull(united);
    assertTrue(united.equals(geom1.union(geom2)));
  }
 @DescribeProcess(
     title = "spatialCluster",
     description =
         "Tests a set of cases and background population to find local clusters of excess, returns a raster surface of hotspots.")
 @DescribeResult(name = "result", description = "The Raster surface showing local clusters")
 public GridCoverage2D execute(
     // @DescribeParameter(name = "features", description =
     // "The feature collection whose geometries will be collected") FeatureCollection
     // features,
     @DescribeParameter(name = "type", description = "The name of the cluster method") String name,
     @DescribeParameter(name = "population", description = "The background population")
         FeatureCollection pop,
     @DescribeParameter(
             name = "popattribute",
             description = "The attribute that contains the population count")
         String popattribute,
     @DescribeParameter(name = "cancer", description = "The case data") FeatureCollection cancer,
     @DescribeParameter(name = "canattribute", description = "The attribute with the cases")
         String canattribute,
     @DescribeParameter(name = "MINRAD", description = "The smallest circle to consider")
         double minrad,
     @DescribeParameter(name = "MAXRAD", description = "The largest circle to consider")
         double maxrad,
     @DescribeParameter(
             name = "step",
             description = "How much to change the size of the circles by")
         double step,
     @DescribeParameter(
             name = "overlap",
             description = "How much should the circles overlap by (0-1)")
         double overlap,
     @DescribeParameter(
             name = "significance",
             description = "name of the significance test",
             min = 0)
         String testName,
     ProgressListener progressListener)
     throws IOException, ProcessException {
   Map<String, Object> params = new HashMap<String, Object>();
   params.put(ClusterMethodFactory.NAME.key, name);
   params.put(ClusterMethodFactory.POPULATION.key, pop);
   params.put(ClusterMethodFactory.POPATTRIBUTE.key, popattribute);
   params.put(ClusterMethodFactory.CANCER.key, cancer);
   params.put(ClusterMethodFactory.CANATTRIBUTE.key, canattribute);
   params.put(ClusterMethodFactory.MINRAD.key, minrad);
   params.put(ClusterMethodFactory.MAXRAD.key, maxrad);
   params.put(ClusterMethodFactory.STEP.key, step);
   params.put(ClusterMethodFactory.OVERLAP.key, overlap);
   if (testName != null && !testName.isEmpty())
     params.put(ClusterMethodFactory.TESTNAME.key, testName);
   ClusterMethodFactory factory = new ClusterMethodFactory();
   Process process = factory.create(params);
   Map<String, Object> results = process.execute(params, progressListener);
   return (GridCoverage2D) results.get(ClusterMethodFactory.RESULT.key);
 }
  public void testExecuteHull() throws Exception {
    NameImpl hullName = new NameImpl("JTS", "convexHull");
    org.geotools.process.Process hull = factory.create(hullName);

    Map<String, Object> inputs = new HashMap<String, Object>();
    Geometry geom = new WKTReader().read("LINESTRING(0 0, 0 1, 1 1)");
    inputs.put("geom", geom);
    Map<String, Object> output = hull.execute(inputs, null);

    assertEquals(1, output.size());
    // there is no output annotation, check there is consistency between what is declared
    // and what is returned
    Geometry result =
        (Geometry) output.get(factory.getResultInfo(hullName, null).keySet().iterator().next());
    assertTrue(result.equals(geom.convexHull()));
  }
  public static PearsonResult process(
      SimpleFeatureCollection inputFeatures, String inputFields, ProgressListener monitor) {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(PearsonCorrelationProcessFactory.inputFeatures.key, inputFeatures);
    map.put(PearsonCorrelationProcessFactory.inputFields.key, inputFields);

    Process process = new PearsonCorrelationProcess(null);
    Map<String, Object> resultMap;
    try {
      resultMap = process.execute(map, monitor);
      return (PearsonResult) resultMap.get(PearsonCorrelationProcessFactory.RESULT.key);
    } catch (ProcessException e) {
      LOGGER.log(Level.FINER, e.getMessage(), e);
    }

    return null;
  }
  public void testRandomProcess() throws Exception {
    File f = TestData.file(this, "all_data.shp");
    // System.out.println(f + " " + f.exists());
    URL url = DataUtilities.fileToURL(f);
    DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory();

    Map<String, Serializable> params2 = new HashMap<String, Serializable>();
    params2.put("url", url);
    params2.put("create spatial index", Boolean.TRUE);
    ShapefileDataStore store = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params2);
    // ShapefileDataStore store = new ShapefileDataStore(url);
    assertNotNull(store);
    FeatureSource featureSource = store.getFeatureSource();
    final FeatureCollection features = featureSource.getFeatures();

    Map<String, Object> params = new HashMap<String, Object>();

    params.put(ClusterMethodFactory.NAME.key, "random");
    params.put(ClusterMethodFactory.POPULATION.key, features);
    params.put(ClusterMethodFactory.POPATTRIBUTE.key, "pop");
    params.put(ClusterMethodFactory.CANCER.key, features);
    params.put(ClusterMethodFactory.CANATTRIBUTE.key, "cases");
    params.put(ClusterMethodFactory.MINRAD.key, 1000.0);
    params.put(ClusterMethodFactory.MAXRAD.key, 5000.0);
    params.put(ClusterMethodFactory.NCIRCLES.key, 500.0);
    params.put(ClusterMethodFactory.TESTNAME.key, "poisson");
    ClusterMethodFactory factory = new ClusterMethodFactory();
    Process process = factory.create(params);
    assertNotNull(process);
    long start = System.currentTimeMillis();
    Map<String, Object> results = process.execute(params, new ClusterMonitor());
    long end = System.currentTimeMillis();
    System.out.println("process took " + ((end - start) / 1000) + " seconds");
    GridCoverage2D grid = (GridCoverage2D) results.get(ClusterMethodFactory.RESULT.key);
    String basename = f.toString();
    basename = basename.substring(0, basename.length() - 4);
    String filename = basename + "_rand.tiff";
    Utilities.writeGrid(filename, grid);

    FeatureCollection outfeatures =
        (FeatureCollection) results.get(ClusterMethodFactory.CIRCLES.key);
    Utilities.writeCircles(basename + "_rand.shp", outfeatures);
  }