NationalSecurityAgency / qgis-shapetools-plugin

Shape Tools creates geodesic shapes and includes a number of geodesic tools for QGIS including the XY to Line tool, geodesic densify tool, geodesic line break, geodesic measure tool, geodesic measurement layer, geodesic scale, rotate and translate tool, and digitize points at an azimuth & distance tools.
GNU General Public License v2.0
154 stars 68 forks source link
arc azimuth bearing decimate donut ellipse geodesic pie polyfoil polygon qgis rose xytoline

QGIS Shape Tools Plugin

Shape Tools is a collection of geodesic tools that are installed in the Vector menu, on the toolbar, in the field calculator, or in the Processing Toolbox. Geodesic is the shortest path between two points on the Earth, a spheroid, or an ellipsoid.

Contents

Create Geodesic Shapes

Examples

All of these shapes can be accessed from the ShapeTools processing algorithms.

Processing Shapes

They can also be accessed from the Vector->Shape Tools->Create geodesic shapes menu.

Create geodesic shapes

The various shapes can be created from the feature's attributes or from default parameters in the Create Shapes tool. Note that if the output layer uses a temporary layer, it will not be saved with the QGIS project. You need to manually save the layer or use the Memory Layer Saver plugin.

The following are details for creating each shape. All of the shapes are created centered around a point feature or from a point feature. Common elements are:

Ellipse

Ellipse

Select a point vector layer and an output layer or use the default temporary output layer. Then select the specific ellipse parameters. The semi-major axis of the ellipse runs along the orientation axis. The orientation of axis is measured in degrees in a clockwise direction from the north line. The units of measure for semi-major, and semi-minor lengths are defined by Radius units.

To the right of the semi-major axis, semi-minor axis, and orientation of axis entries are data defined override buttons . These fields allow the values to be derived from the contents in the attribute table as shown here.

Date defined

Alternatively, the user can click on the Edit... button and use any valid expression.

Line of Bearing

A line of bearing is the line drawn from a starting point in the direction of the asimuth or bearing for the specified distance. The line of bearing uses geodesic math to find the shortest path and is accurate along the Earth's surface.

Points Along a Bearing

A line of bearing is the line drawn from a starting point in the direction of the azimuth or bearing for the specified distance. The line of bearing uses geodesic math to find the shortest path and is accurate along the Earth's surface. In this algoirthm rather than drawing a line, equally spaced points are created along the line.

Arc wedge

In essence this takes a wedge of a donut shape. The parameters are similar to Pie wedge and Donut.

Circle

Create a circle shape. The circle radius is specified from the default value, from the attribute table, or from an expression. Number of drawing segments defines how many line segments it uses to create the circle. A larger value will produce a smoother circle, but will take more time to draw.

Donut

Create a donut shape. The inner and outer radius are specified from the default values, from the attribute table, or expression. If the inner radius is 0 then a solid circle is drawn. Number of drawing segments defines how many line segments it uses to create the circle. A larger value will produce a smoother circle, but will take more time to draw.

Ellipse Rose

Create an N-petal rose. The distance from the center to the outer petals are defined by the radius.

Epicycloid

Create an N-leafed epicycloid. The distance from the center to the outer edge is defined by the radius.

Gear

Create an N-toothed shape that look like a gear.

Heart

Create a mathematical heart which fits within the circle defined by its radius.

Hypocycloid

Create an N-pointed hypocycloid. A hypocycloid is defined as the curve traced by a point on the circumference of a circle that is rolling on the interior of another circle. The distance from the center to the outer cusps are defined by the radius.

Pie Wedge

If Azimuth mode it is set to Use beginning and ending azimuths, then the pie wedge focal point starts at the point layer's geometry extending out to the specified radius. It starts at the Starting azimuth going in a clockwise direction to the Ending azimuth. If Azimuth mode is set to Use center azimuth and width, then a center azimuth is specified which becomes the center of the pie wedge with an arc length of Azimuth width. The pie wedge can either be defined from the point vector layer and the selected parameters or the override to the right allows selection of an attribute to derive the values or an expression. Drawing segments is the number of line segments that would be used to draw a full circle. A wedge will use a proportionally smaller number of segments. Making this larger will give smoother results, but will be slower rendering the shapes. If the azimuth width is 360 degrees, the a donut is created.

