qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.62k stars 3.01k forks source link

A certain layer disappears at certain zoom levels #45062

Open moritzsproll opened 3 years ago

moritzsproll commented 3 years ago

What is the bug or the crash?

I have added a layer that is loaded into QGIS via a CSV file. At the beginning everything seems to be correct and the layer is visible in every zoom level. The layer is added with the "Watch File" option and is supposed to change its position when the coordinates in the CSV file change.

However, as soon as the coordinates have changed and the position of the layer has changed, it is no longer visible at certain zoom levels. Has anyone had a similar problem and knows how to solve it?

`if(QgsProject.instance().mapLayersByName(self.ambulance)): layers = QgsProject.instance().mapLayersByName(self.ambulance) rr = layers[0] QgsProject.instance().removeMapLayer(rr) if self.ambulance == "Ambulance I": coords_var = "coords1" elif self.ambulance == "Ambulance II": coords_var = "coords2" elif self.ambulance == "Ambulance III": pass

    uri = "file:/home/eams/Desktop/system/" + coords_var + ".csv?delimiter=,&crs=epsg:4326&xField=Longitude&yField=Latitude"
    vlayer = QgsVectorLayer(uri,str(self.ambulance),'delimitedtext')
    QgsProject.instance().addMapLayer(vlayer)
    renderer = vlayer.renderer()
    symbol = renderer.symbol()
    vlayer.triggerRepaint()
    #ZoomaufErstelltenLayerVersion2
    vlayer.selectAll()
    mCanvas = iface.mapCanvas()
    mCanvas.zoomToSelected()
    vlayer.removeSelection()

    watcher = QFileSystemWatcher()
    watcher.addPath("/home/eams/Desktop/system/" + coords_var +".csv")
    vlayer.triggerRepaint()
    vlayer.loadNamedStyle("/home/eams/Desktop/system/qgis_style_file/qgis_" + coords_var +".qml")  
    vlayer.setAutoRefreshInterval(2000)
    vlayer.setAutoRefreshEnabled(True)    
    vlayer.triggerRepaint()`

Steps to reproduce the issue

The layer is still visible at this zoom level layer_da If I zoom in, the layer disappears. layer_weg The zoom level display has already been checked, that can't be the problem.

Versions

QGIS version 3.20.2-Odense QGIS code revision 9f59a15664 Qt version 5.12.8 Python version 3.8.10 GDAL/OGR version 3.0.4 PROJ version 6.3.1 EPSG Registry database version v9.8.6 (2020-01-22) Compiled against GEOS 3.8.0-CAPI-1.13.1 Running against GEOS 3.8.0-CAPI-1.13.1 SQLite version 3.31.1 PDAL version 2.0.1 PostgreSQL client version 12.8 (Ubuntu 12.8-0ubuntu0.20.04.1) SpatiaLite version 4.3.0a QWT version 6.1.4 QScintilla2 version 2.11.2 OS version Ubuntu 20.04.3 LTS

Active Python plugins location_help incident_report map_legend sendingmail information_health_facilities GeoCoding capture_coordinates open_telegram open_traccar open_whatsapp get_location_whatsapp change_layers clear MetaSearch processing db_manager

Supported QGIS version

New profile

Additional context

No response

gioman commented 3 years ago

@moritzsproll please attach the CSV file.

gioman commented 3 years ago

also please describe the necessary steps to replicate.

moritzsproll commented 3 years ago

also please describe the necessary steps to replicate.

koordinaten2.csv

Everything else has been described or what else do you mean by steps to replicate ?

uclaros commented 3 years ago

I've had watched csv layers misbehave like that when new points were added outside the initial layer's extent. My solution was to add four points to the initial csv that defined a bigger initial extent.

gioman commented 3 years ago

I've had watched csv layers misbehave like that when new points were added outside the initial layer's extent

@uclaros was this unreported previously?

uclaros commented 3 years ago

I remember only finding some closed reports regarding csv watch functionality.

I think snapping was also affected, some points were visible but not snappable...

My other solution was running the following:

filePath = r'c:\coords.txt'

from PyQt5.QtCore import QFileSystemWatcher
import os
layerName = os.path.splitext(os.path.basename(filePath))[0]
watcher = QFileSystemWatcher()
watcher.addPath(filePath)
watchedLayer = QgsProject.instance().mapLayersByName(layerName)[0]
def reload_watched_layer():
    watchedLayer.dataProvider().forceReload()

watcher.fileChanged.connect(reload_watched_layer)
github-actions[bot] commented 3 years ago

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale". If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue. In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue. If there is no further activity on this issue, it will be closed in a week.

uclaros commented 3 years ago

Don't close this, having delimited text layers that work properly with dynamic data would be super useful! It is not clear by the docs if watch file is supposed to trigger an automatic reload (ie not need to zoom/pan for the new points to appear) or if without it no content is added/removed at all, but here's some more info on how it currently misbehaves:

Without watch

  1. Create a file, points.csv with one line containing 1,1
  2. Add it as a delimited text layer, don't check watch file
  3. The point is visible on all zoom levels and snappable
  4. Add a new line to the file: 2,1 and save.
  5. When the canvas refreshes, the point is added to the layer, even though watch file was unchecked. The new point is not snappable and when zoomed to it stops being visible. It is also not selectable unless the select rectangle also contains the first point.
  6. Each subsequent point added has the same behavior.
  7. Delete the first line in the file. The first point disappears but it is still snappable.

With watch

  1. Create a file, points.csv with one line containing 1,1
  2. Add it as a delimited text layer, check watch file
  3. The point is visible on all zoom levels and snappable
  4. Add a new line to the file: 2,1 and save.
  5. Canvas needs to be refreshed for the new point to appear, even if file is watched. The new point is both visible, snappable and selectable at all zoom levels.
  6. Add a new line to the file: 3,1 and save.
  7. When the canvas refreshes, the point is added to the layer. The new point is not snappable and when zoomed to it stops being visible. It is also not selectable unless the select rectangle also contains one of the two first points.
  8. Each subsequent point added has the same behavior.
  9. Delete the first line in the file. The first point disappears but it is still snappable.