Saturday, April 3, 2010

Converting Coordinate System From Smallworld to FME

When setting up an FME Workspace to interact with Smallworld, you always want to be sure that your SWORLDSWAF reader/writer coordinate system is the same as your Smallworld session's Application Coordinate System (see discussion here). The post "Smallworld/FME Configuration Tips and Tricks" has a link to a slideshow that describes how to make sure that your Smallworld Application Coordinate System and FME SWORLDSWAF reader/writer coordinate systems match . The relevant information starts on slide 31.

I recently discovered another way of figuring out the FME COORDINATE_SYSTEM_DEF that corresponds to a Smallworld coordinate_system.

The FME Workbench's CoordinateSystemDescriptioConvertor Transformer (see example here) can take a Proj.4 coordinate system definition string and convert it into a suitable FME definition.

And how do you get the Proj.4 definition string? Easy... just use the following method.


_pragma(classify_level=basic)
_method coordinate_system_mixin.proj4_string
## proj4_string : string
##
## returns a string that represents self in the Proj.4 format.
## This can be used by coordinate system converters to convert
## self into other representations.

# according to the comments in
# coordinate_system_mixin.new_proj(): "PROJ_TYPE is a symbol
# specifying the projection type. The naming convention is
# similar, but not identical, to that used in the USGS Proj4
# library. See below for details."
#
# because the Magik names are not always identical to the Proj4
# names, we provide a lookup table here.
_local projection_name_lookup << hash_table.new_with(:accurate_tmerc,:tmerc,
:accurate_utm,:utm)

_local (proj,params) << _self.proj_type_and_params

_local info << rope.new()
info.add_last(write_string("+proj=",projection_name_lookup[proj].default(proj)))

_for k,v _over params.fast_keys_and_elements()
_loop
info.add_last(write_string("+",k,"=",v))
_endloop

_local int_str << internal_text_output_stream.new()

int_str.write_list_with_separator(info,space_char)

_return int_str.string

_endmethod
$


The next step will be to write a Magik method that actually converts the Smallworld coordinate_system definition directly into the FME COORDINATE_SYSTEM_DEF string all within Magik. That should allow for some greater flexibility in automating various Smallworld/FME processes.

Enjoy!

1 comment:

bragg.ken said...

Wow I did not know that transformer existed: CoordinateSystemDescriptioConvertor
Cool.

Ken Bragg
Safe Software