0

I'm currently developing an algorith that recives a network with nodes positionated in real lifes coords and must return a network with new positions for each node. The main idea is take a real life positions nodes and make a reduced map of an electrical network, preserving the relations and positions for each node to another. (Ideally, return grided positions, for example x:340, Y:670) For this, we can use some of the st functions or the posgis library.

I tryed reducing the real coords network and then aplying a st_snaptogrid function. Then moving the nodes that are positionated in the same position, but this way is deforming the network. Is there some algorithm that we can use? Every idea is welcome.

CREATE OR REPLACE FUNCTION reduce_nodes(
    p_origin_geom    geometry,
    p_factor         float8)
RETURNS void AS $$
DECLARE
    v_node_geom     geometry;
    v_node_id       core_object_id;
    v_x_offset      float8;
    v_y_offset      float8;
    v_node_pin_geom geometry;
BEGIN
    FOR v_node_id, v_node_geom IN SELECT node_id, node_geom FROM tmp_node_positions
    LOOP
        v_node_geom := st_centroid(v_node_geom);
        v_x_offset := (st_x(v_node_geom) - st_x(p_origin_geom)) * 0.9;
        v_y_offset := (st_y(v_node_geom) - st_y(p_origin_geom)) * 0.9;
        v_node_pin_geom :=
            st_snaptogrid(
                st_makepoint(
                    st_x(v_node_geom) - v_x_offset,
                    st_y(v_node_geom) - v_y_offset
                ),
                10
            )
        ;
        UPDATE tmp_node_positions
        SET
            node_geom = v_node_pin_geom,
            x_log     = st_x(v_node_pin_geom),
            y_log     = st_y(v_node_pin_geom)
        WHERE node_id = v_node_id;
    END LOOP;
END;
$$ LANGUAGE plpgsql;
2
  • 1
    Please see minimal reproducible example. Present what you have tried as actual code instead of vague description. Commented Feb 1, 2024 at 5:45
  • It is unclear if you are seeking for recommendation for algorithm or a review to your current algorithm; but either way this question should be closed. Commented Feb 1, 2024 at 12:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.