Using Attribute Queries

Attribute queries are one of the most commonly used techniques in map generation. They allow users to filter records using a variety of operators and select only the features that should be displayed on the map.

Queries are built using the SELECT command in SQL (Structured Query Language).

The operators = and <> (not equal to) can be used with both numeric and alphanumeric fields. Examples include:

CITY = ‘São Paulo’
CITY <> ‘Campinas’
POPULATION = 12000000

The operators > and < are used with numeric fields. Examples include:

POPULATION < 250000
SALES > 100000

More complex queries involving multiple fields must use logical operators such as AND or OR. For example:

POPULATION < 250000 OR SALES > 100000

Generating maps with attribute queries

In the example shown in Figure 1, the query being performed is:

“Display municipalities where soybean production in 2015 was at least twice the production recorded in 2014.”

The SQL statement is:

SELECT *
FROM prod_soja_munic_shp
WHERE P_SOJA_15 / P_SOJA_14 > 2

Geração de mapa através de consulta por atributo

Figure 1 – Map generation using an attribute query

Result of the attribute query

The result of this query is shown in Figure 2.

To exclude municipalities where soybean production was zero in 2014, an additional condition must be added to the SQL expression:

AND P_SOJA_14 <> 0

The complete query becomes:

SELECT *
FROM prod_soja_munic_shp
WHERE P_SOJA_15 / P_SOJA_14 > 2
AND P_SOJA_14 <> 0

Resultado da consulta por atributo

Figure 2 – Result of the attribute query

The map presented above was generated using the Soybean Production by Municipality (SHP) dataset.

Advantages of attribute queries

Attribute queries are valuable because they allow users to:

  • Select specific geographic features based on predefined criteria.
  • Focus analysis on relevant records.
  • Simplify map visualization.
  • Identify geographic patterns and trends.
  • Generate customized thematic maps.
  • Support decision-making through targeted spatial analysis.

Common SQL operators used in GIS

Operator and description

  • = Equal to
  • <> Not equal to
  • > Greater than
  • < Less than
  • >= Greater than or equal to
  • <= Less than or equal to
  • AND Both conditions must be true
  • OR At least one condition must be true

Applications

Attribute queries are widely used in:

  • Agricultural analysis
  • Market studies
  • Demographic research
  • Environmental monitoring
  • Sales territory management
  • Infrastructure planning
  • Public administration
  • Business intelligence projects

By combining SQL queries with GIS software, users can transform geographic databases into powerful analytical tools that reveal spatial patterns and support more informed decision-making.


The examples shown in this article were generated using Gismaps Viewer, a free GIS application that supports thematic mapping, attribute queries, and spatial analysis. More information and the software download are available at:

Gismaps Viewer Download Page