コード例 #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Data storage
            DataTree <Point3d> wayPoints = new DataTree <Point3d>();
            DataTree <string>  wayKeys   = new DataTree <string>();

            // input data
            List <OSMPointData> osmData = new List <OSMPointData>();
            string xmlString            = string.Empty;

            DA.GetDataList(0, osmData);
            DA.GetData(1, ref xmlString);


            if (xmlString != string.Empty && osmData.Count >= 1)
            {
                // Convert the OSMPointData to a standard OSMPoint
                List <OSMPoint> osmPoints = new List <OSMPoint>();
                foreach (OSMPointData opd in osmData)
                {
                    osmPoints.Add(opd.Value);
                }


                List <OSMWay> motorWays = ElkLib.GatherWays("highway", new string[] { "motorway" }, xmlString, osmPoints);
            }
        }
コード例 #2
0
        public static Dictionary <string, object> OSMData(List <OSMPoint> OSM, string File, string featureType, List <string> subTypes)
        {
            // Convert the string featureType to the FeatureType wayFT.
            if (featureType != way)
            {
                wayFT = ElkLib.ByName(featureType);
                way   = wayFT.ToString();
            }

            selectedTypes = subTypes;
            if (selectedTypes.Count == 0)
            {
                selectedTypes = new List <string> {
                    "*"
                };
            }

            way = wayFT.ToString().ToLower();

            // Gather the ways
            List <OSMWay> collectedWays = ElkLib.GatherWays(way, selectedTypes.ToArray(), File, OSM);

            Point[][][]           wayPoints = new Point[collectedWays.Count][][];
            List <List <string> > tags      = new List <List <string> >();

            try
            {
                // Convert all of the OSMPoints to Dynamo Points
                for (int i = 0; i < collectedWays.Count; i++)
                {
                    OSMWay currentWay = collectedWays[i];
                    wayPoints[i] = new Point[currentWay.Points.Count][];
                    for (int j = 0; j < currentWay.Points.Count; j++)
                    {
                        try
                        {
                            List <LINE.Geometry.Point3d> pointList = currentWay.Points[j];
                            wayPoints[i][j] = new Point[pointList.Count];
                            for (int k = 0; k < pointList.Count; k++)
                            {
                                LINE.Geometry.Point3d pt = pointList[k];
                                try
                                {
                                    wayPoints[i][j][k] = Point.ByCoordinates(pt.X, pt.Y, pt.Z);
                                }
                                catch
                                {
                                    wayPoints[i][j][k] = Point.Origin();
                                }
                            }
                        }
                        catch { }
                    }

                    // Collect all of the tags
                    List <string> tagList = new List <string>();
                    foreach (KeyValuePair <string, string> tag in currentWay.Tags)
                    {
                        try
                        {
                            string currentTag = tag.Key + ":" + tag.Value;
                            tagList.Add(currentTag);
                        }
                        catch { }
                    }
                    tags.Add(tagList);
                }
            }
            catch { }

            return(new Dictionary <string, object>
            {
                { "Points", wayPoints },
                { "Keys", tags }
            });
        }
