From c114ccea339efa21fb608cc60c8e55b62bc87047 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Tue, 10 Jan 2017 14:37:31 -0500 Subject: [PATCH] add condition on null-valued geometries, ref: #143 --- .../crankshaft/crankshaft/pysal_utils/pysal_utils.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/py/crankshaft/crankshaft/pysal_utils/pysal_utils.py b/src/py/crankshaft/crankshaft/pysal_utils/pysal_utils.py index 0be95c7..35cfec1 100644 --- a/src/py/crankshaft/crankshaft/pysal_utils/pysal_utils.py +++ b/src/py/crankshaft/crankshaft/pysal_utils/pysal_utils.py @@ -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)