Polyfoil

Create an N-leafed polyfoil. The distance from the center to the outer leafs are defined by the radius.

Polygon

Create an N-sided polygon centered on the vector point. The vertices of the polygon lie on a circle of the default radius.

Radial lines

Create N-radial lines equally spaced around the point starting from the inner radius and extending out to the outer radius.

Rings with radial lines

Create N-rings around a point. The number or rings, inner ring radius and distance between rings can be specified from the dialog box or from parameters in each feature. N-radial lines can be drawn from the center point to the outer ring.

Star

Create an N-pointed star with the outer vertices located on a circle defined by the outer radius. The inner vertices are located along the circle defined by the inner radius. One of the radius' can be negative which gives an interesting shape.

Interactive Geodesic Shapes

The Interactive geodesic shapes algorithms allow the user to click on the map canvas to capture a coordinate and then generate a single shape as defined from the processing dialog box centered around the coordinate. So far there are two shapes that can be created. These can be accessed from the QGIS menu at Vector->Shape Tools->Interactive geodesic shapes or from the processing tool box like this.

Interactive geodesic shapes
Concentric Circles

XY to Line XY to Line

This creates geodesic, great circle, or simple lines based on starting and ending coordinates in each table record. One of the coordinates can be from a point layer geometry or both can come from the attribute table data where each record has a starting x-coordinate, starting y-coordinate, and an ending x-coordinate and ending y-coordinate.

XY to Line

Input Layer - This can either be a point layer, a simple table, or any other vector data set that has two coordinates among its data fields. For example a CSV file containing starting and ending coordinates could be imported using Layer->Add Layer->Add Delimited Text Layer... located in the QGIS menu. From this dialog box the user can specify one of the coordinates for the layer's geometry or No Geometry can be used. Both types of layers will be visible to XY to Line.

Output point layer - Optional points layer that can be created in QGIS. It can contain the starting point, ending point, both points, or no points in which case it will not be created.

Output line layer - Output line layer file that is created in QGIS.

Input CRS for coordinates within the vector fields - CRS of the input coordinates within the table data fields.

Output layer CRS - CRS of the output line and point layers.

Line type - 1) Geodesic creates a highly accurate shortest path between two points. 2) Great Circle creates a Great Circle arc between the two points. 3) Simple Line creates a non-geodesic straight line between the two points.

Starting point - Specify whether to use the Layer's point geometry (not applicable for layers that don't have Point geometry) or to specify the Starting X Field (lon) and Starting Y Field (lat) from the layer's fields.

Ending Point - Specify whether to use the Layer's geometry (not applicable for layers that don't have Point geometry) or to specify the Ending X Field (lon) and Ending Y Field (lat) from the layer's fields.

Show starting point - If checked the output point layer will include an entry for the starting point if an Output point layer has been specified.

Show ending point - If checked the output point layer will include an entry for the ending point if an Output point layer has been specified.

Break lines at -180, 180 boundary for better rendering - Depending on the QGIS projection when lines cross the international date line, strange behavior may occur. Checking this box breaks the line at the -180, 180 boundary in a way that it displays properly.

This function can also be accessed from the Processing Toolbox.

Processing Toolbox

Geodesic Line Break at -180,180 Geodesic Line Break at -180,180

If you have ever created a geospatial masterpiece that has crossings across the International Date Line at a longitude of -180°/180° and it turned out like the image on the left, you are not alone.

Break lines

Geodesic line break will break lines at the -180°/180° boundary along a geodesic path which is the shortest distance along the earth's surface between two points. The algorithm is very simple with just an input and output layer. The resulting output is shown in the above right side image. Depending on your data you may find it useful to also run the Geodesic Densifier on the data prior to this routine.

Geodesic Line Break

Geodesic Densifier Geodesic Densifier

Densify a line or polygon vector layer by adding geodesic points in between individual line segments when its length is too great. This gives it a nice smooth curved appearance. For line vectors a geodesic line can be drawn between just the beginning and ending points.

Geodesic Densifier

The following shows the before and after results of running this function on a polygon layer.

