I have a polygon layer and a polyline layer. I want to project the polygons onto the polyline like I show in the following images.

The first image shows the features I have.

1_cells and polyline

The second image shows the projection lines (red dashed lines) as I think the concept might work.

2_projection lines

The third image shows the resulted segments of the polyline as I expect them to be.

3_resulted segments

I don't know if this can help, the cells are from a raster grid layer and the polylines represent a road.

It is like the shadow of the polygons cast on the polyline using perpendicular lines to the polyline from the vertices of the polygon. However, the perpendicular is just a concept. I don’t know how it could better work.

I can use: QGIS version 3.10.1-A Coruña Or ArcGIS 10.4.1 for Desktop

  • Thank you Taras, very nice process and illustrations I can follow – panka May 12 '20 at 16:09

Solution for QGIS

Let's assume there are two layers 'squares' (green) and 'lines' (blue) with its corresponding attribute tables accordingly, see image below.


Step 1. Proceed with 'Extract vertices' (Apply additionally 'Delete duplicate geometries' or 'Remove duplicate vertices' if needed)


Step 2. By means of a 'Virtual Layer' through Layer > Add Layer > Add/Edit Virtual Layer... use a query query with ST_ClosestPoint()

SELECT v.id, sv.Name, ST_ClosestPoint(l.geometry, v.geometry) AS geom
FROM "vertices" AS v, lines AS l


Step 3. Proceed with 'Points to path'. Do not forget about "Order field"


Step 4. Proceed with 'Buffer'. Do not forget about 'End cap style' and 'Join Style'.


Step 5. Proceed with 'Difference' or as was mentioned in comments apply 'Intersection'.



  • Hi Taras, in the Step 3, when you mention 'Points to path', you mean 'Points to Line'? – panka May 26 '20 at 9:19
  • Hi @Taras, the steps 2 and 3 I cannot execute them. Since they are an individual process, and it is a kind different between different software, I posted a separate question which you have already commented. I addressed a different question for each software which are – panka Jun 7 '20 at 20:32
  • I addressed a separate question for each software which are [Creating polyline segments by points in maximum distance to each other along another polyline using QGIS] <gis.stackexchange.com/questions/363087/…>, and [Creating polyline segments by points in maximum distance to each other along another polyline using ArcGIS Desktop] <gis.stackexchange.com/questions/363083/…> where I provide also the answers. – panka Jun 7 '20 at 20:40
  • At the final Step 5 I actually need ‘Intersect’, not Difference’. – panka Jun 7 '20 at 20:41

Solution for ArcGIS using ArcPy

You can

  • Generate Near Table to find coordinates to nearest line from each polygon

  • Move each polygon to that coordinate with da.UpdateCursor

  • Clip the line using polygons as clip features

import arcpy

arcpy.env.workspace = r'C:\GIS\Somedatabase.gdb' #Change
lines = 'polyline' #Change
output_lines = 'newlines123' #Change

arcpy.GenerateNearTable_analysis(in_features=polygons, near_features=lines, out_table='neartable', location=True, closest=True) #Find nearest line coordinates
d = {oid:[x,y] for oid,x,y in arcpy.da.SearchCursor('neartable',['IN_FID','NEAR_X','NEAR_Y'])} #Store in dictionary of OID:coordinates

with arcpy.da.UpdateCursor(polygons,['OID@','SHAPE@X','SHAPE@Y']) as cursor: #Move each polygon
    for row in cursor:
        row[1], row[2] = d[row[0]]

arcpy.Clip_analysis(in_features=lines, clip_features=polygons, out_feature_class=output_lines)

enter image description here

  • Thank you BERA, nice process and illustrations to follow also. – panka May 12 '20 at 16:12
  • BERA, I am not familiar with arcpy and coding in general. But, I applied the process by getting the cells centroids, snap them to polylines using Near Tool, creating circular buffer around the points and then Feature Envelope To Polygone to get the cells with their centroids on the nearest road. However, it is not suitable for me because the roads have high curvature and there are cells that intersect with different segments of the same road. Otherwise the process is very good and proper. – panka May 27 '20 at 9:50

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.