| | |
| | | String fileName, |
| | | String geomType, |
| | | String saveFolder) { |
| | | String path = saveFolder + "/" + fileName; |
| | | //创建保存shp文件夹 |
| | | File dir = new File(saveFolder); |
| | | File dir = new File(path); |
| | | if (!dir.exists()) { |
| | | FileUtil.mkdir(dir); |
| | | } |
| | | //shp文件路径 |
| | | String shpFileName = fileName + ".shp"; |
| | | String fileUrl = saveFolder + shpFileName; |
| | | String fileUrl = path+ "/" + shpFileName; |
| | | File file = new File(fileUrl); |
| | | |
| | | FeatureWriter<SimpleFeatureType, SimpleFeature> writer = null; |
| | |
| | | String geomProperty = "the_geom"; |
| | | String idProperty = "ID"; |
| | | String nameProperty = "name"; |
| | | String descriptionProperty = "desc"; |
| | | |
| | | //设置图形类型 |
| | | if ("Polygon".equals(geomType)) { |
| | |
| | | //设置对应属性类型 |
| | | tb.add(idProperty, String.class); |
| | | tb.add(nameProperty, String.class); |
| | | tb.add(descriptionProperty, String.class); |
| | | |
| | | //设置默认geometry |
| | | tb.setDefaultGeometry(geomProperty); |
| | |
| | | //属性赋值 geometry要赋值wkt格式的 |
| | | feature.setAttribute(geomProperty, new WKTReader().read((MapUtil.getStr(map, "geometry")))); |
| | | feature.setAttribute(idProperty, MapUtil.getStr(map, idProperty)); |
| | | feature.setAttribute(nameProperty, MapUtil.getStr(map, "名称")); |
| | | String description = MapUtil.getStr(map, "描述"); |
| | | if (CharSequenceUtil.isNotBlank(description)) { |
| | | feature.setAttribute(descriptionProperty, description); |
| | | } |
| | | feature.setAttribute(nameProperty, MapUtil.getStr(map, nameProperty)); |
| | | // String description = MapUtil.getStr(map, "描述"); |
| | | // if (CharSequenceUtil.isNotBlank(description)) { |
| | | // feature.setAttribute(descriptionProperty, description); |
| | | // } |
| | | } |
| | | writer.write(); |
| | | } catch (IOException | FactoryException | ParseException e) { |