SLD 1.0.0 および SLD 1.1.0 で機能する geotools を使用して SLD ファイルを解析する組み込みの方法はありますか?
1 に答える
1
組み込みの方法は見つかりませんでしたが、考えられる解決策の 1 つは、XML ファイルから SLD バージョンを取得することです。Configuration
バージョンによっては、適切なクラスで解析できます。
public Style createStyleFromSld(String uri) throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document xmlDocument = db.parse(uri);
XPath xPath = XPathFactory.newInstance().newXPath();
String version = xPath.compile("/StyledLayerDescriptor/@version").evaluate(xmlDocument);
Configuration sldConf;
if (version != null && version.startsWith("1.1")) {
sldConf = new org.geotools.sld.v1_1.SLDConfiguration();
} else {
sldConf = new org.geotools.sld.SLDConfiguration();
}
StyledLayerDescriptor sld = (StyledLayerDescriptor) new DOMParser(sldConf, xmlDocument).parse();
NamedLayer l = (NamedLayer) sld.getStyledLayers()[0];
Style style = l.getStyles()[0];
return style;
}
于 2019-09-26T12:47:17.087 に答える