Designing Queries for GIS Map Markers
As a simpler alternative to specifying the SQL query within a Map Set hyperlink, you can use a User Query database item. You can configure the User Query to hold a database query of Geo SCADA Expert database items that are to be displayed on maps. When configured, the context-sensitive menu for the User Query database item will include a Display Query Results option. You can use this menu option to display the query results in a list, which is useful for testing the SQL query. The columns that are shown in the Queries List differ, depending on the SQL columns that you include in the SQL query. Each individual entry within the SQL query list should translate to a Map Marker when shown on a map, although entries with the same location will appear superimposed over each other, obscuring the view of some markers. Data referred to by the SQL query will update whenever the map moves, or at the rate of once per minute (this can be customized in a User Query).
You can use the following SQL column names to define the behavior of the Map Marker:
- FullName (used as the database reference for the Display Query Results menu option)
- Foreground
- Background
- Blink
- ToolTip (this is an optional extension that overrides the text that is shown in the ToolTip that appears when you place the cursor over the Map Marker).
If you want to specify a custom Map Marker to use in place of a default Map Marker symbol, you can also include the following SQL column names:
-
MarkerShape—A case-insensitive string that defines the shape of the Map Marker. Specify one of the following: square, circle, triangle, or diamond. The default is a square (this is the shape that Geo SCADA Expert uses if this column is omitted from the SQL query).
-
MarkerSize—An integer that defines the size of the Map Marker. The default is 10 (this is the Marker size that is used if this column is not included in the SQL query). The minimum value that you can specify is 0 (which hides the Map Marker but enables any marker text to be shown on the map). The maximum value is 100. If the value specified is greater than 100, the value is capped at 100, and if less than zero, the value is set to zero.
-
MarkerText—Use to define the text that is to be displayed near the Map Marker. Specify the Marker text as one of the following:
-
A string that defines the text that is to be displayed near the Map Marker
'Zone 1' AS MarkerText
Displays the text 'Zone 1' near the Map Marker.
-
CHAR(n)
where n is the integer value of the Unicode character that is to be displayed near the Map MarkerCHAR(42) AS MarkerText
Displays an asterisk (*) character near the Map Marker. (42 is the Unicode integer value for an asterisk.)
If Geo SCADA Expert is unable to apply the requested CHAR() value, it will display a question mark in a box in place of the requested character. This appears as an outline box symbol in the Queries List that you can display using the Display Query Results option.
Optionally use a combination of the MarkerText columns below to define other properties for the text or character.
Omit the MarkerText column name and the other MarkerText column names if you do not want to include any marker text.
-
-
MarkerTextColor—An integer that defines the font color of the marker text. Specify this using the same format as that used for the Map Marker foreground and background color. The default is black (0), which is the color that is used if this column is omitted from the SQL query.
-
MarkerTextOutline—An integer that defines the font outline color of the marker text. Specify this using the same format as that used for the Map Marker foreground and background color. The default is white (16777215 (the sum of 255+(255*256)+(255*65536))), which is the color that is used if this column is omitted from the SQL query.
-
MarkerTextSize—An integer that defines the font size of the marker text, in points. The default is 10 (this is the text size that is used if this column is omitted from the SQL query).
-
MarkerTextOffset—An integer that defines the vertical offset of the marker text in relation to the center of the Map Marker symbol. The default is 0 (no offset, the text appears centrally on top of the Map Marker); this is the value that Geo SCADA Expert uses if this column is omitted from the SQL query.
Specify a negative value to position the text above the Map Marker. Specify a positive value to position the text below the Map Marker. The text displays in a horizontal line at the vertical offset specified and is centered horizontally in relation to the Map Marker.
If you want to customize the action that is to occur when a user clicks on a Map Marker on a map, include the following SQL column name:
-
DefaultAction—A case-sensitive string that defines either the action display name or the action Id for the action that Geo SCADA Expert is to perform when a users clicks on the Map Marker. For more information, see Customize the Click Action on a Map Marker. If this column is omitted from the SQL query, or if the requested action cannot be performed, Geo SCADA Expert will perform the relevant default action instead (see About Map Markers).
In order to display the assets on a map, the SQL queries that are within hyperlinks need to contain the following columns as a minimum:
- FullName (the name of the database item – used to generate the default ToolTip and as the database reference for the Display Query Results menu option)
- GISLocation->Latitude (Latitude)
- GISLocation->Longitude (Longitude).
The above columns are parsed based on Name rather than Attribute, allowing for color animations to be customized as required. You can configure the ToolTip to contain HTML formatting codes.
The following map hyperlink uses the AlarmSetCount, AlarmAcceptedCount and AlarmClearedCount variables on the CGroup table to manipulate the Foreground color, adjusting the color used to display the associated map icon for each Group. The ordering of the result set causes the assets with active alarms to display on top of those without, if there is any overlap.
SELECT FULLNAME, FULLNAME || '<br>Highest_Severity:_' || AlarmSeverityDesc as "TOOLTIP", GISLOCATION->LATITUDE, GISLOCATION->LONGITUDE,
CASE WHEN AlarmSetCount > 0 THEN 255
WHEN AlarmAcceptedCount > 0 THEN 255
WHEN AlarmClearedCount > 0 THEN 150*256 ELSE 0 END AS "Foreground", Background,
CASE WHEN AlarmSetCount > 0 THEN 1 ELSE 0 END AS "Blink", AlarmSetCount, AlarmAcceptedCount, AlarmClearedCount
FROM CGROUP
ORDER BY AlarmSetCount, AlarmAcceptedCount, AlarmClearedCount
The color value 255
is red. This is the equivalent of 225+0*256+0*256*256
, but as the green and blue color value elements each equate to 0 there is no need to specify them as 0 is the default for any color value element that is omitted from the SQL query.
The color value 150*256
is the equivalent of 0+150*256+0*256*256
. Again as the red and blue color value elements each equate to 0, there is no need to specify them.
This example results in the display containing a smooth range of colors, as the Map Marker's foreground color is based on the value of a point that is associated with a group’s location:
SELECT g.Id as "Id", g.FullName as "FullName",
g.FullName || '<br>Value: ' || FormatValue (r.Walk Using '0.00') as "Tooltip",
g.GISLOCATION->LATITUDE as "GISLOCATION->LATITUDE", g.GISLOCATION->LONGITUDE as "GISLOCATION->LONGITUDE",
case
when r.Walk < 50 then (cast(r.Walk/100*2*255 as INT) + 255*256)
when r.Walk > 50 then (255 + cast( (100-r.Walk)/100*2*255 as INT)*256)
end as "Foreground",
255+256*255+256*256*255 as "Background", 0 as "Blink"
FROM CGROUP AS g left join CRandom as r on r.ParentGroupId = g.Id
WHERE g.FULLNAME LIKE 'Sites.%'
This example results in custom square Map Markers appearing on a map, overlaid with the marker text 'S'. One marker appears for each Advanced OPC Analog Point that exists in the database. The size of each Map Marker is determined by that particular point's current value (in the range 0-100). The marker position indicates the geographical location of the plant to which each point relates, specified on the relevant configuration Form's Location tab.
SELECT FullName, gislocation->latitude, gislocation->longitude,
Foreground, Blink, Background,
'SQUARE' AS MarkerShape,
'S' AS MarkerText,
0 AS MarkerTextColor,
65280 AS MarkerTextOutline,
15 AS MarkerTextSize,
0 AS MarkerTextOffset,
CurrentValue AS MarkerSize FROM CAdvOPCAnalog
The color value 65280
is the decimal equivalent of 255*256
(or 0+255*256+0*256*256
but as the red and blue color value elements each equate to 0, there is no need to specify them).
Colors
As with colors used elsewhere in expressions in Geo SCADA Expert, you specify Map Marker colors by their RGB (red, green, and blue) values, however the syntax that you use differs slightly to that used for some other color properties and functions.
You use an integer to specify the Map Marker color. You calculate the integer value using the following formula:
<red value>+<green value>+<blue value>
with the required color values being within the following ranges:
0-255
for the red value
0-255*256
for the green value
0-255*65536
(or 0-255*256*256
) for the blue value
If you omit any color value element from a Map Marker color, that color value element will default to 0.
You can specify a Map Marker color using the format shown above, or as a decimal value that comprises the sum of the 3 color value elements (within the range 0 (black) to 16777215 (white), with 16777215 being the sum of 255+(255*256)+(255*65536)).
Aliases
Query column names are not case-sensitive, and should not contain the table name or alias; therefore, a column alias should be used if more than one table is referenced in the query.
If you are using table alias names, then you must also use an alias for the column.
If you use this table alias name:
FROM CGROUP AS g
Then you must also use an alias for the column:
g.GISLOCATION->LATITUDE as "GISLOCATION->LATITUDE"
It is important that you use the AS keyword for table and column aliases. While it can be omitted and the query will still work, the keyword must be present in order for the map to parse the query.
Spacing
Take care with spacing between:
- The SELECT clause and column names
- The FROM clause and table name
- The WHERE clause and column names.
Ensure that there is only one space (or a single new line) between each of the above clauses and column or table names.
You can check the database server log to see how the query has been interpreted and modified.
Linked Tables and Nested SELECTs
The query used by the map display is altered automatically by the map code. This is to limit the data that the query retrieves, because the markers are outside the bounds of the display.
The following additional WHERE clause is added, and if there is an existing WHERE clause it is added with an additional AND keyword:
WHERE (GEOPOSITION WITHIN REGION '5.05811437435571,-95.017822265625' TO '-5.05811437435572,-60.982177734375' )
When using data from external Geo SCADA Expert databases, you may need to use a nested SELECT.
SELECT * FROM ( SELECT TOP (5000)
A.FULLNAME, B.LATITUDE AS "GISLOCATION->LATITUDE", B.LONGITUDE AS "GISLOCATION->LONGITUDE"
FROM
ODBC_GROUP AS A JOIN ODBC_TEST AS B ON A.ID = B.ID
WHERE (A.GISLOCATIONSOURCE = True)
)
You should structure your query slightly differently if either of the following scenarios applies:
-
You want to query a Geo SCADA Expert table that is not part of the default schema (such as a Data Table or Data Grid), in which case, the SQL of that custom table will not support the WITHIN REGION clause
-
The external database is not Geo SCADA Expert, therefore the SQL of the external database will not support the WITHIN REGION clause
With either scenario, you may want to alter the query to prevent the additional WHERE clause from being added. Do this by including an additional WHERE clause within a nested SELECT, although this will affect performance because the map will query all rows. There is a limit of 5000 records in map queries, which will apply in this case.
For more information about custom tables, see Custom Tables - An Overview.
Sorting
Map markers are drawn from the start of the results to the end of those results. By using an ORDER BY clause you can control which markers appear on top. You may want to take advantage of this to display significant locations last, such as those indicating alarm states.
Further Information
Associating User Queries with a Map Set.
Specify the Refresh Interval of a query on a map: see Configuring a User Query.
Working with SQL: see the Geo SCADA Expert Guide to SQL.
Creating a Hyperlink to a Map.
GISLOCATION: see Expressions.expr-primary-location, also see de-reference operator and Geospatial Index in the Geo SCADA Expert Guide to SQL.
GEOPosition: see Expressions.expr-primary-region and see Expressions.expr-primary-location in the Geo SCADA Expert Guide to SQL.