예제 #1
0
        public static Dictionary <OSMTag, List <Brep> > BuildingBrepsFromCoords(ref RequestHandler result, bool outputHeighted)
        {
            var   geometryResult  = new Dictionary <OSMTag, List <Brep> >();
            var   unitScale       = RhinoMath.UnitScale(UnitSystem.Meters, RhinoDoc.ActiveDoc.ModelUnitSystem); // OSM conversion assumes meters
            var   tolerance       = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
            Coord lengthPerDegree = GetDegreesPerAxis(result.MinBounds, result.MaxBounds, unitScale);

            foreach (var entry in result.FoundData)
            {
                geometryResult[entry.Key] = new List <Brep>();

                for (int i = entry.Value.Count - 1; i >= 0; i--)
                {
                    var outlinePoints = new List <Point3d>();
                    foreach (var coord in entry.Value[i].Coords)
                    {
                        outlinePoints.Add(GetPointFromLatLong(coord, lengthPerDegree, result.MinBounds));
                    }

                    var outline = new PolylineCurve(outlinePoints); // Creating a polylinecurve from scratch makes invalid geometry
                    if (!outline.IsClosed)
                    {
                        if (outline.IsClosable(ALLOWABLE_CLOSURE)) // Force-close the curve
                        {
                            outline.MakeClosed(ALLOWABLE_CLOSURE);
                        }
                        else // Skip this curve as no valid Brep can be made
                        {
                            entry.Value.RemoveAt(i);
                            continue;
                        }
                    }

                    var height = GetBuildingHeights.ParseHeight(entry.Value[i].Tags, unitScale);
                    if (outputHeighted && height > 0.0) // Output heighted buildings
                    {
                        var toHeight = new Vector3d(0, 0, height);

                        var envelope = Surface.CreateExtrusion(outline, toHeight);
                        var floor    = Brep.CreatePlanarBreps(outline, tolerance);
                        outline.Translate(toHeight);
                        var roof = Brep.CreatePlanarBreps(outline, tolerance);

                        var volume = Brep.JoinBreps(new Brep[] { floor[0], envelope.ToBrep(), roof[0] }, tolerance);
                        geometryResult[entry.Key].Add(volume[0]);
                    }
                    else if (!outputHeighted && height == 0.0) // Output unheighted buildings
                    {
                        var builtSurface = Brep.CreatePlanarBreps(outline, tolerance);
                        if (builtSurface != null && builtSurface.Length > 0)
                        {
                            geometryResult[entry.Key].Add(builtSurface[0]);
                        }
                    }
                    else // Item wasn't matched, so should be removed from result so its metadata is not output
                    {
                        entry.Value.RemoveAt(i);
                    }
                }

                geometryResult[entry.Key].Reverse(); // We iterated in reverse order, so swap list back to right direction
            }

            return(geometryResult);
        }