I have a script where I am attempting to parse a JSON and send to an Esri file geodatabase using NumPy. I am receving an error for my latitude and longitude fields which should be floats stating that the data type is not understood.
import jsonpickle
import arcpy
import json
import numpy
import requests
X = 471316.3835861763
Y= 5000448.782036674
fc = "C:\MYLATesting.gdb\MYLA311"
if arcpy.Exists(fc):
arcpy.Delete_management(fc)
f = open('C:\Users\Administrator\Desktop\myla311.json', 'r')
data = jsonpickle.encode( jsonpickle.decode(f.read()) )
url = "myUrl.com"
headers = {'Content-type': 'text/plain', 'Accept': '/'}
r = requests.post(url, data=data, headers=headers)
sr = arcpy.SpatialReference(4326)
decoded = json.loads(r.text)
# print json.dumps(decoded, sort_keys=True, indent=4)
#
# vehicles = []
# for Response, ServiceRequest in decoded.iteritems():
# vehicles.append(tuple(item[k] for k in ndtype.names))
# print response, ServiceRequest
ndtype = numpy.dtype([
('status', 'S12'),
(X, numpy.float64),
(Y, numpy.float64)
])
vehicles = []
for item in decoded['status']:
vehicles.append(tuple(decoded(X(Y[k] for k in ndtype.names))))
narr = numpy.array([vehicles], ndtype)
arcpy.da.NumPyArrayToFeatureClass(narr, fc,[X, Y] , sr)
Decoded JSON:
{
"Response": {
"ListOfServiceRequest": {
"ServiceRequest": [
{
"ActionTaken": "",
"AddressVerified": "Y",
"Anonymous": "N",
"AssignTo": "North Central - 104 - IED",
"Assignee": "Siebel Administrator",
"CreatedByUserLogin": "PRASAD89",
"CreatedDate": "12/31/2014 13:49:23",
"CustomerAccessNumber": "",
"Email": "[email protected]",
"FirstName": "Prasad",
"HomePhone": "3123123123",
"IntegrationId": "1420033765921",
"LADWPAccountNo": "",
"Language": "English",
"LastName": "Pp",
"Latitude": "34.064937",
"ListOfAuditTrailItem2": {},
"ListOfChildServiceRequest": {},
"ListOfLa311BarricadeRemoval": {},
"ListOfLa311BeesOrBeehive": {},
"ListOfLa311BillingCsscAdjustment": {},
"ListOfLa311BillingEccAdjustment": {},
"ListOfLa311BillingRsscAdjustment": {},
"ListOfLa311BillingRsscExemption": {},
"ListOfLa311BrushItemsPickup": {},
"ListOfLa311BulkyItem": {},
"ListOfLa311BusPadLanding": {},
"ListOfLa311Containers": {},
"ListOfLa311CurbRepair": {},
"ListOfLa311DeadAnimalRemoval": {},
"ListOfLa311DocumentLog": {},
"ListOfLa311ElectronicWaste": {},
"ListOfLa311Flooding": {},
"ListOfLa311GeneralStreetInspection": {},
"ListOfLa311GenericBc": {
"La311GenericBc": [
{
"ATTRIB_08": "",
"ListOfLa311GenericbcAuditTrail": {},
"NAME": "41572025-3803-49c4-8561-6e7ef41775df",
"PAR_ROW_ID": "1-N607",
"ROW_ID": "1-N60A",
"TYPE": "GIS"
},
{
"ATTRIB_08": "",
"ListOfLa311GenericbcAuditTrail": {},
"NAME": "a5b5b2b9-d2e7-400a-bf75-1138ff013caa",
"PAR_ROW_ID": "1-N607",
"ROW_ID": "1-N609",
"TYPE": "Homeless Encampment"
},
{
"ATTRIB_08": "",
"ListOfLa311GenericbcAuditTrail": {},
"NAME": "010420150405",
"PAR_ROW_ID": "1-N607",
"ROW_ID": "1-RN2D",
"TYPE": "Subscription"
}
]
},
"ListOfLa311GisLayer": {
"La311GisLayer": [
{
"A_Call_No": "",
"Area": "",
"BOSRadioHolderName": "",
"CommunityPlanningArea": "Westlake",
"Day": "",
"DirectionSuffix": "",
"DistrictAbbr": "",
"DistrictName": "Central",
"DistrictNumber": "104",
"DistrictOffice": "North Central",
"Fraction": "",
"LastUpdatedBy": "",
"Name": "41572025-3803-49c4-8561-6e7ef41775df",
"R_Call_No": "",
"SectionId": "5279800",
"ShortDay": "",
"StreetFrom": "BOYLSTON ST",
"StreetLightId": "",
"StreetLightStatus": "",
"StreetTo": "FIRMIN ST",
"Type": "GIS",
"Y_Call_No": ""
}
]
},
"ListOfLa311GraffitiRemoval": {},
"ListOfLa311GuardWarningRailMaintenance": {},
"ListOfLa311GutterRepair": {},
"ListOfLa311HomelessEncampment": {
"La311HomelessEncampment": [
{
"ApprovedBy": "",
"AssignedTo": "",
"CompletedBy": "",
"Contact": "",
"ContactDate": "",
"Crew": "",
"DateCompleted": "12/31/2014 00:00:00",
"InspectedBy": "",
"InspectionDate": "",
"LastUpdatedBy": "",
"Location": "Alley",
"Name": "a5b5b2b9-d2e7-400a-bf75-1138ff013caa",
"OptionalTrackingCode": "",
"Type": "Homeless Encampment"
}
]
},
"ListOfLa311IllegalAutoRepair": {},
"ListOfLa311IllegalConstruction": {},
"ListOfLa311IllegalConstructionFence": {},
"ListOfLa311IllegalDischargeOfWater": {},
"ListOfLa311IllegalDumpingInProgress": {},
"ListOfLa311IllegalDumpingPickup": {},
"ListOfLa311IllegalExcavation": {},
"ListOfLa311IllegalSignRemoval": {},
"ListOfLa311IllegalVending": {},
"ListOfLa311InformationOnly": {},
"ListOfLa311LandMudSlide": {},
"ListOfLa311LeafBlowerViolation": {},
"ListOfLa311ManualPickup": {},
"ListOfLa311MedianIslandMaintenance": {},
"ListOfLa311MetalHouseholdAppliancesPickup": {},
"ListOfLa311MoveInMoveOut": {},
"ListOfLa311MultipleStreetlightIssue": {},
"ListOfLa311NewsRackViolation": {},
"ListOfLa311Obstructions": {},
"ListOfLa311Other": {},
"ListOfLa311OvergrownVegetationPlants": {},
"ListOfLa311PalmFrondsDown": {},
"ListOfLa311Pothole": {},
"ListOfLa311Resurfacing": {},
"ListOfLa311SanitationBillingBif": {},
"ListOfLa311SanitationBillingCssc": {},
"ListOfLa311SanitationBillingEcc": {},
"ListOfLa311SanitationBillingInquiry": {},
"ListOfLa311SanitationBillingLifeline": {},
"ListOfLa311SanitationBillingRssc": {},
"ListOfLa311SanitationBillingSrf": {},
"ListOfLa311ServiceNotComplete": {},
"ListOfLa311ServiceRequestNotes": {
"La311ServiceRequestNotes": [
{
"Comment": "",
"CommentType": "External",
"CreatedByUser": "PRASAD89",
"CreatedDate": "12/31/2014 13:49:23",
"Date1": "",
"Date2": "",
"Date3": "",
"FeedbackSRType": "",
"IntegrationId": "1420033765921",
"IsSrNoAvailable": "N",
"ListOfLa311SrNotesAuditTrail": {},
"Notification": "N",
"Text1": ""
}
]
},
"ListOfLa311SidewalkRepair": {},
"ListOfLa311SingleStreetlightIssue": {},
"ListOfLa311SrPhotoId": {
"La311SrPhotoId": []
},
"ListOfLa311StreetSweeping": {},
"ListOfLa311StreetTreeInspection": {},
"ListOfLa311StreetTreeViolations": {},
"ListOfLa311SubscribeDuplicateSr": {
"La311SubscribeDuplicateSr": [
{
"Activeflag": "Y",
"EmailId": "[email protected]",
"LastUpdatedBy": "",
"Name": "010420150405",
"Type": "Subscription"
}
]
},
"ListOfLa311TablesAndChairsObstructing": {},
"ListOfLa311TreeEmergency": {},
"ListOfLa311TreeObstruction": {},
"ListOfLa311TreePermits": {},
"ListOfLa311WeedAbatementForPrivateParcels": {},
"LoginUser": "",
"Longitude": "-118.252968",
"MobilOS": "iOS",
"NewContactEmail": "",
"NewContactFirstName": "",
"NewContactLastName": "",
"NewContactPhone": "",
"Owner": "BSS",
"ParentSRLinkDate": "",
"ParentSRLinkUser": "",
"ParentSRNumber": "",
"ParentSRStatus": "",
"ParentSRType": "",
"Priority": "Normal",
"ReasonCode": "",
"RescheduleCounter": "",
"ResolutionCode": "",
"SRAddress": "1200 W TEMPLE ST, 90026",
"SRAddressName": "",
"SRAreaPlanningCommission": "Central APC",
"SRAreaPlanningCommissionId": "4",
"SRCity": "",
"SRCommunityPoliceStation": "",
"SRCommunityPoliceStationAPREC": "RAMPART",
"SRCommunityPoliceStationPREC": "2",
"SRCouncilDistrictMember": "Gilbert Cedillo",
"SRCouncilDistrictNo": "1",
"SRCrossStreet": "",
"SRDirection": "W",
"SRHouseNumber": "",
"SRNeighborhoodCouncilId": "44",
"SRNeighborhoodCouncilName": "GREATER ECHO PARK ELYSIAN NC",
"SRNumber": "1-1080871",
"SRStreetName": "TEMPLE",
"SRSuffix": "ST",
"SRTBColumn": "E",
"SRTBMapGridPage": "634",
"SRTBRow": "2",
"SRType": "Homeless Encampment",
"SRUnitNumber": "",
"SRXCoordinate": "6485064",
"SRYCoordinate": "1846114",
"ServiceDate": "12/31/2014 00:00:00",
"Source": "311",
"Status": "Open",
"UpdatedByUserLogin": "PRASAD89",
"UpdatedDate": "12/31/2014 13:49:23",
"Zipcode": "90026"
}
]
},
"NumOutputObjects": "1"
},
"status": {
"cause": "",
"code": 311,
"message": "Service Request Successfully Queried."
}
}
1 Answer 1
Do you mean to name your fields 'X' and 'Y':
ndtype = numpy.dtype([
('status', 'S12'),
('X', numpy.float64),
('Y', numpy.float64)
])
At the moment you are refering to actual float objects X and Y here, which isn't the right syntax for declaring a dtype. The above statement declares it using a list of tuples where each tuple is a string name followed by a data type (or string that can be resolved into a data type).
6 Comments
decoded JSON here - it's this it seems you need to parse into values in your array with dtype ndtype we've just defined.'status', 'X', and 'Y' in your NumPy structured array?