示例#1
0
 /// <summary>
 /// Adds features from on collection to another.
 /// </summary>
 public static void Add(this NetTopologySuite.Features.FeatureCollection features, NetTopologySuite.Features.FeatureCollection featuresToAdd)
 {
     foreach (var feature in featuresToAdd.Features)
     {
         features.Add(feature);
     }
 }
示例#2
0
        public static Mapsui.Map CreateMap()
        {
            var map = new Mapsui.Map
            {
                BackColor = Mapsui.Styles.Color.Transparent,
                Home      = n => n.NavigateTo(new Mapsui.Geometries.Point(0, 0), 63000)
            };

            // OsmStreamSource source = null;
            // OsmSharp.Geo.Streams.IFeatureStreamSource features = null;
            // System.Collections.Generic.List<IFeature> features = null; ;
            NetTopologySuite.Features.FeatureCollection features = new NetTopologySuite.Features.FeatureCollection();


            // new Mapsui.Providers.MemoryProvider()
            Mapsui.Providers.IProvider source = null; // new Mapsui.Providers.MemoryProvider(features);

            Mapsui.Layers.ILayer layer = new Mapsui.Layers.MemoryLayer
            {
                Style      = null,
                DataSource = source,
                Name       = "Line"
            };

            map.Layers.Add(layer);
            return(map);
        }
        /// <summary>
        /// Creates a GeoJson from all ProjectGeometries in the current project (session has to be set)
        /// </summary>
        /// <returns>GeoJson string</returns>
        private string createGeoJson()
        {
            string projectId = HttpContext.Session.GetString("Project");

            if (projectId == null)
            {
                return("");
            }

            //TODO chb
            //Project myProject = db.Projects.Include(m => m.Geometries).Where(m => m.ProjectId == new Guid(projectId)).FirstOrDefault();
            Project myProject = db.Projects
                                .Include(p => p.ProjectGroups).ThenInclude(m => m.Geometries)
                                .Where(m => m.ProjectId == new Guid(projectId)).FirstOrDefault();

            if (myProject == null)
            {
                return("");
            }

            if (myProject != null)
            {
                NetTopologySuite.Features.FeatureCollection featureCollection = new NetTopologySuite.Features.FeatureCollection();

                //TODO chb
                //foreach (ReferenceGeometry g in myProject.Geometries.Where(m => m.StatusId != StatusEnum.deleted))
                foreach (ReferenceGeometry g in myProject.ProjectGroups.SelectMany(pg => pg.Geometries).Where(g => g.StatusId != StatusEnum.deleted))
                {
                    NetTopologySuite.Features.Feature f = null;
                    if (g.Point != null)
                    {
                        f = getFeature(g, GeomType.Point);
                    }
                    if (g.Line != null)
                    {
                        f = getFeature(g, GeomType.Line);
                    }
                    if (g.Polygon != null)
                    {
                        f = getFeature(g, GeomType.Polygon);
                    }
                    if (f != null)
                    {
                        featureCollection.Add(f);
                    }
                }


                var jsonSerializer = GeoJsonSerializer.Create();
                var sw             = new System.IO.StringWriter();
                jsonSerializer.Serialize(sw, featureCollection);

                return(sw.ToString());
            }
            else
            {
                return(null);// "No project found";
            }
        }
示例#4
0
        private static string ToJson(NetTopologySuite.Features.FeatureCollection featureCollection)
        {
            Newtonsoft.Json.JsonSerializer jsonSerializer = NetTopologySuite.IO.GeoJsonSerializer.Create();
            System.IO.TextWriter           jsonStream     = new System.IO.StringWriter();
            jsonSerializer.Serialize(jsonStream, featureCollection);
            string json = jsonStream.ToInvariantString();

            return(json);
        }
