SOSI files may be converted to a PosgreSQL/PostGIS dump file for easy database import. The content of related SOSI elements are exported alongside the geometry.

The following command will create an sql file for PostGIS from, let’s say 32_1244Adresse.sos:

sosicon -2psql 32_1244Adresse.sos

The default file name for the export file is postgis_dump.sql. Run it in psql to create the schema and the points table. A database schema called sosicon will be created in the active database, and in it the table object_point is created and filled with the exported SOSI data points. If there are several geometry types in the SOSI files, one table is created for each geometry. The table names are postfixed with the relevant geometry name, i.e. “object_point”, “object_linestring” or “object_polygon”.

Use the -o parameter to specify a different output file name. To specify custom schema or table name, use -schema and -table:

sosicon -2psql -schema municipalities -table austevoll -o austevoll.sql 32_1244Adresse.sos

This vil output austevoll.sql. When imported in PostGIS, the data will be stored in table austevoll_[XXX] within schema municipalities, where [XXX] is the geometry name.

The contents of several SOSI files can be assebled in one SQL dump file by using piping on OS X or Linux systems:

ls *.sos | sosicon -2psql -o whole_country.sql

See the documentation for psql for information on how to import SQL files in PostgreSQL. Check out the \i meta command.

I have also published a simple example on converting a SOSI file to PostGIS and opening it in TileMill.

Please remember that the preliminary sosicon builds are unstable and error prone. Use only for testing purposes!

One thought on “PostGIS”

Leave a Reply

Your email address will not be published. Required fields are marked *