示例#1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get the Rhino Units to properly scale the lat/lon data into Rhino units
            double unitScale = CommonGHProcessors.GetRhinoUnitScale(Rhino.RhinoDoc.ActiveDoc);

            List <OSMPointData> outPoints = new List <OSMPointData>();
            List <OSMPoint>     osmPoints = new List <OSMPoint>();

            LINE.Geometry.Interval2d latlon = new LINE.Geometry.Interval2d();
            string   dataStream             = string.Empty;
            Interval latDomain = new Interval();
            Interval lonDomain = new Interval();

            string path = null;

            DA.GetData(0, ref path);
            if (path != null && System.IO.File.Exists(path))
            {
                ElkLib.NodePreProcess(path, unitScale, out dataStream, out osmPoints, out latlon);
                foreach (OSMPoint op in osmPoints)
                {
                    OSMPointData od = new OSMPointData(op);
                    outPoints.Add(od);
                }
            }

            lonDomain = new Interval(latlon.UMin, latlon.UMax);
            latDomain = new Interval(latlon.VMin, latlon.VMax);

            // Output the data
            DA.SetDataList(0, outPoints);
            DA.SetData(1, path);
            DA.SetData(2, lonDomain);
            DA.SetData(3, latDomain);
        }
        /// <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);
            }
        }
示例#3
0
        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            // Get the lat and long domain
            latMin = Convert.ToDouble(minLatTextBox.Text);
            latMax = Convert.ToDouble(maxLatTextBox.Text);
            lonMin = Convert.ToDouble(minLonTextBox.Text);
            lonMax = Convert.ToDouble(maxLonTextBox.Text);

            LINE.Geometry.Interval2d topoDomain = new LINE.Geometry.Interval2d(lonMin, lonMax, latMin, latMax);

            // output parameters

            string filePath = fileTextBox.Text;


            if (filePath != null && System.IO.File.Exists(filePath))
            {
                List <List <LINE.Geometry.Point3d> > pts = ElkLib.ProcessTopoFile(filePath, unitScale, topoDomain);

                List <XYZ> points = new List <XYZ>();
                for (int i = 0; i < pts.Count; i++)
                {
                    List <LINE.Geometry.Point3d> rowPoints = pts[i];

                    for (int j = 0; j < rowPoints.Count; j++)
                    {
                        XYZ revPoint = new XYZ(rowPoints[j].X, rowPoints[j].Y, rowPoints[j].Z);
                        points.Add(revPoint);
                    }
                }
                using (Transaction trans = new Transaction(doc, "Elk Create Topography"))
                {
                    trans.Start();

                    if (points.Count > 2)
                    {
                        TopographySurface topo = TopographySurface.Create(doc, points);
                    }
                    trans.Commit();
                }
            }
            Close();
        }
示例#4
0
        public static Dictionary <string, object> Location(string filePath)
        {
            List <OSMPoint> osmPoints = new List <OSMPoint>();

            LINE.Geometry.Interval2d latlon = new LINE.Geometry.Interval2d();
            string dataStream = string.Empty;

            // Get the Revit Units for scale
            double scale     = 1.0;
            string exception = null;

            try
            {
                scale = Elk.DynamoCommon.GetRevitUnitScale();
            }
            catch (Exception ex)
            {
                exception = ex.Message;
            }
            if (exception == null)
            {
                exception = scale.ToString();
            }

            string path = filePath;

            if (path != null && System.IO.File.Exists(path))
            {
                ElkLib.NodePreProcess(path, scale, out dataStream, out osmPoints, out latlon);
            }

            return(new Dictionary <string, object>
            {
                { "OSM", osmPoints },
                { "XML", path },
                { "Loc", latlon }
                //{"test", exception}
            });
        }
示例#5
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 }
            });
        }
示例#6
0
        public static Dictionary <string, object> CreateTopo(string filePath, LINE.Geometry.Interval2d location = null)
        {
            // Get the file information
            List <string> fileInfo = Elk.Common.ElkLib.TopoFileInfo(filePath);

            // output parameters
            List <List <Point> > topoPoints = null;
            List <NurbsCurve>    curves     = null;
            NurbsSurface         ns         = null;

            // try to get the scale
            double scale = 1.0;

            try
            {
                scale = Elk.DynamoCommon.GetRevitUnitScale();
            }
            catch { }



            if (filePath != null && System.IO.File.Exists(filePath) && location != null)
            {
                List <List <LINE.Geometry.Point3d> > pts = ElkLib.ProcessTopoFile(filePath, scale, location);

                Point[][] surfPoints = new Point[pts.Count][];
                topoPoints = new List <List <Point> >();
                curves     = new List <NurbsCurve>();
                for (int i = 0; i < pts.Count; i++)
                {
                    List <LINE.Geometry.Point3d> rowPoints = pts[i];
                    List <Point> crvPts = new List <Point>();

                    for (int j = 0; j < rowPoints.Count; j++)
                    {
                        Point dynPoint = Point.ByCoordinates(rowPoints[j].X, rowPoints[j].Y, rowPoints[j].Z);
                        crvPts.Add(dynPoint);
                    }
                    surfPoints[i] = crvPts.ToArray();
                    topoPoints.Add(crvPts);
                    NurbsCurve nc = NurbsCurve.ByPoints(crvPts, 3);

                    //PolyCurve pc = PolyCurve.ByPoints(crvPts, false);
                    curves.Add(nc);
                }
                try
                {
                    ns = NurbsSurface.ByPoints(surfPoints, 3, 3);
                }
                catch
                {
                    ns = null;
                }
                return(new Dictionary <string, object>
                {
                    { "Info", fileInfo },
                    { "Points", topoPoints },
                    { "Curves", curves },
                    { "Surface", ns }
                });
            }
            else
            {
                return(new Dictionary <string, object>
                {
                    { "Info", fileInfo },
                    { "Points", null },
                    { "Curves", null },
                    { "Surface", null }
                });
            }
        }
