@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());
  }
  /** {@inheritDoc } */
  @Override
  public double[] getResolution(final CoordinateReferenceSystem crs) {
    if (CRS.equalsIgnoreMetadata(objectiveCRS, crs)) {
      return getResolution();
    } else {
      final double[] res = new double[crs.getCoordinateSystem().getDimension()];

      final Envelope env;
      try {
        env = CRS.transform(canvasObjectiveBBox2D, crs);
        final Rectangle2D canvasCRSBounds =
            new Rectangle2D.Double(0, 0, env.getSpan(0), env.getSpan(1));
        res[0] = Math.abs(canvasCRSBounds.getWidth() / canvasDisplaybounds.getWidth());
        res[1] = Math.abs(canvasCRSBounds.getHeight() / canvasDisplaybounds.getHeight());
        for (int i = 2; i < res.length; i++) {
          // other dimension are likely to be the temporal and elevation one.
          // we set a hug resolution to ensure that only one slice of data will be retrived.
          res[i] = Double.MAX_VALUE;
        }
      } catch (TransformException ex) {
        LOGGER.log(Level.WARNING, null, ex);
      } catch (IllegalArgumentException ex) {
        LOGGER.log(Level.WARNING, null, ex);
      } catch (Exception ex) {
        LOGGER.log(Level.WARNING, null, ex);
      }

      return adjustResolutionWithDPI(res);
    }
  }
Exemplo n.º 3
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.º 4
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();
  }
Exemplo n.º 5
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);
  }
Exemplo n.º 6
0
 /**
  * Returns the CRS code for the specified envelope, or {@code null} if not found.
  *
  * @param envelope The envelope to return the CRS code.
  */
 public static String toCrsCode(final Envelope envelope) {
   if (org.geotoolkit.referencing.CRS.equalsIgnoreMetadata(
       envelope.getCoordinateReferenceSystem(), CommonCRS.WGS84.normalizedGeographic())) {
     return "EPSG:4326";
   }
   final Set<Identifier> identifiers = envelope.getCoordinateReferenceSystem().getIdentifiers();
   if (identifiers != null && !identifiers.isEmpty()) {
     return identifiers.iterator().next().toString();
   }
   return null;
 }
  @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
    }
  }
Exemplo n.º 8
0
  public JCRSList() {

    // obtain the factory only for epsg codes
    //        String authority = "EPSG";
    //        this.factory = FallbackAuthorityFactory.create(CRSAuthorityFactory.class,
    //             filter(AuthorityFactoryFinder.getCRSAuthorityFactories(null), authority));

    this.factory = CRS.getAuthorityFactory(Boolean.FALSE);

    try {
      this.codeList = new CodeList(factory, CoordinateReferenceSystem.class);
      liste.setModel(codeList);
    } catch (FactoryException e) {
      e.printStackTrace();
    }

    liste.getSelectionModel().setSelectionMode(liste.getSelectionModel().SINGLE_SELECTION);

    setLayout(new GridLayout());
    add(BorderLayout.CENTER, new JScrollPane(liste));

    liste
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {

              @Override
              public void valueChanged(ListSelectionEvent e) {
                int index = e.getFirstIndex();

                if (index >= 0) {
                  try {
                    selectedCRS = (CoordinateReferenceSystem) getSelectedItem();
                  } catch (FactoryException ex) {
                    ex.printStackTrace();
                  }
                }
              }
            });
  }
  @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));
  }