Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there a kind of wrapper/library written in python which would enable me to programatically create exports from postgis database into different file formats (most common being, shapefile, dxf, dgn,...). If not i ll probably build one myself using psycopg2, gdal and ogr, these are probably components to start with, yeah?

I need this because i ll be making some kind of web service for data exports.

Thanks

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

i think you dont need lots of search for your work about exporting from postgis. everything is clear gdal, psycopg2 and python can make lots of things for your request.

i have been using them with geodjango for same request from user for a long time. you can get more info about Using psycopg2 with PostgreSQL here and a document which name is Reading and Writing Vector Data with OGR highly recommended for you to read...

the basic connection with postgis:

res = []
con = psycopg2.connect("dbname='mydb' user='reid' host='127.0.0.1' password='reid'")
cur = con.cursor()
cur.execute("SELECT ST_Area(the_geom) FROM mypoly")
rows = cur.fetchall()

for row in rows:
    respre = row[2] # find your result.
    res.append(respre)     

con.commit()
cur.close()
con.close()

i hope it helps you....

share|improve this answer
    
Thats exactly what i ll in the end, i was just wondering if someone did the dirty work for me already ;) –  U2ros Nov 29 '12 at 13:23
    
@U2ros the code i have shared with you is not all the code for your purpose, you have to work on it for reaching the end point. Good Luck :) –  Aragon Nov 29 '12 at 13:31
    
I know i know, still, i appreciate the "outline" –  U2ros Nov 29 '12 at 13:50
add comment

You mention dgn and dxf and open source code then answer is probably No. To my knowledge there is no good free or open source solutions to work with dgn (v8, v7 may even work) (not sure about dxf) files

If you dont have to touch dgn (v8, v7 may even work) then GDAL supports kml (use st_ASKML and XML to get full kml). QGIS has option to "Save as..." for vector layers and probably has somekind python library for it.

I use FME for my dgn to shp/db/dgn/csv/raster conversion. Also FME has support for PostGIS and Postgresql databases (and with some strange lisence you get support for Esri etc..). Works great and costs a lot, isn't open source.

share|improve this answer
    
I don't have any problems exporting when i have working needs to do so ;) I love FME as well hehe. However, i was thinking about a tool or a bunch of scripts, that i could add into a web service context for the consumers environment who won't ne using advanced tools but rather s simple webgis. Thanks anyway –  U2ros Nov 29 '12 at 13:09
    
FME server or FME SDK? prbably can handle that service part. Biggest problem are dgn and dxf fileformats. –  simplexio Nov 29 '12 at 13:14
    
And i forgot GeoServer. It can export published layer in several formats WFS (docs.geoserver.org/latest/en/user/services/wfs/…) and WMS (docs.geoserver.org/stable/en/user/services/wms/…) –  simplexio Nov 29 '12 at 13:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.