Beispiel #1
0
    public static LegLatLng GetLngLatFromPixelCoords(int levelofDetail, int pixx, int pixy)
    {
        TileSystem.PixelXYToLatLong(pixx, pixy, levelofDetail, out var lat, out var lng);
        var rv = new LegLatLng(lat, lng);

        return(rv);
    }
Beispiel #2
0
        public void PixelXYToLatLonTest(int pixelX, int pixelY, int zoom, double lon, double lat)
        {
            var(latitude, longitude) = TileSystem.PixelXYToLatLong(pixelX, pixelY, zoom);

            Assert.Equal(lat, latitude, 2);
            Assert.Equal(lon, longitude, 2);
        }
Beispiel #3
0
        public string GenerateMap(List <object> hexagons, HexagonDefinition hexagonDefinition, int hexagonReferenceZoom)
        {
            GeoJsonWriter writer = new GeoJsonWriter();

            FeatureCollection hexagonCollection = new FeatureCollection();

            foreach (IDictionary <string, object> hexagon in hexagons)
            {
                HexagonLocationUV locationUV = new HexagonLocationUV(Convert.ToInt32(hexagon["U"]), Convert.ToInt32(hexagon["V"]));

                IList <PointXY> points = HexagonUtils.GetPointsXYOfHexagon(locationUV, hexagonDefinition);

                LinearRing ring = new LinearRing(points.Select(pixelCoordinate =>
                {
                    var(latitude, longitude) = TileSystem.PixelXYToLatLong((int)pixelCoordinate.X, (int)pixelCoordinate.Y, hexagonReferenceZoom);

                    return(new Coordinate(longitude, latitude));
                }).ToArray());


                Polygon hexagonPolygon = new Polygon(ring);

                AttributesTable attributes = new AttributesTable(
                    new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>("U", locationUV.U),
                    new KeyValuePair <string, object>("V", locationUV.V),
                });


                foreach (var key in hexagon.Keys)
                {
                    switch (key)
                    {
                    case "U":
                    case "V":
                        break;

                    default:
                        object value = hexagon[key];
                        attributes.Add(key, value);
                        break;
                    }
                }

                Feature hexagonFeature = new Feature(hexagonPolygon, attributes);
                hexagonCollection.Add(hexagonFeature);
            }

            //4. Export Geojson just for the hexagons in this particular tile

            string result = writer.Write(hexagonCollection);

            return(result);
        }
Beispiel #4
0
        static bool DoesQuadTouchBB(double latitude1, double longitude1, double latitude2, double longitude2, string quadKey)
        {
            double top1 = Math.Max(latitude1, latitude2), bottom1 = Math.Min(latitude1, latitude2), left1 = Math.Min(longitude1, longitude2), right1 = Math.Max(longitude1, longitude2);

            TileSystem.QuadKeyToTileXY(quadKey, out int tileX, out int tileY, out int levelOfDetail);
            TileSystem.TileXYToPixelXY(tileX, tileY, out int pixelX, out int pixelY);
            TileSystem.PixelXYToLatLong(pixelX, pixelY, levelOfDetail, out latitude1, out longitude1);
            TileSystem.PixelXYToLatLong(pixelX + 256, pixelY + 256, levelOfDetail, out latitude2, out longitude2);

            double top2 = Math.Max(latitude1, latitude2), bottom2 = Math.Min(latitude1, latitude2), left2 = Math.Min(longitude1, longitude2), right2 = Math.Max(longitude1, longitude2);

            return(left1 < right2 && left2 < right1 && top1 > bottom2 && top2 > bottom1);
        }
Beispiel #5
0
        public void GetBoundsFromTileTest(int zoom, int x, int y, double west, double north, double east, double south)
        {
            var(pixelXLeft, pixelYTop) = TileSystem.TileXYToPixelXY(x, y);
            var(n, w) = TileSystem.PixelXYToLatLong(pixelXLeft, pixelYTop, zoom);

            var(pixelXRight, pixelYBottom) = TileSystem.TileXYToPixelXY(x + 1, y + 1);
            var(s, e) = TileSystem.PixelXYToLatLong(pixelXRight, pixelYBottom, zoom);

            Assert.Equal(west, w, 6);
            Assert.Equal(north, n, 6);
            Assert.Equal(east, e, 6);
            Assert.Equal(south, s, 6);
        }
