I have a state polygon like the pic shown below, is there a way to find the line which is the maximum horizontal line?
Like this, but I want the maximum distance line.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI have a state polygon like the pic shown below, is there a way to find the line which is the maximum horizontal line?
Like this, but I want the maximum distance line.
Below is a workflow I would suggest - (1) create bunch of horizontal lines, (2) Clip (or intersect) horizontal lines by your polygon, and (3) Select the longest one among the clipped horizontal lines.
(1) Create horizontal lines.
Use Create grid
tool in the Processing ToolBox - Vector creation
. Set Horizontal spacing to be wide enough to cover the polygon entirely. Set Vertical spacing as small as reasonably practicable (fine spacing would give you accurate result, but it may be computationally intensive).
(2) Clip the lines by your polygon
Use Intersection
tool in the Processing ToolBox - Vector overlay
.
(3) Select the longest one
Use Select by Expression
tool in the Processing ToolBox - Vector selection
. Activate Expression window by clicking on a small epsilon button, then enter an expression (as below).
$length = maximum($length)
This expression will see if the length of the relevant line is equal to the maximum of all the clipped lines.
(4) Check your result
Step (3) will return a new layer (usually Matching features
). Check the line visually, and its length.
grid extent
is the area you want to cover by the grid. I selected 'Draw on Canvas' (by clicking on small three-dots icon) and then manually drew an rectangle to cover the polygon.
Picture below shows horizontal distance inside polygon (without holes) to Eastern border. I also shows contour lines of above surface. Points are the cells where focal maximum (3*3) equal to original raster value. The one shown in blue are the most remote per individual polygon segment. They coincide (in raster terms of course) with polygon vertices:
It proves @bugmenot123 statement, that vertices are the only candidates to be checked. This makes task solvable in virtually no time. Note: for polygon with holes the longest line might sit on vertex of internal ring.
So, this is more accurate vector solution: