Example #1
0
        private void decodeWayNodesSingleDelta(List <Point> waySegment, double tileLatitude, double tileLongitude, ReadBuffer readBuffer)
        {
            // get the first way node latitude single-delta offset (VBE-S)
            double wayNodeLatitude = tileLatitude + PointUtils.MicrodegreesToDegrees(readBuffer.ReadSignedInt());

            // get the first way node longitude single-delta offset (VBE-S)
            double wayNodeLongitude = tileLongitude + PointUtils.MicrodegreesToDegrees(readBuffer.ReadSignedInt());

            // store the first way node
            waySegment.Add(new Point(wayNodeLongitude, wayNodeLatitude));

            for (int wayNodesIndex = 1; wayNodesIndex < waySegment.Capacity; ++wayNodesIndex)
            {
                // get the way node latitude offset (VBE-S)
                wayNodeLatitude = wayNodeLatitude + PointUtils.MicrodegreesToDegrees(readBuffer.ReadSignedInt());

                // get the way node longitude offset (VBE-S)
                wayNodeLongitude = wayNodeLongitude + PointUtils.MicrodegreesToDegrees(readBuffer.ReadSignedInt());

                // Decoding near international date line can return values slightly outside valid [-180°, 180°] due to calculation precision
                if (wayNodeLongitude < PointUtils.LONGITUDE_MIN &&
                    (PointUtils.LONGITUDE_MIN - wayNodeLongitude) < 0.001)
                {
                    wayNodeLongitude = PointUtils.LONGITUDE_MIN;
                }
                else if (wayNodeLongitude > PointUtils.LONGITUDE_MAX &&
                         (wayNodeLongitude - PointUtils.LONGITUDE_MAX) < 0.001)
                {
                    wayNodeLongitude = PointUtils.LONGITUDE_MAX;
                }

                waySegment.Add(new Point(wayNodeLongitude, wayNodeLatitude));
            }
        }
Example #2
0
        private Point ReadOptionalLabelPosition(double tileLatitude, double tileLongitude, bool featureLabelPosition, ReadBuffer readBuffer)
        {
            if (featureLabelPosition)
            {
                // get the label position latitude offset (VBE-S)
                double latitude = tileLatitude + PointUtils.MicrodegreesToDegrees(readBuffer.ReadSignedInt());

                // get the label position longitude offset (VBE-S)
                double longitude = tileLongitude + PointUtils.MicrodegreesToDegrees(readBuffer.ReadSignedInt());

                return(new Point(longitude, latitude));
            }

            return(null);
        }
Example #3
0
        private IList <PointOfInterest> ProcessPOIs(double tileLatitude, double tileLongitude, int numberOfPois, BoundingBox boundingBox, bool filterRequired, ReadBuffer readBuffer)
        {
            IList <PointOfInterest> pois = new List <PointOfInterest>();

            Tag[] poiTags = this.mapFileHeader.MapFileInfo.PoiTags;

            for (int elementCounter = numberOfPois; elementCounter != 0; --elementCounter)
            {
                if (this.mapFileHeader.MapFileInfo.DebugFile)
                {
                    // get and check the POI signature
                    string signaturePoi = readBuffer.ReadUTF8EncodedString(SIGNATURE_LENGTH_POI);
                    if (!signaturePoi.StartsWith("***POIStart", StringComparison.Ordinal))
                    {
                        Logger.Log(LogLevel.Warning, "invalid POI signature: " + signaturePoi);
                        return(null);
                    }
                }

                // get the POI latitude offset (VBE-S)
                double latitude = tileLatitude + PointUtils.MicrodegreesToDegrees(readBuffer.ReadSignedInt());

                // get the POI longitude offset (VBE-S)
                double longitude = tileLongitude + PointUtils.MicrodegreesToDegrees(readBuffer.ReadSignedInt());

                // get the special byte which encodes multiple flags
                sbyte specialByte = readBuffer.ReadByte();

                // bit 1-4 represent the layer with
                sbyte layer = (sbyte)((int)((uint)(specialByte & POI_LAYER_BITMASK) >> POI_LAYER_SHIFT));
                // bit 5-8 represent the number of tag IDs
                sbyte numberOfTags = (sbyte)(specialByte & POI_NUMBER_OF_TAGS_BITMASK);

                IList <Tag> tags = new List <Tag>();

                // get the tag IDs (VBE-U)
                for (sbyte tagIndex = numberOfTags; tagIndex != 0; --tagIndex)
                {
                    int tagId = readBuffer.ReadUnsignedInt();
                    if (tagId < 0 || tagId >= poiTags.Length)
                    {
                        Logger.Log(LogLevel.Warning, "invalid POI tag ID: " + tagId);
                        return(null);
                    }
                    tags.Add(poiTags[tagId]);
                }

                // get the feature bitmask (1 byte)
                sbyte featureByte = readBuffer.ReadByte();

                // bit 1-3 enable optional features
                bool featureName        = (featureByte & POI_FEATURE_NAME) != 0;
                bool featureHouseNumber = (featureByte & POI_FEATURE_HOUSE_NUMBER) != 0;
                bool featureElevation   = (featureByte & POI_FEATURE_ELEVATION) != 0;

                // check if the POI has a name
                if (featureName)
                {
                    tags.Add(new Tag(TAG_KEY_NAME, ExtractLocalized(readBuffer.ReadUTF8EncodedString())));
                }

                // check if the POI has a house number
                if (featureHouseNumber)
                {
                    tags.Add(new Tag(TAG_KEY_HOUSE_NUMBER, readBuffer.ReadUTF8EncodedString()));
                }

                // check if the POI has an elevation
                if (featureElevation)
                {
                    tags.Add(new Tag(TAG_KEY_ELE, Convert.ToString(readBuffer.ReadSignedInt())));
                }

                Point position = new Point(longitude, latitude);
                // depending on the zoom level configuration the poi can lie outside
                // the tile requested, we filter them out here
                if (!filterRequired || boundingBox.Contains(position))
                {
                    pois.Add(new PointOfInterest(layer, tags, position));
                }
            }

            return(pois);
        }