Tag Info

Hot answers tagged

11

Part count will not yield the correct answer. You could have a multi-part polygon with no holes. See image below for scenario. This would have been a simple query pre-ArcGIS 10 as you could have called ArcObjects to ask if the polygon had a hole but ESRI have removed much of this support in the VBScripting environment to the point its pretty useless now, ...


5

There are better ways to adjust label placement in the placement properties. However, you can pad text using the python parser and .ljust(). "Twp1".ljust(10)


4

You can copy the following script to your QGIS (Processing Toolbox > Scripts > Tools > Create new script). This script takes shapefiles from one folder, uses the Field Calculator algorithm to add the filename as an attribute (with Null values but you can edit this to another expression) and outputs the shapefiles into another folder: ##Test=name import os ...


4

def Reclass(A): Low = 0.208113 Moderate = 0.261517 High = 0.36756 if Low <= A <= Moderate: val = "Low" elif Moderate < A <= High: val = "Moderate" elif A > High: val = "High" return val   Reclass(!grid_code!) This will do what your code seems to be trying to do. My concern is that I think you need to think more ...


4

Your code is fine but you are missing a right parenthesis for each line of code in the nested if part: if(biltype.startswith('Commercial, Education')): return 'Education' elif(biltype.startswith('Commercial, Emergency and Rescue Service')): return 'Emergency Services' elif(biltype.startswith('Commercial, Retail')): ...


3

You need to pass the returned value in a variable, not reference the column itself. Expression: result Codeblock: if [ColumnB] > 0 then result = [ColumnA] / [ColumnB] else result = 0 end if Here's how the two parts fit together in the field calculator - my data doesn't have the same field names, but you get the idea.


3

The problem was that both the current working copy and the shadow copy tables were named the same. The join went fine but the field calculator and geometry were greyed out. To fix this, I simply renamed the backup table name to something different. I was able to field calculate and essentially restore the data. I did not find this resolution documented ...


3

You are defining the function on the first statement, which needs to end in a ":", e.g. def makestr(test): Here is a simple solution: def makestr(test): try: return ''.join(i for i in test if i.isdigit()) except ValueError: pass


2

Using Field Calculator (simple): arcpy.CalculateField_management("Buffer_Field","!Buffer_Field!+400","PYTHON_9.3") Or in ArcMap by opening the attribute table, right click on the Buffer_Field and then in the dialog enter Buffer_Field + 400. Using update cursor (somewhat advanced): import arcpy InTable = "c:\\path\\to\\table" # or feature class with ...


2

The way I just did this assumes that you are using a file geodatabase features class, with an OBJECTID field that starts at 1. I've called my date field DateField so change that for yours. Parser: Python Code Block: def inc162secs(oid): startDataObj = datetime.datetime.strptime("30/01/2015 18:30:00", "%d/%m/%Y %H:%M:%S") return startDataObj + ...


2

With the help of @MichaelMiles-Stimson the Pre-Logic Script Code I ended up using was: def date_only(datetimeVal): datePart = datetimeVal.split(" ")[0] return datePart The reason I needed to do it this way rather than the precise method used by @blah238 in the answer to the other question was that the Field Calculator performs a datetime to ...


2

From an article below, I answered the question. The final code was: http://stackoverflow.com/questions/8990864/calculating-subtypes-and-coded-values-in-arcgis-attribute-table Pre-Logic Script Code: Dim ValueToConvert Dim ConvertedValue ValueToConvert = [ZONING] Select Case ValueToConvert Case "RS" ConvertedValue = "Single Family Residential" Case ...


2

What about "size" * 16 in the field calculator expression?


1

Try this (edited per @alpha-beta-soup comment): def myFunction (inter, prop, patch, shp, nat, edge): myList = [inter, prop, patch, shp, nat, edge] myList.sort() myDict = {'Interconnectivity' : inter, 'PropCover' : prop, 'PatchSize' : patch, 'ShapeIndex': shp, 'Naturalness' : nat, ...


1

I can see that multiple comments aren't being understood. This is what I meant: import os,arcpy from arcpy import env mxd = arcpy.mapping.MapDocument("CURRENT") #arcpy.env.overwriteOutput = True fieldName = "RasterID" RowsField = "unknown" # the field (numeric) for the number of rows ColsField = "unknown" # the field (numeric) for the number of columns ...


1

As @Michael Miles-Stimson has commented your calculate field method will overwrite all row values each loop through the raster list method. So, the table will only have one raster name for each record. In addition, it is unclear from your question if the update table has an equal number of rows for rasters that exist within the directory. If you are ...


1

It is hard to be sure without seeing your error message but I suspect this will work: def Reclass(A): if ( A>= 0.208113 and A <= 0.261517): return "Low" elif (A > 0.261517 and A < 0.301951): return "Moderate" elif (A > 0.301951 and A < 0.335518): return "Moderate" elif (A > 0.335518 and A < 0.36756): return ...


1

You can use this code in field calculator to increment by 1. Parser: Python Expression: autoIncrement() Code Block: rec=0 def autoIncrement(): global rec pStart = 1 #adjust start value, if req'd pInterval = 1 #adjust interval value, if req'd if (rec == 0): rec = pStart else: rec = rec + pInterval return rec


1

Using the python parser, look at ljust() (added as answer, not comment, to include link).


1

Sorry for that stupid question! I did find an very easy way to do what I aked in this thread. Just use the QGis processing tool and the SAGA "merge vector layers" tool. The merged shape file has a column (called "Layer") filled with the shape file names.


1

Are you referring to the difference between the two expressions? If yes, it looks like the bottom one is using Python as the parser where as the one on top is using VB. To change this in the Field Calculator window in ArcGIS, just select VB instead of Python and the top expression should work.


1

Try this: def makestr(test): # Add colon numlist = [] # Don't use name "list" for s in test: if s.isdigit(): numlist.append(s) return ''.join(numlist) # Return a value


1

I found also another error. You have to join the a values at the last loop: def makestr(test): l1=[] for val in test: if val.isdigit(): l1.append(val) return " ".join(l1) or def makestr(test): l1 =[val for val in test if val.isdigit()] return " ".join(l1) You can join list items without iterating over them. Just ...


1

From your comment I would assume that you just want to add a new field? Open the attribute table of the file, start an edit session, and then use this button: In your case you would have to opt for Text:


1

Perhaps this: 'www.google.com/' || "ID_column"


1

The expression would be, for example: 'A' || "someField" someField would be your field that you want to use when updating and || is used to concatenate strings in QGIS. EDIT: Make sure the values are put in between single quotes and the field names are put in between double quotes!


1

You can use: concat('A', "your_column" ) Note: Your column must accept Strings so if your current column type is set to integer, you will have to create a new field in the Field Calculator and set it to String.


1

Simple solution: 'A' || "column name" in a new field of type String.


1

You can do this using arcpy in conjunction with numpy: import arcpy import numpy as np input = "c:/data/usa.gdb/USA/counties" arr = arcpy.da.FeatureClassToNumPyArray(input, ('population_density')) ##to create 3 rank for example p1 = np.percentile(arr, 33) # rank = 0 p2 = np.percentile(arr, 67) # rank = 1 p3 = np.percentile(arr, 100) # rank = 2 #use ...


1

You do not need to do replace. You just need to modify the format string. "Convert" = "{}{:02d}{:02d}".format(!SignatureYear!,!SignatureMonth!, !SignatureDay!)



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