Ejemplo n.º 1
0
        private void decodeWayNodesDoubleDelta(LatLong[] waySegment, double tileLatitude, double tileLongitude)
        {
            // get the first way node latitude offset (VBE-S)
            double wayNodeLatitude = tileLatitude + LatLongUtils.MicrodegreesToDegrees(this.readBuffer.ReadSignedInt());

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

            // store the first way node
            waySegment[0] = new LatLong(wayNodeLatitude, wayNodeLongitude);

            double previousSingleDeltaLatitude  = 0;
            double previousSingleDeltaLongitude = 0;

            for (int wayNodesIndex = 1; wayNodesIndex < waySegment.Length; ++wayNodesIndex)
            {
                // get the way node latitude double-delta offset (VBE-S)
                double doubleDeltaLatitude = LatLongUtils.MicrodegreesToDegrees(this.readBuffer.ReadSignedInt());

                // get the way node longitude double-delta offset (VBE-S)
                double doubleDeltaLongitude = LatLongUtils.MicrodegreesToDegrees(this.readBuffer.ReadSignedInt());

                double singleDeltaLatitude  = doubleDeltaLatitude + previousSingleDeltaLatitude;
                double singleDeltaLongitude = doubleDeltaLongitude + previousSingleDeltaLongitude;

                wayNodeLatitude  = wayNodeLatitude + singleDeltaLatitude;
                wayNodeLongitude = wayNodeLongitude + singleDeltaLongitude;

                waySegment[wayNodesIndex] = new LatLong(wayNodeLatitude, wayNodeLongitude);

                previousSingleDeltaLatitude  = singleDeltaLatitude;
                previousSingleDeltaLongitude = singleDeltaLongitude;
            }
        }
        protected internal virtual void addPOI(TDNode poi)
        {
            if (!poi.POI)
            {
                return;
            }

            sbyte minZoomLevel = poi.ZoomAppear;

            for (int i = 0; i < this.zoomIntervalConfiguration.NumberOfZoomIntervals; i++)
            {
                // is POI seen in a zoom interval?
                if (minZoomLevel <= this.zoomIntervalConfiguration.getMaxZoom(i))
                {
                    long     tileCoordinateX = MercatorProjection.longitudeToTileX(LatLongUtils.microdegreesToDegrees(poi.Longitude), this.zoomIntervalConfiguration.getBaseZoom(i));
                    long     tileCoordinateY = MercatorProjection.latitudeToTileY(LatLongUtils.microdegreesToDegrees(poi.Latitude), this.zoomIntervalConfiguration.getBaseZoom(i));
                    TileData tileData        = getTileImpl(i, (int)tileCoordinateX, (int)tileCoordinateY);
                    if (tileData != null)
                    {
                        tileData.addPOI(poi);
                        countPoiTags(poi);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Convenience method.
 /// </summary>
 /// <param name="position">
 ///            the map start position in format latitude, longitude </param>
 public virtual void addMapStartPosition(string position)
 {
     if (!string.ReferenceEquals(position, null))
     {
         MapStartPosition = LatLongUtils.fromString(position);
     }
 }
Ejemplo n.º 4
0
        // private static final byte ZOOM_NAME = (byte) 16;

        /// <summary>
        /// Constructs a new TDNode from a given osmosis node entity. Checks the validity of the entity.
        /// </summary>
        /// <param name="node">
        ///            the osmosis entity </param>
        /// <param name="preferredLanguages">
        ///            the preferred language(s) or null if no preference </param>
        /// <returns> a new TDNode </returns>
        public static TDNode fromNode(Node node, IList <string> preferredLanguages)
        {
            SpecialTagExtractionResult ster = OSMUtils.extractSpecialFields(node, preferredLanguages);

            short[] knownWayTags = OSMUtils.extractKnownPOITags(node);

            return(new TDNode(node.Id, LatLongUtils.degreesToMicrodegrees(node.Latitude), LatLongUtils.degreesToMicrodegrees(node.Longitude), ster.Elevation, ster.Layer, ster.Housenumber, ster.Name, knownWayTags));
        }
Ejemplo n.º 5
0
        /// <param name="latitude">
        ///            the latitude coordinate in degrees. </param>
        /// <param name="longitude">
        ///            the longitude coordinate in degrees. </param>
        /// <param name="validate"> </param>
        /// <exception cref="IllegalArgumentException">
        ///             if a coordinate is invalid. </exception>
        public LatLong(double latitude, double longitude, bool validate)
        {
            if (validate)
            {
                LatLongUtils.ValidateLatitude(latitude);
                LatLongUtils.ValidateLongitude(longitude);
            }

            this.Latitude  = latitude;
            this.Longitude = longitude;
        }
Ejemplo n.º 6
0
        // **************** JTS CONVERSIONS *********************

        private static double[] computeTileEnlargement(double lat, int enlargementInMeter)
        {
            if (enlargementInMeter == 0)
            {
                return(EPSILON_ZERO);
            }

            double[] epsilons = new double[2];

            epsilons[0] = LatLongUtils.latitudeDistance(enlargementInMeter);
            epsilons[1] = LatLongUtils.longitudeDistance(enlargementInMeter, lat);

            return(epsilons);
        }
Ejemplo n.º 7
0
        private LatLong ReadOptionalLabelPosition(double tileLatitude, double tileLongitude, bool featureLabelPosition)
        {
            if (featureLabelPosition)
            {
                // get the label position latitude offset (VBE-S)
                double latitude = tileLatitude + LatLongUtils.MicrodegreesToDegrees(this.readBuffer.ReadSignedInt());

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

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

            return(null);
        }
Ejemplo n.º 8
0
        private static double[] bufferInDegrees(long tileY, sbyte zoom, int enlargementInMeter)
        {
            if (enlargementInMeter == 0)
            {
                return(EPSILON_ZERO);
            }

            double[] epsilons = new double[2];
            double   lat      = MercatorProjection.tileYToLatitude(tileY, zoom);

            epsilons[0] = LatLongUtils.latitudeDistance(enlargementInMeter);
            epsilons[1] = LatLongUtils.longitudeDistance(enlargementInMeter, lat);

            return(epsilons);
        }
Ejemplo n.º 9
0
        private static IList <int?> toCoordinateList(Geometry jtsGeometry)
        {
            Coordinate[] jtsCoords = jtsGeometry.Coordinates;

            List <int?> result = new List <int?>();

            for (int j = 0; j < jtsCoords.Length; j++)
            {
                LatLong geoCoord = new LatLong(jtsCoords[j].y, jtsCoords[j].x, true);
                result.Add(Convert.ToInt32(LatLongUtils.degreesToMicrodegrees(geoCoord.latitude)));
                result.Add(Convert.ToInt32(LatLongUtils.degreesToMicrodegrees(geoCoord.longitude)));
            }

            return(result);
        }
Ejemplo n.º 10
0
        internal static void ReadBoundingBox(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder)
        {
            double minLatitude  = LatLongUtils.MicrodegreesToDegrees(readBuffer.ReadInt());
            double minLongitude = LatLongUtils.MicrodegreesToDegrees(readBuffer.ReadInt());
            double maxLatitude  = LatLongUtils.MicrodegreesToDegrees(readBuffer.ReadInt());
            double maxLongitude = LatLongUtils.MicrodegreesToDegrees(readBuffer.ReadInt());

            try
            {
                mapFileInfoBuilder.boundingBox = new BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude);
            }
            catch (System.ArgumentException e)
            {
                throw new MapFileException(e.Message);
            }
        }
Ejemplo n.º 11
0
 private void ReadMapStartPosition(ReadBuffer readBuffer)
 {
     if (this.HasStartPosition)
     {
         double mapStartLatitude  = LatLongUtils.MicrodegreesToDegrees(readBuffer.ReadInt());
         double mapStartLongitude = LatLongUtils.MicrodegreesToDegrees(readBuffer.ReadInt());
         try
         {
             this.StartPosition = new LatLong(mapStartLatitude, mapStartLongitude, true);
         }
         catch (System.ArgumentException e)
         {
             throw new MapFileException(e.Message);
         }
     }
 }
Ejemplo n.º 12
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: private static org.mapsforge.map.writer.model.TileCoordinate[] getWayBoundingBox(final org.mapsforge.map.writer.model.TDWay way, byte zoomlevel, int enlargementInMeter)
        private static TileCoordinate[] getWayBoundingBox(TDWay way, sbyte zoomlevel, int enlargementInMeter)
        {
            double maxx = double.NegativeInfinity, maxy = double.NegativeInfinity, minx = double.PositiveInfinity, miny = double.PositiveInfinity;

            foreach (TDNode coordinate in way.WayNodes)
            {
                maxy = Math.Max(maxy, LatLongUtils.microdegreesToDegrees(coordinate.Latitude));
                miny = Math.Min(miny, LatLongUtils.microdegreesToDegrees(coordinate.Latitude));
                maxx = Math.Max(maxx, LatLongUtils.microdegreesToDegrees(coordinate.Longitude));
                minx = Math.Min(minx, LatLongUtils.microdegreesToDegrees(coordinate.Longitude));
            }

            double[] epsilonsTopLeft     = computeTileEnlargement(maxy, enlargementInMeter);
            double[] epsilonsBottomRight = computeTileEnlargement(miny, enlargementInMeter);

            TileCoordinate[] bbox        = new TileCoordinate[2];
            bbox[0] = new TileCoordinate((int)MercatorProjection.longitudeToTileX(minx - epsilonsTopLeft[1], zoomlevel), (int)MercatorProjection.latitudeToTileY(maxy + epsilonsTopLeft[0], zoomlevel), zoomlevel);
            bbox[1] = new TileCoordinate((int)MercatorProjection.longitudeToTileX(maxx + epsilonsBottomRight[1], zoomlevel), (int)MercatorProjection.latitudeToTileY(miny - epsilonsBottomRight[0], zoomlevel), zoomlevel);

            return(bbox);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a BoundingBox that is a fixed meter amount larger on all sides (but does not cross date line/poles). </summary>
        /// <param name="meters"> extension (must be >= 0) </param>
        /// <returns> an extended BoundingBox or this (if meters == 0) </returns>
        public virtual BoundingBox ExtendMeters(int meters)
        {
            if (meters == 0)
            {
                return(this);
            }
            else if (meters < 0)
            {
                throw new System.ArgumentException("BoundingBox extend operation does not accept negative values");
            }

            double verticalExpansion   = LatLongUtils.LatitudeDistance(meters);
            double horizontalExpansion = LatLongUtils.LongitudeDistance(meters, Math.Max(Math.Abs(MinLatitude), Math.Abs(MaxLatitude)));

            double minLat = Math.Max(MercatorProjection.LATITUDE_MIN, this.MinLatitude - verticalExpansion);
            double minLon = Math.Max(-180, this.MinLongitude - horizontalExpansion);
            double maxLat = Math.Min(MercatorProjection.LATITUDE_MAX, this.MaxLatitude + verticalExpansion);
            double maxLon = Math.Min(180, this.MaxLongitude + horizontalExpansion);

            return(new BoundingBox(minLat, minLon, maxLat, maxLon));
        }
Ejemplo n.º 14
0
        /// <param name="minLatitude">
        ///            the minimum latitude coordinate in degrees. </param>
        /// <param name="minLongitude">
        ///            the minimum longitude coordinate in degrees. </param>
        /// <param name="maxLatitude">
        ///            the maximum latitude coordinate in degrees. </param>
        /// <param name="maxLongitude">
        ///            the maximum longitude coordinate in degrees. </param>
        /// <exception cref="IllegalArgumentException">
        ///             if a coordinate is invalid. </exception>
        public BoundingBox(double minLatitude, double minLongitude, double maxLatitude, double maxLongitude)
        {
            LatLongUtils.ValidateLatitude(minLatitude);
            LatLongUtils.ValidateLongitude(minLongitude);
            LatLongUtils.ValidateLatitude(maxLatitude);
            LatLongUtils.ValidateLongitude(maxLongitude);

            if (minLatitude > maxLatitude)
            {
                throw new System.ArgumentException("invalid latitude range: " + minLatitude + ' ' + maxLatitude);
            }
            else if (minLongitude > maxLongitude)
            {
                throw new System.ArgumentException("invalid longitude range: " + minLongitude + ' ' + maxLongitude);
            }

            this.MinLatitude  = minLatitude;
            this.MinLongitude = minLongitude;
            this.MaxLatitude  = maxLatitude;
            this.MaxLongitude = maxLongitude;
        }
Ejemplo n.º 15
0
 private static Coordinate toCoordinate(int latitude, int longitude)
 {
     return(new Coordinate(LatLongUtils.microdegreesToDegrees(longitude), LatLongUtils.microdegreesToDegrees(latitude)));
 }
Ejemplo n.º 16
0
 public MockTDNode(double lat, double lon) : base(0, LatLongUtils.degreesToMicrodegrees(lat), LatLongUtils.degreesToMicrodegrees(lon), (short)0, (sbyte)0, null, null)
 {
 }
Ejemplo n.º 17
0
        private IList <PointOfInterest> ProcessPOIs(double tileLatitude, double tileLongitude, int numberOfPois, BoundingBox boundingBox, bool filterRequired)
        {
            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 = this.readBuffer.ReadUTF8EncodedString(SIGNATURE_LENGTH_POI);
                    if (!signaturePoi.StartsWith("***POIStart", StringComparison.Ordinal))
                    {
                        LOGGER.Warn("invalid POI signature: " + signaturePoi);
                        return(null);
                    }
                }

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

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

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

                // bit 1-4 represent the layer
                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 = this.readBuffer.ReadUnsignedInt();
                    if (tagId < 0 || tagId >= poiTags.Length)
                    {
                        LOGGER.Warn("invalid POI tag ID: " + tagId);
                        return(null);
                    }
                    tags.Add(poiTags[tagId]);
                }

                // get the feature bitmask (1 byte)
                sbyte featureByte = this.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(this.readBuffer.ReadUTF8EncodedString())));
                }

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

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

                LatLong position = new LatLong(latitude, longitude);
                // 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);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Creates a new BoundingBox from a comma-separated string of coordinates in the order minLat, minLon, maxLat,
 /// maxLon. All coordinate values must be in degrees.
 /// </summary>
 /// <param name="boundingBoxString">
 ///            the string that describes the BoundingBox. </param>
 /// <returns> a new BoundingBox with the given coordinates. </returns>
 /// <exception cref="IllegalArgumentException">
 ///             if the string cannot be parsed or describes an invalid BoundingBox. </exception>
 public static BoundingBox FromString(string boundingBoxString)
 {
     double[] coordinates = LatLongUtils.ParseCoordinateString(boundingBoxString, 4);
     return(new BoundingBox(coordinates[0], coordinates[1], coordinates[2], coordinates[3]));
 }