Geotools中读取shapefile路网数据,并创建DirectedGraph
2024-09-06 19:37:39
记录一下如何创建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();
最新文章
- # Hawk:开源贡献计划,设计,反思
- [UCSD白板题] Maximum Pairwise Product
- linux笔记七---------管道
- Python 模块,数据类型,元组
- ubuntu + subversion + apache2 设置
- PHP中MySql函数收集
- struts1、 struts2所有版本jar包下载地址大全
- 犹记当年写出bug睡不着,回想今天只求睡好渡余生……
- 转:Spring与Mybatis整合的MapperScannerConfigurer处理过程源码分析
- Flatten Nested List Iterator
- 小黄人IP营销的四种玩法思维导图
- iOS--崩溃日志的格式化分析---格式化crash日志
- 返回值为 Record类型的函数 初始化 Result
- Controller与Switch建立连接
- 执行git命令出现 xcrun: error:
- C++调用Python脚本中的函数
- 通过管道传输快速将MySQL的数据导入Redis
- vim中多行注释和多行删除命令
- Servlet和SpringMVC补课
- 使用C# .NET 将结构数组绑定到 Windows 窗体的方法