/// <summary> /// Bake a layered table of Nucleus geometry to Rhino equivalent /// geometries and layers /// </summary> /// <param name="geometryTable"></param> /// <returns></returns> public static void BakeAll(GeometryLayerTable geometryTable) { foreach (GeometryLayer layer in geometryTable) { BakeAll(layer); } }
/// <summary> /// Read a list of ESRI Shapefiles and convert and compile them into a /// .NUCLEUS geometry layer table. Each separate filePath will form a separate /// layer in the table. /// </summary> /// <param name="filePaths">A list of filepaths of the shapefiles to be read</param> /// <returns></returns> public GeometryLayerTable ReadShapeFiles(IList <FilePath> filePaths) { var result = new GeometryLayerTable(); foreach (FilePath filePath in filePaths) { result.Add(ReadShapefile(filePath)); } return(result); }
private void DXFLoadButton_Click(object sender, RoutedEventArgs e) { var openDialog = new OpenFileDialog(); openDialog.Title = "Select .DXF file to open"; openDialog.Filter = "AutoCAD DXF File (*.dxf)|*dxf"; if (openDialog.ShowDialog(this) == true) { var dxfReader = new DXFReader(); VertexGeometryCollection geometry = dxfReader.ReadDXF(openDialog.FileName); GeometryLayerTable layers = geometry.Layered(); DXFCanvas.ViewBounds = new BoundingBox(geometry); DXFCanvas.Layers = layers; LayerBox.ItemsSource = layers; } }
/// <summary> /// Write the given geometry table to a DXF file. /// </summary> /// <param name="filePath"></param> /// <param name="geometry"></param> /// <returns></returns> public bool WriteDXF(FilePath filePath, GeometryLayerTable geometry, bool binary = false) { var header = new HeaderVariables(); header.InsUnits = netDxf.Units.DrawingUnits.Meters; DxfDocument doc = new DxfDocument(header); foreach (GeometryLayer layer in geometry) { Layer dxfLayer = ToDXF.Convert(layer); doc.Layers.Add(dxfLayer); foreach (VertexGeometry geo in layer) { foreach (EntityObject entity in ToDXF.Convert(geo)) { entity.Layer = dxfLayer; doc.AddEntity(entity); } } } return(doc.Save(filePath, binary)); }
/// <summary> /// Read a map from a stream /// </summary> /// <param name="stream"></param> /// <param name="originLatLong"></param> /// <param name="layerNames"></param> /// <returns></returns> public GeometryLayerTable ReadMap(Stream stream, AnglePair originLatLong, IList <string> layerNames = null) { var result = new GeometryLayerTable(); var source = new XmlOsmStreamSource(stream); var nodes = new Dictionary <long, OsmSharp.Node>(); var ways = new Dictionary <long, OsmSharp.Way>(); if (layerNames == null) { layerNames = new List <string>(); layerNames.Add("Building"); layerNames.Add("Highway"); } foreach (var element in source) { if (element.Id != null) { if (element.Type == OsmSharp.OsmGeoType.Node) { nodes.Add((long)element.Id, (OsmSharp.Node)element); } else if (element.Type == OsmSharp.OsmGeoType.Way) { ways.Add((long)element.Id, (OsmSharp.Way)element); } //TODO: Relations? } } foreach (var way in ways.Values) { var pts = new List <Vector>(way.Nodes.Length); for (int i = 0; i < way.Nodes.Length; i++) { long nodeID = way.Nodes[i]; if (nodes.ContainsKey(nodeID)) { var node = nodes[nodeID]; pts.Add(node.Position(originLatLong)); } } VertexGeometry geometry = null; if (pts.Count == 2) { geometry = new Line(pts[0], pts[1]); } else if (pts.Count > 2) { geometry = new PolyLine(pts); //TODO: Areas } if (geometry != null) { string layerName = "Miscellaneous"; //Assign layer according to keys: if (way.Tags != null) { foreach (string name in layerNames) { string lName = name.ToLower(); if (way.Tags.ContainsKey(lName)) { string value = way.Tags[lName]; if (LayerSeparator != null && !string.IsNullOrWhiteSpace(value) && value != "yes") { layerName = name + LayerSeparator + value; } else { layerName = name; } break; } } if (ExtrudeBuildings) { if (geometry is Curve && way.Tags.ContainsKey("height")) { string heightTag = way.Tags["height"]; heightTag = heightTag.TrimEnd('m').Trim(); double height; if (double.TryParse(heightTag, out height)) { // TODO: Deal with tags with different units on the end! geometry = new Extrusion((Curve)geometry, new Vector(0, 0, height)); } } if (geometry is Curve && way.Tags.ContainsKey("building:levels")) { // Height not supplied - fall back to storeys: string levelsTag = way.Tags["building:levels"]; double levels; if (double.TryParse(levelsTag, out levels)) { geometry = new Extrusion((Curve)geometry, new Vector(0, 0, levels * StoreyHeight + ByStoreysExtraHeight)); } } if (geometry is Curve && DefaultBuildingHeight > 0 && way.Tags.ContainsKey("building")) { // No indication of height supplied - fall back to default: geometry = new Extrusion((Curve)geometry, new Vector(0, 0, DefaultBuildingHeight)); } } } var layer = result.GetOrCreate(layerName); layer.Add(geometry); } } return(result); }