org.geotools.styling.Rule.getLegend()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中org.geotools.styling.Rule.getLegend方法的一些代码示例,展示了Rule.getLegend的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rule.getLegend方法的具体详情如下:
包路径:org.geotools.styling.Rule
类名称:Rule
方法名:getLegend

Rule.getLegend介绍

暂无

代码示例

代码示例来源:origin: geotools/geotools

public RuleBuilder reset(Rule rule) {
  if (rule == null) {
    return unset();
  }
  name = rule.getName();
  title = rule.getTitle();
  ruleAbstract = rule.getAbstract();
  minScaleDenominator = rule.getMinScaleDenominator();
  maxScaleDenominator = rule.getMaxScaleDenominator();
  filter = rule.getFilter();
  elseFilter = rule.isElseFilter();
  symbolizers.clear();
  symbolizers.addAll(rule.symbolizers()); // TODO: unpack into builders in order to "copy"
  symbolizerBuilder = null;
  unset = false;
  legend.reset(rule.getLegend());
  return this;
}

代码示例来源:origin: geotools/geotools

@Test
public void testGraphicLegendNegativeScale() throws Exception {
  // Load image directly from file, for comparison with painter output
  final URL imageURL = TestData.getResource(this, "icon64.png");
  final BufferedImage testImage = ImageIO.read(imageURL);
  final int width = testImage.getWidth();
  final int height = testImage.getHeight();
  // Get graphic legend from style
  final Style style = RendererBaseTest.loadStyle(this, "testGraphicLegend.sld");
  final Rule rule = style.featureTypeStyles().get(0).rules().get(0);
  final GraphicLegend legend = (GraphicLegend) rule.getLegend();
  // Paint legend using StyledShapePainter
  final Point point =
      new GeometryFactory().createPoint(new Coordinate(width / 2, height / 2));
  final LiteShape2 shape = new LiteShape2(point, null, null, false);
  int imageType = testImage.getType();
  if (imageType == BufferedImage.TYPE_CUSTOM) {
    imageType = BufferedImage.TYPE_INT_RGB;
  }
  final BufferedImage paintedImage = new BufferedImage(width, height, imageType);
  final Graphics2D graphics = paintedImage.createGraphics();
  final StyledShapePainter painter = new StyledShapePainter();
  painter.paint(graphics, shape, legend, -1, false);
  graphics.dispose();
  // Ensure painted legend matches image from file
  Assert.assertTrue(imagesIdentical(paintedImage, testImage));
}

代码示例来源:origin: geotools/geotools

