Go up one levelGo to Previous Go to Next

Working with Catalogs in C++

A catalog is opened with the static member function open :

 
AstroCatalog* cat = AstroCatalog::open(catalogName); 
if (!cat) { 
    error(...); 
}

The catalog name may be either the long name or the short name , as defined in the catalog config file. The return value from the call to open is a pointer to an AstroCatalog object allocated for the given catalog. It should be deleted with the C++ delete operator when no longer needed.

If the argument passed to AstroCatalog ::open is the name of a file, the return value will point to a subclass of AstroCatalog called LocalCatalog , which works with local catalog files, but otherwise has the same basic interface:

 
AstroCatalog* cat = AstroCatalog::open(fileName); 
if (!cat) { 
    error(...); 
}

For TCS catalogs 1 , the calling sequence is similar:

 
TcsCatalog* cat = TcsCatalog::open(catalogName);

or for local catalogs, if the argument is a file name, the return value points to a derived class of TcsCatalog called TcsLocaCatalog , which is specialized in local TCS catalog files.

The tree below illustrates the class hierarchy of the basic catalog access classes mentioned above:

 

Catalog Queries

There are a number of methods defined in the catalog classes for making queries. The main method is AstroCatalog::query . To use it, you first create an AstroQuery(3) object to represent the query and pass it, along with some other arguments, to the query method:

 
WorldCoords pos(3, 19, 48, 41, 30, 39); 
char* filename = NULL; 
AstroQuery q; 
q.pos(pos);	 
q.radius(0, 10); 
q.maxRows(10); 
AstroObject* result = NULL; 
int numRows = cat->query(q, filename, result);

The AstroQuery object holds the query parameters. Any fields that are not specified are taken to be null and are not used in the query. In the example above, the WorldCoords class (see WorldCoords(3) in the astrotcl package) was used to create the center position argument as 3:19:48 +41:30:39 and a radius range was specified for the query. The table below lists all of the possible query parameters. In most cases, these are the names of two AstroQuery methods - one to set the value (with 1 argument) and another to get the value (with no arguments).

Method

Description

id

Object Id from a previous query (if specified, other fields are ignored)

pos

(a, d, equinox) or (x, y)

Center position for query (class WorldOrImageCoords ).

The value represents either a World Coordinate position ( ra, dec, equinox ) or an image (pixel) coordinate position ( x, y ).

mag

(mag1, mag2)

Min and max magnitude of object. If the catalog does not contain a column called "mag", these are ignored.

radius

(radius1, radius2)

Find objects at a distance of between radius1 and radius2 from the center position, or up to a distance of radius . The units of the radius values depends on the position argument and are either arcmin for a World Coordinate position or image pixels for an image coordinate position.

maxRows

Maximum number of rows to return.

width,

height

Dimensions of area to search (converted internally to a center position and radius). the units are the same as for radius above.

colNames,

numCols

List of column names to return,

the number of column names.

sortCols

numSortCols

sortOrder

List of column names to sort by,

the number of sort columns,

the sort order ( increasing or decreasing ).

condition

searchCols

numSearchCols

minValues

maxValues

These attributes are used together to specify a simple condition to the query. The condition is that the given columns ( searchCols ) have values between minValues and maxValues . All the values are specified in string form, inorder to be type independent, however the comparisons are still done numerically where applicable. Each of the lists have the same length: numSearchCols .

The actual query is made by the query method, which takes the AstroQuery object and an optional filename , does the query and returns the number of objects found. On success, the last parameter, result , is filled with the results of the query.

Query Results

The QueryResult(3) class represents the result of a query and provides methods to get the column names and the value at a given row and column. As an example, the following code would print out the result of the query:

 
char* value; 
for (i = 0; i < result.numRows(); i++)  
    for (j = 0; i < result.numCols(); j++) { 
        if (result->get(i, j, value) == 0)  
            cout << "row: " << i << ", col: " << j << ": " << value << endl; 
        else error(...); 
    }		

}

In this case, the column value was declared as string, however, there are also overloaded methods that extract result values as ints , shorts , floats , doubles , and also as world coordinates (class WorldCoords ) in a given format and equinox.

The following table lists some of the public methods in class QueryResult (and its base class TabTable ) for accessing the results of a query.

Method

Description

numRows

Return the number of result rows.

numCols

Return the number of result columns.

colIndex

Return the result column index for the given result column name.

colNames

Return a pointer to an array of result column names.

get

Get result values by row and column index or name. Multiple overloaded versions of this method support specifying the column as an index or column name and getting the type as an int , short , char , char *, float or double .

getPos

Get the position value for the given result row.

A number of QueryResult methods were not listed here because they are only used to implement local catalogs and are not normally needed otherwise.

TCS Catalogs

