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

Taras
  • 32,823
  • 4
  • 66
  • 137
panka
  • 107
  • 6

2 Answers2

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:

Taras
  • 32,823
  • 4
  • 66
  • 137
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

Taras
  • 32,823
  • 4
  • 66
  • 137
BERA
  • 72,339
  • 13
  • 72
  • 161
  • 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 09:50