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
Post a Comment