Beispiel #1
0
        private static string AddFeatures(IReadOnlyList <Feature> features, int fromIndex, int toIndex)
        {
            StringWriter stringWriter = new StringWriter();

            using (GeoJsonWriter writer = new GeoJsonWriter(stringWriter))
            {
                writer.WriteFeatures(features, fromIndex, toIndex);

                stringWriter.Flush();
                return(stringWriter.ToString());
            }
        }
Beispiel #2
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));
        }