We help IT Professionals succeed at work.
Get Started

Extract x,y points from DWG file with a C++ library

290 Views
Last Modified: 2020-04-14
I'm developing a path following application for my robot in order to make it move towards some x,y points in a map.
The points are contained in a DWG file, so I need to find out a way to extract them and use them as navigation waypoints.

I'm using libopencad in C++ since I would like to export the coordinates about the shapes contained in a standard DWG file.

Let's say that I have a DWG file which contains two rectangles:

two rectangles in the DWG file
By using the cadinfo.cpp sample file, I'm successfully able to open the DWG file and extract the coordinates of each line that belongs both rectangles.

Layers count: 1
1. Layer 0 contains 8 geometries
|---------Line---------|
Start Position:     62.5852 -36.5942    0
End Position:   -62.5852    -36.5942    0

Entity color: #ffffffff
|---------Line---------|
Start Position:     62.5852 -36.5942    0
End Position:   62.5852 36.5942 0

Entity color: #ffffffff
|---------Line---------|
Start Position:     62.5852 36.5942 0
End Position:   -62.5852    36.5942 0

Entity color: #ffffffff
|---------Line---------|
Start Position:     -62.5852    -36.5942    0
End Position:   -62.5852    36.5942 0

Entity color: #ffffffff
|---------Line---------|
Start Position:     62.5852 -76.4212    0
End Position:   -62.5852    -76.4212    0

Entity color: #ffffffff
|---------Line---------|
Start Position:     62.5852 -76.4212    0
End Position:   62.5852 -61.4214    0

Entity color: #ffffffff
|---------Line---------|
Start Position:     62.5852 -61.4214    0
End Position:   -62.5852    -61.4214    0

Entity color: #ffffffff
|---------Line---------|
Start Position:     -62.5852    -76.4212    0
End Position:   -62.5852    -61.4214    0

Entity color: #ffffffff

Open in new window



The problem is: how can I understand what are the coordinates that belong to the first rectangle and the coordinates that belong to the second one?
Moreover, there can be more than two rectangles in each DWG file.
Comment
Watch Question
Consulting
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
Unlock 1 Answer and 23 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE