コード例 #1
0
        ///// <summary>
        ///// Converts a list of DataPolygons to a GeoJSON FeatureCollection.
        ///// </summary>
        ///// <param name="dataPolygons">The DataPolygons.</param>
        ///// <returns></returns>
        //public static FeatureCollection ConvertToGeoJSONFeatureCollection(List<DataPolygon> dataPolygons, IUserContext userContext, CoordinateSystem fromCoordinateSystem, CoordinateSystem toCoordinateSystem)
        //{
        //    var featureCollection = new FeatureCollection(new List<Feature>());
        //    DataContext dataContext = new DataContext(userContext);
        //    foreach (DataPolygon dataPolygon in dataPolygons)
        //    {
        //        var pol = dataPolygon.ToPolygon(dataContext);
        //        pol = GisTools.CoordinateConversionManager.GetConvertedPolygon(pol, fromCoordinateSystem, toCoordinateSystem);

        //        Polygon polygon = ConvertToGeoJSONPolygon(dataPolygon);

        //        var feature = new Feature(polygon);
        //        featureCollection.Features.Add(feature);
        //    }

        //    return featureCollection;
        //}

        /// <summary>
        /// Converts a DataPolygon to a GeoJSON polygon.
        /// </summary>
        /// <param name="dataPolygon">The DataPolygon to convert.</param>
        /// <returns></returns>
        public static Polygon ConvertToGeoJSONPolygon(DataPolygon dataPolygon)
        {
            var polygon = new Polygon(new List <LineString>());

            if (dataPolygon.IsNull() || dataPolygon.LinearRings.IsEmpty())
            {
                return(polygon);
            }

            foreach (DataLinearRing dataLinearRing in dataPolygon.LinearRings)
            {
                var coordinates = new List <GeographicPosition>();
                foreach (DataPoint dataPoint in dataLinearRing.Points)
                {
                    var position = new GeographicPosition(dataPoint.X, dataPoint.Y, dataPoint.Z);
                    coordinates.Add(position);
                }
                var lineString = new LineString(coordinates);
                polygon.Coordinates.Add(lineString);
            }
            return(polygon);
        }