예제 #1
0
        private static void GetCenterCoordinateValues(AIXMBasicMessage msg)
        {
            var firstMember = msg.hasMember.Select(t =>
                                                   t.Airspace.timeSlice.AirspaceTimeSlice1.geometryComponent.AirspaceGeometryComponent.theAirspaceVolume
                                                   .AirspaceVolume.horizontalProjection.Surface.patches.PolygonPatch.exterior.LinearRing.posList
                                                   .Split(' ')).First();

            mCenterLat = double.Parse(firstMember[1]);
            mCenterLon = double.Parse(firstMember[0]);
        }
예제 #2
0
        private static void CalculateAveragePolylabelCellSize(AIXMBasicMessage msg, out double averageCellSize)
        {
            // Calculate the average polylabel cell size to "guestimate" what the font scaling value should be

            double aggregatedCellSize = 0;
            int    totalTests         = 0;

            foreach (var member in msg.hasMember)
            {
                var polygonTest = new List <MyPoint>();

                var coords = member.Airspace.timeSlice.AirspaceTimeSlice1.geometryComponent.AirspaceGeometryComponent
                             .theAirspaceVolume.AirspaceVolume.horizontalProjection.Surface.patches.PolygonPatch.exterior
                             .LinearRing.posList.Split(' ');

                ReverseArray(coords);

                var interiorCoords = new List <string>();
                if (member.Airspace.timeSlice.AirspaceTimeSlice1.geometryComponent
                    .AirspaceGeometryComponent.theAirspaceVolume.AirspaceVolume.horizontalProjection.Surface.patches
                    .PolygonPatch.interior != null)
                {
                    foreach (var tmp in member.Airspace.timeSlice.AirspaceTimeSlice1.geometryComponent
                             .AirspaceGeometryComponent.theAirspaceVolume.AirspaceVolume.horizontalProjection.Surface.patches
                             .PolygonPatch.interior.Select(interior => interior.LinearRing.posList.Split(' ')))
                    {
                        ReverseArray(tmp);
                        interiorCoords.AddRange(tmp);
                    }
                }

                var combined = new List <LatLng>();
                if (interiorCoords.Count > 0)
                {
                    // If the polygons are overlapping, then we need to do some extra
                    // magic to ensure the mva label is placed in the correct polygon.
                    // To do this, we combine the exterior and interior coordinate groups
                    // which will be used to calculate the polylabel bounding box.
                    var combinedCoords = coords.Concat(interiorCoords).ToArray();

                    for (var i = 0; i < combinedCoords.Length; i += 2)
                    {
                        combined.Add(new LatLng(double.Parse(combinedCoords[i]), double.Parse(combinedCoords[i + 1])));
                    }

                    for (var i = 0; i < combined.Count; i++)
                    {
                        var x1 = i == 0 ? (combined[i].Lat) : (combined[i - 1].Lat);
                        var y1 = i == 0 ? (combined[i].Lon) : (combined[i - 1].Lon);

                        var geo = GeoUtils.GeoToPixels(x1, y1, mCenterLat, mCenterLon);
                        polygonTest.Add(new MyPoint(geo.X, geo.Y));
                    }
                }

                var temp = new List <LatLng>();

                for (var i = 0; i < coords.Length; i += 2)
                {
                    temp.Add(new LatLng(double.Parse(coords[i]), double.Parse(coords[i + 1])));
                }

                for (var i = 0; i < temp.Count; i++)
                {
                    var x1 = i == 0 ? (temp[i].Lat) : (temp[i - 1].Lat);
                    var y1 = i == 0 ? (temp[i].Lon) : (temp[i - 1].Lon);

                    if (interiorCoords.Count == 0)
                    {
                        var geo = GeoUtils.GeoToPixels(x1, y1, mCenterLat, mCenterLon);
                        polygonTest.Add(new MyPoint(geo.X, geo.Y));
                    }
                }

                var poly = PolyLabel.GetPolyLabel(polygonTest);
                aggregatedCellSize += poly.Radius / 100;
                totalTests++;
            }

            averageCellSize = aggregatedCellSize / totalTests;
        }
