|
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
|
1628
|
|
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
|
1628
|
|
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
|
7679
|
|
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
|
7679
|
|
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
|
3651
|
|
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
|
3651
|
|
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
|
3651
|
|
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
|
7679
|
|
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
|
3675
|
|
POST
|
The second code sample in the ArcGIS Help 10.2 - ListFeatureClasses (arcpy) gets you most of the way there. The code below is adapted from the second code example: import arcpy
import os
gdb = #
arcpy.env.workspace = gdb
datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []
fcList = []
for ds in datasets:
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
fcList.append(os.path.join(gdb, ds, fc))
# fcList.append(os.path.join(ds, fc)) # if you don't want gdb path included
fcList.sort() The Esri sample code, beyond providing the functional framework, incorporated two notable tips/ideas/practices. The first is that including an empty string '' in the datasets list will allow the datasets loop to include the feature classes that aren't in a data set, i.e., the feature classes that are in the root/base of the geodatabase. The second is that os.path.join is used to create the full path of the feature classes being listed. If you are going to do any further processing of the list of feature classes, having the full path to them in the list makes the next steps easier. Even if you are just listing feature classes to know what is present, including the data set along with the feature class will provide for more context.
... View more
02-23-2015
08:21 AM
|
2
|
0
|
7019
|
|
POST
|
Huh, not sure then. For me, Background geoprocessing generates that exact error and disabling it makes it go away using the code above. Maybe close out of ArcGIS Desktop and clean out all of the PYC and PYO files in the comtypes site package folder as well as clear out the gen folder under comtypes.
... View more
02-20-2015
03:20 PM
|
1
|
1
|
5633
|
|
POST
|
Now I remember why this sounded so familiar, I ran into the same issue about six months back. Turn off "Background Processing." I am guessing you have it enabled, which means some of the code is being run out of process, so there is no AppRef.
... View more
02-20-2015
02:01 PM
|
0
|
3
|
5633
|
|
POST
|
Posting the exact snippet and error code are helpful. There are lots of snippets. How are you running the code, the interactive Python windows in ArcGIS Desktop or as a standalone script?
... View more
02-20-2015
01:13 PM
|
0
|
5
|
5633
|
|
POST
|
I would look into creating a map package: "A map package contains a map document (.mxd) and the data referenced by the layers it contains, packaged into one convenient, portable file." The creation of map packages can be fine tuned and scripted using the Package Map (Data Management) tool.
... View more
02-20-2015
07:55 AM
|
1
|
1
|
2558
|
|
POST
|
It would be helpful if you could elaborate a bit more on the final data structure you are looking at creating. The sample JSON object is large and sparse, which would create a large and sparse table if you want to load it all into a single table. I am unclear whether you are interested in all items in the list or certain subsets. You seem to be working with electronic waste, is that the subset you want to extract? When you say you want to "iterate through most of the fields shown in the JSON response(not all)," what is your criteria for not iterating over something?
... View more
02-20-2015
07:45 AM
|
1
|
14
|
7679
|
| Title | Kudos | Posted |
|---|---|---|
| 2 | 4 weeks ago | |
| 1 | 05-29-2026 08:22 AM | |
| 1 | a month ago | |
| 3 | a month ago | |
| 1 | 05-22-2026 05:27 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|