python - Retrieve SQLite result as ndarray -


i retrieving set of latitude , longitudinal points sqlite database this:

cur = con.execute("select distinct latitude, longitude messagetype1 latitude>{bottomlat} , latitude<={toplat} , longitude>{bottomlong} , longitude<={toplong}".format(bottomlat = bottomlat, toplat = toplat,  bottomlong = bottomlong, toplong = toplong)) 

however, supposed make convexhull (http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.convexhull.html#scipy.spatial.convexhull) has ndarray input, need save results cur ndarray. how that?

right fetch values :

    positions = [[floats(x[0]) floats(x[1])]  x in cur] 

is correct?

you don't need convert positions ndarray. scipy.spatial.convexhull can accept list of lists well:

import scipy.spatial spatial hull = spatial.convexhull(positions) 

also, if messagetype1 table has latitude, longitude fields of type float, should not need call float explicitly. instead of

positions = [[floats(x[0]) floats(x[1])]  x in cur] 

you use

positions = cur.fetchall() 

note if using numpy slicing syntax, such positions[:, 0], need convert list of lists/tuples numpy array:

positions = np.array(cur.fetchall()) 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -