I decided to use PostJIS because I was dealing with a little detailed map information. I was working while looking at various installation methods, but there were some things that got stuck, so I will write it as a memorandum.
You will be able to save latitude, longitude, area, etc. using a dedicated data type (geometry type, etc.) that will be available once installed. You can use this to calculate location information and work with map objects using GIS objects.
See here for details: https://lets.postgresql.jp/documents/tutorial/PostGIS/1
PostGIS has a lot to do with it. I will install the following.
First, prepare the DB to be actually used.
###Install repository $ sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm ###Install PostgreSQL $ sudo yum install postgresql11 $ sudo yum install postgresql11-server ###Check if it was done $ id postgres uid=26(postgres) gid=26(postgres) groups=26(postgres) $ ls /usr/pgsql-11 bin lib share ###Password setting, you will be asked twice, so enter the same password $ sudo su - postgres -c '/usr/pgsql-11/bin/initdb -E UTF8 --locale=C -A scram-sha-256 -W' ###Switch account to postgres sudo su - postgres ### pgsql_Open profile and write below vi ~/.pgsql_profile PATH=/usr/pgsql-11/bin:$PATH MANPATH=/usr/pgsql-11/share/man:$MANPATH PGDATA=/var/lib/pgsql/11/data export PATH MANPATH PGDATA ### bash_Reload profile and exit postgres $ . ~/.bash_profile $ exit ### postgresql-Start 11 and complete if you can start it safely $ sudo systemctl start postgresql-11.service
In addition, install the necessary packages to facilitate the work to be performed later. Depending on your environment, you may already have one installed, but in that case, skip the command.
###enable wget $ sudo yum install wget ###Prevent postgres11 from getting angry with LLVM-related package dependencies $ sudo yum install epel-release centos-release-scl ###Enable gcc compilation $ sudo yum install gcc-c++ ###Development header files and libraries ### epel-release and centos-release-If you do not install scl, you may not be able to install due to dependencies, so install it $ sudo yum install postgresql11-devel ###Library that handles XML $ sudo yum install libxml2-devel ###Enable python3 sudo yum install python36
We will install PostGIS when the preparations are complete. The flow is to install PostGIS after installing the module for using PostGIS.
$ cd /tmp/ $ wget http://download.osgeo.org/geos/geos-3.7.2.tar.bz2 $ tar xf geos-3.7.2.tar.bz2 $ cd geos-3.7.2/ $ ./configure $ make $ sudo make install $ cd ../ $ rm -rf geos-3.7.2
$ sudo yum install proj-devel.x86_64
$ sudo yum install libstdc++.so.6 $ cd /tmp/ $ wget https://download.osgeo.org/gdal/2.4.0/gdal-2.4.0.tar.gz $ tar xzf gdal-2.4.0.tar.gz $ cd gdal-2.4.0 $ ./configure $ make $ sudo make install $ cd ../ $ rm -rf gdal-2.4.0
$ sudo yum install llvm-toolset-7 $ /tmp/ $ wget https://download.osgeo.org/postgis/source/postgis-2.5.5.tar.gz $ tar xvzf postgis-2.5.5.tar.gz $ cd postgis-2.5.5 $ ./configure --with-pgconfig='/usr/pgsql-11/bin/pg_config' $ make $ sudo make install $ cd ../ $ rm -rf postgis-2.5.5
If you do not have "--with-pgconfig ='/ usr / pgsql-11 / bin / pg_config'" in the ./configure option when installing PostGIS, the following error may occur.
configure: error: could not find pg_config within the current path. You may need to re-run configure with a --with-pgconfig parameter.
I can't find pg_config, so I'm told to specify it, so set the options and it's OK.
$ ls -l /usr/pgsql-11/lib/libgdal.so.20
Probably, "/usr/pgsql-11/lib/libgdal.so.20" cannot be found. Therefore, I will create a symbolic link below.
$ sudo ln -s /usr/local/lib/libgdal.so.20.5.0 /usr/pgsql-11/lib/libgdal.so.20
Without this, the following error will occur when creating EXTENSION from psql.
test_postgis=# CREATE EXTENSION postgis; ERROR: could not load library "/usr/pgsql-11/lib/postgis-2.5.so": libgeos_c.so.1: cannot open shared object file: No such file or directory
Finally cache the shared library again. At that time, write "/ usr / local / lib" in the last line of "/etc/ld.so.conf". If you don't do this, you may get another error when creating EXTENSION.
$ sudo vi /etc/ld.so.conf /usr/local/lib ← Add only this line $ sudo ldconfig
This completes the installation work.
Create a DB to check if it was installed properly. For the time being, restart postgresql-11 before working.
$ sudo systemctl restart postgresql-11.service ###Start psql $ psql -U postgres ###Create a test DB for confirmation postgres=# CREATE DATABASE test_postgis; CREATE DATABASE postgres=# \c test_postgis ###Create EXTENSION test_postgis=# CREATE EXTENSION postgis; CREATE EXTENSION test_postgis=# \dx List of installed extensions Name | Version | Schema | Description ---------+---------+------------+--------------------------------------------------------------------- plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language postgis | 2.5.5 | public | PostGIS geometry, geography, and raster spatial types and functions (2 rows)
If the return value of \ dx looks like the above, it is successful.
Certainly it seems that the installation is done, but it may be ... so I will input the data and check it.
###Create table test_postgis=# CREATE TABLE station_position ( id serial PRIMARY KEY, station_name varchar(20), position geometry ); CREATE TABLE ###Insert data test_postgis=# INSERT INTO station_position (id, station_name, position) VALUES (1, 'Ikebukuro Station', ST_GeomFromText('POINT(139.710911 35.729660)', 4326)), (2, 'Shibuya station', ST_GeomFromText('POINT(139.701647 35.658252)', 4326)), (3, 'Tokyo Station', ST_GeomFromText('POINT(139.767114 35.681437)', 4326)); ###Data confirmation test_postgis=# SELECT * FROM station_position; 1 |Ikebukuro Station| 0101000020E6100000BCEB6CC8BF7661408599B67F65DD4140 2 |Shibuya station| 0101000020E6100000C5CA68E4737661406743FE9941D44140 3 |Tokyo Station| 0101000020E6100000B8C9A8328C78614066A4DE5339D74140
After inputting, let's check the data using pgAdmin. If pgAdmin is not included, the following article will be helpful. Reference URL: pgAdmin installation procedure If you try to check the contents of the table created by pgAdmin, you will see the following screen. I think there is an eye-like icon surrounded by a red frame. If you click on it, the map will be displayed from "Geometry Viewer", and if you press the "+" button to enlarge it, you can see the blue dots at Tokyo Station. That is the location set in the DB. Finally, let's calculate the distance. Use a function that calculates how far Tokyo Station and Ikebukuro Station are by a straight line distance.
test_postgis=# SELECT ST_Distance( (SELECT position FROM station_position WHERE station_name = 'Tokyo Station')::GEOGRAPHY , (SELECT position FROM station_position WHERE station_name = 'Ikebukuro Station')::GEOGRAPHY, TRUE); 7382.264423442
The unit is meters, so it's about 7.38km. When I check the distance on google map, it is 7.36km, so it is almost there.
When I installed it myself, I couldn't find much material and got an error and stumbled, so I hope it helps someone.
Installing PostgreSQL on CentOS https://medium.com/@basstazz3/install-postgis-2-5-to-centos-7-48bd5b261f1a