// Y方向上的分割 void splitRoadByBlockY() { List<RoadNew> spiltRoadList = new ArrayList<RoadNew>(); for (RoadNew road : this.roadList) { List<ShpPoint> points = new ArrayList<ShpPoint>(road.coordinate); ShpPoint startPoint = points.get(0); ShpPoint headerSplitPoint = null; int startBlockNo_y = taskData.calcBlockNo(startPoint).iY; int splitIndexFrom = 0; int splitIndexTo = 0; ShpPoint splitPoint = null; for (int index = 1; index < points.size(); ) { ShpPoint currentPoint = points.get(index); int currentBlockNo_y = taskData.calcBlockNo(currentPoint).iY; // 道路跨Y方向边界 if (currentBlockNo_y != startBlockNo_y) { boolean ascY = (currentBlockNo_y > startBlockNo_y); // 分割时y值 int blockPoint_y = (startBlockNo_y + (ascY ? 1 : 0)) * taskData.blockInfo.iBlockHight; // 根据相对位置计算X值 long blockPoint_x = startPoint.x; // long 类型为了避免溢出发生 if (currentPoint.x != startPoint.x) { blockPoint_x = (long) (currentPoint.x - startPoint.x) * (blockPoint_y - startPoint.y) / (currentPoint.y - startPoint.y) + startPoint.x; } // 切割位置 if (ascY) { splitPoint = new ShpPoint((int) blockPoint_x, blockPoint_y - 1); } else { splitPoint = new ShpPoint((int) blockPoint_x, blockPoint_y); } splitIndexTo = index; // 计算BlockNo road.blockNo = taskData.calcBlockNo(splitPoint); // 产生新的Block边界Node,插入点 RoadNew splitRoad = createSplitRoad( road, splitIndexFrom, splitIndexTo, points, headerSplitPoint, splitPoint, new ShpPoint((int) blockPoint_x, blockPoint_y)); splitIndexFrom = splitIndexTo; if (ascY) { headerSplitPoint = new ShpPoint((int) blockPoint_x, blockPoint_y); } else { headerSplitPoint = new ShpPoint((int) blockPoint_x, blockPoint_y - 1); } // 收集新道路 spiltRoadList.add(splitRoad); startPoint = new ShpPoint((int) blockPoint_x, blockPoint_y); ; startBlockNo_y = startBlockNo_y + (ascY ? 1 : -1); } else { startPoint = currentPoint; index++; } } // 原始道路(最后一段道路) 添加Block值 ShpPoint endPoint = points.get(points.size() - 1); road.blockNo = taskData.calcBlockNo(endPoint); if (headerSplitPoint != null) { road.coordinate = new ArrayList<ShpPoint>(points.subList(splitIndexFrom, points.size())); road.coordinate.add(0, headerSplitPoint); } } // 添加新结果 this.roadList.addAll(spiltRoadList); }
/** * 判断是否是block边界 * * @param node */ public void judgeMMblockBordNode(NodeNew node) { ShpPoint regpoint = taskData.calcRegular(node.point); if (regpoint.x == 0 || regpoint.x == 255 || regpoint.y == 0 || regpoint.y == 255) { node.mmBlockBorderNode = true; } }
// X方向上的Block分割 void splitRoadByBlockX() { List<RoadNew> spiltRoadList = new ArrayList<RoadNew>(); for (int i = 0; i < this.roadList.size(); i++) { RoadNew road = this.roadList.get(i); List<ShpPoint> points = new ArrayList<ShpPoint>(road.coordinate); ShpPoint startPoint = points.get(0); ShpPoint headerSplitPoint = null; int startBlockNo_x = taskData.calcBlockNo(startPoint).iX; int splitIndexFrom = 0; int splitIndexTo = 0; ShpPoint splitPoint = null; for (int index = 1; index < points.size(); ) { ShpPoint currentPoint = points.get(index); int currentBlockNo_x = taskData.calcBlockNo(currentPoint).iX; // 道路跨X方向边界 if (currentBlockNo_x != startBlockNo_x) { boolean ascX = currentBlockNo_x > startBlockNo_x; // 分割线x值 int blockPoint_x = (startBlockNo_x + (ascX ? 1 : 0)) * taskData.blockInfo.iBlockWidth + DataManager.MAP_GEO_LOCATION_LONGITUDE_MIN; // 根据相对位置计算Y值 long blockPoint_y = startPoint.y; // long 类型为了避免溢出发生 if (currentPoint.y != startPoint.y) { blockPoint_y = (long) (blockPoint_x - startPoint.x) * (currentPoint.y - startPoint.y) / (currentPoint.x - startPoint.x) + startPoint.y; } // 切割点 if (ascX) { splitPoint = new ShpPoint(blockPoint_x - 1, (int) blockPoint_y); } else { splitPoint = new ShpPoint(blockPoint_x, (int) blockPoint_y); } // 切割位置 splitIndexTo = index; // 计算BlockNo road.blockNo = taskData.calcBlockNo(splitPoint); // 产生新的Block边界Node,插入点 RoadNew splitRoad = createSplitRoad( road, splitIndexFrom, splitIndexTo, points, headerSplitPoint, splitPoint, new ShpPoint(blockPoint_x, (int) blockPoint_y)); splitIndexFrom = splitIndexTo; if (ascX) { headerSplitPoint = new ShpPoint(blockPoint_x, (int) blockPoint_y); } else { headerSplitPoint = new ShpPoint(blockPoint_x - 1, (int) blockPoint_y); } // 收集新道路 spiltRoadList.add(splitRoad); startPoint = new ShpPoint(blockPoint_x, (int) blockPoint_y); ; startBlockNo_x = startBlockNo_x + (ascX ? 1 : -1); } else { startPoint = currentPoint; index++; } } // 原始道路(最后一段道路) 添加Block值 ShpPoint endPoint = points.get(points.size() - 1); road.blockNo = taskData.calcBlockNo(endPoint); if (headerSplitPoint != null) { road.coordinate = new ArrayList<ShpPoint>(points.subList(splitIndexFrom, points.size())); road.coordinate.add(0, headerSplitPoint); } } // 添加新结果 this.roadList.addAll(spiltRoadList); }