Example #1
0
        public override bool Read(GH_IO.Serialization.GH_IReader reader)
        {
            try
            {
                show3d            = reader.GetBoolean("Generate3d");
                individualOutputs = reader.GetBoolean("IndividualOutputs");
                way = reader.GetString("Feature");
                System.Globalization.TextInfo ti = new System.Globalization.CultureInfo("en-US", false).TextInfo;
                wayFT = ElkLib.FeatureType.Building;
                bool tryEnum = Enum.TryParse(ti.ToTitleCase(way), out wayFT);

                if (wayFT == ElkLib.FeatureType.Building)
                {
                    show3dMenuItem.Enabled = true;
                }
                else
                {
                    show3dMenuItem.Enabled = false;
                    show3d = false;
                }

                selectedTypes = new List <string>();
                bool keepGoing = true;
                int  i         = 0;
                while (keepGoing)
                {
                    try
                    {
                        string selection = reader.GetString("SelectedTypes", i);
                        if (selection != null && selection != string.Empty)
                        {
                            selectedTypes.Add(selection);
                        }
                        else
                        {
                            keepGoing = false;
                        }
                    }
                    catch
                    {
                        keepGoing = false;
                    }
                    i++;
                }

                AdjustParams();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("ReadError:\n" + ex.ToString());
            }
            return(base.Read(reader));
        }
Example #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 }
            });
        }