|
| 1 | +GIS support in SQLite Foreign Data Wrapper for PostgreSQL |
| 2 | +========================================================= |
| 3 | + |
| 4 | +<img src="https://www.tmapy.cz/wp-content/uploads/2021/02/postgis-logo.png" align="center" height="80" alt="PostGIS"/> + <img src="https://www.gaia-gis.it/fossil/libspatialite/logo" align="center" height="80" alt="SpatiaLite"/> |
| 5 | + |
| 6 | +SQLite FDW for PostgreSQL can connect PostgreSQL with or without [PostGIS](https://www.postgis.net/) |
| 7 | +to [SpatiaLite](https://www.gaia-gis.it/fossil/libspatialite/index) SQLite database file. |
| 8 | +This description contains only information about GIS support without common SQL and |
| 9 | +system descriptions from [common FDW description](README.md). |
| 10 | + |
| 11 | +Notes about compilation environment and PROJ library |
| 12 | +---------------------------------------------------- |
| 13 | +Both SpatiaLite and PostGIS uses [PROJ C++ library](https://github.com/OSGeo/PROJ) from |
| 14 | +[Open Source Geospatial Foundation](https://github.com/OSGeo) for reprojecting and some calculations. |
| 15 | +Recommended configuration of SQLite FDW with GIS support contains both SpatiaLite and PostGIS. |
| 16 | +**It is recommended to install only 1 version of PROJ in a system to avoid integration issue**. |
| 17 | +Before compilation you should ensure equal versions of PROJ library required by SpatiaLite and PostGIS on |
| 18 | +your system. Otherwise some encapsualted and unwanted memory freeing errors can occur. |
| 19 | +If you need different PROJ library versions, you can reference [this PROJ issue](https://github.com/OSGeo/PROJ/issues/4361) |
| 20 | +and try to use something like `CFLAGS="$CFLAGS -DPROJ_RENAME_SYMBOLS -O2"` during compilation of |
| 21 | +SpatiaLite or PostGIS to link one of this extensions with other PROJ version. |
| 22 | + |
| 23 | +Common conditions of GIS support |
| 24 | +-------------------------------- |
| 25 | + |
| 26 | +1. SQLite FDW should be compiled with `ENABLE_GIS=1` environment variable value. |
| 27 | +2. You must install SpatiaLite header files before compilation. |
| 28 | +Linux packages like `libspatialite-dev` or `libspatialite-devel` can contain this files. |
| 29 | +3. A column should have data type (domain) name from following list: |
| 30 | + * addbandarg |
| 31 | + * box2d |
| 32 | + * box3d |
| 33 | + * geography |
| 34 | + * geometry |
| 35 | + * geometry_dump |
| 36 | + * geomval |
| 37 | + * getfaceedges_returntype |
| 38 | + * rastbandarg |
| 39 | + * raster |
| 40 | + * reclassarg |
| 41 | + * summarystats |
| 42 | + * topoelement |
| 43 | + * topoelementarray |
| 44 | + * topogeometry |
| 45 | + * unionarg |
| 46 | + * validatetopology_returntype |
| 47 | + |
| 48 | + Only listed data types have full data transformation support: |
| 49 | + * geography |
| 50 | + * geometry |
| 51 | + |
| 52 | +All other data types (domains) are treated as PostGIS specific, but unsupported. |
| 53 | + |
| 54 | +You can use SpatiaLite GIS data support _without PostGIS installation_ after such |
| 55 | +SQL commands as `CREATE DOMAIN geometry AS bytea;` and `CREATE DOMAIN geography AS bytea;`. |
| 56 | +This allows to have in PostgreSQL PostGIS compatible `bytea` data easy |
| 57 | +convertable to PostGIS storage format. |
| 58 | + |
| 59 | +PostGIS and SpatiaLite vector data formats |
| 60 | +------------------------------------------- |
| 61 | + |
| 62 | +Vector GIS data in PostGIS can be stored in a columns with `geography` or `geometry` |
| 63 | +data type. This columns contains a binary data. |
| 64 | +[Well-known binary (WKB)](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary) |
| 65 | +data storage format is a standard of [Open Geospatial Consortium (OGC)](https://en.wikipedia.org/wiki/Open_Geospatial_Consortium) |
| 66 | +and supported by [GEOS library](https://libgeos.org). PostGIS internal GIS data |
| 67 | +storage format based on WKB with [SRID](https://en.wikipedia.org/wiki/Spatial_reference_system#Identifiers) |
| 68 | +additions. This format is known as [EWKB](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Format_variations) and supported by |
| 69 | +[GEOS library](https://libgeos.org) and SpatiaLite input/output functions. |
| 70 | + |
| 71 | +Hexadecimal text representation of EWKB data is a transport form for `geography` |
| 72 | +and `geometry` GIS data between PostgreSQL and *SpatiLite input/output functions*. |
| 73 | +Hence no PostGIS input/output functions are necessary, but all of this functions |
| 74 | +are supported. |
| 75 | + |
| 76 | +EWKB hexadecimal text data transport is faster than |
| 77 | +[EWKT](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) |
| 78 | +but slower than EWKB blob data transport. |
| 79 | + |
| 80 | +SpatiaLite internal storage based on `blob` data [affinity](https://www.sqlite.org/datatype3.html) |
| 81 | +and is not a standard of [OGC](https://en.wikipedia.org/wiki/Open_Geospatial_Consortium). |
| 82 | +Also this format doesn't supported by [GEOS library](https://libgeos.org). |
| 83 | + |
| 84 | +Limitations |
| 85 | +----------- |
| 86 | + |
| 87 | +* In opposition to PostGIS, **SpatiaLite doesn't allow to store any GIS vector data without SRID**. |
| 88 | +Hence any well-formed SpatiaLite data can be converted for PostGIS, but |
| 89 | +well-formed PostGIS data _without SRID_ cannot be converted for SpatiaLite. |
| 90 | +All of SpatiaLite input functions will return `NULL` in this case. |
| 91 | +Please use [ST_SetSRID PostGIS function](https://postgis.net/docs/ST_SetSRID.html) |
| 92 | +in case of incomplete SRID data to prepare PostGIS data for importing to SpatiaLite |
| 93 | +or comparing with SpatiaLite data. |
| 94 | + |
| 95 | +* Only `=` PostgreSQL operator is pushed down to SQLite (SpatiaLite) for vector GIS data such |
| 96 | +as `geography` or `geometry`. `<>` PostgreSQL operator is NOT pushed down. |
| 97 | + |
| 98 | +End of description. |
0 commit comments