Mercurial > hg > events2kml
diff eventsDB2kml.py @ 0:26c06d568e1d
first
author | dwinter |
---|---|
date | Thu, 13 Sep 2012 16:56:49 +0200 |
parents | |
children | 283badd62593 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/eventsDB2kml.py Thu Sep 13 16:56:49 2012 +0200 @@ -0,0 +1,56 @@ +#diese klasse fragt die postgres db ab und erzeugt ein kml file aus den abfragen + +import psycopg2 +import harvestDataFromEvents + +class DBQuery: + def __init__(self): + self.conn=psycopg2.connect("dbname='mmpermits' user='postgres' host='localhost' password='XX'") + self.cur=self.conn.cursor() + + + + def searchXPath(self,xpath,searchTerm): + query="""select data from locations + where + '%s' = ANY (cast (xpath('%s', data) as text[])) ; + """%(searchTerm,xpath) + + + self.cur.execute(query) + + + results= self.cur.fetchall() + + ret="" + for result in results: + ret+=result[0]+"\n" + + + + return ret + + def query(self,q): + self.cur.execute(q) + results= self.cur.fetchall() + + return results + + +if __name__ == '__main__': + db = DBQuery() + res= "<events>"+db.searchXPath("//name/text()", "Brian L. Cypher")+"</events>" + + + + hv=harvestDataFromEvents.EventKMLTransformer() + + + x,cnt=hv.readString(res, ".//research_location/place_information", 0) + + hv.close() + + s = hv.toKML(x) + + print s +