com.powsybl.gse.map.SubstationGraphicIndex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powsybl-gse-network-map Show documentation
Show all versions of powsybl-gse-network-map Show documentation
A GSE plugin to draw a network on a map
/**
* Copyright (c) 2018, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.gse.map;
import com.github.davidmoten.rtree.RTree;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Point;
import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Objects;
/**
* @author Geoffroy Jamgotchian
*/
public final class SubstationGraphicIndex {
private static final Logger LOGGER = LoggerFactory.getLogger(SubstationGraphicIndex.class);
private final RTree tree;
private SubstationGraphicIndex(RTree tree) {
this.tree = Objects.requireNonNull(tree);
}
public static SubstationGraphicIndex build(Collection substations) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
RTree tree = RTree.create();
for (SubstationGraphic substation : substations) {
Point point = Geometries.pointGeographic(substation.getPosition().getLon(),
substation.getPosition().getLat());
tree = tree.add(substation, point);
}
LOGGER.info("Substation R-tree built in {} ms", stopWatch.getTime());
return new SubstationGraphicIndex(tree);
}
public RTree getTree() {
return tree;
}
}