4

I am trying to make a plugin for Qgis with python. I have the four corner coordinates for a rectangle. I want to give the user the inputs, line space and angle (0 -180 degrees).

With these inputs, I want to fill this rectangle with lines in the direction of the specified angle and with the specified line spacing between the lines.

I guess what I need is the same type of code as for making a grid. But I can only find information about grids which are vertical or horizontal. I will try to code it myself, but if anyone have a webpage with information, I would gladly to read it.

1

Here is how I would proceed

1. Get the slope of the lines

I am not sure of the lines between which is the angle.

If between the line and the x axis: formula1

If between the origin and a given point: formula2

2. Get the parametric equation of the lines

This can be achieved with the traditional line equation formula3 or with the point-slope equation formula4. In both case, this (the origin b or the point) will be obtained based on the spacing between the lines.

3. Create the segment

With the equation of each line, we can create a segment contained withing the rectangle. For this step, I would use the functions in the shapely library (union, intersection,...)

4. Export that in whatever format

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.