This type of data is not that unusual to have. For an example, let’s say we have an ASCII file of lighting strike information containing records with a time an X and Y coordinate of the strike. It turns out to be fairly simple to get this data into the GTViewer format. One of the benefits of using the GTViewer family of products is that you have a variety of methods for creating data in the GTViewer format. Safe Software’s FME is always an option in cases like this, but if you do not have FME or do not know some of the details of using it with custom formats, it may not be a desirable option. Another option is to use GTViewer’s or GTVx’s OLE Automation (and Visual Basic) to programmatically create any elements you need. And yet another option and the topic for this blog entry is to use GTCreate (one of the tools delivered with the GTViewer SDK).
The approaches for using GTViewer’s and GTVx’s OLE Automation and GTCreate to create data are very similar. In each case, you call a method to generate an element after specifying its symbology characteristics, an optional linkages, and optional embedded data. There are a few guidelines for deciding which tool to use for creating GTViewer data from a custom format. GTViewer and GTVx are good options if you need visual confirmation or any real-time graphical cues as the data is converted. Since both GTViewer and GTVx have display capabilities, they are more appropriate when some form of graphical user interaction or verification is required as part of the data creation. A deciding point here is that GTViewer does not required the GTViewer SDK to develop with whereas GTVx does; however, GTVx has significantly more functionality when it comes to creating data programatically. GTCreate does not have any display capabilities and is usually a better choice when converting large amounts of data where performance is more important. Although GTCreate is a fairly simple tool, it is very powerful and the basis for several of GTI’s conversion tools including the Smallworld, Geodatabase, and G/Technology converters.
To illustrate how to use GTCreate, let’s start with an ASCII data file with the following information on lightning strikes:
6/27/2005 12:42:27 PM, 457382.5, 1515628.5
6/27/2005 12:42:30 PM, 456551.0, 1515066.0
6/27/2005 12:42:47 PM, 457590.4, 1514540.2
Then in Visual Basic, create a form with a Command Button on it and a GTCreate control.
The code for the command button is shown below:
Private Sub Command1_Click()
Dim buffer As String
Dim xValue As Double
Dim yValue As Double
Dim dateValue As String
Dim id As Long
Dim row As Long
' open tabular data file
Open "c:\temp\lightning.txt" For Input As #1
' open GTViewer graphics file
id = GTCreate1.Create("c:\temp\lightning.gtg")
' Loop through each tabular record
row = 0
While Not EOF(1)
Line Input #1, buffer ' read line from file
pos1 = InStr(buffer, ",") ' find first comma
pos2 = InStr(pos1 + 1, buffer, ",") ' find second comma
' parse out data value
dateValue = Left(buffer, pos1 - 1)
xValue = Val(Mid(buffer, pos1 + 1, pos2 - pos1 - 1))
yValue = Val(Mid(buffer, pos2 + 1))
' Draw circle with embedded data at strike
GTCreate1.SetProperties id, 3, 2, 0 ' color, weight, style
GTCreate1.SetFill id, 1 ' fill circle
GTCreate1.SetData id, 1, "\tLightning\aId\v" + Str(row) + _
"\aTime\v" + dateValue
GTCreate1.AddCircle32 id, xValue, yValue, 25000
row = row + 1 ' increment row counter
' close files
This code is very simple. Most of it deals with reading the tabular file and parsing out the values. When this code is run, it produces a file called lightning.gtg. This is a regular GTViewer graphics file and it can be imported as redlines, used as a Category, or merged into an existing Category.
For simplicity, I will just import the .gtg file into GTViewer with Draw/Import and you will see the 3 circles for the lightning strikes:
Since data was embedded on the lightning strike circles, you can also review them with Attribute Info (with no additional effort):
This example is oversimplified, but I hope that it gives you an idea of the power and flexibility you have with a tool like this GTCreate.