10

I am interested to know whether changing the projection of a PostGIS table will affect the rending speed when viewing it in QGIS.

I have two layers coming from QGIS which are exactly the same and cover a geographical area covering England in the United Kingdom. The only difference is their projection:

  1. The first is ESPG: 4326 (WGS 84)
  2. The second is ESPG: 27700 (BNG)

The former (4326) appears to render in 2500ms and the second one in 7500ms.

Additional info

  • Both layers have a primary key on the same field
  • Both layers have a spatial index
  • The QGIS version is 3.4.15 and the project CRS is 27700
8
  • 2
    Feels odd that it would be faster to render from native EPSG:4326 and re-project into the QGIS project CRS EPSG:27700 than to read native EPSG:27700 directly. Could there be something else than CRS that is different in the tables or indexes? EPSG:27700 version may have more decimals in the coordinates and thus more data to transfer. What is the total rendering time?
    – user30184
    Commented Feb 19, 2020 at 12:39
  • 1
    Are both tables vacuumed? Next you should somehow divide the total time between the time spent for reading the data from the database and time that QGIS is using for rendering.
    – user30184
    Commented Feb 19, 2020 at 15:21
  • 1
    You can consider clustering both tables (ideally by an ID that tends to group nearby features, or using the spatial index, or..). If the features to be drawn are on disk physically near each others, it will be much faster than if the DB has to read many pages of data.
    – JGH
    Commented Feb 19, 2020 at 15:38
  • 2
    Try without QGIS: do a explain analyze using a spatial query (a bounding box) on both tables and see the difference
    – JGH
    Commented Feb 19, 2020 at 15:39
  • 1
    I don't think that coordinate precision matters whatsoever... They are not transferred as text, they are transferred as double precision floating point numbers, which occupy same space no matter what the actual number is...
    – DavidP
    Commented Feb 19, 2020 at 15:40

1 Answer 1

2

It does seem to impact rendering.

This could be very data dependent. I did a test on the townlands data from: https://www.townlands.ie/page/download/

And the version in the QGIS project CRS was faster, both ways.

There could be other variables. Like making sure the geometry types are defined.

My code for creating the tables:

create table render_test.town_4326
as
select ogc_fid,
name_tag,
wkb_geometry::geometry(multipolygon, 4326) as geom
from osm.townlands;
create index idx_town_4326_geom on render_test.town_4326 using gist (geom);
vacuum analyze render_test.town_4326;

create table render_test.town_29902
as
select ogc_fid,
name_tag,
st_transform(wkb_geometry, 29902)::geometry(multipolygon, 29902) as geom;
from osm.townlands
create index idx_town_29902_geom on render_test.town_29902 using gist (geom);
vacuum analyze render_test.town_29902;

Project in EPSG:29902:

First go:

2022-08-01T00:52:05     WARNING    2852 ms: town_4326_cb00dd17_172a_4bfd_8ab7_ad3ee2dd1a50
2022-08-01T00:52:05     WARNING    2117 ms: town_29902_c9954276_b16f_4a91_8a00_fa115f38cf2b
2022-08-01T00:52:05     WARNING    2036 ms: Labeling
2022-08-01T00:52:05     WARNING    0 ms: Annotations_449fae61_b4c5_4aa6_b07d_3f750cdc7845
2022-08-01T00:52:05     WARNING    ---
2022-08-01T00:52:05     WARNING    Canvas refresh: 5009 ms

29902 layer is faster at 2117 ms. Compared to 2852 ms for 4326 layer.

Second go:

2022-08-01T00:54:28     WARNING    2673 ms: town_4326_cb00dd17_172a_4bfd_8ab7_ad3ee2dd1a50
2022-08-01T00:54:28     WARNING    1840 ms: town_29902_c9954276_b16f_4a91_8a00_fa115f38cf2b
2022-08-01T00:54:28     WARNING    1 ms: Labeling
2022-08-01T00:54:28     WARNING    0 ms: Annotations_449fae61_b4c5_4aa6_b07d_3f750cdc7845
2022-08-01T00:54:28     WARNING    ---
2022-08-01T00:54:28     WARNING    Canvas refresh: 2696 ms

29902 layer is again faster at 1840 ms. Compared to 2673 ms for 4326 layer.

Project in EPSG:4326:

First go:

2022-08-01T00:56:20     WARNING    2109 ms: town_29902_c9954276_b16f_4a91_8a00_fa115f38cf2b
2022-08-01T00:56:20     WARNING    1313 ms: town_4326_cb00dd17_172a_4bfd_8ab7_ad3ee2dd1a50
2022-08-01T00:56:20     WARNING    0 ms: Labeling, Annotations_449fae61_b4c5_4aa6_b07d_3f750cdc7845
2022-08-01T00:56:20     WARNING    ---
2022-08-01T00:56:20     WARNING    Canvas refresh: 2123 ms

Now 4326 layer is faster at 1313 ms. Compared to 2109 ms for 29902 layer.

Second go:

2022-08-01T00:57:02     WARNING    3533 ms: town_29902_c9954276_b16f_4a91_8a00_fa115f38cf2b
2022-08-01T00:57:02     WARNING    1662 ms: town_4326_cb00dd17_172a_4bfd_8ab7_ad3ee2dd1a50
2022-08-01T00:57:02     WARNING    0 ms: Labeling, Annotations_449fae61_b4c5_4aa6_b07d_3f750cdc7845
2022-08-01T00:57:02     WARNING    ---
2022-08-01T00:57:02     WARNING    Canvas refresh: 3550 ms

4326 layer is still faster at 1662 ms. Compared to 3533 ms for 29902 layer.

So native CRS is faster to render in my tests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.