@@ -40,6 +40,7 @@ | |||
<de.odysseus.juel.version>2.1.3</de.odysseus.juel.version> | |||
<httpclient.version>4.5.13</httpclient.version> | |||
<net.coobird.version>0.4.8</net.coobird.version> | |||
<fastjson.version>1.2.83</fastjson.version> | |||
</properties> | |||
<!-- 依赖声明 --> | |||
@@ -73,6 +74,13 @@ | |||
<scope>import</scope> | |||
</dependency> | |||
<!-- 阿里JSON解析器 --> | |||
<dependency> | |||
<groupId>com.alibaba</groupId> | |||
<artifactId>fastjson</artifactId> | |||
<version>${fastjson.version}</version> | |||
</dependency> | |||
<!-- 覆盖logback的依赖配置--> | |||
<dependency> | |||
<groupId>ch.qos.logback</groupId> | |||
@@ -0,0 +1,95 @@ | |||
package com.ruoyi.web.controller.gis; | |||
import com.ruoyi.common.annotation.Log; | |||
import com.ruoyi.common.core.controller.BaseController; | |||
import com.ruoyi.common.core.domain.AjaxResult; | |||
import com.ruoyi.common.enums.BusinessType; | |||
import com.ruoyi.system.domain.SysGis; | |||
import com.ruoyi.system.service.ISysGisService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Controller; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.ResponseBody; | |||
/** | |||
* GIS | |||
* @author zhangzl | |||
*/ | |||
@Slf4j | |||
@Controller | |||
@RequestMapping("/gis/map") | |||
public class GisMapController extends BaseController { | |||
@Autowired | |||
private ISysGisService gisService; | |||
/** | |||
* 坐标点 更新 通用 | |||
*/ | |||
@Log(title = "GIS", businessType = BusinessType.UPDATE) | |||
@PostMapping("/point/do") | |||
@ResponseBody | |||
public AjaxResult pointSave(SysGis gis) { | |||
return toAjax(gisService.updateGeomByPoint(gis)); | |||
} | |||
/** | |||
* 坐标点 更新 通用 - 自己指定主键ID | |||
*/ | |||
@Log(title = "GIS", businessType = BusinessType.UPDATE) | |||
@PostMapping("/point/private/do") | |||
@ResponseBody | |||
public AjaxResult pointSavePri(SysGis gis) { | |||
return toAjax(gisService.updateGeomByPointPri(gis)); | |||
} | |||
/** | |||
* 多边形面 更新 通用 | |||
*/ | |||
@Log(title = "GIS", businessType = BusinessType.UPDATE) | |||
@PostMapping("/polygon/do") | |||
@ResponseBody | |||
public AjaxResult areaSave(SysGis gis) { | |||
return toAjax(gisService.updateGeomByPolygon(gis)); | |||
} | |||
/** | |||
* 多边形面 更新 通用 - 自己指定主键ID | |||
*/ | |||
@Log(title = "GIS", businessType = BusinessType.UPDATE) | |||
@PostMapping("/polygon/private/do") | |||
@ResponseBody | |||
public AjaxResult areaSavePri(SysGis gis) { | |||
return toAjax(gisService.updateGeomByPolygonPri(gis)); | |||
} | |||
/** | |||
* 清空 geo 通用 | |||
*/ | |||
@Log(title = "GIS", businessType = BusinessType.UPDATE) | |||
@PostMapping("/clean/do") | |||
@ResponseBody | |||
public AjaxResult cleanSave(SysGis gis) { | |||
return toAjax(gisService.cleanGeomById(gis)); | |||
} | |||
/** | |||
* 清空 geo 通用 - 自己指定主键ID | |||
*/ | |||
@Log(title = "GIS", businessType = BusinessType.UPDATE) | |||
@PostMapping("/clean/private/do") | |||
@ResponseBody | |||
public AjaxResult cleanSavePri(SysGis gis) { | |||
return toAjax(gisService.cleanGeomByIdPri(gis)); | |||
} | |||
} |
@@ -23,6 +23,12 @@ | |||
<artifactId>ruoyi-common</artifactId> | |||
</dependency> | |||
<!-- 阿里JSON解析器 --> | |||
<dependency> | |||
<groupId>com.alibaba</groupId> | |||
<artifactId>fastjson</artifactId> | |||
</dependency> | |||
</dependencies> | |||
</project> | |||
</project> |
@@ -0,0 +1,32 @@ | |||
package com.ruoyi.system.domain; | |||
import lombok.Data; | |||
/** | |||
* gis | |||
* @author zhangzl | |||
* | |||
*/ | |||
@Data | |||
public class SysGis { | |||
private static final long serialVersionUID = 1L; | |||
private Long id; | |||
private String priId; | |||
private String tableName; | |||
private String itemName; | |||
/** 经度 */ | |||
private String longitude; | |||
/** 纬度 */ | |||
private String latitude; | |||
private String theGeom; | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.ruoyi.system.domain.gis; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* gis | |||
* @author zhangzl | |||
* | |||
*/ | |||
@Data | |||
public class GeoPoint { | |||
private static final long serialVersionUID = 1L; | |||
private List<Point> pointList; | |||
} |
@@ -0,0 +1,28 @@ | |||
package com.ruoyi.system.domain.gis; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* gis | |||
* @author zhangzl | |||
* | |||
*/ | |||
@Data | |||
public class Geometry { | |||
private Long id; | |||
private String tableName; | |||
private String itemName; | |||
private String type; | |||
private List<Point> points; | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.ruoyi.system.domain.gis; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* gis | |||
* @author zhangzl | |||
* | |||
*/ | |||
@Data | |||
public class GeometryArea { | |||
private String type; | |||
private List<List<List<String[]>>> coordinates; | |||
} |
@@ -0,0 +1,17 @@ | |||
package com.ruoyi.system.domain.gis; | |||
import lombok.Data; | |||
/** | |||
* gis | |||
* @author zhangzl | |||
* | |||
*/ | |||
@Data | |||
public class GeometryPoint { | |||
private String type; | |||
private String[] coordinates; | |||
} |
@@ -0,0 +1,30 @@ | |||
package com.ruoyi.system.domain.gis; | |||
import lombok.Data; | |||
/** | |||
* gis | |||
* @author zhangzl | |||
* | |||
*/ | |||
@Data | |||
public class Point { | |||
private static final long serialVersionUID = 1L; | |||
/** 经度 */ | |||
private String longitude; | |||
/** 纬度 */ | |||
private String latitude; | |||
@Override | |||
public boolean equals(Object obj) { | |||
if (this == obj) return true; | |||
if (obj == null || getClass() != obj.getClass()) return false; | |||
Point point = (Point) obj; | |||
return longitude == point.longitude && latitude == point.latitude; | |||
} | |||
} |
@@ -0,0 +1,22 @@ | |||
package com.ruoyi.system.domain.gis; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* @description: 面 | |||
* @author: zhangzl | |||
* | |||
*/ | |||
@Data | |||
public class Polygon { | |||
private Long id; | |||
private String deptName; | |||
private String point; | |||
private List<Point> points; | |||
} |
@@ -0,0 +1,28 @@ | |||
package com.ruoyi.system.mapper; | |||
import com.ruoyi.system.domain.SysGis; | |||
/** | |||
* gis 数据层 | |||
* | |||
* @author zhagnzl | |||
*/ | |||
public interface SysGisMapper { | |||
public int updateGeomByPoint(SysGis gis); | |||
public int updateGeomByPointPri(SysGis gis); | |||
public int updateGeomByPolygon(SysGis gis); | |||
public int updateGeomByPolygonPri(SysGis gis); | |||
public int cleanGeomById(SysGis gis); | |||
public int cleanGeomByIdPri(SysGis gis); | |||
} | |||
@@ -0,0 +1,27 @@ | |||
package com.ruoyi.system.service; | |||
import com.ruoyi.system.domain.SysGis; | |||
/** | |||
* gis 业务层 | |||
* @author zhagnzl | |||
*/ | |||
public interface ISysGisService { | |||
public int updateGeomByPoint(SysGis gis); | |||
public int updateGeomByPointPri(SysGis gis); | |||
public int updateGeomByPolygon(SysGis gis); | |||
public int updateGeomByPolygonPri(SysGis gis); | |||
public int cleanGeomById(SysGis gis); | |||
public int cleanGeomByIdPri(SysGis gis); | |||
} |
@@ -0,0 +1,106 @@ | |||
package com.ruoyi.system.service.impl; | |||
import com.alibaba.fastjson.JSON; | |||
import com.ruoyi.system.domain.SysGis; | |||
import com.ruoyi.system.domain.gis.Point; | |||
import com.ruoyi.system.mapper.SysGisMapper; | |||
import com.ruoyi.system.service.ISysGisService; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
/** | |||
* gis 业务层处理 | |||
* | |||
* @author zhagnzl | |||
*/ | |||
@Service | |||
public class SysGsiServiceImpl implements ISysGisService { | |||
@Autowired | |||
private SysGisMapper gisMapper; | |||
@Override | |||
public int updateGeomByPoint(SysGis gis) { | |||
return gisMapper.updateGeomByPoint(gis); | |||
} | |||
@Override | |||
public int updateGeomByPointPri(SysGis gis) { | |||
return gisMapper.updateGeomByPointPri(gis); | |||
} | |||
@Override | |||
public int updateGeomByPolygon(SysGis gis) { | |||
StringBuilder sb = new StringBuilder(); | |||
sb.append("MULTIPOLYGON((("); | |||
//ObjectMapper mapper = new ObjectMapper(); | |||
try { | |||
String theGeom = gis.getTheGeom(); | |||
//GeoPoint gp = mapper.readValue(theGeom, GeoPoint.class); | |||
List<Point> pointList = JSON.parseArray(theGeom, Point.class); | |||
//pointList.remove(pointList.size()-1); | |||
// 检查第一个点和最后一个点是否相同 | |||
if (!pointList.get(0).equals(pointList.get(pointList.size() - 1))) { | |||
// 如果不相同,添加第一个点作为最后一个点来闭合多边形 | |||
pointList.add(pointList.get(0)); | |||
} | |||
pointList.forEach(p -> { | |||
sb.append(p.getLongitude()); | |||
sb.append(" "); | |||
sb.append(p.getLatitude()); | |||
sb.append(","); | |||
}); | |||
sb.setLength(sb.length() - 1); | |||
sb.append(")))"); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
gis.setTheGeom(sb.toString()); | |||
return gisMapper.updateGeomByPolygon(gis); | |||
} | |||
@Override | |||
public int updateGeomByPolygonPri(SysGis gis) { | |||
StringBuilder sb = new StringBuilder(); | |||
sb.append("MULTIPOLYGON((("); | |||
//ObjectMapper mapper = new ObjectMapper(); | |||
try { | |||
String theGeom = gis.getTheGeom(); | |||
//GeoPoint gp = mapper.readValue(theGeom, GeoPoint.class); | |||
List<Point> pointList = JSON.parseArray(theGeom, Point.class); | |||
//pointList.remove(pointList.size()-1); | |||
// 检查第一个点和最后一个点是否相同 | |||
if (!pointList.get(0).equals(pointList.get(pointList.size() - 1))) { | |||
// 如果不相同,添加第一个点作为最后一个点来闭合多边形 | |||
pointList.add(pointList.get(0)); | |||
} | |||
pointList.forEach(p -> { | |||
sb.append(p.getLongitude()); | |||
sb.append(" "); | |||
sb.append(p.getLatitude()); | |||
sb.append(","); | |||
}); | |||
sb.setLength(sb.length() - 1); | |||
sb.append(")))"); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
gis.setTheGeom(sb.toString()); | |||
return gisMapper.updateGeomByPolygonPri(gis); | |||
} | |||
@Override | |||
public int cleanGeomById(SysGis gis) { | |||
return gisMapper.cleanGeomById(gis); | |||
} | |||
@Override | |||
public int cleanGeomByIdPri(SysGis gis) { | |||
return gisMapper.cleanGeomByIdPri(gis); | |||
} | |||
} |
@@ -0,0 +1,51 @@ | |||
<?xml version="1.0" encoding="UTF-8" ?> | |||
<!DOCTYPE mapper | |||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.ruoyi.system.mapper.SysGisMapper"> | |||
<!-- | |||
将dept的坐标转换成资产点位 | |||
SET @R = 6378137; | |||
update `t_asset_permanent` a , sys_dept b set a.the_geom = ST_GeomFromText(concat('POINT(', (@R * b.lng * PI() / 180), ' ', (@R * LOG(TAN(PI() / 4 + b.lat * PI() / 360))), ')')), a.remark='1' where a.dept_id=b.dept_id and a.the_geom is null; | |||
查询点: | |||
ST_AsGeoJSON(the_geom) as the_geom =》 {"type": "Point", "coordinates": [13533963.642572738, 4428568.311858992]} | |||
ST_AsText(the_geom) as the_geom_text =》 POINT(13533963.642572738 4428568.311858992) | |||
查询面: | |||
ST_AsGeoJSON(the_geom) as the_geom =》 | |||
{"type": "MultiPolygon", "coordinates": [[[[13534075.944512954, 4428695.531662217], [13534149.908163859, 4428780.162406675], [13534188.380222911, 4428720.513041605], [13534128.181832636, 4428660.628354907], [13534075.944512954, 4428695.531662217]]]]} | |||
ST_AsText(the_geom) as the_geom_text =》 | |||
MULTIPOLYGON(((13533885.805339003 4428784.072163737,13533945.57236977 4428797.758983824,13534000.47646284 4428625.987592842,13533949.141121512 4428600.888650298,13533885.805339003 4428784.072163737))) | |||
--> | |||
<update id="updateGeomByPoint" parameterType="SysGis"> | |||
update ${tableName} set the_geom = ST_GeomFromText(CONCAT('POINT(', #{deptLongitude}, ' ', #{deptLatitude}, ')'), 4326) where id = #{id} | |||
</update> | |||
<update id="updateGeomByPointPri" parameterType="SysGis"> | |||
update ${tableName} set the_geom = ST_GeomFromText(CONCAT('POINT(', #{deptLongitude}, ' ', #{deptLatitude}, ')'), 4326) where ${priId} = #{id} | |||
</update> | |||
<update id="updateGeomByPolygon" parameterType="SysGis"> | |||
update ${tableName} set the_geom = ST_GEOMFROMTEXT(#{theGeom}) where id = #{id} | |||
</update> | |||
<update id="updateGeomByPolygonPri" parameterType="SysGis"> | |||
update ${tableName} set the_geom = ST_GEOMFROMTEXT(#{theGeom}) where ${priId} = #{id} | |||
</update> | |||
<update id="cleanGeomById" parameterType="SysGis"> | |||
update ${tableName} set the_geom = null where id = #{id} | |||
</update> | |||
<update id="cleanGeomByIdPri" parameterType="SysGis"> | |||
update ${tableName} set the_geom = null where ${priId} = #{id} | |||
</update> | |||
</mapper> |