I am trying to join a polyline feature class and a polygon feature class. The polylines will always have at least their first point in a polygon, and each polyline consists of exactly three points. There is a chance of the last point of the polyline being in another polygon, but I do not want to join that polygon. There will be multiple polylines from within each polygon and I want to join these.

I was thinking of something like this:

arcpy.SpatialJoin_analysis(lines, polygons, linesAndPolygons, #, #, #, "POLYGON_CONTAINS_FIRST_POINT_OF_POLYLINE")

There is of course no explicit match option like above, but that is what I need. Any ideas? I was considering making a new feature class of points from the polylines, joining those to the polygons, and then joining the polylines to the points, but it seems like there should be a simpler way.

  • 1
    Your method is what I would have come up with. – Emil Brundage Jul 17 '15 at 16:52

Assuming you don't have Advanced license level:

Add fields to your polyline feature class to store coordinates (Double) and a join-id field (long) then Calculate Field using Python parser and geometry object:

JoinID = !FID!
FromX = !SHAPE!.firstPoint.X
FromY = !SHAPE!.firstPoint.Y

This will attribute your polylines with their start coordinate whitch you can make into a point layer with Create Feature Class from XY Table.

If you do have an advanced license use Feature Vertices to Points (start) to get the points from the first vertex.. it is a good idea to calculate the JoinID before doing that. Vertex points will have the same attributes as the source line making joining easier.

Either Spatial Join or Intersect the layer with your polygons. Your resulting points will contain (amongst other things):

  • ID of polygon
  • JoinID of polyline
  • Depending on match_option in Spatial Join or join_attributes in Intersect possibly all the attributes of both.

Join the polylines to the joined points with Join by Attributes...

These are the python/geoprocesing tools, if you wish to do this interactively you can use Calculate Field etc.. in exactly the same manner.

  • Very elaborate, but he rejects this approach in his question – FelixIP Jul 18 '15 at 2:47
  • @FelixIP he does not reject this approach, he considers it but postulates there must be a simper way... This approach shows that it's fairly simple. – Michael Stimson Jul 18 '15 at 3:11
  • Well I ended up just doing it this way and it seems to have worked. Wish there was a "FIRST_POINT_IN..." option though, that would certainly be handy... Thanks for your input. – msmi235 Jul 20 '15 at 15:26

Creating start point etc is logical and rather simple, not sure why not using it. This is untested but might worth a try:

  1. Intersect polylines with polygons, output - line
  2. Remove duplicates from result of unique line ids
  3. Join remaining segments to parent line layer

UPDATE: Tested, doesn't work. It picks line part from smaller polygon [FID]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.