New answers tagged

0

This ESRI blog post has code that describes how to concatenate fields when you aren't sure how many fields will need to be concatenated. For example sometimes you have two values, sometimes you have three.


1

Assuming all the times are from the same day, you can calculate the delta between the start time and the end time using the following Python function: import datetime def delta(start, end): start_dt = datetime.datetime.strptime(start, '%H%M') end_dt = datetime.datetime.strptime(end, '%H%M') return (end_dt - start_dt).seconds / 60 This function ...


0

assuming they are the same day, you could just make a quick python function to calculate the time difference. e.g. Codeblock set to: def func(start, end): time_diff = end - start return time_diff and expression being: func(!STRTTIME!, !ENDTIME!) If it splits between days, you'll need some field to record how many days have passed.


1

As @ThingumaBob suggested, virtual fields do not have to be relied upon for assessing a table context. For example in your case is no assurance that the order will remain the same after an update. As a possible workaround, however, you could resort to use the $id function in a virtual field:


1

Tested on QGIS 2.18 and QGIS 3.4 Additionally, I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer.... Let's assume we have the following layer "line" with its Attribute table, see image below. With the following query, it is possible to clean up the line out of "tails"/"dangles". SELECT l1.* FROM line AS l1, ...


3

You can achieve the result that you are striving for with GRASS toolset v.clean for cleaning topology of a vector element. Probably, you will need to deploy rmdangle option. rmdangle: remove dangles, threshold ignored if < 0 Check the following references for more details: Removing 'tails' from line features? Deleting lines in QGIS Automated removal ...


5

The parameter "Correction_Comments" from your function is not used at all within the function. Instead, there is a variable "MSAGSTREETNAME", a local variable that is not referenced elsewhere. In addition, the if statement is using an assignment (=) rather than a test (==). Modifications: def Reclass(streetnamefield): if streetnamefield == 'HEMLOCK': ...


1

Check the syntax for the arcpy.CalculateField() function: CalculateField_management(in_table, field, expression, {expression_type}, {code_block}) In the expression parameter you have to pass a string referencing a field. However, the way you reference another field will depend on the expression_type. In your code you are specifying VB. In the tool's ...


0

When you put the name of your variable into quotes, you are essentially just passing the name of the variable as a string. What you want to do is pass the variable itself, as it is a reference to a string. Do it just like you do for the numeric variable and pass the variable name without quotes and it should work as expected. arcpy....


2

I agree with radouxju. Because the projection you have chosen is meant to preserve distance and not area, you're getting dramatic exaggeration of areas the further out you go from the center point. Choosing an equal area CRS and being sure it's defined before you calculate the area should fix it. If you prefer an azimuthal projection, you can use NAD 83 ...


1

To get accurate area calculations, use a local CRS. Since you're making these calculations for the entire world, you'll need to use many hundreds of different local CRS's. The most efficient way would be to add a "local_CRS" field, and enter the EPSG code of the best local CRS available for each area. Eg, for the USA, each state is covered by between one ...


6

First, you should be aware that an equidistant projection will not preserve the area of polygons (it preserves the distances along a set of straight lines). therefore you should use a projection of the "equal area" family (which does represent polygon with their undistorted area over their domain of application). Examples of such projections are sinusoidal (...


2

You need to create a custom function for this purpose. In the Field Calculator, go to Function Editor and create a new function name it TextCount, as you can see below, and copy and paste the following code: from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def textCount(text_field, feature, parent): split_text = ...


1

Use split to split into list, default split character is whitespaces: a = "Can I somehow count strings? I would like to know how many words (strings) I have in every cell. So I know that somewere is too many words. Len function calculates individual string character (also spaces ). Tanks!" a.split() ['Can', 'I', 'somehow', 'count', 'strings?', 'I', 'would',...


Top 50 recent answers are included