New answers tagged

1

I hope I understood your problem sufficiently. As far as I got it, I would try the following: # predefine the constant parts of your expression using a variable: constant = "\ftp\raw\YYYYMMDD\Files\Charles" nameVar = "yourobject.Name" # use the built in function .format for setting up the expression for your arcpy.CaculateField_management function: ...


6

Here's a simple expression with no need to define a function in the codeblock: Headwater = 0 if !NextDown_Copy! else 1 This checks if each value of NextDown_Copy is truthy (i.e. not a null, 0, empty string), and returns a 0 if so, otherwise it returns a 1.


2

Python uses None to denote null values. I'd replace your Null with None (no quotes or brackets)and see what you get. Your script is essentially looking for a text string value of null. Furthermore, it's not contained in single quotes, so you're throwing a syntax error twice over.


4

With the next release QGIS 2.14 this will be fixed. If you have python knowledge, it should be straightforward to port the code linked to above to a small python snippet that copies joins and virtual fields from one layer to another. Please note that this is not a bug tracker and instead you should raise the awareness on the issue page you linked to, on ...


0

I ended up selecting all the features in the layer and exporting to a new layer. The python script worked fine after that. Not sure what the issue was but this resolved it.


1

The custom function can be used to run a specific function on each feature in a layer. But this will be feature specific. For more uses for this please see the following posts specifically for this: http://www.lutraconsulting.co.uk/blog/2015/06/05/qgis-function-editor/ http://nathanw.net/2012/11/10/user-defined-expression-functions-for-qgis/ ...


4

What about using re and set and setting a flag ( here 0 and 1) in python- re will extract all the names (last and first) from BENNETT MCCARL & ARNETTE BENNETT without &. For pattern matching re is of highest priority- you can use re how you want. import re def sorter(val): words = re.findall(r'\w+',val) uniques = set(words) if ...


2

Field calculator expression based on this answer def cw(sentence): words = sentence.split() counts = {} nMax=0 for word in words: if word not in counts:counts[word] = 0 counts[word] += 1 nMax=max(nMax, counts[word]) return nMax '================================================== cw( !MUID!) It will return maximum count of same words in ...


4

You can use the Python collections module and an Update Cursor to accomplish this. This method adds a new field and populates it with a 1 if there are any duplicates, otherwise a 0 if there are no duplicates. import arcpy, collections shp = r'C:\temp\names.shp' # Add a field called "check" to store binary data. arcpy.AddField_management(shp, field_name = ...


2

Assuming your source data is a FeatureClass/Table in a File GeoDatabase then the following query will select the rows you require: SUBSTRING(name FROM 1 FOR 7) = 'BENNETT' AND SUBSTRING(name FROM (CHAR_LENGTH(name) - 6) FOR 7) = 'BENNETT name is the field, I just happened to call it name. The first part is testing the left hand side the second part is ...


1

Your indentation is off, you're missing an indent on the "Else" line: def reLabel(typeLabel): if typeLabel == 'BPS Easement': return 'BPS' else: return 'Other'


2

So we have a definite answer to the question: The problem involves QGIS not liking the backslash try this replace ("Hotlink" , 'ABCD' , 'Maps\\ABCD\\ABCD') see esdm.co.uk/qgis-field-calculator-backslash-gotcha


4

$area is the area of the current feature. It's a numeric variable. area is a function which takes a geometry, and returns its area. This geometry could be any geometry, not just the current feature. You could say that $area is the same thing as area($geometry) Some examples - you could use area (the function) to get the area of the bounding box of the ...


3

!a! is not valid Python. Is this a typo? Calculate Field defaults to the VB parser, so you'll want to change that to Python. Something like the following should work: str.format() for reference. arcpy.CalculateField_management(fc, b, "!{}!".format(a), "PYTHON_9.3") To simplify things, you can combine all your for loops into one: for fc in ...


0

