本文整理汇总了Java中org.geotools.styling.StyleFactory类的典型用法代码示例。如果您正苦于以下问题:Java StyleFactory类的具体用法?Java StyleFactory怎么用?Java StyleFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StyleFactory类属于org.geotools.styling包,在下文中一共展示了StyleFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDefaultLineFeatureTypeStyle
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
private FeatureTypeStyle createDefaultLineFeatureTypeStyle(String strokeWidth, String strokeColor, String opacity){
StyleFactory sf = CommonFactoryFinder.getStyleFactory(new Hints(Hints.KEY_RENDERING, Hints.VALUE_RENDER_SPEED));
FilterFactory filterFactory = new FilterFactoryImpl();
Stroke lineStroke = sf.getDefaultStroke();
lineStroke.setWidth(filterFactory.literal(new Integer(strokeWidth)));
lineStroke.setColor(filterFactory.literal(strokeColor));
lineStroke.setOpacity(filterFactory.literal(opacity));
LineSymbolizer lineSymbolizer = sf.createLineSymbolizer();
lineSymbolizer.setStroke(lineStroke);
Rule lineRule = sf.createRule();
lineRule.symbolizers().add(lineSymbolizer);
FeatureTypeStyle lineFeatureTypeStyle = sf.createFeatureTypeStyle(new Rule[]{lineRule});
return lineFeatureTypeStyle;
}
示例2: createStyle
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
@SuppressWarnings({"deprecation"})
private static Style createStyle() {
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
PolygonSymbolizer symbolizer = styleFactory.createPolygonSymbolizer();
Fill fill = styleFactory.createFill(
filterFactory.literal("#FFAA00"),
filterFactory.literal(0.5)
);
symbolizer.setFill(fill);
Rule rule = styleFactory.createRule();
rule.setSymbolizers(new Symbolizer[]{symbolizer});
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
fts.setRules(new Rule[]{rule});
Style style = styleFactory.createStyle();
style.addFeatureTypeStyle(fts);
return style;
}
示例3: convertToSLD_1_1
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
private void convertToSLD_1_1() {
if (style == null) {
JOptionPane.showMessageDialog(this, "Style not defined");
return;
}
// Wrap style as an SLD
StyleFactory factory = CommonFactoryFinder.getStyleFactory();
StyledLayerDescriptor sld = factory.createStyledLayerDescriptor();
org.geotools.sld.v1_1.SLDConfiguration configuration = new org.geotools.sld.v1_1.SLDConfiguration();
Encoder encoder = new org.geotools.xml.Encoder(configuration);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
encoder.encode(style,
org.geotools.sld.bindings.SLD.STYLEDLAYERDESCRIPTOR,
outputStream);
String document = outputStream.toString("UTF-8");
display(document, SLD_1_1);
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: getDirectRasterStyle
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
private static FeatureTypeStyle getDirectRasterStyle(
final String geometryPropertyName,
final Expression transformation ) {
final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
final FeatureTypeStyle style = styleFactory.createFeatureTypeStyle();
final Rule rule = styleFactory.createRule();
rule.setName("distributed render - direct raster");
rule.setTitle("Distributed Render - Direct Raster");
final RasterSymbolizer symbolizer = styleFactory.createRasterSymbolizer();
symbolizer.setGeometryPropertyName(geometryPropertyName);
rule.symbolizers().add(
symbolizer);
style.rules().add(
rule);
style.setTransformation(transformation);
return style;
}
示例5: createSLDFromString
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
/**
* Creates a StyledLayerDescriptor object containing a SLD from a string.
*
* @param sldData the sld data
* @return the styled layer descriptor
*/
public static StyledLayerDescriptor createSLDFromString(SLDDataInterface sldData) {
if ((sldData == null) || (sldData.getSld() == null)) {
return null;
}
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
InputStream stream = new ByteArrayInputStream(sldData.getSld().getBytes());
SLDParser styleReader = new SLDParser(styleFactory, stream);
URL resourceLocator = getResourceLocator(sldData);
sldData.setResourceLocator(resourceLocator);
setResourcelocator(styleReader, resourceLocator);
StyledLayerDescriptor sld = null;
try {
sld = styleReader.parseSLD();
} catch (RuntimeException e) {
String errorMessage = String.format("SLD Parser error : %s",
sldData.getStyle().toString());
ConsoleManager.getInstance().error(SLDUtils.class, errorMessage);
ConsoleManager.getInstance().error(SLDUtils.class, e.getMessage());
}
return sld;
}
示例6: createGraphic
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
/**
* Creates the graphic.
*
* @param url the url
* @param styleFactory the style factory
* @return the graphic
*/
private Graphic createGraphic(URL url, StyleFactory styleFactory) {
List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>();
ExternalGraphic externalGraphic = styleFactory.createExternalGraphic(url, "image/png");
symbolList.add(externalGraphic);
Graphic graphicFill = styleFactory.graphicFill(symbolList, null, null, null, null, null);
return graphicFill;
}
示例7: styleFactoryExample
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
/**
* This example is limited to just the gt-opengis style interfaces which are immutable once created.
*
* @throws Exception
*/
private void styleFactoryExample() throws Exception {
// styleFactoryExample start
//
org.opengis.style.StyleFactory sf = CommonFactoryFinder.getStyleFactory();
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
//
// create the graphical mark used to represent a city
Stroke stroke = sf.stroke(ff.literal("#000000"), null, null, null, null, null, null);
Fill fill = sf.fill(null, ff.literal(Color.BLUE), ff.literal(1.0));
// OnLineResource implemented by gt-metadata - so no factory!
OnLineResourceImpl svg = new OnLineResourceImpl(new URI("file:city.svg"));
svg.freeze(); // freeze to prevent modification at runtime
OnLineResourceImpl png = new OnLineResourceImpl(new URI("file:city.png"));
png.freeze(); // freeze to prevent modification at runtime
//
// List of symbols is considered in order with the rendering engine choosing
// the first one it can handle. Allowing for svg, png, mark order
List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
symbols.add(sf.externalGraphic(svg, "svg", null)); // svg preferred
symbols.add(sf.externalGraphic(png, "png", null)); // png preferred
symbols.add(sf.mark(ff.literal("circle"), fill, stroke)); // simple circle backup plan
Expression opacity = null; // use default
Expression size = ff.literal(10);
Expression rotation = null; // use default
AnchorPoint anchor = null; // use default
Displacement displacement = null; // use default
// define a point symbolizer of a small circle
Graphic circle = sf.graphic(symbols, opacity, size, rotation, anchor, displacement);
PointSymbolizer pointSymbolizer = sf.pointSymbolizer("point", ff.property("the_geom"), null,
null, circle);
// styleFactoryExample end
}
示例8: importSLD
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
protected void importSLD() {
File file = importStyleWizard("Select style layer descriptor 1.0 document","sld","style layer descriptor");
if( file == null ) return; // cancel
StyleFactory factory = CommonFactoryFinder.getStyleFactory();
SLDParser sldParser = new SLDParser(factory);
}
示例9: readSLD_1_0
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
private void readSLD_1_0() {
StyleFactory factory = CommonFactoryFinder.getStyleFactory();
StringReader reader = new StringReader(text.getText());
SLDParser sldParser = new SLDParser(factory, reader);
Style[] parsed = sldParser.readXML();
if (parsed != null && parsed.length > 0) {
style = parsed[0];
}
}
示例10: createDefaultSLD
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
public static StyledLayerDescriptor createDefaultSLD(Style style) {
StyleFactory factory = CommonFactoryFinder.getStyleFactory();
StyledLayerDescriptor sld = factory.createStyledLayerDescriptor();
UserLayer layer = factory.createUserLayer();
// FeatureTypeConstraint ftc =
// styleFactory.createFeatureTypeConstraint(null, Filter.INCLUDE, null);
layer.setLayerFeatureConstraints(new FeatureTypeConstraint[] { null });
sld.addStyledLayer(layer);
layer.addUserStyle((org.geotools.styling.Style) style);
return sld;
}
示例11: sldExample
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
private void sldExample() {
// sldExample start
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
sld.setName("example");
sld.setAbstract("Example Style Layer Descriptor");
UserLayer layer = styleFactory.createUserLayer();
layer.setName("layer");
FeatureTypeConstraint constraint = styleFactory.createFeatureTypeConstraint("Feature",
Filter.INCLUDE, null);
layer.layerFeatureConstraints().add(constraint);
Style style = styleFactory.createStyle();
style.getDescription().setTitle("Style");
style.getDescription().setAbstract("Definition of Style");
// define feature type styles used to actually
// define how features are rendered
//
layer.userStyles().add(style);
sld.layers().add(layer);
// sldExample end
}
示例12: twoFeatureTypeStyles
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
private void twoFeatureTypeStyles() {
// twoFeatureTypeStyles start
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2();
Style style = styleFactory.getDefaultStyle();
// Feature type style 1
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
fts.featureTypeNames().add(new NameImpl("feature-type-1"));
style.featureTypeStyles().add(fts);
// Feature type style 2
FeatureTypeStyle fts2 = styleFactory.createFeatureTypeStyle();
fts2.featureTypeNames().add(new NameImpl("feature-type-2"));
// creating the rule 1
Rule rule1 = styleFactory.createRule();
rule1.setName("rule1");
Filter aFilter = filterFactory.id(Collections.singleton(filterFactory.featureId("FID")));
rule1.setFilter(aFilter);
fts2.rules().add(rule1);
// creating the rule 2
Rule rule2 = styleFactory.createRule();
rule2.setIsElseFilter(true);
rule2.setName("rule2");
fts2.rules().add(rule2);
style.featureTypeStyles().add(fts2);
// twoFeatureTypeStyles end
}
示例13: createPolygonStyle
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
private static Style createPolygonStyle() {
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
PolygonSymbolizer symbolizer = styleFactory.createPolygonSymbolizer();
org.geotools.styling.Stroke stroke = styleFactory.createStroke(
filterFactory.literal("#FFFFFF"),
filterFactory.literal(0.0)
);
symbolizer.setStroke(stroke);
Fill fill = styleFactory.createFill(
filterFactory.literal("#FFFFFF"),
filterFactory.literal(1.0)
);
symbolizer.setFill(fill);
Rule rule = styleFactory.createRule();
rule.symbolizers().add(symbolizer);
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
fts.rules().add(rule);
Style style = styleFactory.createStyle();
style.featureTypeStyles().add(fts);
return style;
}
示例14: getSuitabilityStyle
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
public StyledLayerDescriptor getSuitabilityStyle(String columnName) {
LOGGER.debug("creating a style for suitability column: for", columnName);
StyleFactory sf = CommonFactoryFinder.getStyleFactory();
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
UserLayer layer = sf.createUserLayer();
layer.setName("layer");
StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
sld.setName("sld");
sld.setTitle("Example");
sld.setAbstract("Example Style Layer Descriptor");
// define constraint limited what features the sld applies to
FeatureTypeConstraint constraint = sf.createFeatureTypeConstraint(
"Feature", Filter.INCLUDE, null);
layer.layerFeatureConstraints().add(constraint);
//
// create a "user defined" style
Style style = sf.createStyle();
style.setName("style");
style.getDescription().setTitle("User Style");
style.getDescription().setAbstract("Definition of Style");
// define feature type styles used to actually define how features are
// rendered
FeatureTypeStyle featureTypeStyle = sf.createFeatureTypeStyle();
// RULE 1
// first rule to draw cities
Rule rule1 = sf.createRule();
rule1.setName("rule1");
rule1.getDescription().setTitle("City");
rule1.getDescription().setAbstract("Rule for drawing cities");
rule1.setFilter(ff.less(ff.property("POPULATION"), ff.literal(50000)));
//
// create the graphical mark used to represent a city
Stroke stroke = sf.stroke(ff.literal("#000000"), null, null, null, null,
null, null);
Fill fill = sf.fill(null, ff.literal(Color.BLUE), ff.literal(1.0));
StyleBuilder styleBuilder = new StyleBuilder();
PolygonSymbolizer polygonSymbolizer = styleBuilder.createPolygonSymbolizer(Color.BLUE);
polygonSymbolizer.getFill().setOpacity(ff.literal(0.5)); // 50% blue
polygonSymbolizer.setStroke(styleBuilder.createStroke(Color.BLACK, 2.0));
// will create a default feature type style and rule etc...
//Style style = styleBuilder.createStyle(polygonSymbolizer);
rule1.symbolizers().add(polygonSymbolizer);
featureTypeStyle.rules().add(rule1);
style.featureTypeStyles().add(featureTypeStyle);
layer.userStyles().add(style);
sld.layers().add(layer);
// // create the parser with the sld configuration
// org.geotools.xml.Configuration configuration = new
// org.geotools.sld.SLDConfiguration();
// Parser parser = new org.geotools.xml.Parser(configuration);
// // the xml instance document above
// InputStream xml = new FileInputStream("markTest.sld");
// // parse
// StyledLayerDescriptor sld = (StyledLayerDescriptor) parser.parse(xml);
// DuplicatingStyleVisitor xerox = new DuplicatingStyleVisitor();
// style.accepts( xerox );
// Style copy = (Style) xerox.getCopy();
return sld;
}
示例15: viewCoverage
import org.geotools.styling.StyleFactory; //导入依赖的package包/类
@Execute
public void viewCoverage() throws Exception {
StyleFactory sf = CommonFactoryFinder.getStyleFactory(null);
// RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();
// Style rasterStyle = SLD.wrapSymbolizers(sym);
StyleBuilder sB = new StyleBuilder(sf);
RasterSymbolizer rasterSym = sf.createRasterSymbolizer();
ColorMap colorMap = sf.createColorMap();
RenderedImage renderedImage = raster.getRenderedImage();
double max = Double.NEGATIVE_INFINITY;
double min = Double.POSITIVE_INFINITY;
RectIter iter = RectIterFactory.create(renderedImage, null);
do {
do {
double value = iter.getSampleDouble();
if (value > max) {
max = value;
}
if (value < min) {
min = value;
}
} while( !iter.nextPixelDone() );
iter.startPixels();
} while( !iter.nextLineDone() );
// red to blue
Color fromColor = Color.blue;
Color toColor = Color.red;
Expression fromColorExpr = sB.colorExpression(new java.awt.Color(fromColor.getRed(), fromColor.getGreen(), fromColor
.getBlue(), 255));
Expression toColorExpr = sB.colorExpression(new java.awt.Color(toColor.getRed(), toColor.getGreen(), toColor.getBlue(),
255));
Expression fromExpr = sB.literalExpression(min);
Expression toExpr = sB.literalExpression(max);
ColorMapEntry entry = sf.createColorMapEntry();
entry.setQuantity(fromExpr);
entry.setColor(fromColorExpr);
colorMap.addColorMapEntry(entry);
entry = sf.createColorMapEntry();
entry.setQuantity(toExpr);
entry.setColor(toColorExpr);
colorMap.addColorMapEntry(entry);
rasterSym.setColorMap(colorMap);
Style rasterStyle = SLD.wrapSymbolizers(rasterSym);
// Set up a MapContext with the two layers
final MapContext map = new DefaultMapContext();
map.setTitle("Coverage Viewer");
map.addLayer(raster, rasterStyle);
// Create a JMapFrame with a menu to choose the display style for the
final JMapFrame frame = new JMapFrame(map);
frame.setSize(800, 600);
frame.enableStatusBar(true);
frame.enableTool(JMapFrame.Tool.ZOOM, JMapFrame.Tool.PAN, JMapFrame.Tool.RESET);
frame.enableToolBar(true);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing( WindowEvent e ) {
frame.setVisible(false);
}
});
while( frame.isVisible() ) {
Thread.sleep(300);
}
}