Quem trabalha com geolocalização já deve ter ouvido falar do Postgis.
Ele é um framework muito robusto e usado por diversas empresas de classe global ao redor do mundo.
Para realizar usa instalação, porém, o caminho pode ser tortuoso. Principalmente se você quiser instalar via código-fonte.
Abaixo segue uma receita de como fazer isso em um CentOS 7.
Receita:
INSTALANDO O POSTGRES
cd /usr/local/src
wget https://ftp.postgresql.org/pub/source/v12.3/postgresql-12.3.tar.gz
tar zxf postgresql-12.3.tar.gz
cd postgresql-12.3/
yum groupinstall “Development Tools”
yum install readline-devel libxml2-devel openssl-devel
./configure –prefix=/usr/local/pgsql-12.3 –with-openssl –with-libxml –without-ldap
make -j16
make install
cd /usr/local
ln -s pgsql-12.3/ pgsql
vi /etc/profile.d/postgresql.sh
export PATH=/usr/local/pgsql/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/pgsql/lib:$LD_LIBRARY_PATH
export PGDATA=/pasta/pgdata
source /etc/profile.d/postgresql.sh
cd /usr/local/src/postgresql-12.3/contrib/
make -j10
make install
cd start-scripts/
cp linux /etc/init.d/postgresql
chmod +x /etc/init.d/postgresql
chkconfig postgresql on
vi /etc/init.d/postgresql
PGDATA=/pasta/pgdata
useradd –system –user-group –create-home –comment “PostgreSQL Admin User” –shell /bin/bash postgres
mkdir -p $PGDATA
chown -R postgres. /dados/
chmod -R 700 /dados/pgdata
su – postgres
chmod 700 $PGDATA
cd $PGDATA
initdb -E utf8 –locale=pt_BR.utf-8 -D $PGDATA
ROOT:
/etc/init.d/postgresql start
INICIANDO INSTALAÇÃO DO POSTGIS
cd /usr/local/src
wget https://download.osgeo.org/postgis/source/postgis-3.0.1.tar.gzyum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install epel-release-latest-7.noarch.rpm
INSTALANDO BIBLIOTECAS POSTGIS
yum –showduplicates list geos | expand
yum install geos38.x86_64 geos38-devel.x86_64
yum install proj proj-devel
yum install gdal gdal-devel
yum install cmake
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/json-c-devel-0.11-4.el7_0.x86_64.rpm
sudo yum install json-c-devel-0.11-4.el7_0.x86_64.rpm
wget https://github.com/protobuf-c/protobuf-c/releases/download/v1.1.1/protobuf-c-1.1.1.tar.gz
tar zxf protobuf-c-1.1.1.tar.gz
wget https://github.com/protocolbuffers/protobuf/releases/download/v2.6.0/protobuf-2.6.0.tar.gz
tar zxf protobuf-2.6.0.tar.gz
cd protobuf-2.6.0/
./autogen.sh
./configure
make
make install
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
cd ../protobuf-c-1.1.1/
./configure
make
make install
FINALMENTE INSTALANDO O POSTGIS
cd ../
tar zxf postgis-3.0.1.tar.gz
cd postgis-3.0.1/
make clean SE FOR DA SEGUNDA VEZ EM DIANTE
./configure –with-geosconfig=/usr/geos38/bin/geos-config
make
make install
reiniciar pg
/etc/init.d/postgresql stop
/etc/init.d/postgresql start
TESTANDO O POSTGIS
psql -U postgres
create extension postgis;
SELECT encode(ST_AsGeobuf(q, ‘geom’), ‘base64’) FROM (SELECT ST_GeomFromText(‘POLYGON((0 0,0 1,1 1,1 0,0 0))’) AS geom) AS q;
OUTRAS BIBLIOTECAS:
PG_CRON
wget https://github.com/citusdata/pg_cron/archive/master.zip
mv master.zip pg_cron-master.zip
unzip pg_cron-master.zip
cd pg_cron-master/
make
make install
postgresql.conf
shared_preload_libraries = ‘pg_cron’
cron.database_name = ‘postgres’
reiniciar pg
/etc/init.d/postgresql stop
/etc/init.d/postgresql start
ORACLE_FDW
wget https://download.oracle.com/otn_software/linux/instantclient/195000/oracle-instantclient19.5-basic-19.5.0.0.0-1.x86_64.rpm
wget https://download.oracle.com/otn_software/linux/instantclient/195000/oracle-instantclient19.5-devel-19.5.0.0.0-1.x86_64.rpm
wget https://download.oracle.com/otn_software/linux/instantclient/195000/oracle-instantclient19.5-tools-19.5.0.0.0-1.x86_64.rpm
rpm -i oracle-instantclient19.5-basic-19.5.0.0.0-1.x86_64.rpm
rpm -i oracle-instantclient19.5-devel-19.5.0.0.0-1.x86_64.rpm
rpm -i oracle-instantclient19.5-tools-19.5.0.0.0-1.x86_64.rpm
wget https://github.com/laurenz/oracle_fdw/archive/master.zip
mv master.zip oracle_fdw.zip
unzip oracle_fdw.zip
cd oracle_fdw-master/
ls -l /usr/include/oracle/
OPCAO 1
cp Makefile orig_makefile
sed -i ‘s/19.6/19.5/g’ Makefile
OPCAO 2:
Add the following to Makefile yourself:
To PG_CPPFLAGS add -I/usr/include/oracle/XX.X/client64, and to SHLIB_LINK add -L/usr/lib/oracle/XX.X/client64/lib.
make
make install
TDS-FDW (SQL SERVER)
sudo yum install epel-release
sudo yum install freetds-devel
sudo yum install centos-release-scl
sudo yum install llvm-toolset-7-clang llvm5.0
yum install git
cd /usr/local/src
git clone https://github.com/tds-fdw/tds_fdw.git
cd tds_fdw
make USE_PGXS=1 PG_CONFIG=/usr/local/pgsql/bin/pg_config
sudo make USE_PGXS=1 PG_CONFIG=/usr/local/pgsql/bin/pg_config install