6

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

2
  • Thank you Taras, very nice process and illustrations I can follow
    – panka
    May 12, 2020 at 16:09
  • See also this solution about how to project polygons to lines: gis.stackexchange.com/a/384194/88814
    – Babel
    Aug 26, 2021 at 7:12

2 Answers 2

12

QGIS Solution

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

input

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

step_1

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_2

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

step_3

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

step_4

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

step_5


References:

4
  • Hi Taras, in the Step 3, when you mention 'Points to path', you mean 'Points to Line'?
    – panka
    May 26, 2020 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, 2020 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, 2020 at 20:40
  • At the final Step 5 I actually need ‘Intersect’, not Difference’.
    – panka
    Jun 7, 2020 at 20:41
10

ArcGIS Solution 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
polygons = 'squares' #Change. WILL BE ALTERED SO BACKUP YOUR DATA BEFORE BEFORE EXECUTING CODE
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]]
        cursor.updateRow(row)

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

enter image description here

1
  • 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, 2020 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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