def writeHeader(self, osmVersion, phyghtmapVersion): # write reset self.writeReset() header = [] #file format dataset (0xe0), length (0x04), format (o5m2) header.extend( [writableInt(0xe0), writableInt(0x04), writableString("o5m2")]) # timestamp dataset timestampDataset = self.makeTimestampDataset() header.append(timestampDataset) # bounding box dataset bboxDataset = self.makeBBoxDataset() header.append(bboxDataset) #write the header self.outf.write(join(header))
def makeTimestampDataset(self): timestampDataset = [ writableInt(0xdc), ] timestampData = sint2str(self.timestamp) timestampDataset.append(int2str(len(timestampData))) timestampDataset.append(timestampData) return join(timestampDataset)
def makeBBoxDataset(self): # bbox dataset, with length bboxDataset = [ writableInt(0xdb), ] bboxData = join([sint2str(int(i * HUNDREDNANO)) for i in self.bbox]) bboxDataset.append(int2str(len(bboxData))) bboxDataset.append(bboxData) return join(bboxDataset)
def writeWay(self, way, idDelta, first=False): wayDataset = [] # 0x11 means way wayDataset.append(writableInt(0x11)) wayData = self.makeWayData(way, idDelta, first) wayDataLen = len(wayData) wayDataset.append(int2str(wayDataLen)) wayDataset.append(wayData) self.outf.write(join(wayDataset))
def writeNode(self, node, lastNode, idDelta): nodeDataset = [] # 0x10 means node nodeDataset.append(writableInt(0x10)) nodeData = self.makeNodeData(node, lastNode, idDelta) nodeDataLen = len(nodeData) nodeDataset.append(int2str(nodeDataLen)) nodeDataset.append(nodeData) self.outf.write(join(nodeDataset))
def makeVersionChunk(self, first=False): data = [] # version data.append(int2str(1)) # timestamp = self.timestamp or 0, if self.timestamp, write changeset and # uid # timestamp is delta coded if first and self.writeTimestamp: data.append(sint2str(self.timestamp)) else: data.append(sint2str(0)) if self.writeTimestamp: # changeset, delta coded if first: data.append(sint2str(1)) else: data.append(sint2str(0)) # userid, username = ("", ""), string pair -> 0x00,0x00,0x00 data.append(self.stringTable.stringOrIndex(writableInt(0x00) * 3)) return join(data)
def writeReset(self): self.outf.write(writableInt(0xff)) self.lastNodeId = 0 self.stringTable.reset()
def done(self): self.outf.write(writableInt(0xfe)) self.__del__()