diff --git a/fmtm_splitter/fmtm-splitter_osm_buildings/fmtm-splitter_osm_buildings.sql b/fmtm_splitter/fmtm-splitter_osm_buildings/fmtm-splitter_osm_buildings.sql index 08ff9b3..cee9def 100644 --- a/fmtm_splitter/fmtm-splitter_osm_buildings/fmtm-splitter_osm_buildings.sql +++ b/fmtm_splitter/fmtm-splitter_osm_buildings/fmtm-splitter_osm_buildings.sql @@ -217,8 +217,8 @@ CREATE TABLE clusteredbuildings AS ( clusteredbuildingsnocombineduid AS ( SELECT *, - ST_CLUSTERKMEANS(geom, ((b.numfeatures / 5) + 1)::integer) - OVER (PARTITION BY polyid) + ST_CLUSTERKMEANS(b.geom, ((b.numfeatures / 5) + 1)::integer) + OVER (PARTITION BY b.polyid) AS cid FROM buildingstocluster AS b ), diff --git a/fmtm_splitter/fmtm_algorithm.sql b/fmtm_splitter/fmtm_algorithm.sql index 8b6d116..e336c12 100644 --- a/fmtm_splitter/fmtm_algorithm.sql +++ b/fmtm_splitter/fmtm_algorithm.sql @@ -170,7 +170,7 @@ CREATE TABLE lowfeaturecountpolygons AS ( SELECT * FROM splitpolygons AS p -- TODO: feature count should not be hard-coded - WHERE p.numfeatures < %(num_buildings)s + WHERE p.numfeatures < p.%(num_buildings)s ), -- Find the neighbors of the low-feature-count polygons @@ -244,9 +244,10 @@ CREATE TABLE clusteredbuildings AS ( SELECT *, ST_CLUSTERKMEANS( - geom, CAST((b.numfeatures / %(num_buildings)s) + 1 AS integer) + b.geom, + CAST((b.numfeatures / b.%(num_buildings)s) + 1 AS integer) ) - OVER (PARTITION BY polyid) + OVER (PARTITION BY b.polyid) AS cid FROM buildingstocluster AS b ), diff --git a/fmtm_splitter/splitter.py b/fmtm_splitter/splitter.py index 1906fb0..9c28e16 100755 --- a/fmtm_splitter/splitter.py +++ b/fmtm_splitter/splitter.py @@ -29,6 +29,7 @@ import geojson import numpy as np from geojson import Feature, FeatureCollection, GeoJSON +from osm_rawdata.postgres import PostgresClient from psycopg2.extensions import connection from shapely.geometry import Polygon, shape from shapely.geometry.geo import mapping @@ -42,7 +43,6 @@ drop_tables, insert_geom, ) -from osm_rawdata.postgres import PostgresClient # Instantiate logger log = logging.getLogger(__name__)