目录
地图屏占比
屏占比算法
矩形求重叠面积算法
聚合计算工具类
聚合效果图
地图聚合屏幕占比 = 政区四至面积/屏幕四至面积x100%. 两个矩形确定一个同位点然后计算两点相交部分的长宽面积即可。
图形面积与当前四至面积比对占比值,合理的比重是20%。
https://blog.csdn.net/liuzhenya1994/article/details/80870830?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight
F= 矩形面积/地图四至面积* 100%
矩形集已知,轮询计算
两点确定一条直线,两线确定一面
矩形的面积= 长* 宽
geometry多边形的面积 = geometry直接求算 Postgresql有函数
定义矩形
package com.boonya.beans.gis;
import java.io.Serializable;
/**
* @Copyright: 2019-2021
* @FileName: Rectangle.java
* @Author: PJL
* @Date: 2020/7/14 18:19
* @Description: 矩形
*/
public class Rectangle implements Comparable, Serializable {
private double x; //矩形左下角的x坐标
private double y; //矩形左下角的y坐标
private double length;
private double width;
public Rectangle(double x, double y, double length, double width) {
this.x = x;
this.y = y;
this.length = length;
this.width = width;
}
public double getArea() {
return length * width;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
@Override
public int compareTo(Rectangle o) {
return Double.compare(this.getArea(), o.getArea());
}
}
定义计算面积方法
package com.boonya.beans.gis;
/**
* @Copyright: 2019-2021
* @FileName: RectangleOverlap.java
* @Author: PJL
* @Date: 2020/7/14 18:21
* @Description: 矩形重叠面积
*/
public class RectangleOverlap {
/**
* 计算重叠区域面积
*
* @param rect1
* @param rect2
* @return
*/
public double calculateOverlapArea(Rectangle rect1, Rectangle rect2) {
if (rect1 == null || rect2 == null) {
return -1;
}
double p1_x = rect1.getX(), p1_y = rect1.getY();
double p2_x = p1_x + rect1.getLength(), p2_y = p1_y + rect1.getWidth();
double p3_x = rect2.getX(), p3_y = rect2.getY();
double p4_x = p3_x + rect2.getLength(), p4_y = p3_y + rect2.getWidth();
if (p1_x > p4_x || p2_x < p3_x || p1_y > p4_y || p2_y < p3_y) {
return 0;
}
double Len = Math.min(p2_x, p4_x) - Math.max(p1_x, p3_x);
double Wid = Math.min(p2_y, p4_y) - Math.max(p1_y, p3_y);
return Len * Wid;
}
public static void main(String[] args) {
Rectangle rect1 = new Rectangle(0, 1, 3, 2);
Rectangle rect2 = new Rectangle(2, 0, 2, 2);
RectangleOverlap overlap = new RectangleOverlap();
System.out.println(overlap.calculateOverlapArea(rect1, rect2));
}
}
package com.boonya.beans.util;
import com.alibaba.fastjson.JSONArray;
import com.boonya.beans.Constants;
import com.boonya.beans.gis.Rectangle;
import com.boonya.beans.gis.RectangleOverlap;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import java.util.List;
import java.util.Map;
/**
* @Copyright: 2019-2021
* @FileName: LogicUtil.java
* @Author: PJL
* @Date: 2020/6/29 15:34
* @Description: 逻辑处理工具类
*/
@Slf4j
public class LogicUtil {
/**
* 获取四至范围数组
*
* @param extentArray
* @return
*/
public static Double[] getExtent(JSONArray extentArray) {
int count = extentArray.size();
Double[] extent = new Double[count];
for (int i = 0; i < count; i++) {
extent[i] = extentArray.getDouble(i);
}
return extent;
}
/**
* 解析组织机构数组
*
* @param list
* @return
*/
public static String[] getOrgIds(List
政区聚合递归算法:
/**
* 根据四至计算地图显示数据方式【聚合/散点】==返回组织机构标识
*
* @param org
* @param screenExtent
* @param orgMap k-v = 组织机构ID-组织机构编码:是否聚合(true|false)
* @return
*/
public Map calculateOrgAggregationData(Org org, Double[] screenExtent, Map orgMap) {
Double[] orgExtent = org.getExtent();
// 第一步: 屏幕四至求交组织机构四至
boolean intersected = LogicUtil.isIntersected(screenExtent, orgExtent);
if (intersected) {
// 计算当前组织机构占比
long rate = LogicUtil.getShadowRateOfRectangle(screenExtent, orgExtent);
String key = new StringBuffer(org.getId()).append("-").append(org.getCode()).toString();
if (rate < Constants.MAP_AGGREGATION_SCREEN_RATE) {
orgMap.put(key, true);// 设置是否聚合
} else {
try {
List
Constants.MAP_AGGREGATION_SCREEN_RATE =20