Thursday, March 24, 2011

Integrating OSM, Navteq and ArcGIS Online with Smallworld

Here are some demo videos showing how you can integrate OpenStreetMap, Navteq and ArcGIS Online (or ESRI Data Appliance) data with Smallworld. The videos only show capabilities. It is up to the user to secure appropriate licensing from the relevant data vendors.





Tuesday, March 15, 2011

How to write a delimited list in Magik

Over the years I have seen lots of approaches to writing a delimited string. They usually involved creating a loop, writing a delimiter after each element in the collection and then finally removing the last delimiter that was added in the loop.

For example, if you have a list of voltages and you want to concatenate them all in a string that is delimited with a comma and a space ", " you could write something like this...

voltage_string << "  "
_for i_volt _over voltages.fast_elements()
_loop
voltage_string +<< i_volt+", "
_finally
voltage_string << voltage_string.subseq(1,voltage_string.size-2)+"."
_endloop


... or you could use the core write_string_with_separator() procedure and write equivalent code like this...

voltage_string << write("  ",
write_string_with_separator(voltages,", "),
".")


I like the latter approach because it is more concise and it very clearly indicates what you are trying to do... write a string with delimiter.

A call for identifying your custom changes

Reviewing code changes is difficult at best, but when reviewing a "basic_change" in Magik, it would be very helpful if the changes were very clearly bracketed with private comments.

For example, you might have an #EMQ like this...

_method some_class.some_method()
## some_method() : some_return_value
##
## does something crazy

_global a

(a.b[c], a.b[d]) << (a.b[d], a.b[c])
_endmethod
$


... which you might want to refactor to be more robust. It would be really, really helpful to future code reviewers if you very explicitly indicated which lines of code you changed. Like this...

_method some_class.some_method()
## some_method() : some_return_value
##
## does something crazy

_global a

# BEGIN CHANGES
#(a.b[c], a.b[d]) << (a.b[d], a.b[c])
_try _with cond
(a.b[c], a.b[d]) << (a.b[d], a.b[c])
_when error
write("!!! EMQ !!!",cond.report_string)
_endtry
# END CHANGES
_endmethod
$


You can see that I actually commented out the original line and then put a copy of the line back in the _try block. This makes it very easy for a reviewer (and text diff tools) to see what has changed. I would not recommend using this approach for your own product code. Source Code control systems can identify these changes for you. What I am more concerned about is cases where you have redefined a core Smallworld method to address some business requirement. Once compiled into the image, it is very difficult to find the original version of the method, so the more that you can document as a customizer, the better it will be for future code readers.

Igor over at MagikEmacs pointed out to me that Alt-c in his extended version of Emacs does exactly this "changed code block" highlighting for you. You can see an example in his Screen-cast #3 at 3:50 where he uses exactly this technique.

Dialog Designer now has a forum

Graham's excellent Dialog Designer now has an online forum. You can join here.

If you are not familiar with Dialog Designer, you should try it out. It is a very slick tool that lets you build GUIs in Magik with a drag-and-drop interface. All the difficult GUI generation code is stubbed out for you and you can focus on building the engine/database behavior.

You can read sworldwatch blog posts about Dialog Designer here.

And it is open-sourced by iFactor Consulting so you have free access to the product! You can read more on the product page here.

Monday, March 14, 2011

How not to define a symbol in Magik

Found in some custom code...

tbl_name << "tx_query".as_symbol()

... should really be...

tbl_name << :tx_query

If you are calling :as_symbol() on a string, that should be a red flag to you that you are doing something wrong. You should really only call :as_symbol() on a variable.

Friday, March 11, 2011

How to find the Magik source file for an exemplar definition

Many of you are likely aware of the object.method(method_name).source_file pattern that you can use to determine the file in which the method definition is contained. But did you know that you could also use the same pattern to find the file location for the actual object exemplar?

For example, in my Web Maps Connector image, I want to figure out where map_view.int!do_render() is actually defined. I can do the following to get that information.

MagikSF> map_view.method(:int!do_render|()|).source_file
$
"C:\ifactor\products\workspace\Virtual_Earth_Connector\trunk\source\patches_z_proposed\p1000001_1_if_vec_map_plugin.magik"

But what if I want to determine how that patch of map_view.int!do_render() has modified the original version of that method? Where can I find that original method definition? While it is not 100% guaranteed, Magik style conventions strongly suggest that object method definitions be kept in the same file as the object's exemplar definition. Great. So all we need to do is find the file in which the def_slotted_exemplar(:map_view) is called. Here is how you do that...

MagikSF> map_view.method(:exemplar).source_file
$
"C:/Smallworld41/product/modules/sw_swaf/map_plugin/source/map_view.magik"


The trick is to request the source file for the special method called :exemplar. Happy debugging!

Monday, March 7, 2011

Evil Magik Question

If you can get your mind around this question on Twitter, let me know. Or better yet, reply to the tweet with your answer and hashtag #swgis.


Thursday, March 3, 2011

converting number units in Magik

I was looking at some 3rd party custom code today and noticed what seemed like really helpful methods...
simple_number_mixin.cm_per_foot
simple_number_mixin.cm_to_feet

I think the 3rd party product developers thought this would be a very convenient method. It definitely is, but the problem is that other product developers working on other components made use of these methods. When the 3rd party product was removed, the other custom components broke. The 3rd party product developers rightly declared these methods as RESTRICTED, so the custom product developers should not have called these methods... but we all know that method classifications are widely ignored.

So, how can you make use core Magik classes to do exactly the same thing? Make use of the class unit_value.

Where the custom code might look like...

53.5.cm_to_feet

... you can do exactly the same thing with supported core functionality...

unit_value.new(53.5,:cm).value_in(:feet)


In the same way that each Magik reference to coordinate should really have a corresponding coordinate_system (another pet peeve of mine), most numbers in Magik should ideally be represented as unit_value objects in order to avoid these customized unit conversion methods.

Wednesday, March 2, 2011

This is not your parents' SIAS client

With the advent of GSS a lot of new client possibilities open up for viewing Smallworld data. This video by GEIS shows their Flash-based client that provides some nice intuitive and interactive functionality. Good job guys!

Tuesday, March 1, 2011

Smallworld + ESRI = GIS Love

Someone pointed out to me recently that ESRI provides some really cool web services that you can host as a data appliance behind your firewall. And with existing WMS SOM functionality or other tile-based Smallworld client code, you can easily expose those ESRI data layers as layers in Smallworld. With a data appliance approach you can host it all in-house. If you decide you don't want to host the server in-house you can probably also arrange to use ESRI's cloud-based web services.

Stop reading here if you don't want to see a commercial appeal. (I don't use Google AdWords on my blog so I have created my own ads :) )

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


iFactor Consulting (my employer) has a really cool product called Web Maps Connector. It was originally built to integrate Bing Maps services into Smallworld. But now it can do so much more... from Commercial map service providers, satellite imagery providers, air-photo suppliers, country-specific map providers, open source data, 3rd party data built on open source data and WMS read capabilities, there is something for everyone. Oh, and now it can also integrate ESRI web services into Smallworld. Request more information at info@ifactorconsulting.com