|
POST
|
If the cursor isn't going to be used once and disposed of, using a Python with statement ensures the cursor is reset for its next use. But then again, maybe having the cursor automatically reset isn't what someone wants. Just depends on the situation and need.
... View more
02-27-2015
07:55 AM
|
0
|
0
|
6645
|
|
POST
|
True, for now and in the ArcPy realm, calling the search cursor's next method will get the same result. I suggested using the built-in next method because of broader changes happening with Python outside of ArcPy. For Python 3 after PEP 3114 was approved, it meant the next() iterator method was going away. The Transition Plan for PEP 3114 covers two additional changes needed for moving to Python 3: Method definitions named next will be renamed to __next__ . Explicit calls to the next method will be replaced with calls to the built-in next function. For example, x.next() will become next(x) . The built-in next function was introduced in Python 2.6 to smooth the transition. Since we know that Esri has made the leap to Python 3 with ArcGIS Pro, I suggested an approach using the built-in function. For now, Esri's implementation of the ArcPy Data Access (arcpy.da) module in ArcGIS Pro still includes cursors having explicit next() methods, but I argue the current ArcGIS Pro implementation isn't very pythonic since the explicit next() methods don't add any special functionality beyond simply iterating.
... View more
02-27-2015
07:52 AM
|
1
|
2
|
6645
|
|
POST
|
Are you looking for only a single record/point per SRAddress? I recall you mentioning there may be up to 10 types or collections. Do you want a table that has [Type1, EWT1, ItemCount1, ...., Type10, EWT10, ItemCount10] columns? A table with at least 30 columns, most of which will be empty? Or, are you wanting a separate table that has [SRAddress, Type, EWT, ItemCOunt] that you can use to relate back to a point feature class that has the point locations for each SRAddress? I guess I don't understand what you want the final data structure to look like in terms of how many tables and what those tables look like.
... View more
02-26-2015
03:04 PM
|
0
|
1
|
1185
|
|
POST
|
As Owen Earley suggests, the Summary Statistics tool should work, and it is scriptable through Python. You could also use a data access (arcpy.da) search cursor approach, a bit more involved but likely more performant than Summary Statistics. # import functions from modules that are available but not commonly imported
from collections import defaultdict
from numpy import fromiter, dtype
# sum PCE_VOLU_3 by NO
stats = defaultdict(int)
with arcpy.da.SearchCursor(input_fc, ['NO','PCE_VOLU_3']) as cur:
for k, v in cur:
stats += v
# create iterable and populate numpy array
stats_iterable = ((k, v) for (k, v) in stats.iteritems())
tmp1 = fromiter(stats_iterable,
dtype([('NO', 'i4'), ('SUM_PCE_', 'f8')]))
# Dump numpy array to table
arcpy.da.NumPyArrayToTable(tmp1, out_table)
del tmp1
del stats
... View more
02-26-2015
02:51 PM
|
0
|
0
|
1322
|
|
POST
|
Once you sum the values, how do you want to store them? Do you want a separate table? Do you want a new column in this table where is shows the same sum for all of the records with the same NO?
... View more
02-26-2015
02:23 PM
|
0
|
3
|
1322
|
|
POST
|
Since the arcpy.da.SearchCursor is an iterable that returns one list per row of the table/cursor, the Python built-in next() function can be used to retrieve the next row, which would be the first row if the cursor was just created or reset. import arcpy
fc = 'c:/data/base.gdb/features'
# Open a cursor on some fields in a table
with arcpy.da.SearchCursor(fc, ['OID@', 'SHAPE@AREA']) as cursor:
row = next(cursor)
# Do something with the first row of data here
del cursor
... View more
02-26-2015
02:02 PM
|
4
|
0
|
6645
|
|
POST
|
Python dictionaries are implemented using a hash table. They are effectively an unordered collection of items, which means you shouldn't rely on the order of the elements. I mention this because it seems to me you may be trying to do just that. Instead of an item dictionary, I think an item list of tuples would work better and be more straightforward. f2 = open('C:\Users\Administrator\Desktop\DetailView.json', 'r')
data2 = jsonpickle.encode( jsonpickle.decode(f2.read()) )
url2 = "https://myla311.lacity.org/myla311router/mylasrbe/1/QuerySR"
headers2 = {'Content-type': 'text/plain', 'Accept': '/'}
r2 = requests.post(url2, data=data2, headers=headers2)
decoded2 = json.loads(r2.text)
items = []
for sr in decoded2['Response']['ListOfServiceRequest']['ServiceRequest']:
SRAddress = sr['SRAddress']
latitude = sr['Latitude']
longitude = sr['Longitude']
for ew in sr["ListOfLa311ElectronicWaste"][u"La311ElectronicWaste"]:
CommodityType = ew['Type']
ItemType = ew['ElectronicWestType']
ItemCount = ew['ItemCount']
items.append((SRAddress,
latitude,
longitude,
CommodityType,
ItemType,
ItemCount))
import numpy as np #NOTE THIS
dt = np.dtype([('SRAddress', 'U40'),
('latitude', '<f8'),
('longitude', '<f8'),
('Type', 'U40'),
('ElectronicWestType', 'U40'),
('ItemCount', 'U40')])
arr = np.array(items,dtype=dt)
sr = arcpy.SpatialReference(4326)
arcpy.da.NumPyArrayToFeatureClass(arr, fc, ['longitude', 'latitude'], sr )
... View more
02-26-2015
01:43 PM
|
2
|
3
|
1185
|
|
POST
|
Can you re-post your current code with the loop now integrated into it?
... View more
02-26-2015
11:22 AM
|
0
|
5
|
1185
|
|
POST
|
You are passing the string, '5810 N WILLIS AVE, 91411', as a key name (either for k1, ..., or k6), and the error message is telling you there is not key named that address string.
... View more
02-26-2015
11:19 AM
|
0
|
0
|
6187
|
|
POST
|
ItemCount is holding the item count for a single type, not all of the item counts for all of the type of electronic waste. In the code I provided, the last loop over the electronic waste items grabs the VCR/DVD Players, which has an item count of 1. After the loops are finished, and since I didn't delete ItemCount, it stills exists and has the last value of 1 stored in it.
... View more
02-26-2015
11:17 AM
|
0
|
0
|
6187
|
|
POST
|
I am running ArcGIS 10.3.0.4322, and I don't see the issue you are having if I re-source a file geodatabases using arcpy or the GUI. My original test used a SQLite database, and I think that was causing the issue for me, which makes me think it may be a client-datasource compatibility issue for you. Have the geodatabases you are using been around for a long time, created in an earlier version maybe? If so, does recreating the file geodatabases using your current version change the behavior.
... View more
02-26-2015
11:04 AM
|
0
|
1
|
2651
|
|
POST
|
I think I understand what is going on. Whether it is a bug or not is for you to debate with Esri Support. If you run the following on the problem MXD you talked about, print arcpy.mapping.Layer(r'Work Layers\Replacement Tree').dataSource I am guessing the results come back showing the original data source and not the re-sourced data source. However, running the code below probably shows you the newly re-sourced data source: mxd = arcpy.mapping.MapDocument("CURRENT")
lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == r'Work Layers\Replacement Tree':
print lyr.dataSource In the second example, since you are retrieving the layers from the "CURRENT" MXD, it is showing you what is reflected in ArcMap currently. With the first example, it appears to be going back to the MXD as originally loaded. I haven't tried it, but you could try seeing if re-sourcing the data paths using ArcPy instead of the GUI makes Exists work the way you expect. Is your script looping through the layers using arcpy.mapping.ListLayers?
... View more
02-26-2015
09:40 AM
|
0
|
3
|
2651
|
|
POST
|
In situations like this, or really always, it is helpful to state what version (build number too) and patches you are running.
... View more
02-26-2015
08:46 AM
|
1
|
1
|
2651
|
|
POST
|
The following functional code snippet will loop through all the service requests and then loop through all of the electronic waste items for each service request. Is this sort of what you are after: for sr in decoded['Response']['ListOfServiceRequest']['ServiceRequest']:
SRAddress = sr['SRAddress']
latitude = sr['Latitude']
longitude = sr['Longitude']
for ew in sr["ListOfLa311ElectronicWaste"][u"La311ElectronicWaste"]:
CommodityType = ew['Type']
ItemType = ew['ElectronicWestType']
ItemCount = ew['ItemCount']
... View more
02-25-2015
10:50 AM
|
1
|
12
|
6187
|
|
POST
|
Given that ArcSDE documentation doesn't address SQL Server's compatibility level, I would argue there is an implicit requirement that ArcSDE be installed in SQL Server databases with the default setting.
... View more
02-23-2015
08:38 AM
|
0
|
0
|
2753
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | Monday | |
| 1 | 2 weeks ago | |
| 1 | 3 weeks ago | |
| 1 | 12-19-2025 06:05 AM | |
| 1 | 12-02-2025 07:31 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|