Mercurial > hg > ChinaGisRestApi
comparison RestDbGisApi.py @ 263:3a10287447b1
Integration von Europeana4D UserInterface
author | fknauft |
---|---|
date | Thu, 01 Dec 2011 13:48:56 +0100 |
parents | 6613b9204bda |
children | 52b1247140b7 |
comparison
equal
deleted
inserted
replaced
262:6613b9204bda | 263:3a10287447b1 |
---|---|
12 import time | 12 import time |
13 import datetime | 13 import datetime |
14 import urlFunctions | 14 import urlFunctions |
15 | 15 |
16 from RestDbInterface import * | 16 from RestDbInterface import * |
17 | |
18 | 17 |
19 | 18 |
20 def kmlEncode(s): | 19 def kmlEncode(s): |
21 """returns string encoded for displaying in KML attribute""" | 20 """returns string encoded for displaying in KML attribute""" |
22 res = s.replace("'","__Apostroph__") | 21 res = s.replace("'","__Apostroph__") |
53 "number": "numeric", | 52 "number": "numeric", |
54 "id": "text", | 53 "id": "text", |
55 "gis_id": "text", | 54 "gis_id": "text", |
56 "coord_lat": "numeric", | 55 "coord_lat": "numeric", |
57 "coord_lon": "numeric", | 56 "coord_lon": "numeric", |
58 "the_geom": "the_geom" | 57 "the_geom": "the_geom", |
58 "from_year":"text", | |
59 "until_year":"text" | |
59 } | 60 } |
60 | 61 |
61 def getTableOwner(self,schema,table): | 62 def getTableOwner(self,schema,table): |
62 """returns the owner of the table""" | 63 """returns the owner of the table""" |
63 # what do we do with the schema? | 64 # what do we do with the schema? |
240 elif 'x_coord' in fieldMap and 'y_coord' in fieldMap: | 241 elif 'x_coord' in fieldMap and 'y_coord' in fieldMap: |
241 latField = 'x_coord' | 242 latField = 'x_coord' |
242 lonField = 'y_coord' | 243 lonField = 'y_coord' |
243 else: | 244 else: |
244 logging.error("getKMLdata unable to find position fields") | 245 logging.error("getKMLdata unable to find position fields") |
246 self.REQUEST.RESPONSE.write("Please define Position field") | |
245 return None | 247 return None |
246 | 248 |
247 | 249 |
248 # convert field names to row indexes | 250 # convert field names to row indexes |
249 gisIdIdx = fieldMap.get(gisIdField,None) | 251 gisIdIdx = fieldMap.get(gisIdField,None) |
313 desc = '' | 315 desc = '' |
314 | 316 |
315 timestring = '' | 317 timestring = '' |
316 beg_yr = '' | 318 beg_yr = '' |
317 end_yr = '' | 319 end_yr = '' |
320 from_year = '' | |
321 until_year = '' | |
322 sql = "SELECT field_name FROM public.gis_table_meta_rows WHERE table_name = %s and gis_type = %s" | |
323 # from_year and until_year in metadata first | |
324 res = self.executeSQL(sql, (table,'from_year')) | |
325 if len(res['rows']) > 0: | |
326 from_year = res['rows'][0][0] | |
327 res = self.executeSQL(sql, (table,'until_year')) | |
328 if len(res['rows']) > 0: | |
329 until_year = res['rows'][0][0] | |
318 for i in range (len(dataset)): | 330 for i in range (len(dataset)): |
319 value = dataset[i] | 331 value = dataset[i] |
320 | 332 |
321 name = data['fields'][i][0] | 333 name = data['fields'][i][0] |
322 #logging.debug("value=%s"%value) | 334 #logging.debug("value=%s"%value) |
329 # desc += "<name>%s</name>\n"%value | 341 # desc += "<name>%s</name>\n"%value |
330 # continue | 342 # continue |
331 | 343 |
332 val = "%s: %s"%(name, value) | 344 val = "%s: %s"%(name, value) |
333 value=unicode(value) | 345 value=unicode(value) |
334 if name == 'beg_yr': | 346 if name == from_year: |
335 beg_yr= value | 347 beg_yr= value |
336 if name == 'end_yr': | 348 if name == until_year: |
337 end_yr=value | 349 end_yr=value |
338 # If there is a link within the description data, create a valid href | 350 # If there is a link within the description data, create a valid href |
339 if value.find('http://')>-1: | 351 if value.find('http://')>-1: |
340 link_str_beg=value.find('http://') | 352 link_str_beg=value.find('http://') |
341 link_str_end = -1 | 353 link_str_end = -1 |
359 | 371 |
360 #kmlPlace['description'] = "<![CDATA[%s]]>"%desc | 372 #kmlPlace['description'] = "<![CDATA[%s]]>"%desc |
361 | 373 |
362 if beg_yr!='': | 374 if beg_yr!='': |
363 if end_yr!='': | 375 if end_yr!='': |
364 kmlPlace['TimeSpan'] = '<begin>%s</begin><end>%s</end>'%(beg_yr,end_yr) | 376 kmlPlace['TimeSpan0'] = '%s'%beg_yr |
377 kmlPlace['TimeSpan1'] = '%s'%end_yr | |
365 else: | 378 else: |
366 kmlPlace['TimeStamp'] = '<when>%s</when>'%beg_yr | 379 kmlPlace['TimeStamp'] = '%s'%beg_yr |
367 | 380 |
368 if geomField=='point': | 381 if geomField=='point': |
369 kmlPlace['description'] = "<![CDATA[%s]]>"%desc | 382 kmlPlace['description'] = "<![CDATA[%s]]>"%desc |
370 | 383 |
371 kmlPlace['icon'] = '#marker_icon_'+colorField | 384 kmlPlace['icon'] = '#marker_icon_'+colorField |