Hot answers tagged

16 votes

Finding length and width of polygon in QGIS

You could use the "Oriented minimum bounding boxes" first then run the "Polygons to lines" tool. The output of Polygons to lines will have area, perimeter, angle, width and height of the minimum ...
J.R's user avatar
  • 15.7k
15 votes
Accepted

Calculating length of polygon in GeoPandas

Same way as area but: df.geometry.length or df['geometry'].length See GeoSeries.length: Returns a Series containing the length of each geometry.
BERA's user avatar
  • 71.2k
13 votes
Accepted

Get LineString length in meters (Python, GEODjango)

The length attribute of a LineString will return a value in the units of the coordinate system of the geometry. The coordinate system in your case is not specified, so there is not much meaning to the ...
yellowcap's user avatar
  • 3,013
13 votes

What is unit of Shapely length attribute?

You can now use shapely w/ pyproj to get geodesic length in meters: From: https://pyproj4.github.io/pyproj/stable/api/geod.html#pyproj.Geod.geometry_length from pyproj import Geod from shapely....
Josh Werts's user avatar
12 votes
Accepted

Calculating semi-major and semi-minor axis length of an ellipse in QGIS

Processing Toolbox -> Vector geometry -> Oriented minimum bounding box tool may be another solution. This tool already generates the width and height of the bounding boxes. Half of both will ...
Noura's user avatar
  • 3,429
11 votes
Accepted

Calculating length of each polygon side in PostGIS

See: https://stackoverflow.com/questions/7595635/how-to-convert-polygon-data-into-line-segments-using-postgis : SELECT st_length(ST_MakeLine(sp,ep)) FROM -- extract the endpoints for every 2-point ...
BERA's user avatar
  • 71.2k
10 votes
Accepted

Calculating elipsoidal length of line in PyQGIS

If you use just QgsDistanceArea.measureLength(feat), you get an error: first argument of unbound method must have type 'QgsDistanceArea'. That means you need to create an object of QgsDistanceArea d = ...
Kadir Şahbaz's user avatar
10 votes
Accepted

Show length of selection

You may use the statistics panel (View>Panel>Statistics Panel) with the "Selected feature only" option. You will need to change the field to length or area depending on the information ...
J.R's user avatar
  • 15.7k
8 votes

Calculating elipsoidal length of line in PyQGIS

