def MockCallBacks(self): df = pd.read_csv('data/CrossValidationData.csv') df.columns = ['x', 'y', 'z', 'id', 'is_building', 'label'] deleteIndex = df[df['is_building'] == 0]['id'] labels = df[df['is_building'] == 1][['id', 'label']] # The prune model sd = Methods() df = sd.splitCallBack(labels, 'lidar_sf__1') sd.hullCallBack(df, 'lidar_sf__1') sd.deleteCallBack(df, 'lidar_sf__1') sd.deleteCallBack(deleteIndex, 'lidar_sf__1')
def MockCallBacks(self): df = pd.read_csv('data/CrossValidationData.csv'); df.columns = ['x','y','z','id', 'is_building', 'label'] deleteIndex = df[df['is_building']==0]['id']; labels = df[df['is_building']==1][['id','label']]; # The prune model sd = Methods() df = sd.splitCallBack(labels, 'lidar_sf__1') sd.hullCallBack(df, 'lidar_sf__1'); sd.deleteCallBack(df, 'lidar_sf__1'); sd.deleteCallBack(deleteIndex, 'lidar_sf__1')
def __init__(self, database='building', User='******', host='localhost', projection=4326, transform_to=None): # If the dataset is not in metric units, transform projection self.transform_to = transform_to # file uploads self.upload = pgDataLoader(database=database, User=User, host=host, projection=projection) # methods to cal to server self.methods = Methods(database=database, User=User, host=host, projection=projection) # Reset storage tables self.methods.tableSetUp(transform_to=transform_to)
lambda x: len(x) <= second_layer_screen or len(x) >= 10000) not_blds.reset_index(inplace=True) # Recluster buildings in only x-y to negate the effects of funny-shaped rooves. db = DBSCAN(eps=eps, min_samples=min_samples).fit(blds[['x', 'y']].as_matrix()) blds = pd.DataFrame([blds.id, db.labels_]).T blds.columns = ['id', 'label'] blds['id'] = blds['id'].astype(int) # Is as building: id, label # Not a building: id return blds, not_blds['id'] if __name__ == '__main__': import os from pgMethods import Methods m = Methods(projection=32610) df = m.pg_df('SELECT x, y, z, id FROM lidar_nyc_small') print 'df loaded' #df = pd.read_csv('../tests/data/CrossValidationData.csv') blds, not_blds = dbscan(df) m.df_pg(blds, 'temp12345678') m.pg_post( 'DROP TABLE IF EXISTS checkcheck; CREATE TABLE checkcheck AS SELECT a.* FROM z_20130805_usgsnyc14_18TWL835075 a RIGHT JOIN temp12345678 b ON a.id=b.id;' ) m.pg_post('DROP TABLE temp12345678;')
# Recluster buildings in only x-y to negate the effects of funny-shaped rooves. db = DBSCAN(eps=eps, min_samples=min_samples).fit(blds[['x', 'y']].as_matrix()) blds = pd.DataFrame([blds.id, db.labels_]).T blds.columns = ['id', 'label']; blds['id'] = blds['id'].astype(int) # Is as building: id, label # Not a building: id return blds, not_blds['id'] if __name__ == '__main__': import os from pgMethods import Methods m = Methods(projection=32610); df = m.pg_df('SELECT x, y, z, id FROM lidar_nyc_small') print 'df loaded' #df = pd.read_csv('../tests/data/CrossValidationData.csv') blds, not_blds = dbscan(df) m.df_pg(blds, 'temp12345678'); m.pg_post('DROP TABLE IF EXISTS checkcheck; CREATE TABLE checkcheck AS SELECT a.* FROM z_20130805_usgsnyc14_18TWL835075 a RIGHT JOIN temp12345678 b ON a.id=b.id;') m.pg_post('DROP TABLE temp12345678;')
def MockPartition(self, split=6): sd = Methods(projection=32610) sd.partionSpace('lidar_sf', split=split)
class Building: def __init__(self, database='building', User='******', host='localhost', projection=4326, transform_to=None): # If the dataset is not in metric units, transform projection self.transform_to = transform_to # file uploads self.upload = pgDataLoader(database=database, User=User, host=host, projection=projection) # methods to cal to server self.methods = Methods(database=database, User=User, host=host, projection=projection) # Reset storage tables self.methods.tableSetUp(transform_to=transform_to) def screen(self, file_path, hull=True, load_lidar=False, split=10): # Create table name from file path lidar_name = "z_" + basename(file_path).split('.')[0] if load_lidar: # Load the data to server self.upload.lidar_to_server(file_path, lidar_name, transform_to=self.transform_to) # Split the bounding box into equal children self.methods.partionSpace(lidar_name, split=split, transform_to=self.transform_to) # Get a dataframe of bounding box id's bbox_ids = self.methods.pg_df('SELECT id FROM %s_bbox' % lidar_name) for index, row in bbox_ids.T.iteritems(): # Get the id of the child bounding box child_id = row.id print child_id # Get the points intersecting this bounding box pts = self.methods.partionPoints(child_id) # Get the points of buildings and not buildings blds, not_blds = dbscan(pts, zboost=1.4) pts = None # Save some memory if hull: # Split points into interior points and boundary points. # Save the boundary points to an overflow table. inside_points = self.methods.splitCallBack(blds, child_id) blds = None # Save some memory # Calculate the outline of the interior buildings and save geometries. self.methods.hullCallBack(inside_points, child_id) inside_points = None else: self.methods.loadpointsCallBack(blds, child_id) blds = None