Beispiel #6
0
        public override Uri GetUri(int x, int y, int zoomLevel)
        {
            if (zoomLevel > 0)
            {
                //var Url = string.Format(UriFormat, Server, MapMode, zoomLevel, x, y);

                double lat;
                double lon;
                int    xPix;
                int    yPix;

                TileSystem.TileXYToPixelXY(x, y, out xPix, out yPix);
                xPix += 256 / 2;
                yPix += 256 / 2;

                TileSystem.PixelXYToLatLong(xPix, yPix, zoomLevel, out lat, out lon);
                var Url = string.Format(UriFormat, lat, lon, zoomLevel, MarkOnMap.Current.Latitude, MarkOnMap.Current.Longitude);
                return(new Uri(Url));
            }
            return(null);
        }
        internal static void Process(HexagonDataToMapArgs opts)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            HexagonDefinition hexagonDefinition = opts.GetHexagonDefinition();

            //1.1. Get Bounding box coordinates

            BoundingBox bb = null;

            if (!string.IsNullOrEmpty(opts.Tile))
            {
                string[] tileSegments = opts.Tile.Split(":");

                if (tileSegments.Length != 3)
                {
                    throw new NotSupportedException($"A tile format must be supplied as z:x:y");
                }

                int zoom  = int.Parse(tileSegments[0]);
                int tileX = int.Parse(tileSegments[1]);
                int tileY = int.Parse(tileSegments[2]);

                var(pixelXLeft, pixelYTop) = TileSystem.TileXYToPixelXY(tileX, tileY);
                var(n, w) = TileSystem.PixelXYToLatLong(pixelXLeft, pixelYTop, opts.HexagonReferenceZoom);

                var(pixelXRight, pixelYBottom) = TileSystem.TileXYToPixelXY(tileX + 1, tileY + 1);
                var(s, e) = TileSystem.PixelXYToLatLong(pixelXRight, pixelYBottom, opts.HexagonReferenceZoom);

                bb = new BoundingBox
                {
                    East  = e,
                    West  = w,
                    North = n,
                    South = s
                };
            }
            else if (!string.IsNullOrEmpty(opts.East) && !string.IsNullOrEmpty(opts.West) &&
                     !string.IsNullOrEmpty(opts.North) && !string.IsNullOrEmpty(opts.South))
            {
                bb = new BoundingBox
                {
                    East  = double.Parse(opts.East),
                    West  = double.Parse(opts.West),
                    North = double.Parse(opts.North),
                    South = double.Parse(opts.South)
                };
            }

            List <object> hexagons;

            var hexagonDataReader = new SQLiteHexagonReader(opts.Input);

            if (bb == null)
            {
                hexagons = hexagonDataReader.Read(opts.DataProperties.ToArray()).ToList();
            }
            else
            {
                var(left, top)     = TileSystem.LatLongToPixelXY(bb.North, bb.West, opts.HexagonReferenceZoom);
                var(right, bottom) = TileSystem.LatLongToPixelXY(bb.South, bb.East, opts.HexagonReferenceZoom);
                hexagons           = hexagonDataReader.Read(left, right, top, bottom, opts.DataProperties.ToArray()).ToList();
            }

            using (StreamWriter outfile = new StreamWriter(opts.Output))
            {
                GeojsonExporter exporter = new GeojsonExporter();

                var result = exporter.GenerateMap(hexagons, hexagonDefinition, opts.HexagonReferenceZoom);
                outfile.Write(result);
            }


            stopwatch.Stop();

            Console.WriteLine($"Process took {stopwatch.ElapsedMilliseconds} ms");
        }