<强> java 中Excel转形状文件的实例详解强>
<强>概述:强>
本文讲述如何结合geotools和POI实现Excel到轴马力的转换,再结合前文轴马力到geojson数据的转换,即可实现用户上传Excel数据并在web端的展示功能。
截的图:
,原始Excel文件
运行耗时
运行结果
代码:
包com.lzugis.geotools; 进口com.lzugis.CommonMethod; 进口com.vividsolutions.jts.geom.Coordinate; 进口com.vividsolutions.jts.geom.GeometryFactory; 进口com.vividsolutions.jts.geom.Point; 进口org.apache.poi.hssf.usermodel.HSSFCell; 进口org.apache.poi.hssf.usermodel.HSSFRow; 进口org.apache.poi.hssf.usermodel.HSSFSheet; 进口org.apache.poi.hssf.usermodel.HSSFWorkbook; 进口org.apache.poi.poifs.filesystem.POIFSFileSystem; 进口org.geotools.data.FeatureWriter; 进口org.geotools.data.Transaction; 进口org.geotools.data.shapefile.ShapefileDataStore; 进口org.geotools.data.shapefile.ShapefileDataStoreFactory; 进口org.geotools.feature.simple.SimpleFeatureTypeBuilder; 进口org.geotools.referencing.crs.DefaultGeographicCRS; 进口org.opengis.feature.simple.SimpleFeature; 进口org.opengis.feature.simple.SimpleFeatureType; 进口java.io.File; 进口java.io.FileInputStream; 进口java.io.InputStream; 进口java.io.Serializable; 进口charset; 进口java.util.ArrayList; 进口java.util.HashMap; 进口并不知道; 进口java.util.Map;/* * *由2017/9/6管理。 */公开课Xls2Shape { 静态Xls2Shape xls2Shp=new Xls2Shape (); 私有静态字符串rootPath=System.getProperty (“user.dir”); 私人CommonMethod厘米=new CommonMethod (); 私人HSSFSheet表; 私有类getCellType (HSSFCell细胞){ 如果(cell.getCellType ()==HSSFCell.CELL_TYPE_STRING) { 返回String.class; }else if (cell.getCellType ()==HSSFCell.CELL_TYPE_NUMERIC) { 返回Double.class; 其他}{ 返回String.class; } } 私有对象getCellValue (HSSFCell细胞){ 如果(cell.getCellType ()==HSSFCell.CELL_TYPE_STRING) { .getString返回cell.getRichStringCellValue () (); }else if (cell.getCellType ()==HSSFCell.CELL_TYPE_NUMERIC) { 返回cell.getNumericCellValue (); 其他}{ 返回"; } } 私人List