Exemplo n.º 1
0
  private static SimpleFeatureType createSimpleType()
      throws NoSuchAuthorityCodeException, FactoryException {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName("UnionTest");
    ftb.add("name", String.class);
    ftb.add("geom1", Geometry.class, CRS.decode("EPSG:3395"));
    ftb.add("geom2", Geometry.class, CRS.decode("EPSG:3395"));

    ftb.setDefaultGeometry("geom1");
    final SimpleFeatureType sft = ftb.buildSimpleFeatureType();
    return sft;
  }
Exemplo n.º 2
0
  private FeatureType buildFeatureType() throws NoSuchAuthorityCodeException, FactoryException {

    final FeatureTypeBuilder typeBuilder = new FeatureTypeBuilder();
    typeBuilder.setName("FeatureCoverage");
    typeBuilder.add("position", Point.class, CRS.decode("EPSG:3395"));
    typeBuilder.add("cellgeom", Polygon.class, CRS.decode("EPSG:3395"));
    typeBuilder.add("orientation", String.class);

    for (int i = 0; i < 3; i++) {
      typeBuilder.add("band-" + i, Integer.class);
    }
    typeBuilder.setDefaultGeometry("position");
    return typeBuilder.buildFeatureType();
  }
  @Test
  public void testRenamedDefinition()
      throws DataStoreException, NoSuchAuthorityCodeException, FactoryException {

    final ExtendedDataStore store = new ExtendedDataStore(dataStore);
    final Name name = DefaultName.valueOf("{http://www.geotoolkit.org/test}extsql");
    assertFalse(store.getNames().contains(name));

    // add a new query
    final Query query =
        QueryBuilder.language(
            JDBCDataStore.CUSTOM_SQL,
            "SELECT geometry as geo ,\"intProperty\" as it FROM custom",
            name);
    store.addQuery(query);
    assertTrue(store.getNames().contains(name));

    final FeatureType ft = store.getFeatureType(name);
    assertEquals(name, ft.getName());
    assertEquals(2, ft.getDescriptors().size());
    assertTrue(ft.getDescriptor("geo") != null);
    assertTrue(ft.getDescriptor("it") != null);
    assertEquals(Point.class, ft.getDescriptor("geo").getType().getBinding());
    assertTrue(
        CRS.equalsIgnoreMetadata(
            CRS.decode("EPSG:4326", true),
            ((GeometryDescriptor) ft.getDescriptor("geo")).getCoordinateReferenceSystem()));
    assertEquals(Integer.class, ft.getDescriptor("it").getType().getBinding());
  }
Exemplo n.º 4
0
  private GridCoverageReader buildReader(PixelInCell pixPos)
      throws NoSuchAuthorityCodeException, FactoryException {

    final BufferedImage image = new BufferedImage(max, max, BufferedImage.TYPE_INT_RGB);

    for (int y = 0; y < max; y++) {
      for (int x = 0; x < max; x++) {
        int val = x << 8;
        image.setRGB(x, y, val + y);
      }
    }

    final CoordinateReferenceSystem crs2d = CRS.decode("EPSG:3395");
    AffineTransform2D gridToCRS;
    if (pixPos == PixelInCell.CELL_CENTER) {
      gridToCRS = new AffineTransform2D(1, 0, 0, 1, 0.5, 0.5);
    } else {
      gridToCRS = new AffineTransform2D(1, 0, 0, 1, 0.5, 1.5);
    }
    final GridCoverageBuilder gcb = new GridCoverageBuilder();
    gcb.setCoordinateReferenceSystem(crs2d);
    gcb.setGridToCRS((AffineTransform) gridToCRS);
    gcb.setRenderedImage(image);
    return new SimpleCoverageReader(gcb.getGridCoverage2D(), pixPos);
  }
  @Test
  public void CRSConvertTest()
      throws NoSuchAuthorityCodeException, FactoryException, NonconvertibleObjectException {

    final ObjectConverter<String, CoordinateReferenceSystem> converter =
        StringToCRSConverter.getInstance();

    String inputString = "EPSG:3395";
    CoordinateReferenceSystem convertedCRS = converter.convert(inputString);
    CoordinateReferenceSystem expectedCRS = CRS.decode("EPSG:3395");
    assertEquals(expectedCRS, convertedCRS);

    inputString = "3395";
    try {
      convertedCRS = converter.convert(inputString);
      fail("should not pass");
    } catch (NonconvertibleObjectException ex) {
      // ok
    }
  }
  @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));
  }