add condition on null-valued geometries, ref: #143

This commit is contained in:
Andy Eschbacher
2017-01-10 14:37:31 -05:00
parent 10ce109d09
commit c114ccea33

View File

@@ -25,13 +25,6 @@ def get_weight(query_res, w_type='knn', num_ngbrs=5):
Construct PySAL weight from return value of query
@param query_res dict-like: query results with attributes and neighbors
"""
# if w_type.lower() == 'knn':
# row_normed_weights = [1.0 / float(num_ngbrs)] * num_ngbrs
# weights = {x['id']: row_normed_weights for x in query_res}
# else:
# weights = {x['id']: [1.0 / len(x['neighbors'])] * len(x['neighbors'])
# if len(x['neighbors']) > 0
# else [] for x in query_res}
neighbors = {x['id']: x['neighbors'] for x in query_res}
print 'len of neighbors: %d' % len(neighbors)
@@ -146,14 +139,15 @@ def knn(params):
"FROM ({subquery}) As j " \
"WHERE " \
"i.\"{id_col}\" <> j.\"{id_col}\" AND " \
"%(attr_where_j)s " \
"%(attr_where_j)s AND " \
"j.\"{geom_col}\" IS NOT NULL " \
"ORDER BY " \
"j.\"{geom_col}\" <-> i.\"{geom_col}\" ASC " \
"LIMIT {num_ngbrs})" \
") As neighbors " \
"FROM ({subquery}) As i " \
"WHERE " \
"%(attr_where_i)s " \
"%(attr_where_i)s AND i.\"{geom_col}\" IS NOT NULL " \
"ORDER BY i.\"{id_col}\" ASC;" % replacements
return query.format(**params)