예제 #3
0
        private static void CreatePolygonsAndText(AIXMBasicMessage msg, StringBuilder sb, double averageCellSize)
        {
            sb.AppendLine(
                $"{mMapName.PadRight(26, ' ')}N000.00.00.000 W000.00.00.000 N000.00.00.000 W000.00.00.000 {mColorKey}");

            foreach (var member in msg.hasMember)
            {
                var polygonPoints = new List <MyPoint>();

                var mva = (member.Airspace.timeSlice.AirspaceTimeSlice1.geometryComponent.AirspaceGeometryComponent
                           .theAirspaceVolume.AirspaceVolume.minimumLimit.Value / 100).ToString("00");

                var coords = member.Airspace.timeSlice.AirspaceTimeSlice1.geometryComponent.AirspaceGeometryComponent
                             .theAirspaceVolume.AirspaceVolume.horizontalProjection.Surface.patches.PolygonPatch.exterior
                             .LinearRing.posList.Split(' ');

                ReverseArray(coords);

                var interiorCoords = new List <string>();
                if (member.Airspace.timeSlice.AirspaceTimeSlice1.geometryComponent
                    .AirspaceGeometryComponent.theAirspaceVolume.AirspaceVolume.horizontalProjection.Surface.patches
                    .PolygonPatch.interior != null)
                {
                    foreach (var tmp in member.Airspace.timeSlice.AirspaceTimeSlice1.geometryComponent
                             .AirspaceGeometryComponent.theAirspaceVolume.AirspaceVolume.horizontalProjection.Surface.patches
                             .PolygonPatch.interior.Select(interior => interior.LinearRing.posList.Split(' ')))
                    {
                        ReverseArray(tmp);
                        interiorCoords.AddRange(tmp);
                    }
                }

                var combined = new List <LatLng>();
                if (interiorCoords.Count > 0)
                {
                    // If the polygons are overlapping, then we need to do some extra
                    // magic to ensure the mva label is placed in the correct polygon.
                    // To do this, we combine the exterior and interior coordinate groups
                    // which will be used to calculate the polylabel bounding box.
                    var combinedCoords = coords.Concat(interiorCoords).ToArray();

                    for (var i = 0; i < combinedCoords.Length; i += 2)
                    {
                        combined.Add(new LatLng(double.Parse(combinedCoords[i]), double.Parse(combinedCoords[i + 1])));
                    }

                    for (var i = 0; i < combined.Count; i++)
                    {
                        var x1 = i == 0 ? (combined[i].Lat) : (combined[i - 1].Lat);
                        var y1 = i == 0 ? (combined[i].Lon) : (combined[i - 1].Lon);

                        var geo = GeoUtils.GeoToPixels(x1, y1, mCenterLat, mCenterLon);
                        polygonPoints.Add(new MyPoint(geo.X, geo.Y));
                    }
                }

                var temp = new List <LatLng>();

                for (var i = 0; i < coords.Length; i += 2)
                {
                    temp.Add(new LatLng(double.Parse(coords[i]), double.Parse(coords[i + 1])));
                }

                for (var i = 0; i < temp.Count; i++)
                {
                    var x1 = i == 0 ? (temp[i].Lat) : (temp[i - 1].Lat);
                    var y1 = i == 0 ? (temp[i].Lon) : (temp[i - 1].Lon);

                    var x2 = i == 0 ? (temp[i + 1].Lat) : (temp[i].Lat);
                    var y2 = i == 0 ? (temp[i + 1].Lon) : (temp[i].Lon);

                    if (interiorCoords.Count == 0)
                    {
                        var geo = GeoUtils.GeoToPixels(x1, y1, mCenterLat, mCenterLon);
                        polygonPoints.Add(new MyPoint(geo.X, geo.Y));
                    }

                    sb.AppendLine(
                        $"{new string(' ', 26)}{x1.ToDMS()} {y1.ToDMS()} {x2.ToDMS()} {y2.ToDMS()} {mColorKey}");
                }

                CreateMvaTextLabels(sb, averageCellSize, mva, polygonPoints);
            }
        }