| | |
| | | import org.springframework.stereotype.Service;
|
| | | import org.locationtech.jts.geom.*;
|
| | | import org.locationtech.jts.operation.buffer.BufferOp;
|
| | |
|
| | |
|
| | | import java.util.*;
|
| | | import org.geotools.geometry.jts.JTS;
|
| | | import org.geotools.referencing.CRS;
|
| | | import org.locationtech.jts.geom.Coordinate;
|
| | | import org.locationtech.jts.geom.GeometryFactory;
|
| | | import org.locationtech.jts.geom.Point;
|
| | | //import org.opengis.referencing.FactoryException;
|
| | | //import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
| | | //import org.opengis.referencing.operation.MathTransform;
|
| | | import org.locationtech.proj4j.CRSFactory;
|
| | | import org.locationtech.proj4j.CoordinateReferenceSystem;
|
| | | import org.locationtech.proj4j.CoordinateTransform;
|
| | | import org.locationtech.proj4j.CoordinateTransformFactory;
|
| | | import org.locationtech.proj4j.ProjCoordinate;
|
| | | import java.util.HashMap;
|
| | |
|
| | | @Service
|
| | |
| | |
|
| | | // 关键字查询
|
| | | public String getQueryFiled(String place, String filed, String layerId, String dbId, String queryEntity) throws Exception {
|
| | | String query = filed + " like '%" + place + "%'" + "";
|
| | | String query = "";
|
| | | String valSql = " like '%" + place + "%'";
|
| | | String key = getPublickey();
|
| | | if (filed.indexOf(",") > -1) {
|
| | | String[] fileds = filed.split(",");
|
| | | for (int i = 0; i < fileds.length; i++) {
|
| | | String name = fileds[i];
|
| | | if (i > 0) {
|
| | | query += " or ";
|
| | | }
|
| | | query += name + valSql;
|
| | | }
|
| | | } else {
|
| | | query += filed + valSql;
|
| | | }
|
| | | query += "";
|
| | | System.out.println("rec getQueryFiled:" + query);
|
| | | String encrypt = RsaHelper.encrypt(key, query);
|
| | | HashMap formData = getHashMap(layerId, dbId, "1", "0", encrypt, null);
|
| | | String jsonString = entityHttpUtil.getPostMessage(queryEntity, formData);
|
| | |
| | |
|
| | | // 关键字查询
|
| | | public String getQueryEntity(String place, String filed, String layerId, String dbId, String queryEntity) throws Exception {
|
| | | String query = filed + " like '%" + place + "%'" + "";
|
| | | String query = "";
|
| | | String valSql = " like '%" + place + "%'";
|
| | | String key = getPublickey();
|
| | | if (filed.indexOf(",") > -1) {
|
| | | String[] fileds = filed.split(",");
|
| | | for (int i = 0; i < fileds.length; i++) {
|
| | | String name = fileds[i];
|
| | | if (i > 0) {
|
| | | query += " or ";
|
| | | }
|
| | | query += name + valSql;
|
| | | }
|
| | | } else {
|
| | | query += filed + valSql;
|
| | | }
|
| | | query += "";
|
| | | String encrypt = RsaHelper.encrypt(key, query);
|
| | | HashMap formData = getHashMap(layerId, dbId, "1", "100", encrypt, null);
|
| | | formData.put("querytype", "entity");
|
| | |
| | | JSONObject jsonObject = JSON.parseObject(jsonString1);
|
| | | JSONObject dataObjject = jsonObject.getJSONObject("data");
|
| | | JSONArray dataArray = dataObjject.getJSONArray("items");
|
| | | if(dataArray.size()<=0){
|
| | | if (dataArray.size() <= 0) {
|
| | | return null;
|
| | | }
|
| | | return dataArray.getJSONObject(0).toString();
|
| | |
| | | String query = filed + " like '%" + type + "%'" + "";
|
| | | String encrypt = RsaHelper.encrypt(getPublickey(), query);
|
| | | HashMap formData = getHashMap(layerId, dbid, "1", "0", encrypt, wkt);
|
| | | formData.put("querytype","entity");
|
| | | String jsonString = entityHttpUtil.getPostMessage(entity, formData);
|
| | | JSONObject jsonObject = JSON.parseObject(jsonString);
|
| | | JSONObject dataObj = jsonObject.getJSONObject("data");
|
| | |
| | | hashMap.put("where", where);
|
| | | }
|
| | | if (box != null && box != "") {
|
| | | hashMap.put("box", box);
|
| | | hashMap.put("bbox", box);
|
| | | }
|
| | |
|
| | | return hashMap;
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | //生成WKT
|
| | | public String getWKt(double lon, double lat, int radius) {
|
| | | public String getWKt(double lon, double lat, int radius) throws Exception {
|
| | | // 创建一个坐标点
|
| | | Coordinate coord = new Coordinate(lon, lat);
|
| | | // 创建GeometryFactory实例,并指定坐标参考系统为WGS84
|
| | |
| | | // 创建BufferOp实例,用于生成缓冲区
|
| | | BufferOp bufferOp = new BufferOp(point);
|
| | | int dis = 500;
|
| | | if (radius != 0) {
|
| | | dis = radius;
|
| | | }
|
| | | // if (radius != 0) {
|
| | | // dis = radius;
|
| | | // }
|
| | | // 设置缓冲区距离为500米
|
| | | Geometry bufferedGeometry = bufferOp.getResultGeometry(dis / 111319.9);
|
| | | // 创建WKTWriter实例,用于将Geometry转换为WKT格式
|
| | |
| | | // 输出WKT
|
| | | // System.out.println("WKT: " + wkt);
|
| | | Envelope envelope = bufferedGeometry.getEnvelopeInternal();
|
| | | double[] wkt = new double[4];
|
| | | wkt[0] = envelope.getMinX();
|
| | | wkt[1] = envelope.getMinY();
|
| | | wkt[2] = envelope.getMaxX();
|
| | | wkt[3] = envelope.getMaxY();
|
| | | String arrayAsString = Arrays.toString(wkt);
|
| | | System.out.println("arrayAsString: " + arrayAsString);
|
| | | return arrayAsString;
|
| | |
|
| | | // double[] wkt = new double[4];
|
| | | // wkt[0] = ;
|
| | | // wkt[1] =;
|
| | | // wkt[2] = envelope.getMaxX();
|
| | | // wkt[3] = envelope.getMaxY();
|
| | | //
|
| | | // wkt += envelope.getMinX();
|
| | | // wkt += ","+envelope.getMinY();
|
| | | // wkt += ","+envelope.getMaxX();
|
| | | // wkt += ","+envelope.getMaxY();
|
| | | // System.out.println("WKT: " + wkt);
|
| | | // String arrayAsString = Arrays.toString(wkt);
|
| | | // System.out.println("wkt: " + wkt);
|
| | |
|
| | | CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
|
| | |
|
| | | // 定义源坐标系(WGS 84)
|
| | | String srcCRS = "EPSG:4326";
|
| | | // 定义目标坐标系(中国大地坐标系)
|
| | | String destCRS = "EPSG:4550";
|
| | |
|
| | | // 创建坐标参考系统
|
| | | CRSFactory crsFactory = new CRSFactory();
|
| | | CoordinateReferenceSystem src = crsFactory.createFromName(srcCRS);
|
| | | CoordinateReferenceSystem dest = crsFactory.createFromName(destCRS);
|
| | |
|
| | | // 创建坐标转换器
|
| | | CoordinateTransform transform = ctFactory.createTransform(src, dest);
|
| | |
|
| | | // 定义一个源坐标点(经度,纬度)
|
| | | ProjCoordinate srcgetMin = new ProjCoordinate( envelope.getMinX(), envelope.getMinY()); // 例如:北京的经纬度
|
| | | ProjCoordinate srcgetMax = new ProjCoordinate( envelope.getMaxX(), envelope.getMaxY()); // 例如:北京的经纬度
|
| | | // 执行转换
|
| | | ProjCoordinate destgetMin = new ProjCoordinate();
|
| | | ProjCoordinate destgetMax = new ProjCoordinate();
|
| | | transform.transform(srcgetMin, destgetMin);
|
| | | transform.transform(srcgetMax, destgetMax);
|
| | | String wkt =destgetMin.x+","+destgetMin.y+","+destgetMax.x+","+destgetMax.y;
|
| | | System.out.println("转换后的坐标:X = " +wkt);
|
| | | return wkt;
|
| | |
|
| | | }
|
| | |
|
| | |
|