Mapsui icon indicating copy to clipboard operation
Mapsui copied to clipboard

Lines shapes disappearing from ShapeFile on some zoom level

Open LeoCarriere opened this issue 1 year ago • 6 comments

Mapsui Version Happened with both with 5.0.0-beta.4 and latest stable (4.1.8)

Mapsui Platform Tested in both Wpf and WinUI, so I dont think its linked to UI implementation.

Device Windows 11, 23H2

Describe the bug Hello, I am using a ShapeFile .shp as a layer source, but when zooming in some multilines disappears. See attached Video :

https://github.com/user-attachments/assets/7577b703-fe78-4d75-8566-36ecf147297e

To Reproduce I published a simple repo (which include my .shp file) of my WPF test but here is the main function :

public MainWindow() {
    InitializeComponent();
    MadrauditMapControl.Map = GetMap();
}

private Map GetMap() {
    var map = new Map();
    /* Get ShapeFiles */
    var filesPaths = Directory.GetFiles( Directory.GetParent( Environment.CurrentDirectory ).Parent.Parent.FullName + @"\Maps",  "*.shp" );
    /* Add a layer for each ShapeFile */
    foreach( string shapeFilePath in filesPaths ) {
        /* Set data source */
        ShapeFile shpSource = new ShapeFile( shapeFilePath );
        /* Apply basic styles */
        Mapsui.Layers.Layer layer = new Mapsui.Layers.Layer() {
            DataSource = shpSource,
            Style = new Mapsui.Styles.VectorStyle {
                Fill = new Mapsui.Styles.Brush( Mapsui.Styles.Color.FromArgb( 128, 0 , 255 , 0 ) ) ,
                Line = new Mapsui.Styles.Pen( Mapsui.Styles.Color.FromString("#0969da") , 4 ){PenStrokeCap = Mapsui.Styles.PenStrokeCap.Round, StrokeJoin = Mapsui.Styles.StrokeJoin.Round}
            }
        };
        /* Add the new layer */
        map.Layers.Add( layer );
    }
    return map;
}

Additional context I found a closed issue with a very similar behavior, however I did not manage to fix the problem using a different layout or WinUI.

I also tried to attach MapsuiLogging to the debug Debug Output without success (no exceptions). My ShapeFile projection is EPSG:3857 - WGS 84 / Pseudo-Mercator.

LeoCarriere avatar Oct 30 '24 13:10 LeoCarriere

I can reproduce the behavior, I'm investigating

inforithmics avatar Nov 03 '24 15:11 inforithmics

I investigated it and the reason it doesn't work is that for the Index it reads the BoundingBoxes of the shapes. in the method GetAllFeatureBoundingBoxes So it seems that the saved BoundingBoxes are not correct so that the shapes get Boundingboxes assigned that don't represent the real bounding boxes. for a test a read all shapes and used the calculated bounding boxes and the effect dissapeared.

Question is should mapsui do here something. Because it seems a Data inconsistency.

Simple example. Saved Bounding box is [[0,0],[10,10]] But the line has following points [[0,0][10,10][20,20]] so the real bounding box would be [[0,0][20,20]]

  1. One Solution could be, to check the bounding boxes when a geometry is read and when it is too much off throw an exception.
  2. Add a Method that recreates the BoundingBoxes

inforithmics avatar Nov 17 '24 22:11 inforithmics

@inforithmics Where are those boundingboxes stored? Is there a boundingbox for each record? This is what we read and this is simply not correct for the records it corresponds to?

What to do? We don't want to build too much in our own software for such a specific case. We could just say that data corruption is not our problem. On the other hand it also consumes time to have to identify issues like these. So it may be worthwhile to build something to make this easier.

I guess the minimal solution is to identify that there is a problem. So, we could run a check on startup to recalculate the boundingboxes. The downside is that this could be a big performance penalty, files could be very big. So, if we do this it should be optional. So, we could add a validateData option which is default false.

I am not sure if we should try to fix the problem. Perhaps just throw an error. And the user could perhaps generate the index (or something like that) in a tool like QGIS.

pauldendulk avatar Nov 18 '24 11:11 pauldendulk

If added now an option to calculate the Bounding Boxes new ShapeFile(shapeFilePath, calculateBoundingBoxes: true); per default the Bounding boxes are read from the shp file and if the user specifies it the bounding boxes are calculated from the geometries. The corruption could be detected when reading the geometry, haven't implmented this yet.

inforithmics avatar Nov 22 '24 00:11 inforithmics

@inforithmics fantastic!

@LeoCarriere You could help us (and yourself) if you figure out a way to check the validity of a shapefile, and if you could check if updating the extents (I guess there are tools that can do this) fixes your problem.

pauldendulk avatar Nov 22 '24 10:11 pauldendulk

Hey, I have been working on other side projects lately. I'm investigating this afternoon and let you know as soon I found something. Great job @inforithmics, BoundingBoxes was not something I expected, thank you.

LeoCarriere avatar Nov 22 '24 10:11 LeoCarriere

I assume this is fixed.

pauldendulk avatar Nov 14 '25 09:11 pauldendulk