gpt4 book ai didi

python - NumPy 数据类型不理解

转载 作者:太空宇宙 更新时间:2023-11-03 17:55:38 25 4
gpt4 key购买 nike

我有一个脚本,我正在尝试解析 JSON 并使用 NumPy 发送到 Esri 文件地理数据库。我收到了纬度和经度字段的错误,该错误应该是 float ,表明数据类型不被理解。

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)

解码后的 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": "prasadpotale@gmail.com",
"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": "pratik.desai@yoopmail.com",
"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."
}
}

最佳答案

您的意思是为您的字段命名 'X''Y' :

ndtype = numpy.dtype([
('status', 'S12'),
('X', numpy.float64),
('Y', numpy.float64)
])

目前您指的是实际的 float对象 XY在这里,这不是声明 dtype 的正确语法。 。上面的语句使用list来声明它。的tuple s 其中每个 tuple是一个字符串名称,后跟一个数据类型(或可以解析为数据类型的字符串)。

关于python - NumPy 数据类型不理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28490839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com