cart: empty [ Login ]

Transform DXF coordinates on the canvas to geographic coordinates

1 
pysaman
10/9/2017 12:30 PM
Hello . I Imported a DXF file using the Cadillib library inside the WPF program Written With C#. Then I turned it into a XAML file by XAMLExporter. I showed XAML file in Canvas. XAMLExporter uses a 4-dimensional matrix for mapping. The question is, what method should I use to look at the UTM coordinates of the Canvas by moving the mouse? This is my Code :
C# Code:
public void ExportToXaml(DxfModel model, string filename) { //Scale to fit in a 400 x 400 rectangle. Matrix4D to2DTransform = DxfUtil.GetScaleTransform( bounds.Corner1, // Minimum point in DXF File bounds.Corner2, // Maximum point in DXF File new Point3D(bounds.Corner1.X, bounds.Corner2.Y, 0d), //Base Refernce Point new Point3D(0d, 400d, 0d), // Minimum point in Canvas new Point3D(400d, 0d, 0d),// Maximum point in Canvas new Point3D(0d, 0d, 0d) // Target Refrense Point in Canvas ); GraphicsConfig graphicsConfig = GraphicsConfig.WhiteBackgroundCorrectForBackColor; using (Stream stream = File.Create(filename)) { using (XmlTextWriter w = new XmlTextWriter(stream, Encoding.UTF8)) { w.Formatting = Formatting.Indented; w.WriteStartElement("Window"); w.WriteAttributeString("xmlns", "http://schemas.microsoft.com/winfx/2006/xaml/presentation"); w.WriteAttributeString("xmlns:x", "http://schemas.microsoft.com/winfx/2006/xaml"); w.WriteStartElement("Canvas"); w.WriteAttributeString("x:Name", "Canvas"); XamlExporter xamlExporter = new XamlExporter(w); xamlExporter.Draw(model, graphicsConfig, to2DTransform); w.WriteEndElement(); // Canvas w.WriteEndElement(); // Page w.Close(); } } }
WPF.PNG
Wout
10/9/2017 12:38 PM
So you need to transform back? You can do that by using the inverse of the projection matrix: call method Matrix4D.GetInverse(). - Wout
pysaman
10/10/2017 7:46 PM
OK.The problem is somewhat solved. But this gives a two-dimensional coordinate. Is there a way to get 3D coordinates. Given that I have a transfer matrix.
Wout
10/10/2017 7:52 PM
You can feed a 3D point (x, y, 0) into the Transform method, and you'll get out a 3D point, but the original 0 z-coordinate is pretty much arbitrary. - Wout
pysaman
10/11/2017 5:22 AM
I dumped the DXF file into a DxfModel object, and my map has no path Over each other. That is, each two-dimensional coordinate has only one z. Is it not possible to read Z coordinates inside the model, given that we have two-dimensional coordinates?
C# Code:
DxfModel model = null; try { string extension = SysIO.Path.GetExtension("MinMap.dxf"); model = String.Compare(extension, ".dwg", StringComparison.OrdinalIgnoreCase) == 0 ? DwgReader.Read("MinMap.dxf") : DxfReader.Read("MinMap.dxf"); boundsCalculator = new BoundsCalculator(); boundsCalculator.GetBounds(model); bounds = boundsCalculator.Bounds; } ExportToXaml(model, "MineMap.xaml");
Wout
10/11/2017 8:18 AM
I really don't understand your question. What do you mean by "read Z coordinates inside the model, given that we have two-dimensional coordinates?" - Wout
pysaman
10/15/2017 8:59 PM
I'm sorry. The basic idea is that we want to work with a DXF file in WPF. Since CadLib does not work with WPF 3D, we have to use other tricks. One way was to turn the DXF file into XAML and work with xaml Pathes. But the problem is that we only have two-dimensional coordinates, while in addition to X and Y, we need to Z. The whole thing we need to Z is when the mouse is along the paths, we show the three-dimensional coordinates of that point . Is there no other way?
1