예제 #1
0
        /// <summary>
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="hexagonDefinition"></param>
        /// <returns></returns>
        public static int GetDistanceBetweenHexagonLocationUVs(HexagonLocationUV source, HexagonLocationUV destination,
                                                               HexagonDefinition hexagonDefinition)
        {
            var du = destination.U - source.U;
            var dv = destination.V - source.V;

            return(du * dv > 0 ? Math.Abs(du + dv) : Math.Max(Math.Abs(du), Math.Abs(dv)));
        }
예제 #2
0
        /// <summary>
        ///     Obtains the center point (x,y) of an hexagon given its LocationUv (u,v)
        /// </summary>
        /// <param name="location"></param>
        /// <param name="hexagonDefinition"></param>
        /// <returns></returns>
        public static PointXY GetCenterPointXYOfHexagonLocationUV(HexagonLocationUV location,
                                                                  HexagonDefinition hexagonDefinition)
        {
            var x = hexagonDefinition.NarrowWidth * location.U;
            var y = hexagonDefinition.Height * (location.U * 0.5 + location.V);

            return(new PointXY(x, y));
        }
예제 #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);
        }
예제 #4
0
        /// <summary>
        ///     Determines if a specified point (x,y) is inside a given hexagon Location (u,v)
        /// </summary>
        /// <param name="point"></param>
        /// <param name="location"></param>
        /// <param name="hexagonDefinition"></param>
        /// <returns>True if inside the hexagon, false otherwise</returns>
        public static bool IsPointXYInsideHexagonLocationUV(PointXY point, HexagonLocationUV location,
                                                            HexagonDefinition hexagonDefinition)
        {
            var center = GetCenterPointXYOfHexagonLocationUV(location, hexagonDefinition);

            var d  = hexagonDefinition.Diameter;
            var dx = Math.Abs(point.X - center.X) / d;
            var dy = Math.Abs(point.Y - center.Y) / d;
            var a  = 0.25 * Math.Sqrt(3.0);

            return(dy <= a && a * dx + 0.25 * dy <= 0.5 * a);
        }
예제 #5
0
        public static IList <PointXY> GetPointsXYOfHexagon(HexagonLocationUV location, HexagonDefinition hexagonDefinition)
        {
            var center = GetCenterPointXYOfHexagonLocationUV(location, hexagonDefinition);

            return(new List <PointXY>
            {
                new PointXY(center.X - hexagonDefinition.Diameter / 2.0, center.Y),
                new PointXY(center.X - hexagonDefinition.EdgeSize / 2.0, center.Y - hexagonDefinition.Height / 2.0),
                new PointXY(center.X + hexagonDefinition.EdgeSize / 2.0, center.Y - hexagonDefinition.Height / 2.0),
                new PointXY(center.X + hexagonDefinition.Diameter / 2.0, center.Y),
                new PointXY(center.X + hexagonDefinition.EdgeSize / 2.0, center.Y + hexagonDefinition.Height / 2.0),
                new PointXY(center.X - hexagonDefinition.EdgeSize / 2.0, center.Y + hexagonDefinition.Height / 2.0),
                new PointXY(center.X - hexagonDefinition.Diameter / 2.0, center.Y)
            });
        }
예제 #6
0
        private static Hexagon CreateHexagon(GeoData geoData, LayersLoaderTarget[] targets, HexagonLocationUV hexagonLocation, TargetHandler TargetValueStrategy)
        {
            Hexagon hexagon = new Hexagon {
                LocationUV = hexagonLocation, HexagonData = new HexagonData()
            };

            if (targets != null)
            {
                foreach (LayersLoaderTarget target in targets)
                {
                    hexagon.HexagonData[target.Destination] = TargetValueStrategy(geoData, target);
                }
            }

            return(hexagon);
        }