16
votes
Accepted
Getting dictionary for each feature with their attribute values using PyQGIS
The QgsJsonUtils class has exportAttributes method for getting attributes as a dict.
Solution 1:
Making a dictionary including feature "id" as key, attributes map as value:
{feature1.id: {...
11
votes
Accepted
Converting full road names to abbreviation using ArcGIS field calculator?
Use a dictionary and if/else with list comprehension to replace the words:
Pre-logic:
def replacename( names, new_names):
d = {'Lane':'Ln', 'Road':'Rd', 'Street':'St'}
return ' '.join([d[...
11
votes
Getting dictionary for each feature with their attribute values using PyQGIS
The snippet below should help you. It just prints a dictionary for each feature to the console, but you could do something else with the feature attribute dictionaries if you wanted.
from qgis.utils ...
8
votes
Accepted
Summing Values for Each Item in a Dictionary
Iterate over the dict items and construct a new dict from the key and sum of the values:
>>> slackloopLength = {'abc': [1,2,4,7], 'def': [1,3,5,7,9]}
>>> {k: sum(v) for k, v in ...
7
votes
AttributeError when calculating area in hectares in PyQGIS
Since processing.runAndLoadResults gives you a dictionary, you get the error. You have to use processing.run to get a layer and add it to QGIS manually using QgsProject.instance().addMapLayer(clip).
.....
5
votes
Accepted
Parsing CSV data and updating a dictionary and creating a polyline
Don't use try:...except: when debugging. Don't use silent and overly broad exception handling ever.
Some comments:
You're not using the csv module. You import it, then never use it, instead you ...
5
votes
Accepted
Using dictionary and cursors to calculate a field based on values from another table - KeyError [0]
search_feats_13_8 is a dict with OBJECTID as the key (part between []). upd_row is a tuple where the first element (referenced with [0]) is OBJECTID:
What is being attempted here is to see if ...
5
votes
Getting dictionary for each feature with their attribute values using PyQGIS
# get the fields and features:
fields = indiv.fields()
features = indiv.getFeatures()
# initialise an empty dict with each field name:
attdict = {}
for field in fields:
attdict[field.name()] = []
...
5
votes
Getting dictionary for each feature with their attribute values using PyQGIS
The easiest way is using the underdog __geo_interface__, that was defined by Sean Gillies at https://gist.github.com/sgillies/2217756:
layer = iface.activeLayer()
for feature in layer.getFeatures(...
5
votes
Creating a dictionary using data types from user input
In arcpy.Describe(f) the variable f will evaluate to the filename only, without a directory. arcpy will search for that file in the 'current' directory, i.e. os.getcwd().
You need to either specify ...
5
votes
AttributeError when calculating area in hectares in PyQGIS
You get that error because layer has no method fieldNameIndex, but provider has. Use the following script:
layer = iface.activeLayer()
provider = layer.dataProvider()
field = QgsField("area3&...
4
votes
Accepted
SearchCursor too many values to unpack
I am not sure which field you want your dictionary key to be, but for the answer I am providing I made it the joinldFld, you can easy change it by switching the index.
valueDi = {x[0]: x[1] for x in ...
4
votes
Accepted
Populating dictionary using ArcPy creates only 1 entry?
The problem is that each time around the loop you create a new dictionary called MK_dict over writing the previous one.
MK_dict = {}
for fc in fcs:
COS = arcpy.Describe(fc).spatialReference.name
...
4
votes
Accepted
Create a line chart from a dictionary of values in google earth engine
I missed the bounty, but anyhow I got an answer. See if this is what you needed..
var createFC = function(element, list) {
list = ee.List(list) // cast the 'accumulating' object
element = ee....
4
votes
Accepted
ArcPy UpdateCursor and Dictionary
You have some problems in the update for. 1) I don't understand why you want to iterate the dictionary, you already have the key in row[0]. 2) This comparison v == min(v) it is always false v is an ...
4
votes
Accepted
Computation with dictionary-values in GEE
The objects that you get on your computer (via the Earth Engine Code Editor or otherwise) are always represented as dictionaries (or JSON objects, if you like that term) but within Earth Engine they ...
4
votes
Accepted
How to get dictionary value from reduceRegion in GEE Python
You call get() on the dictionary to get a value from the dictionary. If you know the type of the value, you can also call getArray(), getGeometry(), getNumber(), or getString(). That would return the ...
4
votes
Accepted
Converting CSV file with polygons in dictionary format into GeoDataFrame
I read the CSV file into a Pandas' DataFrame, extract the numbers from your boundary column, convert to shapely polygons, convert Pandas df to GeoPandas gdf:
import pandas as pd
import geopandas as ...
4
votes
Accepted
Filter attribute information based on three different parameters and return ids using PyQGIS
I like to use collections defaultdict list for problems like this. (Your problem can be solved using a simple dictionary if you dont need to list the duplicates, just set one of them to 0.)
from ...
3
votes
Accepted
Using dictionary of file names and DD coordinates to create points in shapefile using shapely?
You don't need ArcPy here, simply use the geospatial pure Python modules as GeoPandas, Fiona, Shapely, pyshp (shapefile) or osgeo.ogr
# the resulting dictionary
dicto = {'IMG_2840.jpg': (39....
3
votes
Comparing Two Tables Using Arcpy
It is this line that is flawed:
if row[0] == ipc[str(row[0])]:
This is essentially asking if 10785823 = 24 which obviously it does not!
I believe you are trying to ask if the dictionary ipc ...
3
votes
Accepted
Reformatting Dictionary Object to rows and columns using Google Earth Engine?
This may not be the only way to do it, but it works:
/** YOUR CODE **/
// Call up WDPA data, filter
var dataset = ee.FeatureCollection('WCMC/WDPA/current/polygons')
.filter(ee.Filter....
3
votes
Accepted
Populating a Dictionary with an Update Cursor "Typeerror: 'Dict' Object Is Not Callable"
I suspect somewhere along the way, the built-in dict() got set to something else (probably like below), and is no longer the object you think it is.
d = dict() # new dictionary
print(d) ...
3
votes
Using ArcPy to check for duplicates AND Latest date?
As mentioned in the comments there are other ways of doing this. But you are correct that a Dictionary can be used. Execute in Python window of ArcMap or if standalone you need to create the feature ...
3
votes
Converting full road names to abbreviation using ArcGIS field calculator?
If you only want to use the abbreviations for labelling then you could investigate Using an abbreviation dictionary and the About abbreviating and truncating words page:
Abbreviation dictionaries ...
3
votes
Accepted
Identifying small polygons that are inside larger bounding polygons within same feature class using ArcPy?
Here is the code snippet that finally solved my problem:
with arcpy.da.SearchCursor(parcels, ['SHAPE@', 'PARCEL_ID']) as sCurs1:
for inside in sCurs1: #small parcels' loop
xmax1 = inside[...
3
votes
Accepted
Using a dictionary to find unique values from one field, populate second field with consecutive integers
For a start ID is irrelevant in your fields, you only need the two fields being worked on 'Name', 'Id_2'. You've also set up a search then an update, you don't need to do this, a single update is ...
3
votes
Accepted
How do I turn dictionary object values into columns for .csv export?
assign properties to a variable (dict) and append the importance dict. The method combine of ee.Classifier returns a dictionary, not a list (as you're casting it to)
(disclaimer: I didn't try this ...
2
votes
Update field's rows with a value of dictionary
I dont understand all of your code but i'll give some parts of it a try: Why do you need a searchcursor inside the updatecursor when you already have created a Dictionary?
You should also need both ...
2
votes
Accepted
Issue utilizing Keys:Values from Dict with da.UpdateCursor
I believe you're trying to do something like this:
dict= {'xyz':'abc','ghi':'lmno'}
for key in dict.iterkeys():
print key + "=" + dict[key]
with arcpy.da.UpdateCursor(item,key) as cursor:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
dictionary × 107arcpy × 60
cursor × 33
google-earth-engine × 22
python × 13
pyqgis × 9
google-earth-engine-javascript-api × 7
arcgis-pro × 5
attribute-table × 5
csv × 5
update × 5
list × 5
arcgis-desktop × 4
arcmap × 3
arcgis-10.2 × 3
python-2.7 × 3
function × 3
key-value-store × 3
gdal × 2
field-calculator × 2
data × 2
geometry × 2
fields-attributes × 2
coordinates × 2
convert × 2