geotools使用外部图片

Style style;

StyleBuilder sb = new StyleBuilder();

Mark circle = (Mark) sb.createMark(StyleBuilder.MARK_CIRCLE, Color.RED);

ExternalGraphic icon;

String filePath = null;

try {

filePath = FileLocator.toFileURL(Platform.getBundle(IAppConstants.APPLICATION_ID)

.getEntry(“”)).toString()+”icons/rain.gif”;; //filePath转换成了绝对路径 file:/E:/pic/rain.gif

} catch (IOException e) {

e.printStackTrace();

}

// icon = sb.createExternalGraphic(“file:///E|/Alu/pic/rain.gif“, “image/gif”); //可以使用绝对路径

icon = sb.createExternalGraphic(filePath, “image/gif”);

// Graphic graph2 = sb.createGraphic(null, circle, null, 1.0, 4.0, 0.0); //使用内部已知图元

Graphic graph2 = sb.createGraphic(icon, null, null, 1.0, 16.0, 0.0); //使用外部图片

PointSymbolizer symbolizer = sb.createPointSymbolizer(graph2);

// PointSymbolizer symbolizer = styleFactory.createPointSymbolizer();

// symbolizer.getGraphic().setSize(filterFactory.literal(10));

// symbolizer.getGraphic().getMarks()[0].setStroke(arg0)

Rule rule = styleFactory.createRule();

rule.setSymbolizers(new Symbolizer[] { symbolizer });

FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();

fts.setRules(new Rule[] { rule });

style = styleFactory.createStyle();

style.addFeatureTypeStyle(fts);

转载自:https://blog.csdn.net/alusc/article/details/4421948

You may also like...