How to Create a PostGIS Spatial Database and Import Shapefile Data
After installing PostgreSQL on Windows, this guide shows how to add the PostGIS extension via pgAdmin, create a new spatial database, verify the installation, and then use the PostGIS Shapefile and DBF Loader Exporter to import a shapefile (with accompanying DBF), handling encoding and path issues, and finally view the imported data.
After installing PostgreSQL on Windows (see the linked tutorial), you can optionally install the PostGIS extension to enable spatial features.
Creating a spatial database
Open pgAdmin, connect with your password, then navigate to Databases → New → Database . Name the database (e.g., demo) and open the Query Tool on that database.
Run the following command to enable PostGIS: CREATE EXTENSION postgis; Click the run button (the triangle icon). After execution, the extension appears in the list. Verify the installation with: SELECT postgis_full_version(); The result confirms that PostGIS is active.
Importing shapefile data
Install the "PostGIS Shapefile and DBF Loader Exporter" tool. You need a .shp file and its accompanying .dbf file; a sample Chinese provincial map is provided in the article.
Ensure that the shapefile name and its directory path contain no Chinese characters.
Launch the loader, click View connection details , and enter the PostgreSQL username, password, host IP, port, and the target database.
After a successful connection, go to Options → Import Options and set the encoding to GBK to handle Chinese characters correctly.
Click the Import button, select the .shp file (and ensure the matching .dbf file is present), then start the import. A success message appears when the operation completes.
To view the imported data, expand the public schema in pgAdmin, locate the new tables, right‑click → View/Edit Data → First 100 rows . The spatial attributes and attribute columns from the shapefile are displayed.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
The Dominant Programmer
Resources and tutorials for programmers' advanced learning journey. Advanced tracks in Java, Python, and C#. Blog: https://blog.csdn.net/badao_liumang_qizhi
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
