diff --git a/docs/dev/ASCRead.md b/docs/dev/ASCRead.md new file mode 100644 index 0000000000..539c7ce9d9 --- /dev/null +++ b/docs/dev/ASCRead.md @@ -0,0 +1,213 @@ +--- +layout: docs +title: ASCRead +category: h2drivers +is_function: true +description: ASC → Table +prev_section: h2drivers +next_section: CSVRead +permalink: /docs/dev/ASCRead/ +--- + +### Signatures + +{% highlight mysql %} +ASCRead(VARCHAR path); +ASCRead(VARCHAR path, BOOLEAN deleteTable); + +ASCRead(VARCHAR path, VARCHAR myTable); +ASCRead(VARCHAR path, VARCHAR myTable, BOOLEAN deleteTable); + +ASCRead(VARCHAR path, INTEGER type); +ASCRead(VARCHAR path, INTEGER type, BOOLEAN deleteTable); + +ASCRead(VARCHAR path, VARCHAR myTable, INTEGER type); +ASCRead(VARCHAR path, VARCHAR myTable, INTEGER type, BOOLEAN deleteTable); + +ASCRead(VARCHAR path, VARCHAR myTable, GEOMETRY geomFilter, + INTEGER downScaleInt, BOOLEAN asPolygons); +ASCRead(VARCHAR path, VARCHAR myTable, GEOMETRY geomFilter, + INTEGER downScaleInt, BOOLEAN asPolygons, BOOLEAN deleteTable); +{% endhighlight %} + +### Description + +Import Esri ASCII Raster file as `POINT` or `POLYGON` geometries. + +Pixels are converted into `PointZ` (or `PolygonZ`) geometry with Z as the pixel value (stored as `DOUBLE`). + +Where: + +- `path` : adress of the `.asc` file. This file may be zipped in a `.gz` file *(in this case, the `ASCRead` driver will unzip on the fly the `.gz` file)*, +- `myTable` : name of the output table, +- `type` : indicates whether the `z` data type will be casted to INTEGER (`1`) or left as DOUBLE (`2` - default value), +- `geomFilter` : extract only pixels that intersects the provided geometry envelope (`null` or empty argument to disable filter), +- `downScaleInt` : a coefficient used for exporting less cells (`1` all cells, `2` for size / 2, ...), +- `asPolygons` : if `true`, pixels are converted into polygons (default value = `false` return points), +- `deleteTable` : if `true` and table `tableName` already exists in the database, then table `tableName` will be removed / replaced by the new one. Else (no `deleteTable` parameter or `deleteTable` equal to `false`), throw an exception if the `tableName` already exist. + +### Examples + +We assume that we have the following `.asc` file, named `dem` and placed here: `/home/user/`. + +```java +ncols 4 +nrows 4 +xllcorner 10 +yllcorner 10 +cellsize 5.0 +NODATA_value -9999 + 28 27 26 25 + 27 25 24 23 + 26 23 20 19 + 25 20 18 17 +``` + + +##### 1. Using the `path` + +{% highlight mysql %} +CALL ASCREAD('/home/user/dem.asc'); +{% endhighlight %} + +Returns the table `dem`, with the following values: + +| PK | THE_GEOM | Z | +|:-----:|:--------:|:---:| +| 1 | POINT Z (12.5 27.5 28) | 28.0 | +| 2 | POINT Z (17.5 27.5 27) | 27.0 | +| 3 | POINT Z (22.5 27.5 26) | 26.0 | +| 4 | POINT Z (27.5 27.5 25) | 25.0 | +| 5 | POINT Z (12.5 22.5 27) | 27.0 | +| 6 | POINT Z (17.5 22.5 25) | 25.0 | +| 7 | POINT Z (22.5 22.5 24) | 24.0 | +| 8 | POINT Z (27.5 22.5 23) | 23.0 | +| 9 | POINT Z (12.5 17.5 26) | 26.0 | +| 10 | POINT Z (17.5 17.5 23) | 23.0 | +| 11 | POINT Z (22.5 17.5 20) | 20.0 | +| 12 | POINT Z (27.5 17.5 19) | 19.0 | +| 13 | POINT Z (12.5 12.5 25) | 25.0 | +| 14 | POINT Z (17.5 12.5 20) | 20.0 | +| 15 | POINT Z (22.5 12.5 18) | 18.0 | +| 16 | POINT Z (27.5 12.5 17) | 17.0 | + +**Remark**: If the `dem.asc` has been zipped into a `.gz` file, execute the following instruction: + +{% highlight mysql %} +CALL ASCREAD('/home/user/dem.asc.gz'); +{% endhighlight %} + +In this case, since the `myTable` parameter has not been specified, the resuling table will be named `DEM_ASC`. + +##### 2. Using `myTable` + +{% highlight mysql %} +CALL ASCREAD('/home/user/dem.asc', 'myDEMTable'); +{% endhighlight %} + +Returns the table `myDEMTable` (same as `dem` table) + +| PK | THE_GEOM | Z | +|:-----:|:--------:|:---:| +| 1 | POINT Z (12.5 27.5 28) | 28.0 | +| 2 | POINT Z (17.5 27.5 27) | 27.0 | +| ... | ... | ... | + + +##### 3. Using `type` + +Here we want to convert Z value into INTEGER +{% highlight mysql %} +CALL ASCREAD('/home/user/dem.asc', 1); +{% endhighlight %} + +Returns the table `myDEMTable` + +| PK | THE_GEOM | Z | +|:-----:|:--------:|:---:| +| 1 | POINT Z (12.5 27.5 28) | 28 | +| 2 | POINT Z (17.5 27.5 27) | 27 | +| ... | ... | ... | + + +##### 4. Using `geomFilter` +Here, we want to keep only `POINT`s that intersect this geometry: `POLYGON((15 15, 15 25, 25 25, 25 15, 15 15))` + +{% highlight mysql %} +CALL ASCREAD( + '/home/user/dem.asc', + 'myDEMTable', + ST_GeomFromText('POLYGON((15 15, 15 25, 25 25, 25 15, 15 15))'), + 1, false); +{% endhighlight %} + +Returns the table `myDEMTable`, with the following values: + +| PK | THE_GEOM | Z | +|:----:|:----------------------:|:---:| +| 1 | POINT Z (17.5 22.5 25) | 25.0 | +| 2 | POINT Z (22.5 22.5 24) | 24.0 | +| 3 | POINT Z (27.5 22.5 23) | 23.0 | +| 4 | POINT Z (17.5 17.5 23) | 23.0 | +| 5 | POINT Z (22.5 17.5 20) | 20.0 | +| 6 | POINT Z (27.5 17.5 19) | 19.0 | +| 7 | POINT Z (17.5 12.5 20) | 20.0 | +| 8 | POINT Z (22.5 12.5 18) | 18.0 | +| 9 | POINT Z (27.5 12.5 17) | 17.0 | + + +##### 5. Using `downScaleInt` + +Here we want to divide the matrix size by 2 + +{% highlight mysql %} +CALL ASCREAD('/home/user/dem.asc', 'myDEMTable', null, 2, false); +{% endhighlight %} + +Returns the table `myDEMTable`, with the following values: + +| PK | THE_GEOM | Z | +|:----:|:----------------------:|:---:| +| 1 | POINT Z (12.5 27.5 28) | 28.0 | +| 2 | POINT Z (22.5 27.5 26) | 26.0 | +| 3 | POINT Z (12.5 17.5 26) | 26.0 | +| 4 | POINT Z (22.5 17.5 20) | 20.0 | + + +##### 6. Using `asPolygons` + +Here we want to have a resulting `POLYGON` layer. + +{% highlight mysql %} +CALL ASCREAD('/home/user/dem.asc', 'myDEMTable', null, 1, true); +{% endhighlight %} + +Returns the table `myDEMTable`, with the following values: + + + +| PK | THE_GEOM | Z | +|:----:|:--------------------------------------------------------------:|:---:| +| 1 | POLYGON Z ((10 30 28, 10 25 28, 15 25 28, 15 30 28, 10 30 28)) | 28.0 | +| 2 | POLYGON Z ((15 30 27, 15 25 27, 20 25 27, 20 30 27, 15 30 27)) | 27.0 | +| 3 | POLYGON Z ((20 30 26, 20 25 26, 25 25 26, 25 30 26, 20 30 26)) | 26.0 | +| 4 | POLYGON Z ((25 30 25, 25 25 25, 30 25 25, 30 30 25, 25 30 25)) | 25.0 | +| 5 | POLYGON Z ((10 25 27, 10 20 27, 15 20 27, 15 25 27, 10 25 27)) | 27.0 | +| 6 | POLYGON Z ((15 25 25, 15 20 25, 20 20 25, 20 25 25, 15 25 25)) | 25.0 | +| 7 | POLYGON Z ((20 25 24, 20 20 24, 25 20 24, 25 25 24, 20 25 24)) | 24.0 | +| 8 | POLYGON Z ((25 25 23, 25 20 23, 30 20 23, 30 25 23, 25 25 23)) | 23.0 | +| 9 | POLYGON Z ((10 20 26, 10 15 26, 15 15 26, 15 20 26, 10 20 26)) | 26.0 | +| 10 | POLYGON Z ((15 20 23, 15 15 23, 20 15 23, 20 20 23, 15 20 23)) | 23.0 | +| 11 | POLYGON Z ((20 20 20, 20 15 20, 25 15 20, 25 20 20, 20 20 20)) | 20.0 | +| 12 | POLYGON Z ((25 20 19, 25 15 19, 30 15 19, 30 20 19, 25 20 19)) | 19.0 | +| 13 | POLYGON Z ((10 15 25, 10 10 25, 15 10 25, 15 15 25, 10 15 25)) | 25.0 | +| 14 | POLYGON Z ((15 15 20, 15 10 20, 20 10 20, 20 15 20, 15 15 20)) | 20.0 | +| 15 | POLYGON Z ((20 15 18, 20 10 18, 25 10 18, 25 15 18, 20 15 18)) | 18.0 | +| 16 | POLYGON Z ((25 15 17, 25 10 17, 30 10 17, 30 15 17, 25 15 17)) | 17.0 | + + +##### See also + +* [`CSVRead`](../CSVRead) +* Source code diff --git a/docs/dev/ASCRead_1.png b/docs/dev/ASCRead_1.png new file mode 100644 index 0000000000..57f611dd55 Binary files /dev/null and b/docs/dev/ASCRead_1.png differ diff --git a/docs/dev/CSVRead.md b/docs/dev/CSVRead.md index 2cc1abd87e..da4daa64c9 100644 --- a/docs/dev/CSVRead.md +++ b/docs/dev/CSVRead.md @@ -4,7 +4,7 @@ title: CSVRead category: h2drivers is_function: true description: CSV → Table -prev_section: h2drivers +prev_section: ASCRead next_section: CSVWrite permalink: /docs/dev/CSVRead/ --- diff --git a/docs/dev/CSVWrite.md b/docs/dev/CSVWrite.md index 74476da22a..343fe5da1c 100644 --- a/docs/dev/CSVWrite.md +++ b/docs/dev/CSVWrite.md @@ -26,42 +26,49 @@ CSVWrite(VARCHAR path, VARCHAR sqlSelectTable, target="_blank">documentation on the H2 website.
-Writes a CSV file from the SQL select statement `sqlSelectTable` to -the CSV file specified by `path`. +Writes a CSV file from the SQL select statement `sqlSelectTable` to the CSV file specified by `path`. {% include stringDecode.html %} ### Examples +In the following examples, we are using a table named `AREA` and defined as follow: + {% highlight mysql %} --- Create an example table to use with CSVWrite: CREATE TABLE AREA(THE_GEOM VARCHAR(100), ID INT PRIMARY KEY); INSERT INTO AREA VALUES ('POLYGON((-10 109, 90 9, -10 9, -10 109))', 1), ('POLYGON((90 109, 190 9, 90 9, 90 109))', 2); --- Write it to a CSV file: +{% endhighlight %} + +Write it to a CSV file: +{% highlight mysql %} CALL CSVWrite('/home/user/area.csv', 'SELECT * FROM AREA'); + -- Read it back: SELECT * FROM CSVRead('/home/user/area.csv'); -- Answer: --- | THE_GEOM | ID | --- | ---------------------------------------- | ------ | --- | POLYGON((-10 109, 90 9, -10 9, -10 109)) | 1 | --- | POLYGON((90 109, 190 9, 90 9, 90 109)) | 2 | +-- | THE_GEOM | ID | +-- | ---------------------------------------- | -- | +-- | POLYGON((-10 109, 90 9, -10 9, -10 109)) | 1 | +-- | POLYGON((90 109, 190 9, 90 9, 90 109)) | 2 | +{% endhighlight %} --- Try writing it with a specific charset and field separator: +Try writing it with a specific charset and field separator: + +{% highlight mysql %} CALL CSVWRITE('/home/user/area.csv', - 'SELECT * FROM AREA', 'charset=UTF-8 - fieldSeparator=;'); + 'SELECT * FROM AREA', + 'charset=UTF-8 fieldSeparator=;'); -- Read it back: SELECT * FROM CSVRead('/home/user/area.csv', NULL, 'charset=UTF-8 fieldSeparator=;'); -- Answer: --- | THE_GEOM | ID | --- | ---------------------------------------- | ------ | --- | POLYGON((-10 109, 90 9, -10 9, -10 109)) | 1 | --- | POLYGON((90 109, 190 9, 90 9, 90 109)) | 2 | +-- | THE_GEOM | ID | +-- | ---------------------------------------- | -- | +-- | POLYGON((-10 109, 90 9, -10 9, -10 109)) | 1 | +-- | POLYGON((90 109, 190 9, 90 9, 90 109)) | 2 | {% endhighlight %} ##### See also diff --git a/docs/dev/DBFRead.md b/docs/dev/DBFRead.md index 8936b72190..75eea1718b 100644 --- a/docs/dev/DBFRead.md +++ b/docs/dev/DBFRead.md @@ -13,18 +13,28 @@ permalink: /docs/dev/DBFRead/ {% highlight mysql %} DBFRead(VARCHAR path); +DBFRead(VARCHAR path, BOOLEAN deleteTable); + DBFRead(VARCHAR path, VARCHAR tableName); +DBFRead(VARCHAR path, VARCHAR tableName, BOOLEAN deleteTable); + DBFRead(VARCHAR path, VARCHAR tableName, VARCHAR fileEncoding); +DBFRead(VARCHAR path, VARCHAR tableName, VARCHAR fileEncoding, + BOOLEAN deleteTable); {% endhighlight %} ### Description -Reads the file specified by `path` as a [dBase][wiki] file and -copies its contents into a new table `tableName` in the database. -Define `fileEncoding` to force encoding (useful when the header is -missing encoding information). +Reads the file specified by `path` as a [dBase][wiki] file and copies its contents into a new table `tableName` in the database. + +A new column named `PK`, storing a primary key (`INT` value), is added. If the input `.dbf` has already a `PK` column then the added column is named `PK2` *(and so on)*. -If the `tablename` parameter is not specified, then the resulting table has the same name as the dBase file. +Define `fileEncoding` to force encoding (useful when the header is missing encoding information) (default value is `ISO-8859-1`). + +If: + +- the `tablename` parameter is not specified, then the resulting table has the same name as the dBase file. +- the `deleteTable` parameter is `true` and table `tableName` already exists in the database, then table `tableName` will be removed / replaced by the new one. Else (no `deleteTable` parameter or `deleteTable` equal to `false`), an error indicating that the table `tableName` already exists will be throwned.When a tablename
is not specified, special caracters in the input file name are not allowed. The possible caracters are as follow: A to Z
, _
and 0 to 9
.
UpdateGeometrySRID
does not to actually change the projection of geom
.
+ For this purpose, use ST_Transform.