Geotools 对shp数据的样式修改

          先来看下效果

       

              代码如下

           

         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 it
         MapContext 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);

转载自:https://blog.csdn.net/u014455405/article/details/52744622

You may also like...

退出移动版