示例#7
0
        public static Dictionary <string, List <string> > SubFeatures(string feature, List <int> subIndexes)
        {
            #region Get Available Types
            List <string>      availableTemp = new List <string>();
            ElkLib.FeatureType featureType   = ElkLib.ByName(feature);
            switch (featureType)
            {
            case ElkLib.FeatureType.Aerialway:
                availableTemp = Elk.Common.ElkLib.Aerialways;
                break;

            case ElkLib.FeatureType.Aeroway:
                availableTemp = Elk.Common.ElkLib.Aeroways;
                break;

            case ElkLib.FeatureType.Amenity:
                availableTemp = Elk.Common.ElkLib.Amenities;
                break;

            case ElkLib.FeatureType.Barrier:
                availableTemp = Elk.Common.ElkLib.Barrier;
                break;

            case ElkLib.FeatureType.Boundary:
                availableTemp = Elk.Common.ElkLib.Boundary;
                break;

            case ElkLib.FeatureType.Building:
                availableTemp = Elk.Common.ElkLib.Building;
                break;

            case ElkLib.FeatureType.Craft:
                availableTemp = Elk.Common.ElkLib.Craft;
                break;

            case ElkLib.FeatureType.Emergency:
                availableTemp = Elk.Common.ElkLib.Emergency;
                break;

            case ElkLib.FeatureType.Geological:
                availableTemp = Elk.Common.ElkLib.Geological;
                break;

            case ElkLib.FeatureType.Highway:
                availableTemp = Elk.Common.ElkLib.Highway;
                break;

            case ElkLib.FeatureType.Historic:
                availableTemp = Elk.Common.ElkLib.Historic;
                break;

            case ElkLib.FeatureType.Landuse:
                availableTemp = Elk.Common.ElkLib.Landuse;
                break;

            case ElkLib.FeatureType.Leisure:
                availableTemp = Elk.Common.ElkLib.Leisure;
                break;

            case ElkLib.FeatureType.ManMade:
                availableTemp = Elk.Common.ElkLib.ManMade;
                break;

            case ElkLib.FeatureType.Military:
                availableTemp = Elk.Common.ElkLib.Military;
                break;

            case ElkLib.FeatureType.Natural:
                availableTemp = Elk.Common.ElkLib.Natural;
                break;

            case ElkLib.FeatureType.Office:
                availableTemp = Elk.Common.ElkLib.Office;
                break;

            case ElkLib.FeatureType.Place:
                availableTemp = Elk.Common.ElkLib.Places;
                break;

            case ElkLib.FeatureType.Power:
                availableTemp = Elk.Common.ElkLib.Power;
                break;

            case ElkLib.FeatureType.PublicTransport:
                availableTemp = Elk.Common.ElkLib.PublicTransport;
                break;

            case ElkLib.FeatureType.Railway:
                availableTemp = Elk.Common.ElkLib.Railway;
                break;

            case ElkLib.FeatureType.Route:
                availableTemp = Elk.Common.ElkLib.Route;
                break;

            case ElkLib.FeatureType.Shop:
                availableTemp = Elk.Common.ElkLib.Shop;
                break;

            case ElkLib.FeatureType.Sport:
                availableTemp = Elk.Common.ElkLib.Sport;
                break;

            case ElkLib.FeatureType.Tourism:
                availableTemp = Elk.Common.ElkLib.Toursim;
                break;

            case ElkLib.FeatureType.Waterway:
                availableTemp = Elk.Common.ElkLib.Waterway;
                break;
            }
            ;
            availableTemp.Sort();
            #endregion

            List <string> selected = new List <string>();
            if (subIndexes == null || subIndexes.Count == 0)
            {
                selected = new List <string> {
                    "*"
                };
            }
            else
            {
                foreach (int index in subIndexes)
                {
                    try
                    {
                        selected.Add(availableTemp[index]);
                    }
                    catch { }
                }
            }

            return(new Dictionary <string, List <string> >
            {
                { "all", availableTemp },
                { "selected", selected }
            });
        }
示例#8
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)
        {
            // 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);
                        }
                    }
                }
            }
        }