Create point shapefile at center of polyline WITH attributes from the polyline

10094
9
Jump to solution
10-29-2014 04:35 PM
MichaelJohnson1
New Contributor

Hi, can anyone tell me how to create a point at the center of a polyline and extract three attributes from the polyline to populate the point shapefile? I have polylines representing electrical conductors - I need to create a point at the center of each polyline as well as transfer length and conductor size attributes from the polyline to the point feature in the center. Much thanks for any help.

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

I should firstly point out, that if you simply add X,Y coordinates into your polyline shapefile's table, you can export the table (from the open table, save to dBase or whatever), THEN reload the table back into ArcMap as an event layer (File, Add Data, Add XY data), then save it out to a new shapefile.  Time taken to do this is about 2-3 minutes max.

On with the explanations and comments

Given you are working with shapefiles and not true curves with the potential errors that Richard pointed out, then you should be able to create the table via several ways...

1  The one that Mark pointed out using the existing tools

2  Add two fields and use the Calculate Geometry to calculate the X and Y midpoint for each line segment (the 50% point which is 0.5 on the scale of 0-1.0

3  Add two fields and use the following python expressions for the 50% points ...or more flexibly ... any position or percentage along the line, using one of the sets of python field calculator expressions assuming your shapefield is named !Shape! .  NOTE you have to use the Python parser in the field calculator.

So for percentages along the line you use values in the 0.0 to 1.0 range, hence 50% is actually 0.5 (I don't know why they don't call this fractional distance) and you set the other option to True

For actual distance along the line, then you specify the actual distances. IF ANY of the values exceed the acceptable range in EITHER case, then the coordinates are placed at the BEGINNING of the line.

So... for actual distance traverse

!Shape!.positionAlongLine(5000,False).centroid.X  #   5000m along a polyline X coordinate

!Shape!.positionAlongLine(5000,False).centroid.Y  #   5000m along a polyline Ycoordinate

For percentage distance traverse

!Shape!.positionAlongLine(0.5,True).centroid.X  #for polylines  use decimal % 0.25 = 25%

!Shape!.positionAlongLine(0.5,True).centroid.Y  #for polylines

Probably doesn't answer your question but it is worth looking into.  By the way see the attached figure.

View solution in original post

0 Kudos
9 Replies
MarkBockenhauer
Esri Regular Contributor

You could try the feature to point tool in toolbox.

ArcGIS Desktop

Check the inside (optional) check box.  It will put the point at the centroid of the line, with all field attributes from the line.

0 Kudos
RichardFairhurst
MVP Honored Contributor

What Mark says is true for densified lines, but not for polylines containing true curves in a geodatabase.  The inside point will usually be placed at the starting point of the line if it contains a true curve, not at the line centroid.  True curves have to be densified to make the point locate itself at the center of the line.  One option is to convert to a shapefile from a geodatabase to do that.

0 Kudos
DanPatterson_Retired
MVP Emeritus

does this statement not apply then?  "For an input line: the output point will be on the line. If the line is a parametric (true) curve, the output point will be at the midpoint of the line."  from the help file.  For shapefiles it is not relevant since they aren't supported in the first place

0 Kudos
RichardFairhurst
MVP Honored Contributor

That statement is not true.  I spent a day with Tech support on this issue and demonstrated that the inside option never put the point on the true curve center.  It only puts the point at the ends of the true curve when the inside option is checked (at least if the line is only a true curve, which was what I was working with since the lines in my routine all came from the outlines of point buffers) or at the centroid that is not on the line if it is not checked.  The point is only placed at the center of the polyline if the lines are densified.  Converting to a shapefile was tech support's recommendation as a workaround.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Obviously it has been reported then? Is there a NIM number? they should correct the help file, it is supposed to be uptodate

0 Kudos
RichardFairhurst
MVP Honored Contributor

No NM was created.  Actually, after rechecking the e-mails with tech support this situation may only arise if the arc is greater than 180 degrees, which was applicable to most of the arcs in my routine.  Here is the last response I got from tech support on Esri Case #01448794 - How to find the midpoint of an arc that is greater than 180 degrees:

Hi Rich,

This is Kory with Esri Support regarding the case number referenced in the subject line. It was a pleasure working with you today. To recap our telephone conversation:

During my testing, I found that when the arc is stored as GDB, feature to point and feature vertices to point do not locate the output point at the midpoint of the arc.  This is the issue you were facing when you called in.

The solution is to output the arcs as a shapefile.  Then, use the Feature Vertices to Points tool , set the Point Type to Mid, and the output point is the midpoint of the arc.

Feature Vertices to Points: http://resources.arcgis.com/en/help/main/10.2/index.html#//00170000003p000000

I will go ahead and mark this case as resolved. Feel free to contact me if you have any other questions regarding this case and I will be glad to re-open it if necessary. You can reply to this email or call me at 888-377-4575 and refer to the case number in the subject line. If you would like to review the notes from this case including our email exchanges feel free to visit the My Support page at http://support.esri.com/en/oim.

Thanks,

Kory

Esri Support Services

0 Kudos
DanPatterson_Retired
MVP Emeritus

I should firstly point out, that if you simply add X,Y coordinates into your polyline shapefile's table, you can export the table (from the open table, save to dBase or whatever), THEN reload the table back into ArcMap as an event layer (File, Add Data, Add XY data), then save it out to a new shapefile.  Time taken to do this is about 2-3 minutes max.

On with the explanations and comments

Given you are working with shapefiles and not true curves with the potential errors that Richard pointed out, then you should be able to create the table via several ways...

1  The one that Mark pointed out using the existing tools

2  Add two fields and use the Calculate Geometry to calculate the X and Y midpoint for each line segment (the 50% point which is 0.5 on the scale of 0-1.0

3  Add two fields and use the following python expressions for the 50% points ...or more flexibly ... any position or percentage along the line, using one of the sets of python field calculator expressions assuming your shapefield is named !Shape! .  NOTE you have to use the Python parser in the field calculator.

So for percentages along the line you use values in the 0.0 to 1.0 range, hence 50% is actually 0.5 (I don't know why they don't call this fractional distance) and you set the other option to True

For actual distance along the line, then you specify the actual distances. IF ANY of the values exceed the acceptable range in EITHER case, then the coordinates are placed at the BEGINNING of the line.

So... for actual distance traverse

!Shape!.positionAlongLine(5000,False).centroid.X  #   5000m along a polyline X coordinate

!Shape!.positionAlongLine(5000,False).centroid.Y  #   5000m along a polyline Ycoordinate

For percentage distance traverse

!Shape!.positionAlongLine(0.5,True).centroid.X  #for polylines  use decimal % 0.25 = 25%

!Shape!.positionAlongLine(0.5,True).centroid.Y  #for polylines

Probably doesn't answer your question but it is worth looking into.  By the way see the attached figure.

0 Kudos
MichaelJohnson1
New Contributor

Thanks to all for your answers and suggestions. I will try each of them and see what happens.

Much appreciation.

0 Kudos
DanPatterson_Retired
MVP Emeritus

let us know if it worked out for you

0 Kudos