feature (geo坐标转换):高德转百度
This commit is contained in:
parent
152f082034
commit
94fdb38c7f
@ -99,13 +99,21 @@
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<!-- <scope>runtime</scope>-->
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.microsoft.sqlserver</groupId>-->
|
||||
<!-- <artifactId>mssql-jdbc</artifactId>-->
|
||||
<!--<!– <scope>runtime</scope>–>-->
|
||||
<!-- <version>7.4.0.jre8</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
<!-- <scope>runtime</scope>-->
|
||||
<version>7.4.0.jre8</version>
|
||||
<version>8.2.2.jre8</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- SpringBoot集成mybatis框架 -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.ruoyi.project.data.basis.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 百度地图apiResponse
|
||||
*
|
||||
* @author lihe
|
||||
*/
|
||||
public class BaiDuMapResponse {
|
||||
|
||||
private Integer status;
|
||||
private List<BaiDuPoint> result;
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public List<BaiDuPoint> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(List<BaiDuPoint> result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.ruoyi.project.data.basis.domain;
|
||||
|
||||
/**
|
||||
* 百度地图点
|
||||
*
|
||||
* @author lihe
|
||||
*/
|
||||
public class BaiDuPoint {
|
||||
|
||||
private Double x;
|
||||
private Double y;
|
||||
|
||||
public Double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(Double x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public Double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(Double y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return x + " " + y;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.ruoyi.project.data.basis.domain;
|
||||
|
||||
/**
|
||||
* Geo对象
|
||||
*
|
||||
* @author lihe
|
||||
*/
|
||||
public class UvGeo {
|
||||
private Integer id;
|
||||
private String geoText;
|
||||
/**
|
||||
* 1 百度
|
||||
* 2 高德
|
||||
* 3 84
|
||||
*/
|
||||
private Integer coordinateType;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getGeoText() {
|
||||
return geoText;
|
||||
}
|
||||
|
||||
public void setGeoText(String geoText) {
|
||||
this.geoText = geoText;
|
||||
}
|
||||
|
||||
public Integer getCoordinateType() {
|
||||
return coordinateType;
|
||||
}
|
||||
|
||||
public void setCoordinateType(Integer coordinateType) {
|
||||
this.coordinateType = coordinateType;
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.ruoyi.project.data.basis.domain.UVBasePrice;
|
||||
import com.ruoyi.project.data.basis.domain.UVBasePriceQueryModel;
|
||||
import com.ruoyi.project.data.basis.domain.UvCommunityGeo;
|
||||
import com.ruoyi.project.data.basis.domain.UvGeo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -30,4 +32,21 @@ public interface UvCommunityGeoMapper {
|
||||
*/
|
||||
int updateGaoDeCoordinate(UvCommunityGeo uvCommunityGeo);
|
||||
|
||||
/**
|
||||
* 获取指定表的geo数据
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
List<UvGeo> getSomeGeo(@Param("tableName") String tableName);
|
||||
|
||||
/**
|
||||
* 更新geo
|
||||
* @param tableName
|
||||
* @param id
|
||||
* @param geo
|
||||
* @return
|
||||
*/
|
||||
int updateSomeGeo(@Param("tableName") String tableName, @Param("geo") String geo, @Param("id") Integer id);
|
||||
|
||||
}
|
||||
|
@ -11,4 +11,12 @@
|
||||
update gis_community set gaode_lng=#{gaodeLng},gaode_lat=#{gaodeLat},update_time=getdate() where
|
||||
community_id=#{communityId}
|
||||
</update>
|
||||
<select id="getSomeGeo" resultType="com.ruoyi.project.data.basis.domain.UvGeo">
|
||||
select OBJECTID as id, Shape.STAsText() as geoText
|
||||
from ${tableName}
|
||||
where BD_shape is null
|
||||
</select>
|
||||
<update id="updateSomeGeo">
|
||||
update ${tableName} set BD_Shape=#{geo} where OBJECTID=#{id};
|
||||
</update>
|
||||
</mapper>
|
@ -2,10 +2,15 @@ package com.ruoyi.routine;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.microsoft.sqlserver.jdbc.Geometry;
|
||||
import com.microsoft.sqlserver.jdbc.SQLServerException;
|
||||
import com.microsoft.sqlserver.jdbc.spatialdatatypes.Figure;
|
||||
import com.microsoft.sqlserver.jdbc.spatialdatatypes.Point;
|
||||
import com.ruoyi.RuoYiApplication;
|
||||
import com.ruoyi.project.data.basis.domain.GDConvertCordinateResult;
|
||||
import com.ruoyi.project.data.basis.domain.UvCommunityGeo;
|
||||
import com.ruoyi.project.data.basis.domain.*;
|
||||
import com.ruoyi.project.data.basis.mapper.UvCommunityGeoMapper;
|
||||
import com.sun.org.apache.regexp.internal.RE;
|
||||
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
@ -24,8 +29,10 @@ import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RuoYiApplication.class)
|
||||
@ -80,4 +87,137 @@ public class GeoTests {
|
||||
});
|
||||
}
|
||||
|
||||
private String convertGaoDe2BaiDu(List<Figure> figureList, List<Point> pointList) {
|
||||
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
String baseUrl = "http://api.map.baidu.com/geoconv/v1/?ak=GNPGIGijImWZHguFphH6GcsPmAYrEfMX&from=3&to" +
|
||||
"=5&coords=";
|
||||
StringBuilder baiDuGeoSb = new StringBuilder("POLYGON (");
|
||||
List<String> polygonPointList = new LinkedList<>();
|
||||
for (int i = 0; i < figureList.size(); i++) {
|
||||
List<Point> partialPointList = null;
|
||||
List<BaiDuPoint> allBaiDuPointList = new LinkedList<>();
|
||||
if (i == figureList.size() - 1) {
|
||||
partialPointList = pointList.stream()
|
||||
.skip(figureList.get(i).getPointOffset())
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
partialPointList = pointList.stream()
|
||||
.skip(figureList.get(i).getPointOffset())
|
||||
.limit(figureList.get(i + 1).getPointOffset() - figureList.get(i).getPointOffset())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
int groupCount = partialPointList.size() / 100;
|
||||
if (0 != partialPointList.size() % 100) {
|
||||
groupCount += 1;
|
||||
}
|
||||
|
||||
for (int j = 0; j < groupCount; j++) {
|
||||
StringBuilder sb = new StringBuilder(baseUrl);
|
||||
sb.append(String.join(";",
|
||||
partialPointList.stream().skip(j * 100).limit(100).map(p -> p.getX() + "," + p.getY()).collect(Collectors.toList())));
|
||||
Request request = new Request.Builder()
|
||||
.url(sb.toString())
|
||||
.build();
|
||||
System.out.println(request.url().toString());
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
String content = response.body().string();
|
||||
BaiDuMapResponse priceApiResult = JSON.parseObject(content,
|
||||
BaiDuMapResponse.class);
|
||||
if (Objects.equals(0, priceApiResult.getStatus())) {
|
||||
List<BaiDuPoint> baiDuPointList = priceApiResult.getResult();
|
||||
allBaiDuPointList.addAll(baiDuPointList);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
String partialWKT = String.join(", ",
|
||||
allBaiDuPointList.stream().map(BaiDuPoint::toString).collect(Collectors.toList()));
|
||||
System.out.println(partialWKT);
|
||||
polygonPointList.add(partialWKT);
|
||||
}
|
||||
|
||||
baiDuGeoSb.append(String.join(", ",
|
||||
polygonPointList.stream().map(s -> "(" + s + ")").collect(Collectors.toList())));
|
||||
baiDuGeoSb.append(")");
|
||||
|
||||
return baiDuGeoSb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 高德坐标转百度
|
||||
*/
|
||||
@Test
|
||||
@DS("teemlink")
|
||||
public void convertGeoGD2Baidu() {
|
||||
String tableName = "上海基准地价2010办公";
|
||||
List<UvGeo> uvGeoList = uvCommunityGeoMapper.getSomeGeo(tableName);
|
||||
|
||||
//
|
||||
uvGeoList.parallelStream().forEach(gaoDeGeo -> {
|
||||
try {
|
||||
Geometry geometry = Geometry.parse(gaoDeGeo.getGeoText());
|
||||
List<Figure> figureList = geometry.getFigureList();
|
||||
List<Point> pointList = geometry.getPointList();
|
||||
|
||||
String baiDuGeoWKT = convertGaoDe2BaiDu(figureList, pointList);
|
||||
uvCommunityGeoMapper.updateSomeGeo(tableName, baiDuGeoWKT, gaoDeGeo.getId());
|
||||
} catch (SQLServerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// StringBuilder baiDuGeoText = new StringBuilder("POLYGON ((");
|
||||
// String geoText = gaoDeGeo.getGeoText().replace("POLYGON ((", "").replace("))", "");
|
||||
// String[] segmentList = geoText.split(",");
|
||||
//
|
||||
//
|
||||
// List<String> polygonPointList = new LinkedList<>();
|
||||
// for (String item : segmentList) {
|
||||
// String[] point = item.trim().split(" ");
|
||||
// polygonPointList.add(String.format("%s,%s", point[0], point[1]));
|
||||
// }
|
||||
//
|
||||
// // 每100个点一组
|
||||
// int groupCount = polygonPointList.size() / 100;
|
||||
// if (0 != polygonPointList.size() % 100) {
|
||||
// groupCount += 1;
|
||||
// }
|
||||
// for (int i = 0; i < groupCount; i++) {
|
||||
// StringBuilder sb = new StringBuilder(baseUrl);
|
||||
// sb.append(String.join(";",
|
||||
// polygonPointList.stream().skip(i * 100).limit(100).collect(Collectors.toList())));
|
||||
// Request request = new Request.Builder()
|
||||
// .url(sb.toString())
|
||||
// .build();
|
||||
// try (Response response = client.newCall(request).execute()) {
|
||||
// String content = response.body().string();
|
||||
// BaiDuMapResponse priceApiResult = JSON.parseObject(content,
|
||||
// BaiDuMapResponse.class);
|
||||
// if (Objects.equals(0, priceApiResult.getStatus())) {
|
||||
// List<BaiDuPoint> baiDuPointList = priceApiResult.getResult();
|
||||
// allBaiDuPointList.addAll(baiDuPointList);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// String rawBaiDuPointText = String.join(",",
|
||||
// allBaiDuPointList.stream().map(BaiDuPoint::toString).collect(Collectors.toList()));
|
||||
//
|
||||
// baiDuGeoText.append(rawBaiDuPointText);
|
||||
// baiDuGeoText.append("))");
|
||||
// uvCommunityGeoMapper.updateSomeGeo(tableName, baiDuGeoText.toString(), gaoDeGeo.getId());
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user