import types import TileData_v4_pb2 from GeomEncoder import GeomEncoder from StaticVals import getValues from StaticKeys import getKeys from TagRewrite import fixTag from TileStache.Core import KnownUnknown import re import logging import struct #import gzip #import cStringIO #import zlib statickeys = getKeys() staticvals = getValues() # custom keys/values start at attrib_offset attrib_offset = 256 try: from psycopg2 import connect as _connect from psycopg2.extras import register_hstore from psycopg2.pool import ThreadedConnectionPool except ImportError: # At least it should be possible to build the documentation. pass class EmptyResponse:
def addItem(self, tile, row, coord, geomparser, tagdict): num_tags = 1024 + len(tagdict) statictags = getTags() statickeys = getKeys() wayTags = [] for tag in row[0].iteritems(): layer = 5 # use unsigned int for layer. i.e. map to 0..10 if "layer" == tag[0]: try: l = max(min(10, int(tag[1])) + 5, 0) if l != 0: layer = l continue except ValueError: continue tag = self.fixTag(tag, coord.zoom) if tag is None: continue if statictags.has_key(tag): wayTags.append(statictags[tag]) logging.debug('add static tag %s', tag) elif tagdict.has_key(tag): # add tag index to way data wayTags.append(tagdict[tag]) logging.debug('add tag %s', tag) elif tag[0] in statickeys: # add tag string to tile data tile.keys.append(statickeys[tag[0]]) tile.values.append(tag[1].decode('utf-8')) logging.debug('add tag: %d %s %s' % (statickeys[tag[0]], tag[0], tag[1])) #tile.tags.append(("%s=%s" % (tag[0], tag[1])).decode('utf-8')) # map tag => tile tag index tagdict[tag] = num_tags # add tag index to way wayTags.append(num_tags) num_tags += 1 if len(wayTags) == 0: return geomparser.parseGeometry(row[1]) way = None; if geomparser.isPoint: way = tile.points.add() # add number of points (for multi-point) if len(geomparser.coordinates) > 2: logging.info('points %s' %len(geomparser.coordinates)) way.indices.add(geomparser.coordinates/2) else: # empty geometry if len(geomparser.index) == 0: return if geomparser.isPoly: way = tile.polygons.add() else: way = tile.lines.add() # add coordinate index list (coordinates per geometry) way.indices.extend(geomparser.index) # add indice count (number of geometries) if len(way.indices) > 1: way.num_indices = len(way.indices) # add coordinates way.coordinates.extend(geomparser.coordinates) # add tags way.tags.extend(wayTags) #if len(wayTags) > 1: # way.num_tags = len(wayTags) logging.debug('tags %d, indices %d' %(len(wayTags),len(way.indices))) # add osm layer if layer != 5: way.layer = layer