Geodesic Polygon

This function can also be accessed from the Processing Toolbox.

Processing Toolbox

Geodesic Line Decimate Geodesic Line Decimate

This simplifies the geometry of a line layer by removing vertices who's distance to the previous vertex is less than the specified value. For each line, the geodesic distance is calculated between vertices and if the distance is less than the specified minimum distance then the vertex is deleted. This repeats until the distance threshold is exceeded. The only exception to this rule is if Preserve final vertex is selected in which case the final vertex is always saved.

Geodesic line decimate

The following shows the before and after results of running this funciton on a line layer.

Geodesic decimation

Parameters

Geodesic Point Decimate Geodesic Point Decimate

This reduces the number of points within a point vector layer by using geodesic distances mesurements between points and/or the time interval between points. This assumes that the points are ordered or that there is a property field that specifies the order of the points. Poiint can also be grouped together based on an attributed in the table in which case points from each grouping are processed separately.

Parameters

Geodesic Measure Tool Geodesic Measure Tool

This provides the ability to measure distances using geodesic (shortest path) algorithms. The results returned are similar to those used by Google Earth and makes for a nice baseline of distances. It also includes the heading from the first point to the second and a heading from the second point to the first. The units are in degrees. The units of distance can be kilometers, meters, centimeters, miles, yards, feet, inches, and nautical miles. Simply click on the Geodesic Measure Tool icon and start left-mouse clicking on the map to get measurements between points. A right-mouse click or ESC key press will end the measurement. Notice that the ellipsoid used to calculate measurements is listed in the lower left-hand corner. By default this is set to WGS 84, but it can be changed in the Settings menu. If snapping is enabled, then the Geodesic Measure Tool will snap to vector layer vertices and features when the mouse hovers over them.

While using the geodesic measure tool the user can quickly copy values of the last heading to, heading from, distance, and total distance onto the clipboard by typing one of the following keys:

The number of significant decimal digits of the value copied onto the clipboard is determined in the Settings.

Geodesic Measure Tool

The Save to Layer button will create a Measurement layer that contains the distance and by default the distance label will be displayed. The number of significant digits used for the label can be configured in Settings.

Geodesic Measure Tool

By right-mouse clicking on the Measurement layer and selecting Open Attribute Table, the following attributes are available for each measured line segment; label, value, units, heading_to, heading_from, and the total distance for all line segments.

Geodesic Measure Tool

If Points of the compass settings are set to somthing other than None, then compass cardinal directions will be added to the Geodesic measure tool dialog box like this.

Geodesic Measure Tool

These attributes will also be saved when exporting by using the Save to Layer button.

Geodesic Measure Tool

By clicking on the Add measurement point icon Add measurement point, a new dialog windows is displayed were precise measurement points can be added. The coordinates can be in WGS 84 (EPSG:4326), the project CRS, or some other custom projection. In the drop down menus specify the projection and the coordinate order in which the coordinates are entered.

Add measurement point

Geodesic Measurement Layer Geodesic Measurement Layer

This takes a polygon or line layer and measures the geodesic distances of each line segment in the lines or polygons or the total distance of all line segments in the shape's geometry. The user can choose whether each line segment is measured or the entire line/polygon geometry is measured. It creates a new line layer of line segments that contain attributes of all the measurements. If Measure total length rather than each line segment is checked, only the total distance is reported and the attributes are: label, distance, and units of measure. If measuring individual line segments, the attributes are: label, distance, units of measure, azimuth/bearing to the next point, and total distance of the geometry. If Compass direction resolution is not None, then the following attributes are added: compass abbreviated cardinal direction, compass name, and compass traditional name. If the total length check box is unchecked and a value other than None is selected for Compass direction resolution and Add compass directions to label based on above resolution is checked, compass cardinal directions are added to the label attribute. Distance units can be kilometers, meters, centimeters, miles, yards, feet, inches, or nautical miles. Use automatic styling styles the QGIS layer with the label string in the attribute table and with the text and line colors found in Settings. Select the checkbox for Retain the original feature's attributes if you want the original attributes included in the output layer; otherewise, only the calculated measurements will be included.

Geodesic Measurement Layer

