Introduction
This example shows how a 2D map in latitude and longitude can be converted into a 3D globe.
In this tutorial, we will walk through how to create the workspace shown in the Files section to the right. The workspace takes a shapefile with very generalized country shapes, chops all countries into separate points, calculates 3D coordinates for each point, rebuilds 3D polygons, and extrudes them according to the extrusion vectors also calculated within the workspace.
Step-By-Step Instructions
Part 1: Create Data
1. Open FME Workbench
Open FME Workbench and click New to create a new workspace.
2. Add the Data to the Canvas
Add the “simpleWorld” shapefile to the canvas by downloading the file from the Files section and dragging the file onto the canvas. Click OK.
3. Add an AttributeCreator and a FeatureColorSetter
Add an AttributeCreator and a FeatureColorSetter to the canvas, and connect them in sequence to the simpleWorld reader feature type. Set the FeatureColorSetter Color Scheme parameter to Random. In the AttributeCreator, create three new attributes as follows:
| New Attribute | Attribute Value |
|---|---|
| _layer | countries |
| _radius | 6100 |
| _elevation | 1000 |
4. Creating the Background and Graticule
Add a Creator and another AttributeCreator to the canvas and connect the new AttributeCreator_2 to the Creator. The Creator parameters will be as follows:
- Geometry Source: 2D Min/Max Box
- Coordinate List: -180 -90 180 90
- Number to Create: 1
- Create at End: No
- Creation Instance: _creation_instance
In the AttributeCreator_2, create new attributes as follows:
| New Attribute | Attribute Value |
|---|---|
| _layer | graticule |
| _radius | 6000 |
| _elevation | 1000 |
5. Add a Tiler
Add a Tiler to the workspace and connect it to both the AttributeCreator Output ports. In the Tiler parameters, set Define Tiles By to Dimensions in Ground Units, Starting Corner to lower left, Width (x): 5, Height (y): 5, and the Output Attribute Names will be set to Row: _row and Column: _column, respectively.
6. Validate Geometry
Add a GeometryValidator to the canvas, connect it to the Tiles output port of the Tiler, and change the Set of Issues to Detect to “Basic Integrity”.
7. Creating Polygons and Providing Them with Unique IDs
Add a Deaggregator and a Counter to the canvas, connect the Deaggregator to the Passed output port of the GeometryValidator, and the Counter to the output port of the Deaggregator. Leave all Deaggregator parameters at their defaults. In the Counter, set the Count output attribute to “polyID”.
Part 2: Vertex Recalculation
In this part, we will be recalculating vertices to geocentric coordinates.
1. Add the Chopper
Add a Chopper to the canvas and connect it to the Counter's output port. The Chopper parameters include setting the Mode to By Vertex, Maximum Vertices to 1, and Aggregate Handling to Deaggregate.
2. Add a Counter and CoordinateExtractor
Add another Counter to the canvas and connect it to the Chopper. In the parameters, set the Count Output Attribute to vertexID.
Next, add a CoordinateExtractor and connect it to the Counter_2. The parameters include setting the Mode to Specify Coordinate, the Coordinate Index to 0, and setting the output attributes for X, Y, and Z to long, lat, and _z, respectively.
3. Add an AngleConverter
Connect an AngleConverter to the CoordinateExtractor. In the parameters, set Covert Angles On to Attributes Only. Then select lat and long as the Attributes Containing Angles. Finally, the Source Angle Type is Decimal Degrees, and the Target Angle Type is Radians.
4. Calculate the Geocentric Coordinates
Add another AttributeCreator, in the parameters, create the following three attributes, which will calculate the geocentric coordinates:
| New Attribute | Attribute Value |
|---|---|
| x | @Value(_radius)*cos(@Value(long)+3.14159)*sin(@Value(lat)+3.14159/2.0) |
| y | @Value(_radius)*sin(@Value(long)+3.14159)*sin(@Value(lat)+3.14159/2.0) |
| z | @Value(_radius)*cos(@Value(lat)-3.14159/2.0) |
5. Calculating the Extrusion Vector
Next, we will calculate the extrusion vector using another AttributeCreator. Connect the AttributeCreator_4 to the AttributeCreator_3. In the parameters, create the following three attributes:
| New Attribute | Attribute Value |
|---|---|
| _vector_x | -@Value(_elevation)*cos(@Value(long)+3.14159)*sin(@Value(lat)+3.14159/2.0)/10.0 |
| _vector_y | -@Value(_elevation)*sin(@Value(long)+3.14159)*sin(@Value(lat)+3.14159/2.0)/10.0 |
| _vector_z | -@Value(_elevation)*cos(@Value(lat)-3.14159/2.0)/10.0 |
Note that steps 3 and 4 could be combined into a single AttributeCreator, but were broken into two transformers for clarity.
Part 3: Building Points and Assembling Polygons
1. Build 3D Points
Add a VertexCreator to the canvas and connect it to the AttributeCreator_4; set the “Replace with Point” mode and set the X, Y, and Z values to x, y, and z, respectively. Add a Sorter to the canvas and connect it to the VertexCreator's output. Have the Sorter sorted by:
| Attribute | Alpha/Num | Order |
|---|---|---|
| polyID | Numeric | Ascending |
| vertexID | Numeric | Ascending |
2. Reassembling Polygons
Add a LineBuilder to the canvas and connect it to the Sorter. Add a LineCloser as well and connect it to the Line output port of the LineBuilder. In the LineBuilder parameters, enable Group Processing, then set the Grouped By to polyID. Leave the LineCloser parameters as default.
Part 4: Output
1. Add an AttributeFilter
Add an AttributeFilter to the canvas and connect it to both the Polygon output of the LineBuilder and the output of the LineCloser. In the parameters, set Attributes to Filter By to _layer, then type in graticule and countries as the Possible Attribute Values.
2. Graticule Output
Add a FeatureColorSetter to the graticule output port of the AttributeFilter and set the Unique Color Limit to 1.
The globe can be exported to any format that supports surfaces or meshes, such as SketchUp, 3D PDF, or Autodesk FBX. In this example, we will write to an Adobe 3D PDF and create two destination feature types for both the graticule and the countries.
Add an Adobe 3D PDF writer to the canvas by typing in the canvas “Adobe 3D PDF”, selecting the writer, providing a path and name, with its Layer Definition set to Automatic, and connect it to the FeatureColorSetter_2 output port.
3. Countries Output
Add an Extruder to the canvas and connect it to the country's output port on the AttributeFilter. In the Extruder parameters, set the Direction to Specified. Next, set Extrusion Vector X, Y, and Z to the attributes _vector_x, _vector_y, and _vector_z, respectively.
On the top menu bar, go to Writers > Add Feature Type, to add another Adobe 3D PDF layer; name this Layer countries. Connect the countries writer feature type to the Extruder.
4. Run Workspace and Check your Output
Run the workspace with Feature Caching enabled to view the output in the Visual Preview window or check the output by opening the file in Adobe. The output should look like this:
Input:
Output in Adobe:
Globe Creation Process
Actually, attempts to make digital 3D globes started many years ago, around 1996. At the time, MicroStation 3D capabilities were amazing, and I |wanted to make something really cool. Creating a sphere and covering the surface with an image representing the map of Saint Petersburg, Russia. (1) The globe was quite well received by colleagues, and one local newspaper published an article about the globe and city planners having fun at work.
Wondering how our geography, cartography, or geodesy would look if those who made our planet also made the same error in trigonometry and used a cosine instead of a sine in this simple formula. (2) The next globe was also not quite right - countries didn't want to stick properly to Earth, which made an interesting effect. (3) Eventually, all the problems were resolved, and we got the final globe. (4)
Data Attribution
Data used in this tutorial originates from Safe Software and from example data that came with the MapInfo 2008 install.