您的位置:首页 > Web前端 > CSS

Geotools 对shp数据的样式修改

2016-10-06 17:18 477 查看
          先来看下效果                     代码如下            File file = JFileDataStoreChooser.showOpenFile("shp", null);if (file == null) {return;}FileDataStore store = FileDataStoreFinder.getDataStore(file);//设置编码格式((ShapefileDataStore) store).setCharset(Charset.forName("GBK"));SimpleFeatureSource featureSource = store.getFeatureSource();// Create a map context and add our shapefile to itMapContext map = new DefaultMapContext();//获取sld文件org.geotools.styling.StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();File stylefile = new File("sld文件路径xxx.sld");SLDParser stylereader = new SLDParser(styleFactory, stylefile.toURI().toURL());org.geotools.styling.Style[] stylearray = stylereader.readXML();org.geotools.styling.Style style = stylearray[0];
//构建图层
FeatureLayer tempLayer = new FeatureLayer(featureSource, style);
map.setTitle("Start");
map.addLayer(tempLayer);
JMapFrame.showMap(map);

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Geotools