How to dissolve features and retain fields/values

5704
11
Jump to solution
03-02-2015 08:54 AM
GeoffreyWest
Occasional Contributor III

I have a feature class with 3 point features, I would like to dissolve these so that my 3 features maintain all fields and values in one feature.

 

I would like one feature that has SRAddress, SRNumber, Type, E-WasteType1, Count1, E-WasteType2, Count2, E-WasteType3, Count3

 

 

 

 

 

 

Capture.PNG

Tags (1)
0 Kudos
11 Replies
GeoffreyWest
Occasional Contributor III

There's a much more elegant and scalable approach to this.

import json
import jsonpickle
import requests
import arcpy
import numpy as np  #NOTE THIS

fc = "C:\MYLATesting.gdb\MYLA311"
if arcpy.Exists(fc):
  arcpy.Delete_management(fc)



ListTable ="C:\MYLATesting.gdb\MYLA311Dissolve"
if arcpy.Exists(ListTable):
  arcpy.Delete_management(ListTable)



f2 = open('C:\Users\Administrator\Desktop\DetailView.json', 'r')
data2 = jsonpickle.encode( jsonpickle.decode(f2.read()) )

url2 = "myURL"
headers2 = {'Content-type': 'text/plain', 'Accept': '/'}

r2 = requests.post(url2, data=data2, headers=headers2)
decoded2 = json.loads(r2.text)


dt = np.dtype([('SRAddress', 'U40'),
   ('latitude', '<f8'),
   ('longitude', '<f8'),
   ('Type', 'U40'),
   ('SRNumber', 'U40'),
   ('FirstName', 'U40'),
   ('LastName', 'U40'),
   ('HomePhone', 'U40'),
   ('Comment', 'U128'),
   ('ItemInfo', 'U128'),
])


items = []
for sr in decoded2['Response']['ListOfServiceRequest']['ServiceRequest']:
  SRAddress = sr['SRAddress']
  latitude = sr['Latitude']
  longitude = sr['Longitude']
  SRNumber = sr['SRNumber']
  FirstName = sr['FirstName']
  LastName = sr['LastName']
  HomePhone = sr['HomePhone']

  ItemInfo = " "

   for ew in sr["ListOfLa311ElectronicWaste"][u"La311ElectronicWaste"]:
  CommodityType = ew['Type']
  ItemType = ew['ElectronicWestType']
  ItemCount = ew['ItemCount']
  ItemInfo += '{0},{1}'.format(ItemType, ItemCount)


  comments = [ cl['Comment'] for cl in sr["ListOfLa311ServiceRequestNotes"][u"La311ServiceRequestNotes"]]
   print comments
  Comment = ' '.join(comments)


items.append((SRAddress,
   latitude,
   longitude,
   CommodityType,
   SRNumber,
   FirstName,
   LastName,
   HomePhone,
   Comment,
   ItemInfo))



arr = np.array(items,dtype=dt)
sr = arcpy.SpatialReference(4326)
arcpy.da.NumPyArrayToFeatureClass(arr, fc, ['longitude', 'latitude'], sr )



print json.dumps(decoded2, sort_keys=True, indent=4)

0 Kudos
RichardFairhurst
MVP Honored Contributor

Please add code comments to explain why you did each step and what each step is accomplishing to reach the desired output.  There is nothing about this code that is transparent or obvious to anyone that has never used this set of interfaces.  I don't know this set of interfaces and I cannot understand why you did what you did or even what the results are.  Nothing can be called elegant or scalable if I have to go read the Python help docs to get anything out of the code you posted.

0 Kudos