| | |
| | | package org.springblade.modules.yw.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.geotools.feature.FeatureCollection; |
| | | import org.geotools.feature.FeatureIterator; |
| | | import org.geotools.geojson.feature.FeatureJSON; |
| | | import org.geotools.geojson.geom.GeometryJSON; |
| | | import org.locationtech.jts.geom.Geometry; |
| | | import org.opengis.feature.simple.SimpleFeature; |
| | | import org.springblade.common.utils.FileUtil; |
| | | import org.springblade.common.utils.ShapeFileUtil; |
| | | import org.springblade.core.tool.api.R; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import java.io.File; |
| | | |
| | | import java.io.*; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 导出 空间信息shp zip 包 |
| | | * @param ids |
| | | * @param response |
| | | * @return |
| | | */ |
| | | @Override |
| | |
| | | private void setFirmId(GeomInfoEntity geomInfoEntity,String firmName) { |
| | | if (!Strings.isBlank(firmName)) { |
| | | QueryWrapper<FirmInfo> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("name", firmName); |
| | | wrapper.like("name", '%' +firmName + '%'); |
| | | FirmInfo one = firmInfoService.getOne(wrapper); |
| | | if (null!=one) |
| | | geomInfoEntity.setFirmId(one.getId()); |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 导入 geojson 文件解析空间信息 |
| | | * @param multipartFile |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R importGeoJson(MultipartFile multipartFile) { |
| | | // 转 file |
| | | File file = FileUtil.toFile(multipartFile); |
| | | |
| | | FeatureJSON featureJSON = new FeatureJSON(); |
| | | try { |
| | | FeatureCollection featureCollection = featureJSON.readFeatureCollection(file); |
| | | FeatureIterator iterator = featureCollection.features(); |
| | | // 遍历feature转为json对象 |
| | | while (iterator.hasNext()) { |
| | | SimpleFeature feature = (SimpleFeature) iterator.next(); |
| | | StringWriter writer = new StringWriter(); |
| | | featureJSON.writeFeature(feature, writer); |
| | | String temp = writer.toString(); |
| | | JSONObject json = JSONObject.parseObject(temp); |
| | | Object value = feature.getDefaultGeometryProperty().getValue(); |
| | | System.out.println("value = " + value); |
| | | try { |
| | | GeomInfoEntity geomInfoEntity = new GeomInfoEntity(); |
| | | // 空间坐标 |
| | | geomInfoEntity.setGeom("'" + value + "'"); |
| | | // 空间类型 |
| | | if (json.getJSONObject("geometry").get("type") != null) { |
| | | geomInfoEntity.setType(json.getJSONObject("geometry").getString("type")); |
| | | } |
| | | // 保存 |
| | | baseMapper.saveGeoInfo(geomInfoEntity); |
| | | } catch (NumberFormatException e) { |
| | | log.error("NumberFormatException: {}", e); |
| | | } catch (Exception e) { |
| | | log.error("Exception: {}", e); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // 返回 |
| | | return R.data(200,"","操作成功!"); |
| | | } |
| | | } |