private static void ReadTags(BufferStream readBuffer, MapFileInfoBuilder mapFileInfoBuilder, out Tag[] tags) { // get and check the number of way tags (2 bytes) int numberOfTags = readBuffer.Readshort(); if (numberOfTags < 0) { throw new System.IO.InvalidDataException("invalid number of tags: " + numberOfTags); } tags = new Tag[numberOfTags]; for (int currentTagId = 0; currentTagId < numberOfTags; ++currentTagId) { // get and check the way tag string tag = readBuffer.ReadUTF8Encodedstring(); if (tag == null) { tags = null; throw new System.IO.InvalidDataException("tag must not be null: " + currentTagId); } tags[currentTagId] = new Tag(tag); } mapFileInfoBuilder.wayTags = tags; }
public static void ReadProjectionName(BufferStream readBuffer, MapFileInfoBuilder mapFileInfoBuilder) { // get and check the projection name string projectionName = readBuffer.ReadUTF8Encodedstring(); mapFileInfoBuilder.projectionName = projectionName; }
public static void readOptionalFields(BufferStream readBuffer, MapFileInfoBuilder mapFileInfoBuilder) { OptionalFields optionalFields = new OptionalFields((byte)readBuffer.ReadByte()); mapFileInfoBuilder.optionalFields = optionalFields; optionalFields.ReadOptionalFields(readBuffer); }
public static void ReadFileVersion(BufferStream readBuffer, MapFileInfoBuilder mapFileInfoBuilder) { // get and check the file version (4 bytes) int fileVersion = readBuffer.ReadInt(); if (fileVersion != SupportedFileVersion) { throw new System.IO.InvalidDataException("unsupported file version: " + fileVersion); } mapFileInfoBuilder.fileVersion = fileVersion; }
public static void ReadFileSize(BufferStream readBuffer, long fileSize, MapFileInfoBuilder mapFileInfoBuilder) { // get and check the file size (8 bytes) long headerFileSize = readBuffer.ReadLong(); if (headerFileSize != fileSize) { throw new System.IO.InvalidDataException("invalid file size: " + headerFileSize); } mapFileInfoBuilder.fileSize = fileSize; }
public static void ReadTilePixelSize(BufferStream readBuffer, MapFileInfoBuilder mapFileInfoBuilder) { // get and check the tile pixel size (2 bytes) int tilePixelSize = readBuffer.Readshort(); if (tilePixelSize != 256) { throw new System.IO.InvalidDataException("unsupported tile pixel size: " + tilePixelSize); } mapFileInfoBuilder.tilePixelSize = tilePixelSize; }
public static void ReadMapDate(BufferStream readBuffer, MapFileInfoBuilder mapFileInfoBuilder) { // get and check the the map date (8 bytes) DateTime mapDate = readBuffer.ReadDateTime(); // is the map date before 2010-01-10 ? if (mapDate < new DateTime(2008, 1, 1)) { throw new System.IO.InvalidDataException("invalid map date: " + mapDate); } mapFileInfoBuilder.mapDate = mapDate; }
public static void ReadBoundingBox(BufferStream readBuffer, MapFileInfoBuilder mapFileInfoBuilder) { double minLatitude = CoordinatesUtil.microdegreesToDegrees(readBuffer.ReadInt()); double minLongitude = CoordinatesUtil.microdegreesToDegrees(readBuffer.ReadInt()); double maxLatitude = CoordinatesUtil.microdegreesToDegrees(readBuffer.ReadInt()); double maxLongitude = CoordinatesUtil.microdegreesToDegrees(readBuffer.ReadInt()); try { mapFileInfoBuilder.boundingBox = new BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude); } catch (ArgumentException e) { throw new System.IO.InvalidDataException(e.Message, e); } }
/** * Reads and validates the header block from the map file. * * @param readBuffer * the ReadBuffer for the file data. * @param fileSize * the size of the map file in bytes. * @return a FileOpenResult containing an error message in case of a failure. * @throws IOException * if an error occurs while reading the file. */ public void ReadHeader(BufferStream readBuffer, long fileSize) { RequiredFields.ReadMagicbyte(readBuffer); RequiredFields.ReadRemainingHeader(readBuffer); MapFileInfoBuilder mapFileInfoBuilder = new MapFileInfoBuilder(); RequiredFields.ReadFileVersion(readBuffer, mapFileInfoBuilder); RequiredFields.ReadFileSize(readBuffer, fileSize, mapFileInfoBuilder); RequiredFields.ReadMapDate(readBuffer, mapFileInfoBuilder); RequiredFields.ReadBoundingBox(readBuffer, mapFileInfoBuilder); RequiredFields.ReadTilePixelSize(readBuffer, mapFileInfoBuilder); RequiredFields.ReadProjectionName(readBuffer, mapFileInfoBuilder); mapFileInfoBuilder.Projection = new RepresentationConverter(Projections.GetProjection(mapFileInfoBuilder.projectionName), mapFileInfoBuilder.tilePixelSize); OptionalFields.readOptionalFields(readBuffer, mapFileInfoBuilder); RequiredFields.ReadNodeTags(readBuffer, mapFileInfoBuilder); RequiredFields.ReadWayTags(readBuffer, mapFileInfoBuilder); ReadSubFileParameters(readBuffer, fileSize, mapFileInfoBuilder); this.mapFileInfo = mapFileInfoBuilder.build(); }
public MapFileInfo(MapFileInfoBuilder mapFileInfoBuilder) { this.Comment = mapFileInfoBuilder.optionalFields.comment; this.CreatedBy = mapFileInfoBuilder.optionalFields.createdBy; this.DebugFile = mapFileInfoBuilder.optionalFields.isDebugFile; this.FileSize = mapFileInfoBuilder.fileSize; this.FileVersion = mapFileInfoBuilder.fileVersion; this.LanguagePreference = mapFileInfoBuilder.optionalFields.languagePreference; this.BoundingBox = mapFileInfoBuilder.boundingBox; this.MapDate = mapFileInfoBuilder.mapDate; this.NumberOfSubFiles = mapFileInfoBuilder.numberOfSubFiles; this.NodeTags = mapFileInfoBuilder.nodeTags; this.ProjectionName = mapFileInfoBuilder.projectionName; this.StartPosition = mapFileInfoBuilder.optionalFields.startPosition; this.StartZoomLevel = mapFileInfoBuilder.optionalFields.startZoomLevel; this.TilePixelSize = mapFileInfoBuilder.tilePixelSize; this.WayTags = mapFileInfoBuilder.wayTags; this.Projection = new RepresentationConverter(Projections.GetProjection(ProjectionName), TilePixelSize); }
private void ReadSubFileParameters(BufferStream readBuffer, long fileSize, MapFileInfoBuilder mapFileInfoBuilder) { // get and check the number of sub-files (1 byte) byte numberOfSubFiles = (byte)readBuffer.ReadByte(); if (numberOfSubFiles < 1) { throw new System.IO.InvalidDataException("invalid number of sub-files: " + numberOfSubFiles); } mapFileInfoBuilder.numberOfSubFiles = numberOfSubFiles; SubFileParameter[] tempSubFileParameters = new SubFileParameter[numberOfSubFiles]; this.zoomLevelMinimum = byte.MaxValue; this.zoomLevelMaximum = byte.MinValue; // get and check the information for each sub-file for (byte currentSubFile = 0; currentSubFile < numberOfSubFiles; ++currentSubFile) { SubFileParameterBuilder subFileParameterBuilder = new SubFileParameterBuilder(); // get and check the base zoom level (1 byte) byte baseZoomLevel = (byte)readBuffer.ReadByte(); if (baseZoomLevel < 0 || baseZoomLevel > BASE_ZOOM_LEVEL_MAX) { throw new System.IO.InvalidDataException("invalid base zooom level: " + baseZoomLevel); } subFileParameterBuilder.baseZoomLevel = baseZoomLevel; // get and check the minimum zoom level (1 byte) byte zoomLevelMin = (byte)readBuffer.ReadByte(); if (zoomLevelMin < 0 || zoomLevelMin > 22) { throw new System.IO.InvalidDataException("invalid minimum zoom level: " + zoomLevelMin); } subFileParameterBuilder.zoomLevelMin = zoomLevelMin; // get and check the maximum zoom level (1 byte) byte zoomLevelMax = (byte)readBuffer.ReadByte(); if (zoomLevelMax < 0 || zoomLevelMax > 22) { throw new System.IO.InvalidDataException("invalid maximum zoom level: " + zoomLevelMax); } subFileParameterBuilder.zoomLevelMax = zoomLevelMax; // check for valid zoom level range if (zoomLevelMin > zoomLevelMax) { throw new System.IO.InvalidDataException("invalid zoom level range: " + zoomLevelMin + SPACE + zoomLevelMax); } // get and check the start address of the sub-file (8 bytes) long startAddress = readBuffer.ReadLong(); if (startAddress < HEADER_SIZE_MIN || startAddress >= fileSize) { throw new System.IO.InvalidDataException("invalid start address: " + startAddress); } subFileParameterBuilder.startAddress = startAddress; long indexStartAddress = startAddress; if (mapFileInfoBuilder.optionalFields.isDebugFile) { // the sub-file has an index signature before the index indexStartAddress += SIGNATURE_LENGTH_INDEX; } subFileParameterBuilder.indexStartAddress = indexStartAddress; // get and check the size of the sub-file (8 bytes) long subFileSize = readBuffer.ReadLong(); if (subFileSize < 1) { throw new System.IO.InvalidDataException("invalid sub-file size: " + subFileSize); } subFileParameterBuilder.subFileSize = subFileSize; subFileParameterBuilder.boundingBox = mapFileInfoBuilder.boundingBox; // add the current sub-file to the list of sub-files tempSubFileParameters[currentSubFile] = subFileParameterBuilder.build(mapFileInfoBuilder.Projection); updateZoomLevelInformation(tempSubFileParameters[currentSubFile]); } // create and fill the lookup table for the sub-files this.subFileParameters = new SubFileParameter[this.zoomLevelMaximum + 1]; for (int currentMapFile = 0; currentMapFile < numberOfSubFiles; ++currentMapFile) { SubFileParameter subFileParameter = tempSubFileParameters[currentMapFile]; for (byte zoomLevel = subFileParameter.ZoomLevelMin; zoomLevel <= subFileParameter.ZoomLevelMax; ++zoomLevel) { this.subFileParameters[zoomLevel] = subFileParameter; } } }
public static void ReadWayTags(BufferStream readBuffer, MapFileInfoBuilder mapFileInfoBuilder) { ReadTags(readBuffer, mapFileInfoBuilder, out mapFileInfoBuilder.wayTags); }