{"id":140,"date":"2015-12-17T02:18:37","date_gmt":"2015-12-17T02:18:37","guid":{"rendered":"https:\/\/www.acugis.com\/docs\/?p=140"},"modified":"2017-03-13T22:31:27","modified_gmt":"2017-03-13T22:31:27","slug":"load-shp-file","status":"publish","type":"post","link":"https:\/\/acugis.com\/docs\/postgis\/load-shp-file\/","title":{"rendered":"Loading SHP Files"},"content":{"rendered":"<h2><span style=\"color: #800000;\">Loading SHP Files<\/span><\/h2>\n<p>This post will cover loading shp files to your PostGIS database.<\/p>\n<p>We&#8217;ll look at loading files via our shp2pgsql GUI in your control panel, as well as via command line (SSH) and via your desktop.<\/p>\n<p>In this demonstration, we will be using the states_basic21.zip file from the ESRI ArcGIS site, which you can download at:<\/p>\n<p><a href=\"https:\/\/www.arcgis.com\/home\/item.html?id=f7f805eb65eb4ab787a0a3e1116ca7e5\" target=\"_blank\">https:\/\/www.arcgis.com\/home\/item.html?id=f7f805eb65eb4ab787a0a3e1116ca7e5<\/a><\/p>\n<p>If you do not already have a PostGIS database ready, you will need to:<\/p>\n<p>1. Create a <a href=\"https:\/\/www.brainfurnace.com\/postgres-tutorials\/create-database-cpanel.html\" target=\"_blank\">PostgreSQL database<\/a><\/p>\n<p>2. Install <a href=\"https:\/\/www.brainfurnace.com\/postgres-tutorials\/install-postgis-cpanel.html\" target=\"_blank\">PostGIS extensions<\/a> into the database we created.<\/p>\n<p>(Video tutorials courtesy of our <a href=\"https:\/\/www.brainfurnace.com\" target=\"_blank\">brainfurnace.com<\/a> site).<\/p>\n<h3 style=\"text-align: center;\"><\/h3>\n<h3 style=\"text-align: center;\"><\/h3>\n<h3 style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><span style=\"color: #800000; text-decoration: underline;\">Loading via our control panel shp2pgsql tool<\/span><\/span><\/h3>\n<p>With our PostGIS database, we&#8217;ll load the ESRI file using the shp2pgsql tool in your control panel.<\/p>\n<h6><span style=\"color: #800000;\"><strong>1. In your control panel, under GIS Tools, click on the shp2pgsql icon:<\/strong><\/span><\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-142\" src=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/shp2pgsql.png\" alt=\"shp2pgsql\" width=\"179\" height=\"81\" \/><\/p>\n<p>&nbsp;<\/p>\n<h6><span style=\"color: #800000;\">2. Upload the\u00a0states_basic21.zip file (do <strong>not<\/strong> unzip it &#8211; you need all of the files!):<\/span><\/h6>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-143\" src=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/upload-shp-file.jpg\" alt=\"upload-shp-file\" width=\"702\" height=\"367\" srcset=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/upload-shp-file.jpg 702w, https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/upload-shp-file-300x157.jpg 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h6><span style=\"color: #800000;\">3.\u00a0 Select the database and select states.shp from the &#8220;File to Load&#8221; dropdown.<\/span><\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-141\" src=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/shp2pgsql.jpg\" alt=\"shp2pgsql\" width=\"471\" height=\"360\" srcset=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/shp2pgsql.jpg 471w, https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/shp2pgsql-300x229.jpg 300w\" sizes=\"(max-width: 471px) 100vw, 471px\" \/><\/p>\n<p>Using the defaults, which is fine for most cases, a new table called &#8216;states&#8217; will be created with a GEOM column.<\/p>\n<p>Optionally, you can set the table name to something else, set the SRID, append to an existing table, and specify the schema.<\/p>\n<h6><span style=\"color: #800000;\">4. <a style=\"color: #800000;\" href=\"https:\/\/www.brainfurnace.com\/postgres-tutorials\/connect-with-phppgadmin.html\" target=\"_blank\">Log into phpPgAdmin<\/a>, and you should see the states table has been created:<\/span><\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-144\" src=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/phppgadmin.png\" alt=\"phppgadmin\" width=\"652\" height=\"236\" srcset=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/phppgadmin.png 652w, https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/phppgadmin-300x109.png 300w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3 style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><span style=\"color: #800000; text-decoration: underline;\">Loading via Command Line (SSH).<\/span><\/span><\/h3>\n<p>You can also load your shp files via the command line.<\/p>\n<h6><span style=\"color: #800000;\">1. Start and SSH session and upload the zip file (or download it using wget).<\/span><\/h6>\n<h6><span style=\"color: #800000;\">2. Unzip the file.<br \/>\n<\/span><\/h6>\n<p>user@demo [~\/home]# unzip &#8211; q states_21basic.zip<\/p>\n<h6><span style=\"color: #800000;\">3. Move into the shp fil directory directory :<\/span><\/h6>\n<p>user@demo [~\/home]# cd states_basic<\/p>\n<p>user@demo [~\/states_basic]#<\/p>\n<h6><span style=\"color: #800000;\">4. Issue ls to check all of the file are present.<\/span><\/h6>\n<p>user@demo [~\/states_basic]# ls<br \/>\n.\/\u00a0\u00a0 states.dbf\u00a0 states.sbn\u00a0 states.shp\u00a0\u00a0\u00a0\u00a0\u00a0 states.shx<br \/>\n..\/\u00a0 states.prj\u00a0 states.sbx\u00a0 states.shp.xml<\/p>\n<h6><span style=\"color: #800000;\">5. Issue the following to load the file into your database using the defaults:<\/span><\/h6>\n<p>user@demo [~\/states_basic]# shp2pgsql states states | psql -d demo_db<\/p>\n<h6><span style=\"color: #800000;\">6. You should see something like below when using defaults:<\/span><\/h6>\n<p>Shapefile type: Polygon<br \/>\nPostgis type: MULTIPOLYGON[2]<br \/>\nPassword:<br \/>\nSET<br \/>\nSET<br \/>\nBEGIN<br \/>\nCREATE TABLE<br \/>\nALTER TABLE<br \/>\naddgeometrycolumn<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\npublic.states.geom SRID:0 TYPE:MULTIPOLYGON DIMS:2<br \/>\n(1 row)<\/p>\n<p>INSERT 0 1<br \/>\nINSERT 0 1<br \/>\nINSERT 0 1<br \/>\nINSERT 0 1<br \/>\nINSERT 0 1<br \/>\nINSERT 0 1<br \/>\nINSERT 0 1<\/p>\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<br \/>\nINSERT 0 1<br \/>\nCOMMIT<br \/>\nuser@demo [~\/states_basic]#<\/p>\n<p>For a list shp2pgsql command line options, see:<\/p>\n<p><a href=\"http:\/\/www.bostongis.com\/pgsql2shp_shp2pgsql_quickguide.bqg\" target=\"_blank\">http:\/\/www.bostongis.com\/pgsql2shp_shp2pgsql_quickguide.bqg<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3 style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><span style=\"color: #800000; text-decoration: underline;\">Loading via Desktop Client<br \/>\n<\/span><\/span><\/h3>\n<p>If you have installed PgAdminIII on your Desktop (or using the stand alone shp2pgsql GUI), follow below:<\/p>\n<h6><span style=\"color: #800000;\">1. Download the states_basic21.zip file and UNZIP it on your desktop<\/span><\/h6>\n<h6><span style=\"color: #800000;\">2. In PgAdminIII, go to plugins &gt; PostGIS Shapefile and DBF Loader:<\/span><\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-149\" src=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/desktop-shp-file-a.jpg\" alt=\"desktop-shp-file-a\" width=\"454\" height=\"104\" srcset=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/desktop-shp-file-a.jpg 454w, https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/desktop-shp-file-a-300x69.jpg 300w\" sizes=\"(max-width: 454px) 100vw, 454px\" \/><\/p>\n<h6><span style=\"color: #800000;\">3. Click on View Connection Details and add your connection information:<\/span><\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-148\" src=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/desktop-shp-file-1.jpg\" alt=\"desktop-shp-file-1\" width=\"470\" height=\"641\" srcset=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/desktop-shp-file-1.jpg 470w, https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/desktop-shp-file-1-220x300.jpg 220w\" sizes=\"(max-width: 470px) 100vw, 470px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h6><span style=\"color: #800000;\">4. Click on Options (note they are the same as the tool in our control panel):<\/span><\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-150\" src=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/options.jpg\" alt=\"options\" width=\"549\" height=\"363\" srcset=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/options.jpg 549w, https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/options-300x198.jpg 300w\" sizes=\"(max-width: 549px) 100vw, 549px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h6><span style=\"color: #800000;\">5. Navigate to the location you have unzip the shp file to:<\/span><\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-151\" src=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/desktop-shp-file.jpg\" alt=\"desktop-shp-file\" width=\"723\" height=\"568\" srcset=\"https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/desktop-shp-file.jpg 723w, https:\/\/acugis.com\/docs\/wp-content\/uploads\/2015\/12\/desktop-shp-file-300x236.jpg 300w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/p>\n<h6><span style=\"color: #800000;\">6. Click the Open button and then click on Import.<br \/>\n<\/span><\/h6>\n<p>If all went well, you should see something like below displayed in the panel:<\/p>\n<p>connecting:\u00a0 host=mydomain.com port=5432 user=demo password=&#8217;********&#8217; dbname=demo_db<\/p>\n<p>==============================<br \/>\nImporting with configuration: states, public, geom, C:\\Documents and Settings\\user\\Desktop\\db-demo\\states_21basic\\states, mode=c, dump=1, simple=0, geography=0, index=1, shape=1, srid=0<br \/>\nShapefile type: Polygon<br \/>\nPostGIS type: MULTIPOLYGON[2]<br \/>\nShapefile import completed.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>NOTE:<\/strong><\/span> <em>In all the above cases, we did not set a SRID<\/em>. For our demonstrations with the states_basic21 file, this will not be an issue. In other instances, it will be required.\u00a0 We will look at setting the SRID, as well as updating it, in subsequent installments.<\/p>\n<p>If you have any questions or require assistance, please create a support ticket.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Loading SHP Files This post will cover loading shp files to your PostGIS database. We&#8217;ll look at loading files via our shp2pgsql GUI in your control panel, as well as via command line (SSH) and via your desktop. In this demonstration, we will be using the states_basic21.zip file from the ESRI ArcGIS site, which you &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/acugis.com\/docs\/postgis\/load-shp-file\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Loading SHP Files&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-postgis"],"_links":{"self":[{"href":"https:\/\/acugis.com\/docs\/wp-json\/wp\/v2\/posts\/140"}],"collection":[{"href":"https:\/\/acugis.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/acugis.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/acugis.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/acugis.com\/docs\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":9,"href":"https:\/\/acugis.com\/docs\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"predecessor-version":[{"id":249,"href":"https:\/\/acugis.com\/docs\/wp-json\/wp\/v2\/posts\/140\/revisions\/249"}],"wp:attachment":[{"href":"https:\/\/acugis.com\/docs\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/acugis.com\/docs\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/acugis.com\/docs\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}