# Looking for methods to work with real world coordinates and lots of data

Discussion in 'Scripting' started by tolgatanriverdi, Aug 1, 2013.

1. ### tolgatanriverdi

Joined:
Jan 30, 2013
Posts:
33
Hello
I've a project which has thousands of buildings location data in real world coordinate system and in my unity project I want to add these building models(in fbx format) to correct places in unity coordinate system and want to show them when I get into that area.
My questions are
1. How can I translate the real world coordinates(latitude,longitude) to unity 3d coordinate system.
2. Which method should I use to add those models into scene

Is there any tutorial or plugin to achive that easily?

Thanks
Tolga

### Unity Technologies

Joined:
Jul 15, 2013
Posts:
16
Hi Tolga,

If I understand correctly your problem, what you are looking for is a method to convert spherical coordinates to cartesian coordinates.
The simple translation is:
x = r * cos(theta) * sin(phi)
y = r * sin(theta) * sin(phi)
z = r * cos(phi)

http://mathworld.wolfram.com/SphericalCoordinates.html

Christophe

3. ### vagos21

Joined:
Sep 3, 2012
Posts:
18
Hello,
your coordinates for latitude and longitude are in the fromat of decimal degrees, or degrees minutes and seconds? if it's the latest you must convert to decimal degrees with this formula:
decDegrees = degrees + mins/60 + secs/3600

do you want your world to be a huge sphere like earth, or do you want it flat? if you want it to be a sphere (i imagine you want to do something like GE?) then you can really use the degrees directly to place your buildings using the formulas groovounet mentioned, phi being your latitude and theta your longitude, r the radius of earth (even though i'd prefer to use a "local area" instead of using huge numbers of meters going around the real earth-that means moving everything around you instead of you moving into 3D space )
so if your project is that huge, you probably want to load objects near the player real time and also destroy them in real time?

4. ### Partel-Lang

Joined:
Jan 2, 2013
Posts:
1,938
Unless you are trying to create a model of the entire Earth, I dont think spherical to cartesian coordinates is the way to handle this. Even if you did, this method would be inaccurate, since the Earth is not a sphere, but an ellipsoid. But if you just have a bunch of buildings in a reasonably small area, like a city, and you need to get them to Unity to fly around, you could simply treat the latitude/longitude as linear 2D units and convert them to metric x/y coordinates (see https://en.wikipedia.org/wiki/Geographic_coordinate_system the chapter about Expressing latitude and longitude as linear units), or ask whoever provided the data to send it to you in whatever projected 2D coordinate system that is commonly used in that area.

About managing the thousands of fbx files and the data, you will have to put together an editor script that can load in that data, find the building asset for each entry and instantiate it in the correct place.

Joined:
Jan 30, 2013
Posts:
33