New answers tagged

0

You may create your own custom python function through field calculator function editor to create random strings to populate a field: Click on the function editor tab within field cal Create new file and copy in code below Load the function from qgis.core import * from qgis.gui import * import random, string @qgsfunction(args='auto', group='Custom') def ...


5

You can do this directly within the CalculateField tool; use the following code block: prevval = None def calcowner(ownerval): global prevval val = prevval if ownerval is None else ownerval prevval = val return val And the expression: calcowner(!Owner!) Note that this probably won't work in ArcGIS 10.0 due to a bug that was fixed in 10....


1

This can be done with a custom python parser function like: Here we evaluate if value is NULL or not, if not write value to text file, if NULL pull value from text file: def update(val): if val: f = open('C:/Temp/temp.txt','w') f.write(val) f.close() return val else: f = open('C:/Temp/temp.txt','r') for v in f: return ...


0

Create a temporary attribute temp with rand( 1, 3). The higher number here has to be the number of the random values you want to use. After that, fill the values in drain_name like this: CASE WHEN "temp" = 1 THEN 'ravi' WHEN "temp" = 2 THEN 'Sangpo' WHEN "temp" = 3 THEN 'ganga' END After that you can delete temp again.


2

I think you need to add from qgis.utils import qgsfunction into your code. You can also remove the other imports as they're not necessary. So something like this should work: from qgis.utils import qgsfunction @qgsfunction(args="auto", group='Custom') def sp_split(value1, feature, parent): return value1.split(",")[2]


3

Try to change your code to def calc(Wert1, Wert2, Wert3): if (Wert1 == None): return Wert2/Wert3 else: return Wert1


7

The value that is written into the attribute table depends on what field calculator returns. In your case: CASE WHEN "Z" = 0 THEN "Z" = rand(1,100) END means that it compares Z and 0, and if that's true, it compares Z and a random value from 1 to 100, which has to be false because Z is 0. That's why it writes 0 (=False) into the fields which were 0. And ...


3

You need to use the Field Calculator or Calculate Field tool to calculate your new field equal to your old field. Make sure that your new field is defined the same as the old field. Otherwise it cannot be considered to be a copy.


0

This is copied verbatim from the ArcGIS Desktop help. The instructions are for Windows 7, so it's probably different for newer versions. You get the idea, though. Changing the way ArcMap displays short format dates in Windows 7 You can change the way ArcMap displays date formats by setting date format options within the Regional and Language ...


2

Use an if to check the value of each field, and skip that value if it's one of your "no data" values. You can add other "no data" values to the no_data list to skip those as well. Expression: skip_nodata(!FOR_FISH!, !MINING!, !FARM_EMP!) Code Block: def skip_nodata(val1, val2, val3): no_data = [-98, -99] x = 0 if val1 not in no_data: ...


3

In your if line you need to change your or to an and in the last part. if f4 == f5 and (f1 == f2 or f1 == f3) and (f6 != f7 and f6 != f8): This is because with f6 != f7 (6 != 5) it returns 1, even though f6 != f8 fails (6 = 6) in the second part. With the OR there it returns true if one of them is true. With an AND it would return true only if both are ...


1

This works for me: def setindex(height): dIndexInterval = 50 dCont = height i = dCont / dIndexInterval if ( dCont / dIndexInterval) - i == 0: return 1 else: return 0 And then setindex( !ELEV! ) in the bottom window where ELEV is the name of your elevation field. Edit The code given in the link looks buggy, as far as I can tell it will always ...


2

I would use regexp_substr instead of strpos so in your example something like: regexp_substr("FolderPath",'.*/') The first item ("FolderPath") is your column name (enclosed in "), the second is a standard python regular expression. There is a regexp howto available to help you out.


1

It looks like you put the defined function into the returned field. The message says if you have multi-line you have to cut the code and activate the Show codeblock and paste the code into the "Pre-Logic" Script Code space. The last line should be used to return the defined function exist in the "Pre-Logic" Script Code. Check "Using code blocks" in the ...


0

I just tested this at ArcGIS Pro 1.3 and can confirm what you are saying. I think the reason that field calculations cannot be undone is that they are not being done within an edit session, but rather by the Calculate Field tool of the Geoprocessing pane. I think the only way to try and obtain the software behaviour that you seek is to submit an ArcGIS ...


2

In the FieldPyculator, you will need to: Insert your function as a Global expression and remove the AP parameter as you can choose from the GUI which field you want updated. Slightly change your Field expression by specifying fields using <Mag> instead of !Mag!. This is the global expression I used (not sure what Vector_Mag was so changed these ...


2

You can do it using the following formula in the Field Calculator: regexp_substr("Field_Name",'(\\d+|\\d+.+)') It will give you the following results: 25 2 26A 125 147A Even if you have text with a name 'Text 123456789ABCDEF', the output will be: 123456789ABCDEF


1

In field calculator: right("column", strpos("column" ,' ')) Should do the job.


1

You can vary parameter in expression below, depending on what distribution is required: def aRand(): return arcgis.rand("Normal 2 2") --------------------------------------- aRand()


0

I've found similar issues when adding polygons and updating an area field with ($area/10000). It uses a different method than (area($geometry)) and often returns a different answer. I've concluded that editing, saving edits, turn editing off, open table/recalc field with (area($geometry)) works consistently. I don't mind discrepancies and errors, as I ...


6

In the field calculator, show Codeblock. In the pre-logic script code box: import random def randnum(): return random.random() In the expression box: randnum() Result in a new float field:


0

Buffering features in wgs84 does not work with distances calculated in meters. You first have to reproject each layer to a projected crs suitable for your area. In the modeler this is possible with



Top 50 recent answers are included