
0
Postgresql / PostGIS
Hi, anyone tried importing postgis data from postgresql database directly into micromine format .Dat or .str?
Through ODBC I can access the tables, but the geom column needs to be translated into MMs Strings/Dat
Customer support service by UserEcho
Hi Bahram,
Not sure if the issue is still relevant, but you can use scripting to import data directly from PostgreSQL+PostGIS database to Micromine files.
Let’s consider a small example. I created a small PostgreSQL with two tables: points and polygons. Each table contains two columns: name (char) and geom (PostGIS geom). The backup of this db here postgis_db.
To import data from this db I created two scripts with detailed comments. The first one (convert_postgis_to_dat.py) exports points to .DAT file, the second one (convert_postgis_to_str.py) exports polygons to .STR file. Briefly, scripts read data from PostgreSQL db and then write it to MM files (using MMpy module). I could include everything in one script but at the expense of readability. So, I decided to do two scripts.
To run the scripts, you need to install Python and two external modules: psycopg2 and shapely. You can find information how to install modules here.
Here what I got:
In order to use these scripts for your db, you just need to adjust the following things: path to a new MM file (line 7), connection options to your PostgreSQL (line 10), SQL request (line 18), data prettifying (line 27-28) and MM structure creation (struct = MMpy.FileStruct()).
Please let me know if you have any questions!
This is very helpful Maxim,
Thank you!
I just couldn’t figure out how to get the Geom column into MM format.
Next thing that would be handy if we get prompted on table to import rather than change it in the script but the main thing for me was getting the geometry converted to MM.