geotools处理shapefiles
来源:互联网 发布:淘宝自动好评是加分吗 编辑:程序博客网 时间:2024/06/06 13:59
package org.geotools;import java.io.File;import org.geotools.data.FileDataStore;import org.geotools.data.FileDataStoreFinder;import org.geotools.data.simple.SimpleFeatureIterator;import org.geotools.data.simple.SimpleFeatureSource;import org.geotools.map.FeatureLayer;import org.geotools.map.Layer;import org.geotools.map.MapContent;import org.geotools.styling.SLD;import org.geotools.styling.Style;import org.geotools.swing.JMapFrame;import org.geotools.swing.data.JFileDataStoreChooser;import java.io.IOException;import java.io.FileInputStream;import java.nio.channels.FileChannel;import java.nio.charset.Charset;import java.util.Iterator;import java.util.Vector;import org.geotools.data.shapefile.ShapefileDataStore;import org.geotools.data.shapefile.ShapefileDataStoreFactory;import org.geotools.data.shapefile.dbf.DbaseFileReader;import org.geotools.data.shapefile.dbf.DbaseFileHeader;import org.geotools.data.shapefile.files.ShpFiles;import org.geotools.data.shapefile.shp.ShapefileReader;import org.opengis.feature.Property;import org.opengis.feature.simple.SimpleFeature;import com.vividsolutions.jts.geom.Geometry;import com.vividsolutions.jts.geom.GeometryFactory; public static void main(String[] args) throws Exception { FileChannel in = new FileInputStream("data/test.dbf").getChannel(); DbaseFileReader dr = new DbaseFileReader(in, true, Charset.forName("GBK")); DbaseFileHeader dh = dr.getHeader(); int fields = dh.getNumFields(); ShpFiles sf = new ShpFiles("data/test.shp"); ShapefileReader r = new ShapefileReader( sf, false, false, new GeometryFactory() ); Vector v1=new Vector(); while(dr.hasNext()&&r.hasNext()){ Geometry shape = (Geometry) r.nextRecord().shape(); //com.vividsolutions.jts.geom.Geometry; /*System.out.println(shape.toString());*/ Vector v=new Vector(); v.addElement(shape); DbaseFileReader.Row row = dr.readRow(); for (int i=0;i<fields;i++){ Object data = row.read(i); v.addElement(data); //处理中文 if(dh.getFieldName(i).equals("NAME")){ // TO-DO: charset error here. String name = new String(data.toString().getBytes(),"utf-8"); /* System.out.print(name);*/ }else{ /*System.out.print(data);*/ } /* System.out.print("\t");*/ } v1.addElement(v); } System.out.println(v1); r.close(); dr.close(); }}
0 0
- geotools处理shapefiles
- TigerData2008(二): Nation-based ShapeFiles.
- Convert Shapefiles to PostGIS Tables
- GeoTools学习
- Geotools 简介
- geotools学习
- 什么是geotools
- 什么是geotools
- geotools 实例
- 说一说Geotools
- GeoTools学习篇------GeoTools体系
- GeoTools学习篇------初步了解GeoTools
- GeoTools学习篇------GeoTools+Eclipse搭建QuickStart
- GeoTools学习(referencing)
- geotools使用外部图片
- GeoTools应用-DATA
- GeoTools应用-Filter
- GeoTools应用-JTS(Geometry)
- begin
- 贪心水题(区间覆盖)
- 【深搜优化】关路灯
- java 序列化
- clearcase 常用命令参考
- geotools处理shapefiles
- 会话 0 隔离 - 白皮书
- 马云如何在企业发展中转换角色
- Python语言学习笔记(二)
- Sql字段内容替换
- Java 深度历险(作者成富,是IBM 中国软件开发中心的高级工程师)
- HTML5画布文本颜色教程
- cocos2d-x游戏开发系列教程-超级玛丽02-代码结构
- windows路径操作API函数