Mercurial > hg > ChinaGisRestApi
comparison RestDbGisApi.py @ 93:c23bcd6030a4
automatic map field selection also uses lat/lon
| author | casties |
|---|---|
| date | Wed, 26 Jan 2011 12:53:25 +0100 |
| parents | 3779ad0ba9c7 |
| children | 4c125fbb2c5b |
comparison
equal
deleted
inserted
replaced
| 80:68f210a19435 | 93:c23bcd6030a4 |
|---|---|
| 188 | 188 |
| 189 fieldMap = self.getFieldNameMap(data['fields']) | 189 fieldMap = self.getFieldNameMap(data['fields']) |
| 190 | 190 |
| 191 if (gisIdField is None) and (latField is None or lonField is None): | 191 if (gisIdField is None) and (latField is None or lonField is None): |
| 192 # no fields given - choose automagically | 192 # no fields given - choose automagically |
| 193 sql = 'SELECT field_name FROM public.gis_table_meta_rows WHERE table_name = %s and gis_type = %s' | |
| 193 # gis id in metadata first | 194 # gis id in metadata first |
| 194 #SQL='SELECT "attribute with gis_id" FROM public.metadata WHERE tablename = %s' | |
| 195 sql = 'SELECT field_name FROM public.gis_table_meta_rows WHERE table_name = %s and gis_type = %s' | |
| 196 res = self.executeSQL(sql, (table,'gis_id')) | 195 res = self.executeSQL(sql, (table,'gis_id')) |
| 197 if len(res['rows']) > 0: | 196 if len(res['rows']) > 0: |
| 198 gisIdField = res['rows'][0][0] | 197 gisIdField = res['rows'][0][0] |
| 199 else: | 198 else: |
| 200 logging.warning("no entry in metadata table for table %s"%table) | 199 # latitude in metadata |
| 201 # try field names | 200 res = self.executeSQL(sql, (table,'coord_lat')) |
| 202 if 'latitude' in fieldMap and 'longitude' in fieldMap: | 201 if len(res['rows']) > 0: |
| 203 latField = 'latitude' | 202 latField = res['rows'][0][0] |
| 204 lonField = 'longitude' | 203 # longitude in metadata |
| 205 elif 'x_coord' in fieldMap and 'y_coord' in fieldMap: | 204 res = self.executeSQL(sql, (table,'coord_lon')) |
| 206 latField = 'x_coord' | 205 if len(res['rows']) > 0: |
| 207 lonField = 'y_coord' | 206 lonField = res['rows'][0][0] |
| 208 else: | 207 |
| 209 logging.error("getKMLdata unable to find position fields") | 208 if (gisIdField is None) and (latField is None or lonField is None): |
| 210 return None | 209 logging.warning("no entry in metadata table for table %s" % table) |
| 210 # still no fields - try field names | |
| 211 if 'latitude' in fieldMap and 'longitude' in fieldMap: | |
| 212 latField = 'latitude' | |
| 213 lonField = 'longitude' | |
| 214 elif 'x_coord' in fieldMap and 'y_coord' in fieldMap: | |
| 215 latField = 'x_coord' | |
| 216 lonField = 'y_coord' | |
| 217 else: | |
| 218 logging.error("getKMLdata unable to find position fields") | |
| 219 return None | |
| 220 | |
| 211 | 221 |
| 212 # convert field names to row indexes | 222 # convert field names to row indexes |
| 213 gisIdIdx = fieldMap.get(gisIdField,None) | 223 gisIdIdx = fieldMap.get(gisIdField,None) |
| 214 latIdx = fieldMap.get(latField,None) | 224 latIdx = fieldMap.get(latField,None) |
| 215 lonIdx = fieldMap.get(lonField,None) | 225 lonIdx = fieldMap.get(lonField,None) |
