In my recent work, I have completed one project in Laravel application and it was very similar to the food ordering application like Swiggy/Zomato. For the database, I had used PostgreSQL object-relational and installed PostGIS extension.
PostGIS is open source software program that adds support for geographic objects to the PostgreSQL object-relational database.
I heard about the PostgreSQL database but I never used PostGIS extension so it was a new experience for me. When I was developing API for the mobile application, I had to find nearby restaurants, hotels & cinemas based upon user current location(Latitude and Longitude). So I was searching on google for how to store records with latitude & longitude and how to make queries which return records from the database and after doing some research on google, I found that PostGIS extension which helps me in this scenario.
Before we jump to the PostGIS installation part, I am assuming that you have already installed the latest version of PostgreSQL in your system.
Step 1:
Before you can install PostGIS extension, update your list of available packages so the packages from the new repository are added to the list.
sudo apt-get update
Step 2:
Once your sources update, install the PostGIS extension.
sudo apt-get install postgis
Enter Y when prompted to install PostGIS along with its necessary dependencies. Now we can connect to PostgreSQL and integrate PostGIS.
Step 3:
Using the sudo command and switch to the Postgres user:
sudo -i -u postgres
Step 4:
Connect to the PostGISDemo
database:
psql -d PostGISDemo
Step 5:
Enable the PostGIS extension on the database:
CREATE EXTENSION postgis;
Step 6:
Ok. Now let’s verify that everything worked correctly. Execute the following command in your terminal screen:
SELECT PostGIS_version();
You’ll get this output:
postgis_version --------------------------------------- 2.4 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 (1 row)
Step 7:
We’re all set. Type the below command
\q
to exit the SQL session and return to your terminal prompt.
Keep visiting for new stuff and give your feedback.
Happy Coding 😉
Thank you so much, Manan Patel for this excellent tutorial. As always, you are rocking. Every bit of the information you present is valuable.
Thank you so much, Manan Patel for this excellent tutorial. As always, you are rocking. Every bit of the information you present is valuable.
I didn’t get a PostGISDemo database created
psql -d PostGISDemo
psql: FATAL: database “PostGISDemo” does not exist
[1]+ Done $PANGPA start
Ubuntu 18.04 / PostgreSQL 11.2
First of all, you have to create a blank database and the replace “PostGISDemo” with your database and then connect.
psql -d [PLACE YOUR NEW DB HERE]
I didn’t get a PostGISDemo database created
psql -d PostGISDemo
psql: FATAL: database “PostGISDemo” does not exist
[1]+ Done $PANGPA start
Ubuntu 18.04 / PostgreSQL 11.2
First of all, you have to create a blank database and the replace “PostGISDemo” with your database and then connect.
psql -d [PLACE YOUR NEW DB HERE]
Thanks!
Thanks!
Gracias, funciona perfecto.
Ante posibles dudas de usuarios mas novatos en el tema, se debe crear la base de datos llamada “PostGISDemo”.
Gracias, funciona perfecto.
Ante posibles dudas de usuarios mas novatos en el tema, se debe crear la base de datos llamada “PostGISDemo”.
This won’t work on Ubuntu 19.04, will it? I tried but got “unmet dependencies” errors. I’ll appreciate any help. Thanks.
For the error which you are facing, follow this article which might be helpful for you. 🙂
How To Fix Unmet Dependencies Error On Ubuntu
This won’t work on Ubuntu 19.04, will it? I tried but got “unmet dependencies” errors. I’ll appreciate any help. Thanks.
For the error which you are facing, follow this article which might be helpful for you. 🙂
How To Fix Unmet Dependencies Error On Ubuntu
Wow, cool man. Thanks a lot.
Thanks for reading my blog post. I will glad If you subscribe to my blog & share it on your social platform/or share it with your friends.
Wow, cool man. Thanks a lot.
Thanks for reading my blog post. I will glad If you subscribe to my blog & share it on your social platform/or share it with your friends.