Skip to content

Database Setup

Gabriel edited this page Mar 21, 2019 · 9 revisions

How to install, setup and populate the spatial database

  1. Install the latest version of postgresql with the postgis extension for your system then install pgpointcloud
apt install postgresql-10-postgis-2.4 postgis postgresql-server-dev-10
  1. Create an user for the database and a db assosciated to id:

First log in as the postgres root user

sudo su - postgres

Then create a new role and grant it the superuser privileges (needed to create extensions):

createuser --pwprompt -s dboperator

Then create the db:

createdb -O dboperator terrain_ans
  1. Install pgpointcloud by following the project wiki: https://github.com/pgpointcloud/pointcloud
  2. Create the lidar tables and the extensions in the postgis db:
CREATE EXTENSION postgis;
CREATE EXTENSION pointcloud;
CREATE EXTENSION pointcloud_postgis;
CREATE TABLE lidar_toscana (
    id SERIAL PRIMARY KEY,
    pa PCPATCH(1)
);
CREATE INDEX lidar_toscana_index ON lidar_toscana USING GIST(PC_EnvelopeGeometry(pa));
CREATE TABLE lidar_lyon (
    id SERIAL PRIMARY KEY,
    pa PCPATCH(1)
);
  1. Install pdal and it's dependencies (laszip support mandatory for certain dataset)
apt install pdal
  1. Download the lidar files for your zone and add them using the following script
#!/bin/bash

for file in `ls  ~/data/Toscana/lidar/asc/*.asc`; do
	pdal pipeline toscana.json --readers.gdal.filename=$file && mv $file $file.loaded
	echo $file loaded
done 

The file toscana.json contains the example pipeline for the Tuscanian lidar data. It must be changed for different sources

{
  "pipeline":[
    {
      "type" : "readers.gdal"
    },
    {
     "type":"filters.reprojection",
     "in_srs":"EPSG:3003",
     "out_srs":"EPSG:4326"
    },
    {
     "type" : "filters.ferry",
     "dimensions": "band-1=Z"
    },
    {
     "type":"filters.chipper",
     "capacity":"600"
    },
    {
     "type": "writers.pgpointcloud",
     "connection":"host='hostname' dbname='db_name' user='user' password='password'",
     "table" : "lidar_toscana",
     "column": "pa",
     "srid": "4326",
     "compression":"dimensional",
     "output_dims": "X,Y,Z"
    }
  ]
}
  1. Download the osm building files from an osm mirror
  2. Insert the osm building using the shp2pgsql command (similar flow can be used for other vectorial data)
shp2pgsql -s 4326 -I ~/osm/lyon/gis.osm_buildings_a_free_1.shp  lyon_buildings | sudo -u postgres psql
shp2pgsql -s 4326 -I ~/osm/centro_italy/gis.osm_buildings_a_free_1.shp  centro_buildings | sudo -u postgres psql

Clone this wiki locally