[postgis-users] Noob question with shp2pgsql

David Rush david at rushtone.com
Fri Apr 12 15:41:44 PDT 2013


Brent:

Aha!  I noticed the pipe in the book's listing, but it's at the line break
and I assumed it's was the book's nomenclature indicating it was all one
line.  It also explains the "psql" option (that's the 2nd command, not an
option).

I put in the pipe and re-ran.  It prompted me for password, and replied
with a bunch of "INSERT 0 1" lines, ending with "COMMIT".

I now see that I have a public.us_counties table.

Looks like I have data in it, too.  Awesome.  Thanks, Brent.

David




On Fri, Apr 12, 2013 at 6:25 PM, <pcreso at pcreso.com> wrote:

> Hi David,
>
> Are you familiar with the terms STDIN & STDOUT?
>
> They are the system devices for input & output.
>
> shp2pgsql sends its output to STDOUT which is generally the screen -
> standard output device. So what you see on screen is what you want to send
> to the database - all the commands to create the appropriate table and
> insert the shapefile data in the new table.
>
> What you need to do is redirect the STDOUT content to the database
> instead, done easily enough by adding a "|" (pipe) character before your
> psql command. This redirects the shp2pgsql output to become input to the
> psql command instead of sending it to the screen.
>
> so your command becomes:
>
>
> shp2pgsql -s 4269 -g geom_4269 -W LATIN1
> c:/users/david/downloads/tl_2012_us_county/tl_2012_us_county.shp
> public.us_counties | psql -h localhost -U postgres -p 5432 -d mygisdb
>
> Cheers,
>
>    Brent Wood
>
>
>
>
>
> --- On *Sat, 4/13/13, David Rush <david at rushtone.com>* wrote:
>
>
> From: David Rush <david at rushtone.com>
> Subject: [postgis-users] Noob question with shp2pgsql
> To: postgis-users at lists.osgeo.org
> Date: Saturday, April 13, 2013, 10:14 AM
>
>
> Total noob to PostgreSQL and PostGIS here.  Trying to follow examples from
> the Obe+Hsu book (1st Ed) in using shp2pgsql from the command line to
> import some tiger county data.
>
> I ran this:
>
> shp2pgsql -s 4269 -g geom_4269 -W LATIN1
> c:/users/david/downloads/tl_2012_us_county/tl_2012_us_county.shp
> public.us_counties psql -h localhost -U postgres -p 5432 -d mygisdb
>
> Thanks to an archive of this list that led me to add the "-W LATIN1" param
> (it was failing with an error w/out it).
>
> Now the command runs for several minutes, spitting out mostly zillions of
> hex digits, with no overt errors.  Last line it spits out is "COMMIT;".
>
> But when I go into psql, I can't find the public.us_counties table that I
> thought I just added created:
>
> mygisdb=# select * from public.us_counties;
> ERROR:  relation "public.us_counties" does not exist
> LINE 1: select * from public.us_counties;
>                       ^
> mygisdb=# select table_schema, table_name,table_type from
> information_schema.tables where
> table_schema not in ('pg_catalog','information_schema');
>  table_schema |    table_name     | table_type
> --------------+-------------------+------------
>  public       | geography_columns | VIEW
>  public       | geometry_columns  | VIEW
>  public       | spatial_ref_sys   | BASE TABLE
>  ch01         | lu_franchises     | BASE TABLE
>  ch01         | fastfoods         | BASE TABLE
> (5 rows)
>
> Poking around with pgAdmin III I can't find in anywhere, either.
>
> Is the new table us_counties hiding somewhere?  Or did it quietly fail?
>  Or what?
>
> David
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org<http://mc/compose?to=postgis-users@lists.osgeo.org>
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20130412/20411461/attachment.html>


More information about the postgis-users mailing list