Here is an example of running this on a polygon. Notice how it measures both the outer boundary and the inner boundary.

Measuring a polygon

Here is what the attributes table looks like.

Measurement Attributes

If Compass direction resolution is not None and Measure total length rather than each line segment is not checked, then additional compass cardinal direction atttibutes will be added. Here is what the attributes table looks like with Compass direction resolution is set to 16 point.

Measurement Attributes

Geodesic Transformations Geodesic Transformations Tool

This tool provides the ability to geodesically transform a shape. It supports scaling, rotation and translation. Each of these can use data defined override expressions. The relative size and geometry of each shape will be retained regardless of the projection.

Geodesic Transformations

To the right of each parameter is the data defined override button where the default value is overridden with a value from one of the attributes or an expression. This leads to some powerful and creative applications.

Geodesic Transformation Example

This was created by clicking on the Rotation angle about the centroid data defined override button, clicking on Edit and using the expression randf( -10, 10) and for Scale factor about the centroid using the expression randf(0.65, 0.85). For each polygin in the input layer it rotates them using a random value between -10 and 10 degrees and scales them by a factor betweeen 0.65 and 0.85.

Geodesic Flip and Rotate Tools Geodesic Flip and Rotate Tools

This is a collection of geodesic tools that transform vector features including the ability to flip horizontally, flip vertically, rotate by 180 degrees, rotate clockwise by 90 degrees, and rotate counter clockwise by 90 degrees. The first is a processing toolbox algorithm that allows the selection of one of these five transforms.

Geodesic Flip and Rotate

The following geodesic tools work on an editable line or polygon vector layer. If a feature is selected, these functions only operate on that feature; otherwise, it operates on all features in the layer.

Azimuth, Distance Digitizer Azimuth, Distance Digitizer

This tool works on point and line vector layers and is enabled when they are selected and in edit mode. In either case the following dialog box is displayed when the tool is enabled and a point on the map is clicked on. If snapping is enabled (Project->Snapping Options...), then when the cursor hovers close to an existing point or vertex, a bounding box around the point will be displayed. Clicking near the vertex will snap its location to be used by the Azimuth, Distance Digitizer as its starting point.

Azimuth, Distance Tool

Azimuth is in degrees and distance is in the selected Distance units of measure. The following is how it interacts on point and line layers.

Azimuth Distance Sequence Digitizer Azimuth Distance Sequence Digitizer

Azimuth, Distance Sequence Digitizer

This is similar to the Azimuth, Distance Digitizer, but it provides the ability to click on the map as a starting point and then give a series of bearings and distances in the order of 'bearing 1, distance 1, bearing 2, distance 2, ... bearing N, distance N' and it will create a path. This is useful in some survey work. If older surveying used magnetic north, it can be compensated for by the Bearing / declination adjustment. Magnetic declination changes over time, but the NOAA Magnetic Field Calculator provides an easy interface to estimate the magnetic north declination at a certain latitude, longitude and time, all the way back to 1590. West declination will be a negative number and east declination is a positive number. If a polygon layer is selected then the resulting shape automatically closes the polygon such that the beginning and ending points are the same. If a line layer is selected then you have the option of automatically adding a line segment from the last point in the sequence to the first point. If a point layer is selected, then only the nodes will be added to the layer. If snapping is enabled (Project->Snapping Options...), then when the cursor hovers close to an existing point or vertex, a bounding box around the point will be displayed. Clicking near the vertex will snap its location to be used by the Azimuth, Distance Sequence Digitizer as its starting point.

Expression Functions

Shape Tools includes the following field calculator functions:

st_from_meters() converts a distance measurement from meters into the specified measurement unit.

st_to_meters() converts a distance measurement into meters.

st_geodesic_distance() returns the geodesic distance in meters between two y, x (latitude, longitude) coordinates or two geometry points.

st_geodesic_bearing() returns the geodesic azimuth or bearing starting from the first y, x (latitude, longitude) coordinate in the direction of the second coordinate.

st_geodesic_transform geodesically transfrom a shape (point, line, polygon) using rotation, translation, and scaling.

Settings

The settings dialog box can be accessed from the Shape Tools menu Vector->Shape Tools->Settings. The following are the parameters that can be configured.

Settings