Polygons to Dimension Lines

المشرف العام

Administrator
طاقم الإدارة
It’s just so satisfying when something works.

Last week, I got a project where we need to submit a property map for a grant to install lighting at the baseball park. It requires the lot dimensions as well. Unlike CAD, this isn’t quite as straightforward in GIS. Perhaps due to user error, I couldn’t find anything in the QGIS plug-ins either, but I was able to do the next best thing with modeler.

The first step is to only get the parcels (or other polygons) we want. In recent versions of QGIS, you can simply select the polygons, Edit -> Copy Features then Edit -> Paste Features as… and either save as a file or temporary/memory layer. We’ll come back to this.

Here it is in a nutshell, but I’ll run down the variables you’ll need to build this yourself. As you build this, you can easily search for the tool with by the name shown.*

If you’re new to the model builder, open it in QGIS at Processing -> Graphical modeler. Begin with a Vector Layer input from the Inputs tab on the left panel and drag it into the model window. I’ve renamed the parameter Polygon, assigned it the polygon shape type, and made it required.*

You’ll then do the rest using the Algorithms tab to access the tools. The search bar at the top of the Algorithms tab autocompletes making it really able to quickly find the tool you want. Search first for “Polygons to lines”. You’ll see a few option from more than one provider. Notice the icons for each tool in the screenshot above and that will help you make sure you’re picking the one I used, otherwise your results may be a little different. So in this case, use teh Polygons to lines tool provided by QGIS. When you drag a tool to the model window, a box will pop up for you to fill in the variables. (Hint: don’t name the outputs until the very last tool, otherwise the map will populate with each output when you run it.)*You’ll use the Polygon as the input layer. Subsequent tools will use the output of the previous tool as the input layer, so pay attention that you’re getting the one you want; honestly it’s not usually clear at a glance, so you’ll need to read the input descriptions carefully as you go on.

At Simplify Geometries, I set the tolerance for 1.0 (we’re using feet in my case). This will clean up some of the very subtle changes along the parcel edge as well as the extra vertices at the right-of-way threshold.

The next tool is*v.split.vert - Split lines to shorter segments by max number of vertices. As it is, our lines are running around the perimeter of each parcel. Set the Maximum number of vertices in a segment to 2. This breaks the line to individual edges allowing our end result to give each edge it’s bearing and distance.

In v.clean we’ll use the rmdupl Cleaning tool with a Threshold of 0.1. This will reset the line directions. As you have shared boundaries with other parcels, the line directions may not be the same initially making the GIS interpret these as distinct. This corrects that. (You’d think that “rmdupl” would remove duplicate lines altogether, but I have not found that to be the case. The subsequent steps will take care of this).

Without the next tool,*Refactor fields,*your lines inherit the attributes of it’s polygons. This gives you the option to customize the attribute table. First, I had no desire to retain the parcel data; it would be redundant and since the edges all share with other parcels, it’d just be confusing. Also, coming up, I know I need to dissolve the features by a common field; the Dissolve tool won’t allow to do it by formula, so I added a string field called geomwkt with the formula:

geomtowkt($geometry)

WKT, if you’re wondering, stands for Well Known Text and is much easier to comprehend than the typical geometry field.

Perhaps also you’d prefer to store the dimensional data at this stage and you certainly can do so at this step, but because I’m feeling snooty and wanting the smallest possible footprint of this data, I’ve opted to label these dynamically without the fields. If I was doing the whole county or even a township, I’d add these to the attribute table to save processing time down the road. Here’s the formula for bearing (I found it somewhere on Stack Exchange I believe; apologies for not giving proper credit), followed by length which is obviously much simpler.*

(atan((xat(-1)-xat(0))/(yat(-1)-yat(0)))) * 180/3.14159 + (180 *(((yat(-1)-yat(0)) < 0) + (((xat(-1)-xat(0)) < 0 AND (yat(-1) - yat(0)) >0)*2)))

$length


I’d also suggest wrapping these with ROUND(formula, decimal tolerance), but that’s up to you of course; you may opt to save it for labeling as I do.

Your final tool is Dissolve which as stated earlier will be by the geomwkt field created previously. Name your output. I used DimLines.

Above the model window it requires you enter a model name and a group name. In my case I named it Polygon(s) to Dimension Lines wiht the group name Land Records Mgmt This is how you will find your tool in the QGIS Processing Toolbox. Then in the toolbar, Save or Save As and it will require you to save it as .model in the QGIS models folder. I just give it the same name as the model name. It will return a message if it was saved correctly. Changes to your model you can just hit Save and the same message will again verify it is saved.

To run your model, in the Processing Toolbox, expand Models to find your group name (Land Records Mgmt). Expand that to find all the tools you’ve saved to that group. The nice thing is that now this tool can always be available to use for you.

Double-click the tool and it asks for the Polygon layer you wish to run through this analysis. Select the polygon layer we created at the very beginning of this tutorial. I suggest you leave it save to a temporary file for now. Once it is ran and added to QGIS, we’ll want to examine it to make sure it really is what we want. And we can always save the layer from there. Make sure opening the output file is checked (usually is by default) and run it.

When the layer is added to the map, you’ll need to style it. I will assume you know how to do that much and the labels you can use the bearing and length formulas I provided above. But there is one more thing that will continue to make your life easier. Once you’ve got it looking the way you want, open the layer properties. At the bottom, click the Style button; it’s available from every tab of the Properties box. You can save your style as a QGIS layer style file! Do it! Now go back to your tool and right-click it. Select Edit rendering styles for outputs. We only have one output for our tool, but from the Style column, navigate to the QGIS layer style file you saved. Once you OK that change, every time you run that tool, it will load it into QGIS with the same style.*

Here is the layer style file I created if you’d like.*https://www.dropbox.com/s/qooz8e2cd0ovc8e/DimLines.qml?dl=0
and it looks about like this:

SO MUCH TIME SAVED! And hopefully you learned something! If any of my instructions are unclear or need expanded upon, hit me up on twitter @gisn8



أكثر...
 
أعلى