Solved

Convert 3D models to ECEF?

  • 31 March 2016
  • 5 replies
  • 16 views

Badge

Do you have any Python or TCL code or any example job for converting from a WGS84 3D model to a 3D model with ECEF coordinates?

https://en.wikipedia.org/wiki/ECEF

icon

Best answer by davidcollins 22 April 2016, 00:26

View original

5 replies

Badge

I need to convert lat,long,height coordinates to ECEF coordinates in the 'vertex pool' of a 3D feature, without modifying the 'parts' of the 3D feature. (Visualizer terminology)

I have a Python function that will perform the coordinate conversion.

In a PythonCaller I am able to print out all the vertices that I need to modify, but while reading the API documentation, I have not been able to work out how to modify the list of vertices in the 'vertex pool'.

PythonCaller code for printing the vertices' values ..

geom = feature.getGeometry()
vtcs = geom.numVertices()    # from FMEMesh class
log.logMessageString(str(vtcs))
for i in range(0, vtcs):    log.logMessageString(str(geom.getVertexAt(i)))    # from FMEMesh class
Userlevel 2
Badge +17

Hi @davidcollins, this is a skeleton for the PythonCaller. The strategy is to replace the current mesh with a new mesh which consists of the converted vertex pool and the same parts structure. Please define the "convert" function appropriately to convert coordinates (x, y, z) from WGS84 to ECEF.

import fmeobjects
def processFeature(feature):
    def convert((x, y, z)):
        ###############################################
        # TODO: convert coordinates from WGS84 to ECEF
        ###############################################
        return (x, y, z)

    # Get the current mesh geometry.
    curMesh = feature.getGeometry()
    
    # Create a new mesh geometry,
    # append converted vertex pool to the new mesh,
    # copy every part from the current mesh to the new mesh,
    # set the new mesh to the input feature.
    newMesh = fmeobjects.FMEMesh()
    newMesh.appendVertices([convert(v) for v in curMesh.getVertices()])
    for part in curMesh:
        newMesh.addMeshPart(0, part.getVertexIndices(), None, None)
    feature.setGeometry(newMesh)
Badge

Hi @davidcollins, this is a skeleton for the PythonCaller. The strategy is to replace the current mesh with a new mesh which consists of the converted vertex pool and the same parts structure. Please define the "convert" function appropriately to convert coordinates (x, y, z) from WGS84 to ECEF.

import fmeobjects
def processFeature(feature):
    def convert((x, y, z)):
        ###############################################
        # TODO: convert coordinates from WGS84 to ECEF
        ###############################################
        return (x, y, z)

    # Get the current mesh geometry.
    curMesh = feature.getGeometry()
    
    # Create a new mesh geometry,
    # append converted vertex pool to the new mesh,
    # copy every part from the current mesh to the new mesh,
    # set the new mesh to the input feature.
    newMesh = fmeobjects.FMEMesh()
    newMesh.appendVertices([convert(v) for v in curMesh.getVertices()])
    for part in curMesh:
        newMesh.addMeshPart(0, part.getVertexIndices(), None, None)
    feature.setGeometry(newMesh)

Thanks @takashi.  Has worked brilliantly! :)

For anyone interested in this article ..

I am using the following WGS84 - ECEF conversion, but I think I might need to do some work on it.  http://adore-doris.googlecode.com/svn/trunk/lib/python/basic/projections/ecef.py

For the conversion, I needed scipy, so I installed 64-bit WinPython 2.7 (including the SDK option) and set FME to use this as a 'Custom Python Interpretter'.

To get rid of an 'ImportError: No module named site' error, I needed to ..

  • Run 
    SystemPropertiesAdvanced.exe
     and set system variables ..
    • PYTHONHOME=C:\WinPython27\python-2.7.10.amd64
    • PYTHONPATH=C:\WinPython27\python-2.7.10.amd64\Lib
    • add %PYTHONPATH% to end of PATH system variable 
Badge

Hi @davidcollins, this is a skeleton for the PythonCaller. The strategy is to replace the current mesh with a new mesh which consists of the converted vertex pool and the same parts structure. Please define the "convert" function appropriately to convert coordinates (x, y, z) from WGS84 to ECEF.

import fmeobjects
def processFeature(feature):
    def convert((x, y, z)):
        ###############################################
        # TODO: convert coordinates from WGS84 to ECEF
        ###############################################
        return (x, y, z)

    # Get the current mesh geometry.
    curMesh = feature.getGeometry()
    
    # Create a new mesh geometry,
    # append converted vertex pool to the new mesh,
    # copy every part from the current mesh to the new mesh,
    # set the new mesh to the input feature.
    newMesh = fmeobjects.FMEMesh()
    newMesh.appendVertices([convert(v) for v in curMesh.getVertices()])
    for part in curMesh:
        newMesh.addMeshPart(0, part.getVertexIndices(), None, None)
    feature.setGeometry(newMesh)

I attach development versions of the files.

obj2-collada-neogb.fmw - FME job

neo-gb-5km-devonian.txt (rename to .obj to use - this is a wavefront obj file)

ecef.py - WGS84 to ECEF conversion code

 

These all need to be placed in c:\3D

Badge

Thanks @takashi. Has worked brilliantly! :)

Reply