changeset 93:c23bcd6030a4

automatic map field selection also uses lat/lon
author casties
date Wed, 26 Jan 2011 12:53:25 +0100
parents 68f210a19435
children e76dd62f93fd
files RestDbGisApi.py
diffstat 1 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/RestDbGisApi.py	Fri Jan 07 14:51:36 2011 +0100
+++ b/RestDbGisApi.py	Wed Jan 26 12:53:25 2011 +0100
@@ -190,24 +190,34 @@
         
         if (gisIdField is None) and (latField is None or lonField is None):
             # no fields given - choose automagically
+            sql = 'SELECT field_name FROM public.gis_table_meta_rows WHERE table_name = %s and gis_type = %s'
             # gis id in metadata first
-            #SQL='SELECT "attribute with gis_id" FROM public.metadata WHERE tablename = %s'
-            sql = 'SELECT field_name FROM public.gis_table_meta_rows WHERE table_name = %s and gis_type = %s'
             res = self.executeSQL(sql, (table,'gis_id'))
             if len(res['rows']) > 0:
                 gisIdField = res['rows'][0][0]
             else:
-                logging.warning("no entry in metadata table for table %s"%table)
-                # try field names
-                if 'latitude' in fieldMap and 'longitude' in fieldMap:
-                    latField = 'latitude'
-                    lonField = 'longitude'
-                elif 'x_coord' in fieldMap and 'y_coord' in fieldMap:
-                    latField = 'x_coord'
-                    lonField = 'y_coord'
-                else:
-                    logging.error("getKMLdata unable to find position fields")
-                    return None
+                # latitude in metadata
+                res = self.executeSQL(sql, (table,'coord_lat'))
+                if len(res['rows']) > 0:
+                    latField = res['rows'][0][0]
+                    # longitude in metadata
+                    res = self.executeSQL(sql, (table,'coord_lon'))
+                    if len(res['rows']) > 0:
+                        lonField = res['rows'][0][0]
+                        
+        if (gisIdField is None) and (latField is None or lonField is None):
+            logging.warning("no entry in metadata table for table %s" % table)
+            # still no fields - try field names
+            if 'latitude' in fieldMap and 'longitude' in fieldMap:
+                latField = 'latitude'
+                lonField = 'longitude'
+            elif 'x_coord' in fieldMap and 'y_coord' in fieldMap:
+                latField = 'x_coord'
+                lonField = 'y_coord'
+            else:
+                logging.error("getKMLdata unable to find position fields")
+                return None
+
         
         # convert field names to row indexes
         gisIdIdx = fieldMap.get(gisIdField,None)