wdtinc / mapbox-vector-tile-java

Java Mapbox Vector Tile Library for Encoding/Decoding
Apache License 2.0
147 stars 73 forks source link

Issue with mvt generation for line geometry #27

Closed dsahu75 closed 5 years ago

dsahu75 commented 6 years ago

Found an issue while rendering the osm roads layer. Some of the line geometries does not render properly at lower zoom levels specially where the line segments form a ring.

Original geometry original_line_geom

MVT Geometry mvt_geometry

Original geometry WKT MULTILINESTRING ((545022.4644456336 6867178.738599846, 545023.7891475739 6867185.429774573, 545024.813286887 6867190.64415437, 545029.8894556686 6867190.206583908, 545036.2791944387 6867192.339740138, 545040.0751890754 6867195.7309127385, 545042.7913846518 6867201.255245361, 545043.1476070203 6867206.34201043, 545042.4574261782 6867209.477938888, 545040.03066128 6867213.944815833, 545037.4591810413 6867216.4608537285, 545032.939609716 6867218.794570745, 545028.5536217794 6867219.469160945, 545023.5331127449 6867218.5757847475, 545020.4606947971 6867217.026050759, 545015.5960330492 6867211.611100222, 545014.0486921292 6867206.761349631, 545014.1488796688 6867202.185083897, 545016.5088528739 6867196.4966615895, 545020.0822085281 6867192.868471254, 545024.813286887 6867190.64415437))

dsahu75 commented 6 years ago

Is there a fix planned for this issue ?

ShibaBandit commented 6 years ago

Hey @coder123456 , haven't had a change to investigate this particular geometry you posted yet. I'd need to get some better tests going that actually cut full tile sets to more easily reproduce the issue. I have separate libraries that are currently not open source that can do this kind of thing... but it's not in here yet. If you would like to contribute some sample code that easily reproduced the issue I can take a look at that too. We also accept pull requests, see the contributing file.

If you're in a real hurry, you might try digging into your tile cutting for the problematic tiles and see where in the process your line geometry is being altered and why. All of this type of info is useful for me too.

miyuer commented 6 years ago

In JtsAdapter Class, linesToGeomCmds method, add code as below ` // Check geometry for repeated end points final int repeatEndCoordCount = countCoordRepeatReverse(geomCoords); int minExpGeomCoords = geomCoords.length - repeatEndCoordCount;

    // Guard/Optimization: Not enough geometry coordinates for a line
    if(minExpGeomCoords < 2) {
       return Collections.emptyList();
    }
    //add code as below
    if(repeatEndCoordCount > 0){
        if(repeatEndCoordCount == 1){
            minExpGeomCoords = geomCoords.length;
        }else{
            minExpGeomCoords++;
        }
    }`
ShibaBandit commented 5 years ago

Closing as fixed via #40