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

Posted help-silence

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Geotools中读取shapefile路网数据,并创建DirectedGraph相关的知识,希望对你有一定的参考价值。

记录一下如何创建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的主要内容,如果未能解决你的问题,请参考以下文章

JAVA用geotools读取shape格式文件

GeoJson的生成与解析,JSON解析,Java读写geojson,geotools读取shp文件,Geotools中Geometry对象与GeoJson的相互转换

GeoTools介绍环境安装读取shp文件并显示

autocad数据交换格式dxf读取

C++中怎么读取shapefile格式的文件

如何用python读取arcgis中shapefile文件的属性表