本文整理汇总了Java中org.geotools.styling.SLDParser类的典型用法代码示例。如果您正苦于以下问题:Java SLDParser类的具体用法?Java SLDParser怎么用?Java SLDParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SLDParser类属于org.geotools.styling包,在下文中一共展示了SLDParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getStyleFromFile
import org.geotools.styling.SLDParser; //导入依赖的package包/类
/**
* Get the style from an sld file.
*
* @param file the SLD file or a companion file.
* @return the {@link Style} object.
* @throws IOException
*/
public static Style getStyleFromFile(File file) {
Style style = null;
try {
String name = file.getName();
if (!name.endsWith("sld")) {
String nameWithoutExtention = FileUtilities.getNameWithoutExtention(file);
File sldFile = new File(file.getParentFile(), nameWithoutExtention + ".sld");
if (sldFile.exists()) {
file = sldFile;
} else {
// no style file here
return null;
}
}
SLDParser stylereader = new SLDParser(sf, file);
StyledLayerDescriptor sld = stylereader.parseSLD();
style = getDefaultStyle(sld);
return style;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:32,代码来源:SldUtilities.java
示例2: testLabels
import org.geotools.styling.SLDParser; //导入依赖的package包/类
@Test
public void testLabels() throws IOException {
SymbolizerFilterVisitor visitor = new SymbolizerFilterVisitor();
visitor.setIncludeGeometry(false);
visitor.setIncludeText(true);
SLDParser parser = new SLDParser(styleFactory);
parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld"));
Style[] styles = parser.readXML();
Assert.assertEquals(1, styles.length);
visitor.visit(styles[0]);
Style copy = (Style) visitor.getCopy();
FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next();
Rule rule = featureTypeStyle.rules().iterator().next();
Iterator<Symbolizer> it = rule.symbolizers().iterator();
Assert.assertTrue(it.next() instanceof TextSymbolizer);
Assert.assertFalse(it.hasNext());
}
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:18,代码来源:SymbolizerFilterVisitorTest.java
示例3: testGeometries
import org.geotools.styling.SLDParser; //导入依赖的package包/类
@Test
public void testGeometries() throws IOException{
SymbolizerFilterVisitor visitor = new SymbolizerFilterVisitor();
visitor.setIncludeGeometry(true);
visitor.setIncludeText(false);
SLDParser parser = new SLDParser(styleFactory);
parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld"));
Style[] styles = parser.readXML();
Assert.assertEquals(1, styles.length);
visitor.visit(styles[0]);
Style copy = (Style) visitor.getCopy();
FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next();
Rule rule = featureTypeStyle.rules().iterator().next();
Iterator<Symbolizer> it = rule.symbolizers().iterator();
Assert.assertTrue(it.next() instanceof PointSymbolizer);
Assert.assertFalse(it.hasNext());
}
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:18,代码来源:SymbolizerFilterVisitorTest.java
示例4: testLabelsAndGeometries
import org.geotools.styling.SLDParser; //导入依赖的package包/类
@Test
public void testLabelsAndGeometries() throws IOException{
SymbolizerFilterVisitor visitor = new SymbolizerFilterVisitor();
visitor.setIncludeGeometry(true);
visitor.setIncludeText(true);
SLDParser parser = new SLDParser(styleFactory);
parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld"));
Style[] styles = parser.readXML();
Assert.assertEquals(1, styles.length);
visitor.visit(styles[0]);
Style copy = (Style) visitor.getCopy();
FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next();
Rule rule = featureTypeStyle.rules().iterator().next();
Iterator<Symbolizer> it = rule.symbolizers().iterator();
Assert.assertTrue(it.next() instanceof PointSymbolizer);
Assert.assertTrue(it.next() instanceof TextSymbolizer);
Assert.assertFalse(it.hasNext());
}
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:19,代码来源:SymbolizerFilterVisitorTest.java
示例5: testTransformation
import org.geotools.styling.SLDParser; //导入依赖的package包/类
@Test
public void testTransformation() throws IOException{
SymbolizerFilterVisitor visitor = new SymbolizerFilterVisitor();
visitor.setIncludeGeometry(true);
visitor.setIncludeText(true);
SLDParser parser = new SLDParser(styleFactory);
parser.setInput(getClass().getResource("heatmap.sld"));
Style[] styles = parser.readXML();
Assert.assertEquals(1, styles.length);
visitor.visit(styles[0]);
Style copy = (Style) visitor.getCopy();
FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next();
Assert.assertNotNull(featureTypeStyle.getTransformation());
Rule rule = featureTypeStyle.rules().iterator().next();
Iterator<Symbolizer> it = rule.symbolizers().iterator();
Assert.assertTrue(it.next() instanceof RasterSymbolizer);
Assert.assertFalse(it.hasNext());
}
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:19,代码来源:SymbolizerFilterVisitorTest.java
示例6: createSLDFromString
import org.geotools.styling.SLDParser; //导入依赖的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;
}
开发者ID:robward-scisys,项目名称:sldeditor,代码行数:35,代码来源:SLDUtils.java
示例7: setResourcelocator
import org.geotools.styling.SLDParser; //导入依赖的package包/类
/**
* Sets the resource locator so that relative external graphic files can be found.
*
* @param styleReader the new resource locator
* @param url the url
*/
public static void setResourcelocator(SLDParser styleReader, URL url) {
DefaultResourceLocator resourceLocator = new DefaultResourceLocator();
resourceLocator.setSourceUrl(url);
styleReader.setOnLineResourceLocator(resourceLocator);
}
开发者ID:robward-scisys,项目名称:sldeditor,代码行数:13,代码来源:SLDUtils.java
示例8: createFromSLD
import org.geotools.styling.SLDParser; //导入依赖的package包/类
/**
* Create a Style object from a definition in a SLD document
*
* @param sld
* the sld file.
* @return the created {@link Style} or <code>null</code>.
*/
public static Style createFromSLD(final File sld) {
try {
final SLDParser stylereader = new SLDParser(styleFactory, sld.toURI().toURL());
final Style[] style = stylereader.readXML();
return style[0];
} catch (final Exception e) {
ExceptionMonitor.show(null, e, "Problem creating style");
}
return null;
}
开发者ID:gama-platform,项目名称:gama,代码行数:19,代码来源:Utils.java
示例9: createFromSLD
import org.geotools.styling.SLDParser; //导入依赖的package包/类
public static Style[] createFromSLD(File sld) {
try {
SLDParser stylereader = new SLDParser(styleFactory, sld.toURI().toURL());
return stylereader.readXML();
} catch (IOException e) {
e.printStackTrace();
}
return new Style[0];
}
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:10,代码来源:SLDUtils.java
示例10: convertDomToValue
import org.geotools.styling.SLDParser; //导入依赖的package包/类
@Override
public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException,
ValidationException {
final DomElement child = parentElement.getChild(0);
SLDParser s = new SLDParser(CommonFactoryFinder.getStyleFactory(null), new StringReader(child.toXml()));
final Style[] styles = s.readXML();
return styles[0];
}
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:9,代码来源:FeatureLayerType.java
示例11: importSLD
import org.geotools.styling.SLDParser; //导入依赖的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);
}
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:9,代码来源:StyleConverter.java
示例12: readSLD_1_0
import org.geotools.styling.SLDParser; //导入依赖的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];
}
}
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:12,代码来源:StyleConverter.java
示例13: createFromSLD
import org.geotools.styling.SLDParser; //导入依赖的package包/类
/**
* Create a Style object from a definition in a SLD document
*/
private Style createFromSLD(File sld) {
try {
SLDParser stylereader = new SLDParser(styleFactory, sld.toURI().toURL());
Style[] style = stylereader.readXML();
return style[0];
} catch (Exception e) {
JExceptionReporter.showDialog(e, "Problem creating style");
}
return null;
}
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:15,代码来源:StyleLab.java
示例14: convert
import org.geotools.styling.SLDParser; //导入依赖的package包/类
@Override
public Style convert(UserStyleInfo userStyleInfo) throws LayerException {
IBindingFactory bindingFactory;
try {
// create a dummy SLD root
StyledLayerDescriptorInfo sld = new StyledLayerDescriptorInfo();
sld.setVersion(SLD_VERSION);
StyledLayerDescriptorInfo.ChoiceInfo choice = new StyledLayerDescriptorInfo.ChoiceInfo();
NamedLayerInfo namedLayerInfo = new NamedLayerInfo();
namedLayerInfo.setName(DUMMY_NAMED_LAYER);
NamedLayerInfo.ChoiceInfo userChoice = new NamedLayerInfo.ChoiceInfo();
userChoice.setUserStyle(userStyleInfo);
namedLayerInfo.getChoiceList().add(userChoice);
choice.setNamedLayer(namedLayerInfo);
sld.getChoiceList().add(choice);
// force through Geotools parser
bindingFactory = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
IMarshallingContext marshallingContext = bindingFactory.createMarshallingContext();
StringWriter sw = new StringWriter();
marshallingContext.setOutput(sw);
marshallingContext.marshalDocument(sld);
SLDParser parser = new SLDParser(styleFactory, filterService.getFilterFactory());
parser.setOnLineResourceLocator(new ResourceServiceBasedLocator());
parser.setInput(new StringReader(sw.toString()));
Style[] styles = parser.readXML();
if (styles.length != 0) {
return styles[0];
} else {
throw new LayerException(ExceptionCode.INVALID_USER_STYLE, userStyleInfo.getName());
}
} catch (Exception e) {
throw new LayerException(e, ExceptionCode.INVALID_USER_STYLE, userStyleInfo.getName());
}
}
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:38,代码来源:StyleConverterServiceImpl.java
示例15: readStyle
import org.geotools.styling.SLDParser; //导入依赖的package包/类
/**
* Parse a file and extract the {@link StyledLayerDescriptor}.
*
* @param file the sld file to parse.
* @return the styled layer descriptor.
* @throws IOException
*/
public static StyledLayerDescriptor readStyle( File file ) throws IOException {
SLDParser stylereader = new SLDParser(sf, file);
StyledLayerDescriptor sld = stylereader.parseSLD();
return sld;
}
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:13,代码来源:Utilities.java
注:本文中的org.geotools.styling.SLDParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论