<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi Daniel,<br><br>There are two common ways to do this, using ogr2ogr or shp2pgsql.<br><br>I suggest you try shp2pgsql as it has a simpler command line. It is a utility bundled with Postgis. If you run it with no arguments it provides help with the syntax.<br><br>The default ouput goes to stdout, and comprises a set of SQL commands to create & populate a Postgis table to manage the same content as the shapefile.<br><br>You can save the output as a file, then load it: <span style="font-style: italic;">psql -d <db> -f <file></span> <br>or you can pipe the shp2pgsql ouput directly into psql: <br><span style="font-style: italic;">shp2pgsql ..... | psql -d <db></span><br><br>If Postgres is set up as I suggested in my last post, then QGIS & SPIT should work OK as well. <br><br><br>Cheers,<br><br>  Brent<br><br><br>--- On <b>Fri,
 12/30/11, Daniel Montenegro <i><dmontenegro84@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Daniel Montenegro <dmontenegro84@gmail.com><br>Subject: Re: [postgis-users] How to configure Postgis/Postgresql to use with QGIS<br>To: pcreso@pcreso.com, sindile.bidla@gmail.com, "postgis-users" <postgis-users@postgis.refractions.net><br>Date: Friday, December 30, 2011, 4:54 AM<br><br><div id="yiv1780929876"><div>Thanks Sindile and Brent,</div>
<div> </div>
<div>Actually, I've unnistalled Postgres (the latest version - 9.xx) and downloaded an older one (8.1.4 - I guess). Then I used STACK BUILDER to install PostGIS on Postgres.</div>
<div> </div>
<div>Now let me ask you something else:</div>
<div> </div>
<div>Supose that I have a polygon shape - like "MyCyty.shp", how can I export it to Postgres <em>via</em> Postgis. I tryed to use the SPIT plugin from QGIS but isn't working right yet... Do I have to create some spatial database in Postgres before trying to export it in QGIS?</div>

<div> </div>
<div>Thanks a lot!</div>
<div> </div>
<div> </div>
<div>Daniel<br></div>
<div>P.S.: I'm using PGADMIN.<br></div>
<div class="yiv1780929876gmail_quote">2011/12/29 <span dir="ltr"><<a rel="nofollow" ymailto="mailto:pcreso@pcreso.com" target="_blank" href="/mc/compose?to=pcreso@pcreso.com">pcreso@pcreso.com</a>></span><br>
<blockquote style="BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PADDING-LEFT:1ex;" class="yiv1780929876gmail_quote">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td valign="top">Hi Daniel,<br>The docs are a good place to start, but here is the simple version, from the command line...<br><br>If you have got Postgres installed OK, you need to create a new database, then install Postgis into it, so I'm assuming you have a working Postgres superuser account you can use.  Then:<br>
<br># create the new, empty database<br>createdb test_gis<br><br># add support for the plpgsql language. Not always needed for v9+ of Postgres, but it # won't hurt anything to try it anyway.<br>createlang test_gis plpgsql<br>
<br># find where on your system the postgis.sql & spatial_reference_sys.sql files are<br># run these in your new database<br><br>psql -d test_gis -f postgis.sql<br>psql -d test_gis -f spatial_ref_sys.sql<br><br># You now have a working Postgis database.<br>
# connect to the database<br>psql -d test_gis<br><br># create a simple table there. QGIS likes integer primary keys, this gives it one<br>create table test_tab (id serial primary key, name varchar(12));<br><br># add a lat/long geometry column to the table<br>
select addgeometry('','test_tab','geom',4326,'POINT',2);<br><br># add a couple of points to the table<br>insert into test_tab values (default,'point 1',ST_setsrid(makepoint(179, -45),4326));<br>
insert into test_tab values (default,'point 2',ST_setsrid(makepoint(179.2, -45.2),4326));<br><br># see that they exist:<br>select * from test_tab;<br>select id, name, ST_astext(geom) as geom from test_tab;<br><br>
# exit postgres<br>\q<br><br><br>To open the table & see the points plotted in QGIS you have a bit of configuration to do. By default a Postgres database is installed securely, so external applications & remote computers cannot connect to it.<br>
<br>The instructions here open the database up to anyone, so it is pretty insecure. If you want to address this, read the Postgres docs...<br><br>Shut down your Postgres server. How you do this depends on your operating system & version.<br>
<br>find the file "pg_hba.conf". It contains the access settings.<br>edit this (you may need admin rights) & set all users from all IP addresses for all databases to "trust", as described in the file<br>
<br>find the file postgresql.conf<br>edit this & set "listen_addresses" to "*" as described in the file ( = all)<br><br>restart the Postgresql service, it will now have an open access configuration, as you just specified.<br>
<br>You can now fire up QGIS on a local or remote system & connect to the database test_gis on the specified server (if same system as the database, the host is called localhost). QGIS will show you the table test_tab & adding this should show your two points.<br>
<br>HTH,<br><br>  Brent Wood<br><br>--- On <b>Thu, 12/29/11, Daniel Montenegro <i><<a rel="nofollow" ymailto="mailto:dmontenegro84@gmail.com" target="_blank" href="/mc/compose?to=dmontenegro84@gmail.com">dmontenegro84@gmail.com</a>></i></b> wrote:<br>
<blockquote style="BORDER-LEFT:rgb(16,16,255) 2px solid;PADDING-LEFT:5px;MARGIN-LEFT:5px;"><br>From: Daniel Montenegro <<a rel="nofollow" ymailto="mailto:dmontenegro84@gmail.com" target="_blank" href="/mc/compose?to=dmontenegro84@gmail.com">dmontenegro84@gmail.com</a>><br>Subject: [postgis-users] How to configure Postgis/Postgresql to use with QGIS<br>
To: <a rel="nofollow" ymailto="mailto:postgis-users@postgis.refractions.net" target="_blank" href="/mc/compose?to=postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>Date: Thursday, December 29, 2011, 2:37 PM 
<div>
<div></div>
<div class="yiv1780929876h5"><br><br>
<div>
<div>Hi there!</div>
<div> </div>
<div>I've installed Postgis but I'm not being able to create a "spatial" table with a geometry column in Postgresql. Actually, I think I still didn't get all the steps to configure postgis in postgresql.</div>

<div> </div>
<div>I really need some help!</div>
<div> </div>
<div>Thanks a lot,</div>
<div> </div>
<div> </div>
<div>Daniel</div></div><br></div></div>-----Inline Attachment Follows----- 
<div class="yiv1780929876im"><br><br>
<div>_______________________________________________<br>postgis-users mailing list<br><a rel="nofollow" target="_blank" href="http://mc/compose?to=postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br><a rel="nofollow" target="_blank" href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</div></div></blockquote></td></tr></tbody></table></blockquote></div><br>
</div></blockquote></td></tr></table>