talexb has asked for the wisdom of the Perl Monks concerning the following question:

It pains me that I know little about this area of technology, but I guess it's not possible to know everything. A colleague has a bunch of AutoCAD files that have to do with urban planning, and he wants to extract the following information from the equivalent DXF files:

I have had a look at CPAN and haven't really found anything that will help me. My research on DXF tells me that it's a very low-level file, so I'm guessing that the information required may not even be available in the DXF file.

If some monks have comments, thoughts, suggestions about where to begin, I'd appreciate it. Thanks!

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

  • Comment on Parsing DXF files for dimensional information

Replies are listed 'Best First'.
Re: Parsing DXF files for dimensional information
by wjw (Priest) on Nov 17, 2017 at 19:59 UTC

    I dealt with AutoCad and DXF files a lot many years ago. I also searched CPAN and did not find anything that seemed very useful for what you want to do. Further searching landed me here which might be useful as a starting point.

    I am a bit surprised that there are not more modules to deal with the DXF format, but it is what it is.

    The link is to a blog post (I think) which talks about using Python to do something similar to the first requirement you have( not including longitude/latitude), but it might be a place to start...

    My experience with text files like DXF is that one can usually check out the spec and then write a short script to grab that which one wants only. I have done similar with RS274D and RS274X files and some others.

    Hope there is something useful somewhere here... Best of luck.

    ...the majority is always wrong, and always the last to know about it...

    A solution is nothing more than a clearly stated problem...

Re: Parsing DXF files for dimensional information
by roboticus (Chancellor) on Nov 18, 2017 at 13:16 UTC

    talexb:

    Like wjw, I've done a good bit with DXF files some time ago (pre-2K). I'd ask your colleague about what the drawing conventions are. AutoCAD doesn't really care about the concepts the geometry represents, but the people using it do. So you need to find out what conventions they use to represent the different parts of the drawing. In the jobs I recall, most of the interesting concepts were captured using layers, where one layer could be the property boundaries, another layer could be foundations, etc. Some other concepts were indicated by line types as well.

    I've never seen anyone using Lat/Lon in a drawing, so you'll definitely need to translate for at. So you'll need a direction and scale references too, so be sure to ask about that.

    One of the jobs I did used DXF files for locating electrical systems (transformers, power distribution boxes, etc.) so we'd have position. But some of the drawings had the floor name encoded in the drawing name, rather than put anywhere on the drawing itself. So you may have to prepare to merge the drawing data with some external information source, as well.

    Back then, the drawings were by humans / for humans, so you may need several iterations with various examples to capture all the desired information. The drawing technologies have continued to advance, though, so things may not be as finicky now. (In a later robotics job we were extracting sections of ship plans for the purposes of cutting parts and welding hull sections, so we were able to push a bit of rigor into the drawing side of things.)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Parsing DXF files for dimensional information
by hda (Chaplain) on Nov 19, 2017 at 20:53 UTC
    I am not aware of a (pure) Perl solution but I believe you can solve your problem by using the GDAL (www.gdal.org) library. It can open and understand a wide variety of geospatial formats, and you could in principle export from DXF to a format from which you can extract coordinates easily, as for example ShapeFile or GeoJSON.