示例#5
0
        static void ReadGeometryStream()
        {
            // let's show you what's going on.
            OsmSharp.Logging.Logger.LogAction = (origin, level, message, parameters) =>
            {
                System.Console.WriteLine(string.Format("[{0}] {1} - {2}", origin, level, message));
            };

            // Download.ToFile("http://files.itinero.tech/data/OSM/planet/europe/luxembourg-latest.osm.pbf", "luxembourg-latest.osm.pbf").Wait();

            using (System.IO.FileStream fileStream = System.IO.File.OpenRead(@"D:\username\Documents\Visual Studio 2017\Projects\OsmTilePrerenderer\OsmTilePrerenderer\Data\monaco-latest.osm.pbf"))
            {
                // create source stream.
                OsmStreamSource source = new PBFOsmStreamSource(fileStream);

                // show progress.
                OsmStreamSource progress = source.ShowProgress();

                // filter all powerlines and keep all nodes.
                System.Collections.Generic.IEnumerable <OsmGeo> filtered =
                    from osmGeo in progress
                    where osmGeo.Type == OsmSharp.OsmGeoType.Node ||
                    (osmGeo.Type == OsmSharp.OsmGeoType.Way && osmGeo.Tags != null && osmGeo.Tags.Contains("power", "line"))
                    select osmGeo;

                // convert to a feature stream.
                // WARNING: nodes that are partof powerlines will be kept in-memory.
                //          it's important to filter only the objects you need **before**
                //          you convert to a feature stream otherwise all objects will
                //          be kept in-memory.

                OsmSharp.Geo.Streams.IFeatureStreamSource features = filtered.ToFeatureSource();

                // filter out only linestrings.
                System.Collections.Generic.IEnumerable <NetTopologySuite.Features.IFeature> lineStrings = from feature in features
                                                                                                          where feature.Geometry is LineString
                                                                                                          select feature;

                // build feature collection.
                NetTopologySuite.Features.FeatureCollection featureCollection = new NetTopologySuite.Features.FeatureCollection();
                foreach (NetTopologySuite.Features.IFeature feature in lineStrings)
                {
                    featureCollection.Add(feature);
                }


                // convert to geojson.
                string json = ToJson(featureCollection);



                // var st = new Mapsui.Providers.MemoryProvider(json);
                System.IO.File.WriteAllText("output.geojson", json);
            }
        }
示例#6
0
        /// <summary>
        /// Converts the given polygon enumerable to a feature collection.
        /// </summary>
        public static NetTopologySuite.Features.FeatureCollection ToFeatureCollection(this IEnumerable <LocalGeo.Polygon> polygons)
        {
            var featureCollection = new NetTopologySuite.Features.FeatureCollection();

            foreach (var polygon in polygons)
            {
                featureCollection.Add(new NetTopologySuite.Features.Feature(
                                          polygon.ToPolygon(), new NetTopologySuite.Features.AttributesTable()));
            }
            return(featureCollection);
        }
示例#7
0
        /// <summary>
        /// Converts the instructions to features.
        /// </summary>
        public static NetTopologySuite.Features.FeatureCollection ToFeatures(this IEnumerable <Instruction> instructions, Route route)
        {
            var featureCollection = new NetTopologySuite.Features.FeatureCollection();

            foreach (var instruction in instructions)
            {
                var attributes = new NetTopologySuite.Features.AttributesTable();
                attributes.AddAttribute("text", instruction.Text);
                attributes.AddAttribute("type", instruction.Type);
                var location = route.Shape[instruction.Shape];
                featureCollection.Add(new NetTopologySuite.Features.Feature(
                                          new NetTopologySuite.Geometries.Point(location.ToCoordinate()), attributes));
            }
            return(featureCollection);
        }
示例#8
0
        /// <summary>
        /// Converts the given tree to a feature collection.
        /// </summary>
        public static NetTopologySuite.Features.FeatureCollection ToFeatureCollection(this Algorithms.Networks.Analytics.Trees.Models.Tree tree)
        {
            var featureCollection = new NetTopologySuite.Features.FeatureCollection();

            foreach (var treeEdge in tree.Edges)
            {
                var attributes = new NetTopologySuite.Features.AttributesTable();
                attributes.AddAttribute("weight1", treeEdge.Weight1.ToInvariantString());
                attributes.AddAttribute("weight2", treeEdge.Weight2.ToInvariantString());
                attributes.AddAttribute("edge", treeEdge.EdgeId.ToInvariantString());
                attributes.AddAttribute("previous_edge", treeEdge.PreviousEdgeId.ToInvariantString());
                featureCollection.Add(new NetTopologySuite.Features.Feature(
                                          treeEdge.ToLineString(), attributes));
            }
            return(featureCollection);
        }