How to move a line to keep the lines on another layer attached?

Hello everyone. Can someone help me answer my question? If my statement is not clear enough, you can tell me and let me write clearly. Thanks.

As shown, the red Line A, Line B, and Line C are on one layer (one shapefile). The yellow arrowed Line X and Line Y are on another layer (another shapefile).

Now, I want to move Line B. At the same time, Line A and Line C do not move. However, since Line X and Line Y on another layer are connected to Line B, I need to let Line X and Line Y follow. In other words, I need to change the position of Point 1 on Line X and the position of Point 2 on Line Y.

I thought of an idea, I do not know whether it is feasible, or which interface functions should be used.

(1) According to Line B, I get the line buffer. (2) Then, according to the layer where Line X and Line Y are located, perform intersection analysis with the buffer to obtain Point 1 and Point 2. (3) Finally, use the Shape.put_XY () function to move the positions of Point 1 and Point 2.

I don’t know if this method is feasible. If feasible, what are the interface functions used in this process? If it is not feasible, are there other better solutions? Because I see that all geoprocessing is processed in units of Shapefile, not in units of Shape. Line B and Line X in the figure are shapes, not a shapefile.

https://www.mapwindow.org/documentation/mapwingis4.9/group__shapefile__geoprocessing.html

Thanks.

Hello @Henry

I’m sorry that there has not yet been a reply. I will need more time to review to give a proper response.

Regards,
Jerry.

Hi @Henry

Manually, I think the best you can do is:

  1. On layer 1, move line B to where you want it.
  2. Now in layer 2, highlight line X, click move vertex, slide your cursor over point 1 to pick it up as a little blue square, slide it across to the correct end of the newly positioned line B in the layer 1, and do the same with point 2 to the other end of the new line B.
  3. For maximum accuracy, just zoom to maximum extent to fine tune the locations.

There may be a more complicated solution along the lines you are asking.

Hope it helps. It brings to mind a solution which could work if there weren’t another glitch in MapWindow about which I will make another post.

Ditch

Hello

Thank you very much for your careful approach. A carefully considered approach will definitely be more valuable.

Regards,
Henry.

Hello

I’m sorry, I didn’t describe the problem clearly. I didn’t want to move Line B manually. I also don’t want to move Line X and Line Y manually. I want to move Line B automatically, and then let Line X and Line Y follow automatically.

For example, I use a dialog box to control this linkage effect. First, I select Line B. Then, I enter the starting and ending coordinates of Line B in the dialog box. As a result, the start and end positions of Line B will change. What I want is that Line X and Line Y also follow.

Could you please help me think about how this should be done? Thank you.

Regards,
Henry.

Hello Henry.

The process you originally suggested sounds reasonable.
Using your reference to Line B and the shapefile containing Lines X and Y, here’s a snippet in VB.NET

Dim results As Object
If shapefileXY.GetRelatedShapes2(lineB, tkSpatialRelation.srIntersects, results) Then
    ' we hopefully have the two lines that intersect, 
    ' but you may need to create a small buffer around lineB
    For i As Integer = 0 to UBound(results)
        ' results should contain the IDs of the two shapes (Line X and Line Y)
        If shapefileXY.StartEditing() Then
            Dim shp as Shape = shapefileXY.Shape(results(i))
            ' you'll have to determine which endpoint is the one you want to move
            ' then update the endpoint with the new X,Y
            shapefileXY.StopEditing()
        End If
    Next
End If

I know this is incomplete code, and hopefully you can fill in the blanks. Hopefully this can get you going. Let me know if you have more questions, and I’ll try to help.

Regards,
Jerry.

Hi Henry

Looks like Jerry is the one to help you. I haven’t got into using dialog boxes or code, although I’d like to learn some time.

All the best

Ditch

Hi Ditch

Thank you all the same. Looking forward to better communication with you later.

Best wishes,
Henry.

Hello Jerry.

Thank you for your proposal. I tried using this method, but failed. I used the GetRelatedShapes2 () function, but I couldn’t get the shapeIndex of Line X and Line Y accurately. I paste my code. If you have something you do n’t understand, please tell me again.

In my graph, the X axis represents mileage and the Y axis represents time. Therefore, the start time and end time are used in the parameters of the function. In addition, I need to use this function before moving Line B. If I move Line B first, Line B and Line X Y will not intersect. In this case, the GetRelatedShapes2 () function may not even get Line X and Line Y.

//Bind Line is the yellow arrowed line.

    private void EditBindLine(int curID, DateTime detstdate, DateTime deteddate)
    {
        DataRow[] drs = m_drawXLT.m_drawXLTAPI.m_dtProgress.Select("ID='" + curID + "'");
        if (drs.Length > 0)
        {
            Shapefile sfLine = m_mapControl.get_Shapefile(Convert.ToInt32(drs[0][1]));
            Shape shpLine = sfLine.get_Shape(Convert.ToInt32(drs[0][2]));//Line B
            //Shape shpLineBuffer = shpLine.Buffer(0.2, 6);//Is this buffer creation method correct?

            double x0 = 0.0;
            double y0 = 0.0;
            double x1 = 0.0;
            double y1 = 0.0;
            if (shpLine.get_XY(0, ref x0, ref y0) && shpLine.get_XY(1, ref x1, ref y1))
            {
                int dety0 = m_drawXLT.m_drawXLTAPI.ConvertDateToY(detstdate);
                int dety1 = m_drawXLT.m_drawXLTAPI.ConvertDateToY(deteddate);
                object results = null;
                //if (sfLine.GetRelatedShapes2(shpLineBuffer, tkSpatialRelation.srIntersects, ref results))//This will also fail.
                if (sfLine.GetRelatedShapes2(shpLine, tkSpatialRelation.srIntersects, ref results))
                {
                    int[] resultArray = results as int[];
                    Shapefile sfBindLine = m_mapControl.get_Shapefile(m_drawXLT.m_drawXLTAPI.m_layerHandleLogic5);
                    sfBindLine.FastMode = true;
                    //If I select Line B, I can only get one integer, and the integer is neither the shapeIndex of Line X nor the shapeIndex of Line Y.
                    foreach (int id in resultArray)
                    {
                        Shape shpBindLine = sfBindLine.get_Shape(id);
                        double bx0 = 0.0;
                        double by0 = 0.0;
                        double bx1 = 0.0;
                        double by1 = 0.0;
                        if (shpBindLine.get_XY(0, ref bx0, ref by0) && shpBindLine.get_XY(1, ref bx1, ref by1))
                        {
                            if(Math.Abs(bx0 - x0) < 0.1)
                                shpBindLine.put_XY(0, bx0, dety0);
                            else if (Math.Abs(bx0 - x1) < 0.1)
                                shpBindLine.put_XY(0, bx0, dety1);

                            if(Math.Abs(bx1 - x0) < 0.1)
                                shpBindLine.put_XY(1, bx1, dety0);
                            else if (Math.Abs(bx1 - x1) < 0.1)
                                shpBindLine.put_XY(1, bx1, dety1);
                        }
                    }
                }
                m_mapControl.Redraw();
            }
        }
    }