-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polygon Example & Support #183
Comments
Hi You can use the Polyline 3D import {
DxfWriter,
PolylineFlags,
type PolylineVertex,
} from "@tarikjabiri/dxf";
import { writeFileSync } from "node:fs";
const coordinates = [
// polygon number 1
[
[0, 0, 0], // Vertex 1: x, y, z
[0, 10, 0], // Vertex 2: x, y, z
[10, 10, 0], // Vertex 3: x, y, z
[10, 0, 0], // Vertex 4: x, y, z
],
// polygon number 2
[
[5, 0, 0], // Vertex 1: x, y, z
[55, 10, 0], // Vertex 2: x, y, z
[67, 10, 6], // Vertex 3: x, y, z
[87, 0, 8], // Vertex 4: x, y, z
],
];
// No need to duplicate the first vertex to close the polygon
const dxf = new DxfWriter();
const pvs = coordinates.map((vertices) => {
return vertices.map((v) => {
const pv: PolylineVertex = {
point: {
x: v[0],
y: v[1],
z: v[2],
},
};
return pv;
});
});
for (const pv of pvs) {
dxf.addPolyline3D(pv, {
flags: PolylineFlags.Closed,
});
}
writeFileSync("polygons.dxf", dxf.stringify(), {
encoding: "utf-8",
}); |
Important There is no support for geographic coordinates, you need to use projected coordinates using some transformation. |
Do you have any recommendations on a good approach? So what I would need to do is convert these coordinates against something like an EPSG code? then once they are transformed I should just be able to import it into CAD and view it in the region that I have set for the projection? |
proj4js can do transformations, you can use https://epsg.io/ to get the the code for proj4js, you can search for you projection there and select proj4js |
Hello,
Is there an example of create a
.dxf
of multiple polygons? I cant seem to find it in the documentation on how to implement it.Please bear with me here I am new to creations of
.dxf
filesHere is an example of the code I am trying to use as a tester
These would be
lat
andlng
coordinatesThanks very much
The text was updated successfully, but these errors were encountered: