예제 #1
0
  /**
   * Test that we don't have the geometry added twice by StreamingRenderer#findStyleAttributes when
   * geofence is filtering a layer.
   *
   * @throws Exception
   */
  @Test
  public void testFindLineStyleAttributeWithAddedFilter() throws Exception {
    final List<Filter> filters = new ArrayList<Filter>();

    SimpleFeatureSource testSource =
        new CollectionFeatureSource(createLineCollection()) {
          @Override
          public SimpleFeatureCollection getFeatures(Query query) {
            filters.add(query.getFilter());
            return super.getFeatures(query);
          }
        };

    Style style = createPointStyle();
    MapContent mc = new MapContent();
    FeatureLayer layer = new FeatureLayer(testSource, style);
    mc.addLayer(layer);

    StreamingRenderer sr = new StreamingRenderer();
    sr.setMapContent(mc);

    ReferencedEnvelope envelope =
        new ReferencedEnvelope(0, 100, 0, 100, DefaultGeographicCRS.WGS84);

    // simulate geofence adding a bbox
    BBOX bbox = StreamingRenderer.filterFactory.bbox("", 30, 60, 30, 60, "WGS84");
    StyleFactoryImpl sf = new StyleFactoryImpl();
    Rule bboxRule =
        sf.createRule(
            new Symbolizer[0], new DescriptionImpl(), new Graphic[0], "bbox", bbox, false, 1e12, 0);
    style.featureTypeStyles().get(0).rules().add(bboxRule);

    BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D graphics = bi.createGraphics();
    try {
      sr.paint(graphics, new Rectangle(5, 5, 7, 7), envelope);
    } finally {
      graphics.dispose();
    }

    // must have only one bbox, not two
    assertEquals(1, filters.size());
    assertEquals(FastBBOX.class, filters.get(0).getClass());
  }
예제 #2
0
  public void run() {
    Display display = Display.getCurrent();
    Shell shell = new Shell(display);
    File openFile = JFileImageChooser.showOpenFile(shell);

    if (openFile != null && openFile.exists()) {
      AbstractGridFormat format = GridFormatFinder.findFormat(openFile);
      AbstractGridCoverage2DReader tiffReader = format.getReader(openFile);
      StyleFactoryImpl sf = new StyleFactoryImpl();
      RasterSymbolizer symbolizer = sf.getDefaultRasterSymbolizer();
      Style defaultStyle = SLD.wrapSymbolizers(symbolizer);

      MapContext mapContext = mapPane.getMapContext();
      MapLayer layer = new MapLayer(tiffReader, defaultStyle);
      layer.setTitle(openFile.getName());
      mapContext.addLayer(layer);
      mapPane.redraw();
    }
  }
예제 #3
0
  /** The constructor. */
  public ViewTest() {
    // Create a map content and add our shapefile to it
    map = new MapContent();
    map.setTitle("simple map content");

    // hey, try for an image aswell
    String path = "/Users/ian/Desktop/ukrasterchart/2_BRITISH_ISLES.tif";
    File chartFile = new File(path);
    if (!chartFile.exists()) System.err.println("CANNOT FILE THE CHART FILE!!!");

    WorldImageFormat format = new WorldImageFormat();
    AbstractGridCoverage2DReader tiffReader = format.getReader(chartFile);
    if (tiffReader != null) {
      StyleFactoryImpl sf = new StyleFactoryImpl();
      RasterSymbolizer symbolizer = sf.getDefaultRasterSymbolizer();
      Style defaultStyle = SLD.wrapSymbolizers(symbolizer);

      GeneralParameterValue[] params = null;

      GridReaderLayer res = new GridReaderLayer(tiffReader, defaultStyle, params);
      map.addLayer(res);
    }

    try {
      URL url = GtActivator.getDefault().getBundle().getEntry("data/50m_admin_0_countries.shp");
      String filePath = FileLocator.resolve(url).getFile();
      File file = new File(filePath);
      if (!file.exists()) System.err.println("can't find file!!!");
      FileDataStore store = FileDataStoreFinder.getDataStore(file);
      if (store != null) {
        SimpleFeatureSource featureSource = store.getFeatureSource();

        Style style = SLD.createSimpleStyle(featureSource.getSchema());
        Layer layer = new FeatureLayer(featureSource, style);
        map.addLayer(layer);
      }

    } catch (IOException e) {

    }
    //
  }