码迷,mamicode.com
首页 > 其他好文 > 详细

Geotools中读取shapefile路网数据,并创建DirectedGraph

时间:2019-11-16 17:34:59      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:charset   创建   iterator   source   actor   too   finally   otool   stack   

记录一下如何创建DirectedGraph,便于以后查找使用

  

     static ShapefileDataStore sds= null;
     static DirectedGraph graph = null;
     ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
        try {
            sds = (ShapefileDataStore)dataStoreFactory.createDataStore(new File("E://桌面//route_LI.shp").toURI().toURL());
        } catch (IOException e) {
            e.printStackTrace();
        }
        //设置编码
        Charset charset = Charset.forName("GBK");
        sds.setCharset(charset);
        String typeName = null;
        try {
            typeName = sds.getTypeNames()[0];
        } catch (IOException e) {
            e.printStackTrace();
        }
       
        FeatureSource featureSource = null;
        try {
            featureSource =  sds.getFeatureSource (typeName);
        } catch (IOException e) {
            e.printStackTrace();
        }
       
        SimpleFeatureCollection fCollection =null;
        try {
            fCollection = (SimpleFeatureCollection) featureSource.getFeatures();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
     
        DirectedLineStringGraphGenerator lineStringGen = new DirectedLineStringGraphGenerator();
        FeatureGraphGenerator featureGen = new FeatureGraphGenerator(lineStringGen);
        featureGen.setGraphBuilder(new BasicDirectedLineGraphBuilder());
        SimpleFeatureIterator iterator = fCollection.features();
        try {
            while (iterator.hasNext()) {
                SimpleFeature feature = iterator.next();
                featureGen.add(feature);
            }
        } finally {
            iterator.close();
        }
        sds.dispose();
        graph = (DirectedGraph)featureGen.getGraph();

 

Geotools中读取shapefile路网数据,并创建DirectedGraph

标签:charset   创建   iterator   source   actor   too   finally   otool   stack   

原文地址:https://www.cnblogs.com/help-silence/p/11872194.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!