Import shape files to postgis

This howto is dedicated to Laura, the first that made cun comment on my blog. Well once we have postgis installed on a server (windows or linux) the easiest way to import a shp file to postgis is by using the hp2pgsql command.

All we have to do is look for where our binary shp2psql is, and then we run:
shp2pgsql -I -s 4326 -W latin1 barrios.shp barrios | psql -U postgres -d geoprop

I explain the options:

-I to create a geometric index.
-s projection, 4326 = WGS84
-W the charset, it is very important to use latin1 if they have accents.
-U the user of the database
-d database to be used.

Then they edit the table with pgadmin for example and they change what they want but they will already have all the data, the geometric ones and the associated dbf.

If you need a postgres hosting with mapserver, geoserver and postgis support I recommend Root Solutions .


a little of postgis

What I am going to show you is how from a geographical table (postgis) of segments of streets we are going to put together a table with the intersections of those streets. Surely they are already asking the same question that I asked Fernando, what for? That is, to insert redundancy in the system, and the answer is very simple, performance. While I do not think anyone has this problem on time is a good example of how to play with postgis. Continue reading