Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 
2024 Technology Preview Program

2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations

Archicad C++ API
About Archicad add-on development using the C++ API.

How can I get the Latitude and longitude coordinates coordinate of element?

Not applicable
I set the Latitude and longitude coordinates in the project location.
But when I get the coordinates of the element, the value is the offset by the origin and the unit is meter. How can I get the Latitude and longitude coordinates coordinate of element?

Because ArchiCAD stores coordinates information in meters and related to origin. Latitude and Longitude - is additional assigning to project origin of two numbers.
There is always limitation of floating point number precision - especially when the number becoming too big (that would happen, if we store information of every element in global world coordinate system). It's know problem in ArchiCAD - called "far from origin". There is recommendation not to place ArchiCAD model far from origin, following national CAD rules, because then a lot of bugs might appear and model can be generated wrong - windows can jump out, panels disappear in curtain wall etc.

In your case you need to set additional function, that would recalculate local coordinates into world and convert it into degrees, minutes and seconds.
DevJeer wrote:
How can I get the Latitude and longitude coordinates coordinate of element?
I happen to know about this a little bit.

Lat/Lon coordinates locate you anywhere on the globe, but because it's MUCH more convenient to think of buildings being built on a flat surface than on a sphere, there exists a multitude of coordinate system transformations that go from a spherical coordinates (lat-lon-hgt) to planar cartesian coordinates (x-y-hgt)

Unfortunately, converting from one to the other isn't trivial at all (or at least, it's not a simple C++ function). In fact, because earth isn't a perfect sphere, and because different countries want to define their own standards, there exists a multitude (hundreds) of different coordinate systems to choose from, but essentially, they all take a lat-lon min-max range, and project it on a cartesian grid with min-max range. Look here to understand how a bounded lat-lon area gets converted to a bounded rectilinear area:

And FYI, here's a list of all of the coordinate systems supported around the world:

So, where does this leave you?

Well, first of all, it's not enough to know the lat-lon-height origin of your project. You also need to know which coordinate system you should be using. Do a bit of research to find out which one is most often used in your country/area. You can't just pick any one -- for example it makes no sense to pick an area covering japan if you live in germany.

Anyway, to obtain the lat-lon of your coordinates, do the following:

1) Select a EPSG coordinate system that is valid for your area.
2) Transform your project origin (in lat-lon-height) to the XYH planar coordinate.
3) Add the xy coordinate of your point to your project origin in XYZ planar coordinates. (eg: element.line.begC.x + originX; element.line.begC.y + originY;
4) Make sure you store the result of the addition in doubles (not floats) because the project origin can have huge values when represented as XY.
5) Transform the added result back to lat-lon using the inverse of the transformation you used at step 2.

Of course there are SDKs to help you do this. GDAL is a popular choice for C++ developers. You can look a the tutorials here:

If you are looking for a quick hack, there is another alternative. But it's really a crappy approximations that doesn't work in the general case. But it might be good enough for you if your area is around 50m x 50m.

1) Go here:
2) Select your target coordinate system (do some research vs where you live)
3) Type in your project origin in lat-lon
4) Click Convert. You now have the XY coordinate of your lat-lon origin.
5) Add 1.0 to the X and Y values.
6) Convert back to lat-lon.
7) Subtract the new lat-lon from the original lat-lon.
You now have a correspondence of (1m, 1m) = (deltaLon, deltaLat)

Now, because you have deltaLon/deltaLat increments for 1 meter in each direction, you can easily approximate the lat-lons of any point in your building.

But, I repeat, these ratios are only valid for very small surfaces, and for points close to the projected origin. You can't apply the same deltaLat/Lon ratios for anything that's too far -- even something just 1 km away will be wrong. Things become imprecise very quickly.