Exemple #1
0
        private DirectShape RunBuilding(Document doc, Way building, Dictionary <long?, OsmGeo> allNodes)
        {
            var points = new List <XYZ>();

            foreach (var nodeId in building.Nodes)
            {
                var geometry = allNodes[nodeId];
                if (geometry is Node node)
                {
                    var coords = coordService.GetRevitCoords((double)node.Latitude, (double)node.Longitude);
                    points.Add(coords);
                }
            }

            var curveLoop = new CurveLoop();

            for (int i = 0; i < points.Count - 1; i++)
            {
                Line line = Line.CreateBound(points[i], points[i + 1]);
                curveLoop.Append(line);
            }

            var heightTag  = building.Tags.FirstOrDefault(tag => tag.Key == "height");
            var heightFeet = UnitUtils.ConvertToInternalUnits(3, DisplayUnitType.DUT_METERS);

            if (double.TryParse(heightTag.Value, out double heightMeters))
            {
                heightFeet = UnitUtils.ConvertToInternalUnits(heightMeters, DisplayUnitType.DUT_METERS);
            }

            return(shapeService.Build(doc, new List <CurveLoop> {
                curveLoop
            }, heightFeet, new ElementId(BuiltInCategory.OST_GenericModel)));
        }
Exemple #2
0
        private DirectShape RunBuilding(Document doc, Way building, Dictionary <long?, OsmGeo> allNodes)
        {
            var points = this.geometryService.GetPointsFromNodes(building.Nodes, allNodes);

            if (points == null)
            {
                return(null);
            }

            var curveLoop = new CurveLoop();

            for (int i = 0; i < points.Count - 1; i++)
            {
                Line line = Line.CreateBound(points[i], points[i + 1]);
                curveLoop.Append(line);
            }

            var heightTag  = building.Tags.FirstOrDefault(tag => tag.Key == "height");
            var heightFeet = UnitUtils.ConvertToInternalUnits(3, DisplayUnitType.DUT_METERS);

            if (double.TryParse(heightTag.Value, out double heightMeters))
            {
                heightFeet = UnitUtils.ConvertToInternalUnits(heightMeters, DisplayUnitType.DUT_METERS);
            }

            return(shapeService.Build(doc, new List <CurveLoop> {
                curveLoop
            }, heightFeet, new ElementId(BuiltInCategory.OST_GenericModel)));
        }
Exemple #3
0
        public List <DirectShape> Run(Document doc, List <OsmGeo> everything)
        {
            List <DirectShape> streetsAndIntersections = new List <DirectShape>();

            var osmStreets = everything.Where(n => (n.Type == OsmGeoType.Way &&
                                                    n.Tags != null &&
                                                    n.Tags.ContainsKey("highway") &&
                                                    n is Way)).Cast <Way>().ToList();
            var allNodes = everything.ToDictionary(g => g.Id, g => g);

            var streetDataList       = CreateStreetSegments(osmStreets, allNodes);
            var intersectionDataList = CreateIntersections(streetDataList);

            foreach (var intersData in intersectionDataList)
            {
                var intersection = solidGeometryService
                                   .Build(doc, new List <CurveLoop> {
                    intersData.CurveLoop
                }, osmStore.DefaultStreetThickness, new ElementId(BuiltInCategory.OST_Roads));

                if (intersection == null)
                {
                    continue;
                }

                streetsAndIntersections.Add(intersection);
            }

            foreach (var streetData in streetDataList)
            {
                var start = streetData.Line.GetEndPoint(0);
                var end   = streetData.Line.GetEndPoint(1);
                var mid   = streetData.Line.Evaluate(0.5, true);

                var startIntersect = intersectionDataList.FirstOrDefault(o => o.Origin.IsAlmostEqualTo(start));
                var endIntersect   = intersectionDataList.FirstOrDefault(o => o.Origin.IsAlmostEqualTo(end));

                var newStart = ProjectLineToIntersection(streetData.Line, startIntersect);
                var newEnd   = ProjectLineToIntersection(streetData.Line, endIntersect);

                newStart = newStart ?? start;
                newEnd   = newEnd ?? end;

                if ((newStart - newEnd).GetLength() < 0.005)
                {
                    Console.WriteLine($"Warning: Street services encountered street with lenght less than 0.001 (skipping).");
                    continue;
                }

                var line = Line.CreateBound(newStart, newEnd);

                var lineOff0 = line.CreateOffset(osmStore.DefaultStreetWidth / 2, XYZ.BasisZ);
                var lineOff1 = line.CreateOffset(osmStore.DefaultStreetWidth / 2, -XYZ.BasisZ);

                var curveLoop = lineOff0.CreateCurveLoop(lineOff1);

                var street = solidGeometryService
                             .Build(doc, new List <CurveLoop> {
                    curveLoop
                }, osmStore.DefaultStreetThickness, new ElementId(BuiltInCategory.OST_Roads));
                if (street != null)
                {
                    continue;
                }
                streetsAndIntersections.Add(street);
            }

            return(streetsAndIntersections);
        }