For the TcsCatalog(3) class, the columns of the result are fixed, so there is no need to access them as strings. In this case, the call to the query method should pass an object of type TcsQueryResult(3) rather than its parent class QueryResult(3) . The TcsQueryResult class extends the QueryResult class by adding a method to access rows as objects.

 
TcsQueryResult result; 
int num_results = cat->query(q, NULL, result);

Then you can access the query result rows as objects, as in the following example:

 
 
TcsCatalogObject obj;	 // holds data for one row 
for (int row = 0; row < num_results; row++) { 
    if (result.getObj(row, obj) != 0) 
        cout << "row " << row << ": ERROR\n"; 
    else  
        cout << obj << endl; 
}

For TCS catalogs, replace the get(row, ...) methods with the following:

Method

Description

getObj(row, obj)

 

Put the contents of the given query result row in the given object of type class TcsCatalogObject.

A Tcs catalog row always contains the following columns (any missing columns are set to a predefined null value):

Column

Type

Description

id

char*

Object catalog id

ra

double

Alpha coordinate for the target in decimal degrees

dec

double

Delta coordinate for the target in decimal degrees

cooSystem

char*

Equinox system and equinox ("B1950" or "J2000")

epoch

double

Epoch expressed as decimal year

pma

double

Proper Motion Alpha in radians/year (-10.0 to 10.0)

pmd

double

Proper Motion Delta in radians/year (-10.0 to 10.0)

radvel

double

Radial velocity in km/sec (-200000 to 200000)

parallax

double

Parallax in arcseconds (-10000 to 10000)

cooType

char*

Coordinate type as "M" for mean or "A" for apparent character

band

char*

Magnitude wavelength band ("V")

mag

double

Object's magnitude in given band

more

char*

An HTTP URL pointing to more info on the object

preview

char*

An HTTP URL pointing to an image of the object

distance

double

Distance to center of the field

pa

double

Position angle based on center of the field

Other Query Methods

A number of other methods are less generic, but were defined as a convenience for common queries 2 . For example,

 
cat->GetDescription(numCols, colNames);

sets the parameters to the number of columns in the catalog and the column names. If you have an object Id, you can retrieve the object with the following call:

 
status = cat->getObject(id, numCols, colNames, result);

You pass in the object id and the names of the columns you want and get back an array of column values (as strings). To perform a rectangular area query, specifying two points, you can call the following method:

 
status = cat->getArea(numCols, colNames, pos1, pos2, mag1, mag2, maxRows, 
                      filename, numFound, result);

If filename is specified, the result is also copied to the given file. In any case, you can access the result via the result argument, which is filled with the data on return. A circular search, where you specify a center point and one or two radius values, can be made as follows:

 
status = cat->circularSearch(numCols, colNames, pos, radius1, radius2,  
               mag1, mag2, maxRows,filename, numFound, result);

Again, the results are written to the given file, if specified and to the given result object. To get the closest star or object to a given world coordinate point, you can call this method:

 
status = cat->searchClosestStar(numCols, colNames, pos, mag1, mag2, result);

In this case, the result only represents a single object or row. The following table summarizes the public methods of the AstroCatalog class:

Method

Description

open

Open the named catalog and return a pointer to an AstroCatalog object created for it, or NULL if errors occur.

query

Pass a query to the catalog and return a the number of objects found.

Return result as a pointer to a QueryResult object.

numCols

Return the number of columns in the catalog.

colName

Return the name of the given column (0 is first col).

hasCol

Return true if the catalog has the named column.

colIndex

Return the index of the named column.

symbol

Return the symbol entry for the catalog, to use to plot the catalog objects.

nameToWorldCoords

Convert an astronomical object name to World Coordinates using the given name server (SIMBAD by default).

status

Return status (after constructor) for error checking.

name, longName,

shortName

Return the name (longName) or shortName of this catalog.

more

Return true if more than nrows rows would have been available to the last call to query().

getDescription

Return the number of catalog columns andthe column names.

getObject

Return the values for a specific object, given by Id.

getArea

Return the values for objects in a given rectangular area, given by two points.

circularSearch

Return the values for objects in a circular area given by a point and one or two radius values.

searchClosestStar

Return the values for the object closest to the given point.

getError

Return the text of the most recent error message.

getErrorCode

Return the error code (errno value) fro the most recent error message.

clearError

Reset the saved error message to empty.

feedback

Arrange to have feedback information written to a given FILE while waiting for the query to complete (used to display in a user interface).

See the man page AstroCatalog(3) for more details.


1. TCS catalogs are special catalogs with fixed columns, used by the ESO VLT Telescope Control Software.

2. Actually these methods were required to implement the ESO VLT C interface specification for catalog access.


Go up one levelGo to Previous Go to Next

Please send questions or comments to abrighto@eso.org@eso.org.
Copyright © 1998 ESO - European Southern Observatory