martin/demo/db/initdb/02.sh

23 lines
951 B
Bash
Raw Normal View History

2018-10-15 19:39:45 +03:00
#!/bin/bash
2022-09-17 16:40:30 +03:00
wget -O ${HOME}/taxi_zones.zip https://gitlab.com/maplibre1/nyc-data-2017-part-1/-/raw/main/taxi_zones/taxi_zones.zip
2018-10-15 19:39:45 +03:00
unzip ${HOME}/taxi_zones.zip -d ${HOME}
2018-10-24 14:00:45 +03:00
2018-10-19 16:51:31 +03:00
geomColumn=geom
ogr2ogr -f PostgreSQL PG:dbname=db -nln taxi_zones -nlt MULTIPOLYGON -lco GEOMETRY_NAME=${geomColumn} ${HOME}/taxi_zones.shp
2018-10-17 13:30:25 +03:00
psql -U postgres -d db -c "alter table taxi_zones alter column ${geomColumn} type geometry(multipolygon, 3857) using st_transform(${geomColumn}, 3857); \
create index idx_taxi_zones_geom on taxi_zones using gist(${geomColumn});"
2018-10-15 19:39:45 +03:00
2022-09-17 17:03:06 +03:00
for i in 01 # 02 03 04 05 06
2018-10-15 19:39:45 +03:00
do
fileName=yellow_tripdata_2017-${i}.csv
filePath=${HOME}/${fileName}
2022-09-17 16:40:30 +03:00
wget -O ${filePath} "https://gitlab.com/maplibre1/nyc-data-2017-part-1/-/raw/main/taxo/${fileName}"
dos2unix ${filePath}
echo "format data"
sed -i -e '2d' ${filePath}
echo "load into database"
psql -U postgres -d db -c "COPY trips FROM '${filePath}' WITH csv header;"
done