Esempio n. 1
0
        public static string AreasToGeoJson(Collection <Area> naturområder, bool addAreaLayer)
        {
            int featureCollectionEpsg = -1;

            // Assuming that all naturområder have the same projection.
            if (naturområder.Count > 0)
            {
                featureCollectionEpsg = naturområder[0].Geometry.STSrid.Value;
            }

            var features = new List <Feature>();

            foreach (var naturområde in naturområder)
            {
                var feature = AreaToGeoJson(addAreaLayer, naturområde, featureCollectionEpsg);
                features.Add(feature);
            }

            var featureCollection = new GeoJSON.Net.Feature.FeatureCollection(features);

            if (featureCollectionEpsg != -1)
            {
                featureCollection.CRS = new NamedCRS("EPSG:" + featureCollectionEpsg);
            }

            return(GeoJsonWriter.ToGeoJson(featureCollection));
        }
Esempio n. 2
0
        public static string NatureAreasToGeoJson(IEnumerable <INatureAreaGeoJson> natureAreas, bool addId)
        {
            int featureCollectionEpsg = -1;

            if (natureAreas.Any())
            {
                featureCollectionEpsg = natureAreas.First().Area.STSrid.Value;
            }

            foreach (var natureArea in natureAreas.Skip(1))
            {
                if (featureCollectionEpsg == natureArea.Area.STSrid.Value)
                {
                    continue;
                }

                featureCollectionEpsg = -1;
                break;
            }

            var features = new List <Feature>();

            foreach (var natureArea in natureAreas)
            {
                var properties = new Dictionary <string, object>();

                if (natureArea.Count > 0)
                {
                    properties["Count"] = natureArea.Count;
                }

                if (natureArea.Parameters.Count == 1)
                {
                    properties["ColorCode"] = natureArea.Parameters[0].Code;
                }
                else if (natureArea.Parameters.Count > 1)
                {
                    properties["ColorCode"] = "MOSAIC";
                }

                string id = null;
                if (addId)
                {
                    id = natureArea.UniqueId.LocalId.ToString();
                }

                var feature = CreateFeature(natureArea.Area, properties, id, featureCollectionEpsg);
                features.Add(feature);
            }

            var featureCollection = new GeoJSON.Net.Feature.FeatureCollection(features);

            if (featureCollectionEpsg != -1)
            {
                featureCollection.CRS = new NamedCRS("EPSG:" + featureCollectionEpsg);
            }

            return(GeoJsonWriter.ToGeoJson(featureCollection));
        }
Esempio n. 3
0
        public static string GridToGeoJson(Grid grid, bool addGridLayer)
        {
            int featureCollectionEpsg = -1;

            // Assuming that all grid cells have the same projection.
            if (grid.Cells.Count > 0)
            {
                featureCollectionEpsg = grid.Cells[0].Geometry.STSrid.Value;
            }

            Dictionary <string, object> properties = null;
            var features = new List <Feature>();

            foreach (var cell in grid.Cells)
            {
                if (addGridLayer)
                {
                    properties = new Dictionary <string, object> {
                        { "value", cell.Value }
                    };
                }

                var feature = CreateFeature(cell.Geometry, properties, cell.CellId, featureCollectionEpsg);

                features.Add(feature);
            }

            var featureCollection = new GeoJSON.Net.Feature.FeatureCollection(features);

            if (featureCollectionEpsg != -1)
            {
                featureCollection.CRS = new NamedCRS("EPSG:" + featureCollectionEpsg);
            }

            return(GeoJsonWriter.ToGeoJson(featureCollection));
        }