pgsql数据库添加PostGIs 空间扩展
- CREATE EXTENSION postgis;
- CREATE EXTENSION pgrouting;
- CREATE EXTENSION postgis_topology;
- CREATE EXTENSION fuzzystrmatch;
- CREATE EXTENSION postgis_tiger_geocoder;
- CREATE EXTENSION address_standardizer;
查询坐标系数据转换sql的mapper.xml
- <select id="coordinateTransform" resultType="java.lang.String">
- select st_astext(st_transform(st_setsrid(ST_MakePoint(#{pointX},#{pointY}),#{srcSrid}),#{targetSrid}))
- select>
mapper类
- /**
- * 方法描述: 计算线的夹角
- *
- * @param x 源坐标x
- * @param y 源坐标y
- * @param srcSrid 源坐标系EPSG代号
- * @param targetSrid 目标坐标系EPSG代号
- * @return {@link String}
- */
- String coordinateTransform(@Param("pointX") BigDecimal x, @Param("pointY") BigDecimal y, @Param("srcSrid") int srcSrid, @Param("targetSrid") int targetSrid);
service类
- //坐标系转换
- public CoordinateDTO coordinateTransform(BigDecimal x, BigDecimal y, int srcSrid, int targetSrid) {
- CoordinateDTO vo=new CoordinateDTO();
- String targetPoint = tunnelCenterLineService.coordinateTransform(x,y,srcSrid,targetSrid);
- String[] coordinateArr = StringUtil.subBetween(targetPoint, "(", ")").split(" ");
- if(coordinateArr==null ||coordinateArr.length<2){
- return vo;
- }
- String txs="Infinity".equals(coordinateArr[0])?"0":coordinateArr[0];
- String tys="Infinity".equals(coordinateArr[1])?"0":coordinateArr[1];
- BigDecimal tx=new BigDecimal(txs).setScale(3, BigDecimal.ROUND_HALF_UP);
- BigDecimal ty=new BigDecimal(tys).setScale(3, BigDecimal.ROUND_HALF_UP);
- vo.setX(tx);
- vo.setY(ty);
- return vo;
- }
注:计算结果和专业测量软件转换的结果,误差在1毫米之间。
- @ApiOperation(value = "坐标系转换北京54-国家2000")
- @PostMapping(value = "/bjz54ToCgcs2000")
- public ResponseDTO
bjz54ToCgcs2000(@RequestBody CoordinateDTO dto){ - return ResponseDTO.succData(unionSpaceDataService.coordinateTransform(dto.getX(),dto.getY(),2415,4527));
- }