JTS RTREE

作者: hehehehe | 来源:发表于2020-08-14 14:12 被阅读0次
    public STRtree buildTraceSRTtree(Map<Long, Geometry> traceMap) {
        if (CollectionUtils.isEmpty(traceMap)) {
            return null;
        }
        STRtree stRtree = new STRtree();
        for (Map.Entry<Long, Geometry> entry : traceMap.entrySet()) {
            Long key = entry.getKey();
            Geometry value = entry.getValue();
            Envelope envelope = value.getEnvelopeInternal();
            stRtree.insert(envelope, key);
        }
        stRtree.build();
        return stRtree;
    }
private Long getTraceIndex(Geometry geom, Map<Long, Geometry> traceMap, STRtree stRtree, Double expandBy) {
        if (geom != null && stRtree != null) {
            Coordinate coordinate = geom.getCoordinates()[0];
            Point point = geometryFactory.createPoint(coordinate);
            Envelope envelopeInternal = point.getEnvelopeInternal();
            if (expandBy != null) {
                envelopeInternal.expandBy(expandBy);
            }
            List<Long> indexs = stRtree.query(envelopeInternal);
            Long traceIndex = indexs.get(0);
            double distanceMin = traceMap.get(traceIndex).distance(point);
            for (int i = 1; i < indexs.size(); i++) {
                Long tmpIndex = indexs.get(i);
                double tmp = traceMap.get(tmpIndex).distance(point);
                if (tmp < distanceMin) {
                    distanceMin = tmp;
                    traceIndex = tmpIndex;
                }
            }
            return traceIndex;
        }
        return null;
    }

相关文章

网友评论

      本文标题:JTS RTREE

      本文链接:https://www.haomeiwen.com/subject/ucpgdktx.html