コード例 #3
0
ファイル: OSMComponent.cs プロジェクト: wyldewoods-llc/Elk
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // input data
            List <OSMPointData> osmData = new List <OSMPointData>();
            string xmlString            = string.Empty;

            DA.GetDataList(0, osmData);
            DA.GetData(1, ref xmlString);


            if (xmlString != string.Empty && osmData.Count >= 1)
            {
                // Convert the OSMPointData to a standard OSMPoint
                List <OSMPoint> osmPoints = new List <OSMPoint>();
                foreach (OSMPointData opd in osmData)
                {
                    osmPoints.Add(opd.Value);
                }

                List <OSMWay> collectedWays = ElkLib.GatherWays(way, selectedTypes.ToArray(), xmlString, osmPoints);

                if (!individualOutputs)
                {
                    // Data storage
                    DataTree <Point3d> wayPoints = new DataTree <Point3d>();
                    DataTree <string>  wayKeys   = new DataTree <string>();

                    try
                    {
                        // convert the OSMWays to Rhino Point3d and string objects.
                        for (int i = 0; i < collectedWays.Count; i++)
                        {
                            OSMWay currentWay = collectedWays[i];
                            // Get the points
                            for (int j = 0; j < currentWay.Points.Count; j++)
                            {
                                try
                                {
                                    List <LINE.Geometry.Point3d> pointList = currentWay.Points[j];
                                    foreach (LINE.Geometry.Point3d point in pointList)
                                    {
                                        try
                                        {
                                            wayPoints.Add(new Point3d(point.X, point.Y, point.Z), new Grasshopper.Kernel.Data.GH_Path(new int[] { i, j }));
                                        }
                                        catch
                                        {
                                            wayPoints.Add(Point3d.Origin, new Grasshopper.Kernel.Data.GH_Path(new int[] { i, j }));
                                        }
                                    }
                                }
                                catch
                                {
                                    wayPoints.Add(Point3d.Origin, new Grasshopper.Kernel.Data.GH_Path(new int[] { i, j }));
                                }
                            }
                            //System.Windows.Forms.MessageBox.Show("Before Tags");
                            // Get the Tag Data
                            foreach (KeyValuePair <string, string> tag in currentWay.Tags)
                            {
                                try
                                {
                                    string currentTag = tag.Key + ":" + tag.Value;
                                    wayKeys.Add(currentTag, new Grasshopper.Kernel.Data.GH_Path(new int[] { i, 0 }));
                                }
                                catch
                                {
                                    wayKeys.Add("ERROR", new Grasshopper.Kernel.Data.GH_Path(new int[] { i, 0 }));
                                }
                            }
                        }
                    }
                    catch { }

                    // Just output to two default params.
                    DA.SetDataTree(0, wayPoints);
                    if (show3d && show3dMenuItem.Enabled)
                    {
                        // Generate the 3d buildings
                        DataTree <Brep> buildings = Generate3DBuildings(collectedWays);

                        DA.SetDataTree(1, buildings);
                        DA.SetDataTree(2, wayKeys);
                    }
                    else
                    {
                        DA.SetDataTree(1, wayKeys);
                    }
                }
                else
                {
                    // Organize the ways into their own data trees, leave the key as a single tree, just bump up the path.
                    DataTree <string> wayKeys = new DataTree <string>();

                    for (int h = 0; h < selectedTypes.Count; h++)
                    {
                        // Data storage
                        DataTree <Point3d> wayPoints = new DataTree <Point3d>();
                        try
                        {
                            // convert the OSMWays to Rhino Point3d and string objects.
                            int foundWays = 0;
                            foreach (OSMWay currentWay in collectedWays)
                            {
                                if (currentWay.Type == selectedTypes[h])
                                {
                                    // Get the points
                                    for (int j = 0; j < currentWay.Points.Count; j++)
                                    {
                                        try
                                        {
                                            List <LINE.Geometry.Point3d> pointList = currentWay.Points[j];
                                            foreach (LINE.Geometry.Point3d point in pointList)
                                            {
                                                try
                                                {
                                                    wayPoints.Add(new Point3d(point.X, point.Y, point.Z), new Grasshopper.Kernel.Data.GH_Path(new int[] { foundWays, j }));
                                                }
                                                catch
                                                {
                                                    wayPoints.Add(Point3d.Origin, new Grasshopper.Kernel.Data.GH_Path(new int[] { foundWays, j }));
                                                }
                                            }
                                        }
                                        catch
                                        {
                                            wayPoints.Add(Point3d.Origin, new Grasshopper.Kernel.Data.GH_Path(new int[] { foundWays, j }));
                                        }
                                    }

                                    // Get the Tag Data
                                    foreach (KeyValuePair <string, string> tag in currentWay.Tags)
                                    {
                                        try
                                        {
                                            string currentTag = tag.Key + ":" + tag.Value;
                                            wayKeys.Add(currentTag, new Grasshopper.Kernel.Data.GH_Path(new int[] { h, foundWays, 0 }));
                                        }
                                        catch
                                        {
                                            wayKeys.Add("ERROR", new Grasshopper.Kernel.Data.GH_Path(new int[] { h, foundWays, 0 }));
                                        }
                                    }
                                    foundWays++;
                                }
                            }
                            // Assign the data to outputs
                            DA.SetDataTree(h, wayPoints);
                        }
                        catch { }

                        // Assign the Keys and possibly buildings to the output
                        if (show3d && show3dMenuItem.Enabled)
                        {
                            // Generate the 3d building breps
                            DataTree <Brep> buildings = Generate3DBuildings(collectedWays);

                            DA.SetDataTree(Params.Output.Count - 2, buildings);
                            DA.SetDataTree(Params.Output.Count - 1, wayKeys);
                        }
                        else
                        {
                            DA.SetDataTree(Params.Output.Count - 1, wayKeys);
                        }
                    }
                }
            }
        }