Geoffrey.West

Handling blank values not converting string to float with NumPy

Discussion created by Geoffrey.West on May 12, 2015
Latest reply on May 13, 2015 by Dan_Patterson

A web-service is returning blank values in lat/long causing ValueError: could not convert string to float:

Output:

34.0746400246
-118.37200592


34.0968797927
-118.449631186
34.0635760772
-118.327509298
34.0635760772
-118.327509298
34.0746400246
-118.37200592
34.0828880733
-118.320862797
34.0828880733

 

Code:

import requests
import json
import jsonpickle

f2 =open('C:\Users\GeoffreyWest\Desktop\Request.json')
data2 = jsonpickle.decode((f2.read()))
data2 = jsonpickle.encode(data2)
fc= (aFC)



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

r2 = requests.post(url2, data=data2, headers=headers2)
decoded2 = json.loads(r2.text)
print json.dumps(decoded2, sort_keys=True, indent=4)
if arcpy.Exists(fc):
  arcpy.Delete_management(fc)
try:
  r2
except requests.exceptions.ConnectTimeout as e:
   print "Too slow Mojo!"

items = []
for sr in decoded2['Response']['ListOfServiceRequest']['ServiceRequest']:
   SRAddress = sr['SRAddress']
  lat =  "3"
  y = sr['Latitude']
  x = sr['Longitude']
  str_list = filter(None, y)
  str_list2 = filter(None, x)
   print str_list
   print str_list2



  dt = np.dtype([('LatitudeShape', '<f8'),
   ('LongitudeShape', '<f8'),
   ('Latitude', '<f8'),
   ('Longitude', '<f8'),
])

  items.append((str_list2,
  str_list,
  str_list2,
  str_list,
   ))

  sr = arcpy.SpatialReference(4326)

arr = np.array(items,dtype=dt)

NumPyArray = arcpy.da.NumPyArrayToFeatureClass(arr, fc, ['longitudeshape', 'latitudeshape'], sr)
print "success"

Outcomes