Ejemplo n.º 1
0
  @Test
  public void testLenght() throws NoSuchIdentifierException, ProcessException {

    GeometryFactory fact = new GeometryFactory();

    // Inputs first
    final LinearRing ring =
        fact.createLinearRing(
            new Coordinate[] {
              new Coordinate(0.0, 0.0),
              new Coordinate(0.0, 10.0),
              new Coordinate(5.0, 10.0),
              new Coordinate(5.0, 0.0),
              new Coordinate(0.0, 0.0)
            });

    final Geometry geom1 = fact.createPolygon(ring, null);

    // Process
    final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("jts", "lenght");

    final ParameterValueGroup in = desc.getInputDescriptor().createValue();
    in.parameter("geom").setValue(geom1);
    final org.geotoolkit.process.Process proc = desc.createProcess(in);

    // result
    final Double result = (Double) proc.call().parameter("result").getValue();

    final Double expected = geom1.getLength();

    assertTrue(expected.equals(result));
  }
Ejemplo n.º 2
0
  @Test
  public void testMin() throws NoSuchIdentifierException, ProcessException {

    // Inputs first
    final Double[] set = {
      new Double(15.5),
      new Double(10.02),
      new Double(1.43),
      new Double(-3.03),
      new Double(4.53),
      new Double(-6.21)
    };

    // Process
    final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("math", "min");

    final ParameterValueGroup in = desc.getInputDescriptor().createValue();
    in.parameter("set").setValue(set);
    final org.geotoolkit.process.Process proc = desc.createProcess(in);

    // result
    final Double result = (Double) proc.call().parameter("result").getValue();

    assertEquals(new Double(-6.21), result);
  }
Ejemplo n.º 3
0
  @Test
  public void testIntersection() throws ProcessException, NoSuchIdentifierException {

    // Inputs
    final FeatureCollection<?> featureList = buildFeatureList();
    final FeatureCollection<?> featureUnionList = buildFeatureUnionList();

    // Process
    ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("vector", "union");

    ParameterValueGroup in = desc.getInputDescriptor().createValue();
    in.parameter("feature_in").setValue(featureList);
    in.parameter("feature_union").setValue(featureUnionList);
    in.parameter("input_geometry_name").setValue("geom1");
    org.geotoolkit.process.Process proc = desc.createProcess(in);

    // Features out
    final FeatureCollection<?> featureListOut =
        (FeatureCollection<?>) proc.call().parameter("feature_out").getValue();

    // Expected Features out
    final FeatureCollection<?> featureListResult = buildResultList();

    assertEquals(featureListOut.getFeatureType(), featureListResult.getFeatureType());
    assertEquals(featureListOut.getID(), featureListResult.getID());
    assertEquals(featureListOut.size(), featureListResult.size());
    assertTrue(featureListOut.containsAll(featureListResult));
  }
Ejemplo n.º 4
0
  /**
   * Test coverageToFeature process with a PixelInCell.CELL_CENTER coverage
   *
   * @throws NoSuchAuthorityCodeException
   * @throws FactoryException
   */
  @Test
  public void coverageToFeatureTestPixelCenter()
      throws NoSuchAuthorityCodeException, FactoryException, ProcessException {

    Hints.putSystemDefault(Hints.LENIENT_DATUM_SHIFT, Boolean.TRUE);

    PixelInCell pixPos = PixelInCell.CELL_CENTER;
    GridCoverageReader reader = buildReader(pixPos);
    // Process
    ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("coverage", "coveragetofeatures");
    ParameterValueGroup in = desc.getInputDescriptor().createValue();
    in.parameter("reader_in").setValue(reader);
    org.geotoolkit.process.Process proc = desc.createProcess(in);

    // Features out
    final Collection<Feature> featureListOut =
        (Collection<Feature>) proc.call().parameter("feature_out").getValue();

    final List<Feature> featureListResult = (List<Feature>) buildFCResultPixelCenter();

    assertEquals(featureListResult.get(0).getType(), featureListOut.iterator().next().getType());
    assertEquals(featureListOut.size(), featureListResult.size());

    Iterator<Feature> iteratorOut = featureListOut.iterator();
    Iterator<Feature> iteratorResult = featureListResult.iterator();

    ArrayList<Geometry> geomsOut = new ArrayList<Geometry>();
    int itOut = 0;
    while (iteratorOut.hasNext()) {
      Feature featureOut = iteratorOut.next();

      for (Property propertyOut : featureOut.getProperties()) {
        if (propertyOut.getDescriptor() instanceof GeometryDescriptor) {
          geomsOut.add(itOut++, (Geometry) propertyOut.getValue());
        }
      }
    }
    ArrayList<Geometry> geomsResult = new ArrayList<Geometry>();
    int itResult = 0;
    while (iteratorResult.hasNext()) {
      Feature featureResult = iteratorResult.next();

      for (Property propertyResult : featureResult.getProperties()) {
        if (propertyResult.getDescriptor() instanceof GeometryDescriptor) {
          geomsResult.add(itResult++, (Geometry) propertyResult.getValue());
        }
      }
    }
    assertEquals(geomsResult.size(), geomsOut.size());
    for (int i = 0; i < geomsResult.size(); i++) {
      Geometry gOut = geomsOut.get(i);
      Geometry gResult = geomsResult.get(i);
      assertArrayEquals(gResult.getCoordinates(), gOut.getCoordinates());
    }
  }
