Merge branch 'adds-nonspatial-kmeans' of https://github.com/CartoDB/crankshaft into adds-nonspatial-kmeans
This commit is contained in:
commit
3c6d73b7e2
@ -8,13 +8,11 @@ def kmeans(query, no_clusters, no_init=20):
|
|||||||
find centers based on clusteres of latitude/longitude pairs
|
find centers based on clusteres of latitude/longitude pairs
|
||||||
query: SQL query that has a WGS84 geometry (the_geom)
|
query: SQL query that has a WGS84 geometry (the_geom)
|
||||||
"""
|
"""
|
||||||
full_query = '''
|
full_query = ("SELECT array_agg(cartodb_id ORDER BY cartodb_id) as ids,"
|
||||||
SELECT array_agg(cartodb_id ORDER BY cartodb_id) as ids,
|
"array_agg(ST_X(the_geom) ORDER BY cartodb_id) xs,"
|
||||||
array_agg(ST_X(the_geom) ORDER BY cartodb_id) xs,
|
"array_agg(ST_Y(the_geom) ORDER BY cartodb_id) ys "
|
||||||
array_agg(ST_Y(the_geom) ORDER BY cartodb_id) ys
|
"FROM ({query}) As a "
|
||||||
FROM ({query}) As a
|
"WHERE the_geom IS NOT NULL").format(query=query)
|
||||||
WHERE the_geom IS NOT NULL
|
|
||||||
'''.format(query=query)
|
|
||||||
try:
|
try:
|
||||||
data = plpy.execute(full_query)
|
data = plpy.execute(full_query)
|
||||||
except plpy.SPIError, err:
|
except plpy.SPIError, err:
|
||||||
|
Loading…
Reference in New Issue
Block a user