针对不同的地图级别对大数据量的点进行聚合
作者:互联网
package com.sb.service.impl; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.sb.entity.SG_GROUPINDEX; import com.sb.entity.SG_PIPEPOINT; //聚合类 不同的地图级别聚合的距离不一样,每一个地图级别都对应一个聚合结果 public class MarkerClusterer { public MarkerClusterer() { } protected int total; //创建聚合 //points 点集 //dis 聚合距离 //return clusters 聚合点集合 public List<SG_GROUPINDEX> createClusterer(List<SG_PIPEPOINT> points,double dis,int zoom,String thisDay) { //List<SG_PIPEPOINT> points,double dis,int zoom,String thisDay List<SG_GROUPINDEX> clusters= new ArrayList<SG_GROUPINDEX>(); for(int i=0;i<points.size();i++) { boolean incluster=false; SG_PIPEPOINT tmpPT=points.get(i); for(int j=0;j<clusters.size();j++){ //在指定的聚合距离(dis)之内 if(this.getDistance(clusters.get(j).getCenterx(),clusters.get(j).getCentery(),tmpPT)<dis){ if(clusters.get(j).getMinX()>tmpPT.getJd()) clusters.get(j).setMinX(tmpPT.getJd()); if(clusters.get(j).getMaxX()<tmpPT.getJd()) clusters.get(j).setMaxX(tmpPT.getJd()); if(clusters.get(j).getMinY()>tmpPT.getWd()) clusters.get(j).setMinY(tmpPT.getWd()); if(clusters.get(j).getMaxY()<tmpPT.getWd()) clusters.get(j).setMaxY(tmpPT.getWd()); clusters.get(j).addNum(); incluster=true; break; } } if(!incluster) //否则就单独创建一个聚合点 { clusters.add(this.createCluster(tmpPT,dis,zoom,thisDay)); } } return clusters; } //创建一个聚合 private SG_GROUPINDEX createCluster(SG_PIPEPOINT p,double dis,int zoom,String thisDay) { SG_GROUPINDEX cluster=new SG_GROUPINDEX(); cluster.setNum(1); cluster.setCenterx(p.getJd()); cluster.setCentery(p.getWd()); cluster.setMinX(p.getJd()); cluster.setMinY(p.getJd()); cluster.setMaxX(p.getWd()); cluster.setMaxY(p.getWd()); cluster.setDis(dis); cluster.setZoom(zoom); cluster.setCreatetime(thisDay); return cluster; } //计算两点之间的距离 private double getDistance(double x,double y,SG_PIPEPOINT point2){ double pk = 180 / 3.14169 ; double a1 = y / pk ; double a2 = x / pk ; double b1 = point2.getWd() / pk ; double b2 = point2.getJd() / pk ; double t1 =Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math.cos(b2) ; double t2 = Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math.sin(b2) ; double t3 = Math.sin(a1) * Math.sin(b1); double tt = Math.acos(t1 + t2 + t3); return 6366000 * tt; } }
标签:聚合,java,int,List,对大,数据量,clusters,import 来源: https://www.cnblogs.com/GIScore/p/13608997.html