Ejemplo n.º 5
0
  @Test
  public void testFailStop() throws NoSuchIdentifierException, ProcessException {
    final ProcessDescriptor desc =
        ProcessFinder.getProcessDescriptor(
            ConstellationProcessFactory.NAME, StopServiceDescriptor.NAME);

    final ParameterValueGroup in = desc.getInputDescriptor().createValue();
    in.parameter(StopServiceDescriptor.SERVICE_TYPE_NAME).setValue(serviceName);
    in.parameter(StopServiceDescriptor.IDENTIFIER_NAME).setValue("stopInstance5");

    try {
      org.geotoolkit.process.Process proc = desc.createProcess(in);
      proc.call();
      fail();
    } catch (ProcessException ex) {
      // do nothing
    }
  }
Ejemplo n.º 6
0
  @Test
  public void testStop() throws NoSuchIdentifierException, ProcessException {

    createInstance("stopInstance1");
    startInstance("stopInstance1");

    try {
      final int initSize = WSEngine.getInstanceSize(serviceName);
      final ProcessDescriptor desc =
          ProcessFinder.getProcessDescriptor(
              ConstellationProcessFactory.NAME, StopServiceDescriptor.NAME);

      final ParameterValueGroup in = desc.getInputDescriptor().createValue();
      in.parameter(StopServiceDescriptor.SERVICE_TYPE_NAME).setValue(serviceName);
      in.parameter(StopServiceDescriptor.IDENTIFIER_NAME).setValue("stopInstance1");
      org.geotoolkit.process.Process proc = desc.createProcess(in);
      proc.call();

      assertTrue(WSEngine.getInstanceSize(serviceName) == initSize - 1);
      assertFalse(WSEngine.serviceInstanceExist(serviceName, "stopInstance1"));
    } finally {
      deleteInstance(serviceBusiness, "stopInstance1");
    }
  }
  @Test
  public void testOverlapsCRS() throws NoSuchIdentifierException, ProcessException {

    GeometryFactory fact = new GeometryFactory();

    // Inputs first
    final LinearRing ring =
        fact.createLinearRing(
            new Coordinate[] {
              new Coordinate(0.0, 0.0),
              new Coordinate(0.0, 10.0),
              new Coordinate(5.0, 10.0),
              new Coordinate(5.0, 0.0),
              new Coordinate(0.0, 0.0)
            });

    final Geometry geom1 = fact.createPolygon(ring, null);

    final LinearRing ring2 =
        fact.createLinearRing(
            new Coordinate[] {
              new Coordinate(-5.0, 0.0),
              new Coordinate(-5.0, 10.0),
              new Coordinate(2.0, 10.0),
              new Coordinate(2.0, 0.0),
              new Coordinate(-5.0, 0.0)
            });

    Geometry geom2 = fact.createPolygon(ring2, null);

    CoordinateReferenceSystem crs1 = null;
    try {
      crs1 = CRS.decode("EPSG:4326");
      JTS.setCRS(geom1, crs1);
    } catch (FactoryException ex) {
      Logger.getLogger(UnionProcess.class.getName()).log(Level.SEVERE, null, ex);
    }

    CoordinateReferenceSystem crs2 = null;
    try {
      crs2 = CRS.decode("EPSG:4326");
      JTS.setCRS(geom2, crs2);
    } catch (FactoryException ex) {
      Logger.getLogger(UnionProcess.class.getName()).log(Level.SEVERE, null, ex);
    }

    // Process
    final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("jts", "overlaps");

    final ParameterValueGroup in = desc.getInputDescriptor().createValue();
    in.parameter("geom1").setValue(geom1);
    in.parameter("geom2").setValue(geom2);
    final org.geotoolkit.process.Process proc = desc.createProcess(in);

    // result
    final Boolean result = (Boolean) proc.call().parameter("result").getValue();

    MathTransform mt = null;
    try {
      mt = CRS.findMathTransform(crs2, crs1);
      geom2 = JTS.transform(geom2, mt);
    } catch (FactoryException ex) {
      Logger.getLogger(UnionProcess.class.getName()).log(Level.SEVERE, null, ex);
    } catch (TransformException ex) {
      Logger.getLogger(UnionProcess.class.getName()).log(Level.SEVERE, null, ex);
    }

    final Boolean expected = geom1.overlaps(geom2);

    assertTrue(expected.equals(result));
  }