This is my answer: layer = iface.activeLayer() features = layer.getFeatures() d = QgsDistanceArea() d.setSourceCrs(layer.crs(), QgsProject.instance().transformContext()) d.setEllipsoid(QgsProject....
vitorcsm's user avatar
  • 425
8 votes

What is the maximum number of characters for a label in QGIS 3?

After experimenting a little bit, I can confirm that QGIS has definitely no limitation of 1000 characters or less (as the initial form of the question suggested). Empirical evidence suggests that the ...
Babel's user avatar
  • 70.4k
8 votes
Accepted

Automatically updating geometry attributes in QGIS without using Virtual Fields

You can do this: Properties layer -> attribute form -> choose attribute where you need length ->Defaults -> put default value: $length -> check "apply default value on update"...
Pankrat's user avatar
  • 96
8 votes

Calculating sum of line length for hundred vector layers

Use PyQGIS: #Create an empty table in memory and add fields newtable = QgsVectorLayer("None", "Results", "memory") provider = newtable.dataProvider() provider....
BERA's user avatar
  • 71.2k
8 votes
Accepted

Calculating line lengths of road network in PyQGIS

You are adding the field once for each feature, you only need to add the field once for the table. When updating features like this: with edit(layer): .... I have found it often hangs with many ...
BERA's user avatar
  • 71.2k
7 votes
Accepted

Calculating polygon's length along a line?

Using QGIS: (1) Create point layer of the polygon vertices using Extract vertices tool (in the QGIS Processing Toolbox > Vector geometry). (2) Open the attribute table of the newly created Vertices ...
Kazuhito's user avatar
  • 30.7k
7 votes

Calculating length of common boundary lines of two polygon in QGIS

Preamble: this solution was being written before the moment when the author demonstrated his efforts in the field calculator. In QGIS I can suggest using a "Virtual Layer" through Layer >...
Taras's user avatar
  • 32.7k
7 votes

Calculating semi-major and semi-minor axis length of an ellipse in QGIS

Use Menu Processing / Toolbox / Minimum bounding geometry / Minimum Oriented Rectangle. Than the values you look for correspond to half of the sited of the rectangle. Edit: as described in @Kübras ...
Babel's user avatar
  • 70.4k
7 votes
Accepted

Finding the longest horizontal line inside polygon in QGIS

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. ...
Kazuhito's user avatar
  • 30.7k
7 votes
Accepted

Selecting top two features with longest length in the line vector file in QGIS

Use this expression: $length >= array_sort(array_agg($length), 0)[1] Explanation Create an array of the length of each line with array_agg() and $length Sort the value by a length with array_sort(...
Babel's user avatar
  • 70.4k
7 votes
Accepted

Always round up command

Use this expression with the function ceil() (rounds a number upwards). Multiply by 10, round it, then divide it by ten to get rounded up to the first digit: ceil ("number"*10)/10
Babel's user avatar
  • 70.4k
6 votes
Accepted

Length of reversed geometry in meters

Yes, this is a rounding error, a slight difference in the result depending on order of operands. Not sure what ST_LengthSpheroid() differs, but it's possible there's a slightly different code path ...
Paul Ramsey's user avatar
  • 19.8k
6 votes

Calculating length of polygon in GeoPandas

You can use GeoSeries.length for this. Note that geopandas uses Shapely that is crs agnostic. You will need to reproject your geodataframe to a crs in a unit that makes sense. import geopandas as ...
RutgerH's user avatar
  • 3,265
6 votes

Calculating elipsoidal length of line in PyQGIS

One way could be: d = QgsDistanceArea() d.setEllipsoid('WGS84') layer = iface.activeLayer() features = layer.getFeatures() for feat in features: print( d.convertAreaMeasurement( ...
cabesuon's user avatar
  • 1,051
6 votes

Calculating length of common boundary lines of two polygon in QGIS

Similar to @Taras's answer, you can create a virtual layer to get the actual border lines, and then compute their length (or display them, or label them, or ...) Go to the menu Layer > Add Layer &...
JGH's user avatar
  • 41.6k
6 votes

Creating field with cumulative values of line length in QGIS

In your Field Calculator, go into the Function Editor, create a new file, insert this function: """ Define new functions using @qgsfunction. feature and parent must always be the last ...
Kalak's user avatar
  • 3,693
6 votes
Accepted

Creating field with cumulative values of line length in QGIS

+1 for the custom function, they are a good trick to have up your sleeve. In this case you can do it with the built-in aggregate()function: aggregate('Line_CHain', 'sum', "Length", "id&...
M Bain's user avatar
  • 1,997
6 votes
Accepted

Autochange length of line not working in QGIS 3

If you need the line length as an attribute, you should turn to virtual fields. Those update dynamically. Beware that virtual fields are tied to the project, so sharing your file with someone else ...
Erik's user avatar
  • 16.1k
6 votes
Accepted

How to count the number of 100m length chunks in a table with line geometry?

If I get that right this should trivially be SELECT SUM(CEIL(ST_Length(geom) / 100.0))::INT FROM <lines> ; in the case that you want to count 100m (or less) segments per LineString ( -> 12)...
geozelot's user avatar
  • 29.9k
6 votes
Accepted

Splitting lines by multiple polygons, taking length of particular segment, using PostGIS

The query below will: 1 - Intersect the lines and polygons, 2 - extract the startpoints of each intersect output line geometry, 3 - Use the startpoints as input to ST_LineLocatePoint to get a number ...
BERA's user avatar
  • 71.2k
6 votes
Accepted

Setting symbol rendering based on feature visible length in QGIS

Simply calculate the length on the map canvas using $length / @map_scale and than check if this is longer than the threshold you want: $length / @map_scale > X (don't forget to convert units from ...
Babel's user avatar
  • 70.4k
6 votes

Getting perimeter for each polygon without shared sides in QGIS

Use this expression to calculate the perimeter without shared sides: length( intersection ( boundary($geometry), boundary( buffer ( ...
Babel's user avatar
  • 70.4k

Only top scored, non community-wiki answers of a minimum length are eligible