put("title", rule.getTitle());
put("abstract", rule.getAbstract());
if (rule.getLegend() != null) {
  Graphic graphic = null;
  if (rule.getLegend() instanceof Graphic) {
    graphic = (Graphic) rule.getLegend();
  } else {
    point.setGraphic(rule.getLegend());
    graphic = point.getGraphic();

代码示例来源:origin: geotools/geotools

@Test
public void testGraphicLegend() throws Exception {
  // Load image directly from file, for comparison with painter output
  final URL imageURL = TestData.getResource(this, "icon64.png");
  final BufferedImage testImage = ImageIO.read(imageURL);
  final int width = testImage.getWidth();
  final int height = testImage.getHeight();
  // Get graphic legend from style
  final Style style = RendererBaseTest.loadStyle(this, "testGraphicLegend.sld");
  final Rule rule = style.featureTypeStyles().get(0).rules().get(0);
  final GraphicLegend legend = (GraphicLegend) rule.getLegend();
  // Paint legend using StyledShapePainter
  final Point point =
      new GeometryFactory().createPoint(new Coordinate(width / 2, height / 2));
  final LiteShape2 shape = new LiteShape2(point, null, null, false);
  int imageType = testImage.getType();
  if (imageType == BufferedImage.TYPE_CUSTOM) {
    imageType = BufferedImage.TYPE_INT_RGB;
  }
  final BufferedImage paintedImage = new BufferedImage(width, height, imageType);
  final Graphics2D graphics = paintedImage.createGraphics();
  final StyledShapePainter painter = new StyledShapePainter();
  painter.paint(graphics, shape, legend, 1, false);
  graphics.dispose();
  // Ensure painted legend matches image from file
  Assert.assertTrue(imagesIdentical(paintedImage, testImage));
}

代码示例来源:origin: geotools/geotools

public void testGraphicLegendRotation() throws Exception {
  FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
  GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();
  // Load image directly from file, for comparison with painter output
  final URL imageURL = TestData.getResource(this, "icon64.png");
  final BufferedImage testImage = ImageIO.read(imageURL);
  final int width = testImage.getWidth();
  final int height = testImage.getHeight();
  // Get graphic legend from style
  final Style style = RendererBaseTest.loadStyle(this, "testGraphicLegend.sld");
  final Rule rule = style.featureTypeStyles().get(0).rules().get(0);
  final GraphicLegend legend = (GraphicLegend) rule.getLegend();
  // Set rotation to 45 degrees
  legend.setRotation(ff.literal(45.0));
  // Paint legend using StyledShapePainter
  final Point point = gf.createPoint(new Coordinate(width / 2, height / 2));
  final LiteShape2 shape = new LiteShape2(point, null, null, false);
  int imageType = testImage.getType();
  if (imageType == BufferedImage.TYPE_CUSTOM) {
    imageType = BufferedImage.TYPE_INT_RGB;
  }
  final BufferedImage paintedImage = new BufferedImage(width, height, imageType);
  final Graphics2D graphics = paintedImage.createGraphics();
  final StyledShapePainter painter = new StyledShapePainter();
  painter.paint(graphics, shape, legend, 1, false);
  graphics.dispose();
  // Ensure painted legend does not match image from file
  Assert.assertFalse(imagesIdentical(paintedImage, testImage));
}

代码示例来源:origin: geotools/geotools

@Test
public void testLegend() throws Exception {
  String yaml =
      "feature-styles:\n"
          + "- rules:\n"
          + "  - legend:\n"
          + "      symbols:\n"
          + "      - external:\n"
          + "          url: smileyface.png\n"
          + "          format: image/png\n"
          + "    symbolizers:\n"
          + "    - point:\n"
          + "        symbols:\n"
          + "        - mark:\n"
          + "            shape: circle\n"
          + "            fill-color: '#FF0000'";
  StyledLayerDescriptor sld = Ysld.parse(yaml);
  Rule rule = SLD.rules(SLD.defaultStyle(sld))[0];
  assertThat(rule.getLegend().graphicalSymbols().get(0), instanceOf(ExternalGraphic.class));
  ExternalGraphic legend = (ExternalGraphic) rule.getLegend().graphicalSymbols().get(0);
  assertEquals(new URL("file:smileyface.png"), legend.getLocation());
  assertEquals("image/png", legend.getFormat());
  PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld));
  assertEquals("circle", SLD.wellKnownName(SLD.mark(p)));
  assertEquals(Color.RED, SLD.color(SLD.fill(p)));
}

代码示例来源:origin: geotools/geotools

GraphicLegend legend = (GraphicLegend) SLD.rules(style)[0].getLegend();
assertEquals(32, Filters.asInt(legend.getSize()));

代码示例来源:origin: robward-scisys/sldeditor

/**
 * @param existingRule
 * @return
 */
private Graphic[] updateLegend(org.geotools.styling.Rule existingRule) {
  int index;
  GraphicLegend existingLegend = existingRule.getLegend();
  Graphic[] legendGraphics = null;
  if (existingLegend != null) {
    int legendGraphicCount = existingLegend.graphicalSymbols().size();
    legendGraphics = new Graphic[legendGraphicCount];
    index = 0;
    for (GraphicalSymbol graphicalSymbol : existingLegend.graphicalSymbols()) {
      legendGraphics[index] = (Graphic) graphicalSymbol;
      index++;
    }
  } else {
    legendGraphics = new Graphic[0];
  }
  return legendGraphics;
}

代码示例来源:origin: org.geoserver/gs-wms

final GraphicLegend graphic = applicableRules[i].getLegend();

代码示例来源:origin: robward-scisys/sldeditor

final GraphicLegend graphic = applicableRules[i].getLegend();

相关文章