A quick and easy way would be to: Add another column that has the total area. total_area. (or just take note of the total area and hard code it at step 3 as @Frezter suggested in the comments. Then create a percent_Area column with float property with the desired number of decimal points. Either use (!Area_ha!)/(!total_area!) using Python OR ...


0

You do not say whether you are working with raster data. I do not know much about python in ArcMap, but I know when you want to have a table of attributes in a raster file you need to convert to integer. Maybe you need to make the calculations in integer.


1

I was able to get this done by creating a model with many tedious steps but it worked. Basically, I selected any Feeders without a certain voltage then merged and summarized the table with the total lengths of each Feeder of that voltage. This gave me a length value for each Feeder.


2

If you switch the parser to Python, and desired Secondary values are always the same length and position (e.g., Secondary is always the last 4 characters), you could do this: def FindLabel([PRIMARY], [SECONDARY]): primType = [PRIMARY].upper() second = [SECONDARY].upper() if primType == 'PRIMARY': return second[-1] # last character of ...


2

If i follow you correctly, you can do this in vbs without using the left/right Dim Result if [TYPE] = "PRIMARY" then Result = "B" elseif [TYPE] = "SECONDARY" then Result = "D20" End If [LABEL] = Result * EDIT * with the new information (and how i understand your question) i think this will work (I am not at the office nor do I have Arc handy ...


0

You would need to use the Summary Statistics GP tool for that. Choose TSS as statistics field and GR_NAME (or other group field) as case field. Choose the MEAN statistic type. You will get a resultant table which will contain the group name and the average value (among all rows found in your source points tables with that group name). Now you can use join ...


1

If you need MORE control over the class/label name and interval WISELY and want to use ANY type of equality check then a way is to use dictionary that keeps order (i.e. OrderedDict) and eval check as below where you have good command in interval for class and label for a class.To edit class (i.e. 1,2,3 etc.) and interval (i.e. ...


4

Try this out: def Get_Class(depth): breaks=[0.5,1,2,3,5,10,100000] n=len(breaks) for i in range(n): if breaks[i] >= depth: m=i+1; break return m '=============================================== Get_Class( !AREA_HA! ) It will look cooler with enumerate though


1

As @PolyGeo comments you can do this with Summary Statistics with any license level. Use the Length field as statistics field with the 'SUM' statistic type the FeederId and OperatingVolt as case fields. You will get the total length of all combinations of FeederID and OperatingVolt values. This is a single step process so I don't see much added value ...


3

A switch statement is ideal for what you want to do. Since Python doesn't support switch statements, you can use dictionary mapping to accomplish the same thing. def des(num): the_dict = {1: 'Flat', 2: 'North', 3: 'Northeast', 4: 'East', 5: 'Southeast', 6: 'South', ...


0

thanks everyone for your help! I just realized I never responded. Sorry about that! I fixed the problem but can't remember now how I did it! Oops.


4

def des(num): aList=['Flat', 'N', 'NE', 'E','SE','S','SW','W','NW','N'] if num in range(1,11):return aList[num-1] return 'N/A' Alternatively select valid records and use: ['Flat', 'N', 'NE', 'E','SE','S','SW','W','NW','N'][ !MajAspNum! -1]


1

here it is in vbs, i can do it in python later when i have the time. dim result1 if [MajAspNum] = "1" then result1 = "flat" Elseif [MajAspNum] = "2" then result1 = "north" Elseif [MajAspNum] = "3" then result1 = "northeast" ... Else result1 = "N/A" end if ^^ codeblock Direction = result1 I found this searching the site, Writing ...


1

With the advanced license you can use the frequency tool to produce the table you want. The analysis fields are feeder and voltage, the summary field is length Any nulls in either field will be aggregated and reported in the table. You can add the tool to a model.http://pro.arcgis.com/en/pro-app/tool-reference/analysis/frequency.htm


1

If your trying to obtain the line (vector) segment linear distance. Project the feature class, add a field and then use the Calculate Geometry function to obtain the length.


2

As you have already noticed, if you use your same expression for a real field and increase the precision, you could see that each id value is incremented with an almost-constant number (in your case, 0.2) depending on the parameters you specified. These are then rounded to give a whole number which I assume is what your scaled_id field-type is: I did ...


1

Your answer, actually helped, but I didn't find a way to get feature by feature id. So I created new field ID containing feature id, expression is simple: @row_number And then solved my task distance(centroid($geometry), centroid(geometry(getFeature(@layer_name, 'ID', 6609)))) Thanks!


0

I figured out eventually that I was getting this error because within the large annotation data set, there were characters that were not numbers (ex. ', !, #, etc.) and it was therefore throwing that error.


0

I just didn't know what I needed to search for. I've now discovered the concatenate option under "String > concat". To solve my problem I used the expression; concat('500m.',$ID)


1

I found a solution Instead of editing the fields myself I found a plugin that coould do the job (quickmultiattributeedit) Thank you for your help and time


2

Try this if("laeskaerm"='1' OR "laeskaerm"='true','true','false') in 2.2 Case when "laeskaerm"='1' OR "laeskaerm"='true' then 'true' Else 'false' End


2

You could use the following expression to update your "laeskaerm" field: CASE WHEN "laeskaerm" = 1 THEN 'True' WHEN "laeskaerm" = 2 THEN 'False' ELSE "laeskaerm" END


4

The function you are looking for is actually getFeature (at least in QGIS 2.8). It takes 3 arguments (hence your "Parsing Error") : the name of the layer, the name of the field, and the value of the field. So it would be something like getFeature( 'your_layer', 'id', 6679 ). Additionnal point : you actually have to use geometry(getFeature( ... )) in your ...


3

If you select your features before running the Field Calculator in the modeler, the output will contain only those selected features. A workaround would be to use a custom script in your model which allows you to update your selected features within the same layer. To do this, go to Processing Toolbox > Scripts > Tools > Create new script and copy the ...


2

Go to your layer properties by double-clicking the layer (or right-click > Properties) and go to the Fields tab. You will see the list of fields available including virtual fields. The expressions are stored in the Comment column as shown in the image (the red circle highlights the Expression Builder tool which you can click to edit your expression): ...


4

VBScript does not support syntax such as a=b=c to compare three values. Instead, you should write something like a=b AND a=c. The complete pre-logic block could be If [Grunntype] = [Grunntyp_1] And [Grunntype] = [Grunntyp_2] Then Lik_grtyp = 3 ElseIf [Grunntype] <> [Grunntyp_1] And [Grunntype] <> [Grunntyp_2] And [Grunntyp_1] <> ...


1

You can do that from command line with ogrinfo http://www.gdal.org/ogrinfo.html and SQLite SQL dialect http://www.gdal.org/ogr_sql_sqlite.html. Example: Select state called "Colorado" from spapefile, convert geometry into EPSG:3857 and compute the area. Unit corresponds with the base unit of the projection and in this case will be square meter. ogrinfo ...


1

When you don't compose the expression by point and click be sure to surround field names with double quotation marks. "POP"/"Area" To include string constants use single quotation marks.



Top 50 recent answers are included