How to edit polyline attributes

So i want to edit my polyline data, but i dont know how to get the selected line. Anybody can help me

Hello @noir, and welcome.

I’m not sure what your context is, if you want to select and edit from the map, or iterate the shapes programmatically to edit. Here are the API calls used for editing. and you could also review this sample code, which provides for selecting and editing shapes from the map.

If you would like more guidance, please provide more detail regarding what you are trying to do.

Regards,
Jerry.

Hi jerry thanks for your suggestion,

So I have this shp file in the form of a polyline, each line has a different data,
so what I want to do is take data from the selected line and edit it.
but the problem is that after I tried the sample code that you gave me, nothing happened.
So I think maybe it happened because of a different shp model. So helppppppp me pls :upside_down_face:

Hello @noir

Yes, you’re right; the sample was specific to Polygons and did not work with Polylines. So I made just a few changes so that it should be usable to at least get you started. I have tested it with the changes to make sure it worked.

Form1.zip (2.7 KB)

If you create a simple c# Forms-based application called Examples, you should be able to replace Form1.cs with this file. Of course, you will have to change the file path and name to your file.

The primary changes I had to make were:

  1. Instead of checking the mouse click point for containment within a Polygon, I had to expand the point out and check for Intersection with the Polyline (I randomly decided on a 10 meter square around the mouse click point).
  2. If there are too many fields within the shapefile (I had 40) then the label and edit dialog fail because there are too many fields to fit nicely on the screen. So I decided to cap the number at 12. If there are more than 12 fields in the shapefile, you will only get the first 12.

But with these changes, the code should work, and you can at least see how the code is working. You can then change the logic so that you can edit the fields you want to edit.

Let me know if there are more issues.

Regards,
Jerry.

Hi jerry thanks for your help, it work
But there is a small problem left.

So every time i select a line, more than one line is selected.
So i thought the problem was in the line width so i change the line width, but after changing the line width nothing happened. is there any suggestion

Hello @noir

If you mean that you changed the line width through the DrawingOptions, that will not solve the problem. The drawing width only changes the visual display. The line itself has not changed.

If more than one line is selected, then that means the Extents you are using for the Intersection is too big; it is encompassing multiple lines. So what you want to do is make the Extents around the mouse click-point smaller. I simply added 5 units in each direction (my units were meters). Depending upon your units (for example, if they are degrees) the Extents could be huge.

You could use the Utils.ConvertDistance function to get from your map units to the desired units. So if your map units are degrees and you want to know how many degrees is 5 meters, you would do something like the following (pseudo-c# code):

Utils utils = new Utils();
double distance = 5;
if (utils.ConvertDistance(umMeters, umDecimalDegrees, ref distance))
{
    // here, distance will be equal to 5 meters in decimal degrees
}

Then use ‘distance’ instead of ‘5’ as the amount to set up your Extents. Around line 103 of the sample code I sent:

// for polylines, make a slightly larger box, and use Intersection
ext.SetBounds(projX - distance, projY - distance, 0.0, projX + distance, projY + distance, 0.0);

Hope that helps.
Jerry.

Hi jerry, thanks for your help,

The code works perfectly :laughing:
I realy appreciate your help, because of you my problem were solved
When i start this topic i had no idea what im doing i just so frustrated and just hoping that someone will tell me what should i do, the information and advice that you gave made my error gone, now i can sleep peacefully.
I greatly appreciate your help :relieved: :relieved:

Hi jerry,
I just realized that the line that i edit before didn’t save after i restart the application.

i allready run this code and it didnt work
sf.StopEditingShapes(true, true, null);

Hello @noir

The edits you are making are to the in-memory copy of the Shapefile. To persist the changes, you need to do one of the Save or SaveAs calls.

Thank for the information jerry, i will try it now