/**
   * 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());
    }
  }
Example #2
0
  @Test
  public void placemarkWriteTest()
      throws KmlException, IOException, XMLStreamException, ParserConfigurationException,
          SAXException {
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();

    final Coordinate coordinate =
        kmlFactory.createCoordinate(-90.86948943473118, 48.25450093195546, 0);
    final CoordinateSequence coordinates = kmlFactory.createCoordinates(Arrays.asList(coordinate));
    final Point point = kmlFactory.createPoint(coordinates);

    final LookAt lookAt = kmlFactory.createLookAt();
    lookAt.setLongitude(-90.86879847669974);
    lookAt.setLatitude(48.25330383601299);
    lookAt.setHeading(2.7);
    lookAt.setTilt(8.3);
    lookAt.setRange(440.8);

    final Feature placemark = kmlFactory.createPlacemark();
    final Collection<Property> placemarkProperties = placemark.getProperties();
    placemarkProperties.add(
        FF.createAttribute("Google Earth - New Placemark", KmlModelConstants.ATT_NAME, null));
    placemarkProperties.add(
        FF.createAttribute("Some Descriptive text.", KmlModelConstants.ATT_DESCRIPTION, null));
    placemarkProperties.add(FF.createAttribute(lookAt, KmlModelConstants.ATT_VIEW, null));
    placemarkProperties.add(
        FF.createAttribute(point, KmlModelConstants.ATT_PLACEMARK_GEOMETRY, null));

    final Kml kml = kmlFactory.createKml(null, placemark, null, null);

    final File temp = File.createTempFile("testPlacemark", ".kml");
    temp.deleteOnExit();

    final KmlWriter writer = new KmlWriter();
    writer.setOutput(temp);
    writer.write(kml);
    writer.dispose();

    DomCompare.compare(new File(pathToTestFile), temp);
  }
  private List<Feature> buildFCResultPixelCorner()
      throws NoSuchAuthorityCodeException, FactoryException {

    FeatureType type = buildFeatureType();
    final List<Feature> featureList = new ArrayList<Feature>();
    GeometryFactory geometryFactory = new GeometryFactory();

    double buffX = 0;
    double buffY = 0;
    for (int y = 0; y < max; y++) {
      for (int x = 0; x < max; x++) {
        buffX = x;
        buffY = y + 1.0;
        Point pos = geometryFactory.createPoint(new Coordinate(buffX, buffY));
        LinearRing line =
            geometryFactory.createLinearRing(
                new Coordinate[] {
                  new Coordinate(buffX, buffY),
                  new Coordinate(buffX + 1.0, buffY),
                  new Coordinate(buffX + 1.0, buffY - 1.0),
                  new Coordinate(buffX, buffY - 1.0),
                  new Coordinate(buffX, buffY)
                });

        Feature myfeature = FeatureUtilities.defaultFeature(type, "id-" + x + "-" + y);
        myfeature.getProperty("cellgeom").setValue(geometryFactory.createPolygon(line, null));
        myfeature.getProperty("position").setValue(pos);
        myfeature.getProperty("orientation").setValue(PixelInCell.CELL_CENTER.name());
        myfeature.getProperty("band-0").setValue(0.0);
        myfeature.getProperty("band-1").setValue((Integer) x);
        myfeature.getProperty("band-2").setValue((Integer) y);

        featureList.add((x + (y * max)), myfeature);
      }
    }
    return featureList;
  }
Example #4
0
  @Test
  public void placemarkReadTest()
      throws IOException, XMLStreamException, KmlException, URISyntaxException {

    final KmlReader reader = new KmlReader();
    reader.setInput(new File(pathToTestFile));
    final Kml kmlObjects = reader.read();
    reader.dispose();

    final Feature placemark = kmlObjects.getAbstractFeature();
    assertTrue(placemark.getType().equals(KmlModelConstants.TYPE_PLACEMARK));
    assertEquals(
        "Google Earth - New Placemark",
        placemark.getProperty(KmlModelConstants.ATT_NAME.getName()).getValue());
    assertEquals(
        "Some Descriptive text.",
        placemark.getProperty(KmlModelConstants.ATT_DESCRIPTION.getName()).getValue());

    final AbstractView view =
        (AbstractView) placemark.getProperty(KmlModelConstants.ATT_VIEW.getName()).getValue();
    assertTrue(view instanceof LookAt);
    LookAt lookAt = (LookAt) view;
    assertEquals(-90.86879847669974, lookAt.getLongitude(), DELTA);
    assertEquals(48.25330383601299, lookAt.getLatitude(), DELTA);
    assertEquals(2.7, lookAt.getHeading(), DELTA);
    assertEquals(8.3, lookAt.getTilt(), DELTA);
    assertEquals(440.8, lookAt.getRange(), DELTA);

    final AbstractGeometry geometry =
        (AbstractGeometry)
            placemark.getProperty(KmlModelConstants.ATT_PLACEMARK_GEOMETRY.getName()).getValue();
    assertTrue(geometry instanceof Point);
    Point point = (Point) geometry;
    final CoordinateSequence coordinates = point.getCoordinateSequence();
    assertEquals(1, coordinates.size());
    Coordinate coordinate = coordinates.getCoordinate(0);
    assertEquals(-90.86948943473118, coordinate.x, DELTA);
    assertEquals(48.25450093195546, coordinate.y, DELTA);
    assertEquals(0, coordinate.z, DELTA);
  }