官术网_书友最值得收藏!

SQL in GIS

SQL is the query language of relational databases. Traditionally, it was developed to help make easy and powerful queries on relational tables. As attribute data can be considered tabular, its power for creating intuitive queries on vector layers is unquestionable. No matter if some modern GIS software uses an object-oriented structure for working with vector data internally, the tradition of using SQL, or near-SQL syntax for creating simple queries has survived. This language is very simple at its core, thus, it is easy to learn and understand. A simple query on a database looks like the following:

    SELECT * FROM table WHERE column = value;

It uses the * wildcard for selecting everything from the table named table, where the content of the column named column matches value. In GIS software, like QGIS, this line can be translated to the following:

    SELECT * FROM layer WHERE column = value;

Furthermore, as basic queries only allow selecting from one layer at a time, the query can be simplified as the software knows exactly which layer we would like to query. Therefore, this simple query can be formulated in a GIS as follows:

    column = value

There is one final thing we have to keep in mind. Based on the software we use, these queries can be turned into real SQL queries used on internal relational tables, or parsed into something entirely different. As a result, GIS software can have their own SQL flavor with their corresponding syntactical conventions. In QGIS, the most important convention is how we differentiate column names from regular strings. Column names are enclosed in double quotation marks, while strings are enclosed in single ones. If we turn the previous query into a QGIS SQL syntax and consider value as a string, we get the following query:

    "column" = 'value'
主站蜘蛛池模板: 秦皇岛市| 武邑县| 疏附县| 永州市| 股票| 洪雅县| 平凉市| 巨鹿县| 沽源县| 清河县| 青海省| 石嘴山市| 织金县| 沅江市| 博白县| 鄂州市| 福安市| 唐山市| 阜新| 长阳| 清苑县| 望都县| 泸州市| 永吉县| 堆龙德庆县| 石棉县| 新巴尔虎左旗| 昌吉市| 肥东县| 巧家县| 法库县| 大新县| 昭苏县| 多伦县| 区。| 九寨沟县| 五大连池市| 东乡族自治县| 濮阳市| 六盘水市| 保德县|