Giter VIP home page Giter VIP logo

Comments (2)

xivk avatar xivk commented on July 30, 2024

As a test case take the Russia boundary from OSM.

from nettopologysuite.io.vectortiles.

FObermaier avatar FObermaier commented on July 30, 2024

Adding an additional PreparedGeometry.Contains check to return the whole tile as geometry should improve the performance a lot:

    /// <summary>
    /// Returns all the tiles this polygon is part of and the polygonal portion in it..
    /// </summary>
    /// <param name="polygon">The linestring.</param>
    /// <param name="zoom">The zoom.</param>
    /// <param name="margin">The margin for the tiles polygon (in %)</param>
    /// <returns>An enumerable of all tiles.</returns>
    public static IEnumerable<(ulong, IPolygonal)> Tiles(Polygon polygon, int zoom, int margin = 5)
    {
        // Get the envelope
        var envelope = polygon.EnvelopeInternal;
        var lt = Tile.CreateAroundLocation(envelope.MaxY, envelope.MinX, zoom);
        if (lt == null) throw new Exception();
        var rb = Tile.CreateAroundLocation(envelope.MinY, envelope.MaxX, zoom);
        if (rb == null) throw new Exception();

        // Compute the possible tile range
        var tileRange = new TileRange(lt.X, lt.Y, rb.X,rb.Y, zoom);

        // Build a prepared geometry to perform faster intersection predicate
        var prep = Geometries.Prepared.PreparedGeometryFactory.Prepare(polygon);

        // Test polygon tiles.
        foreach (var tile in tileRange)
        {
            if (tile == null) continue;
            var testPolygon = tile.ToPolygon(margin);
            if (prep.Contains(testPolygon))
            {
                // the whole tile polygon is inside the geometry
                yield return (tile.Id, testPolygon);
            }
            else if (prep.Intersects(testPolygon))
            {
                // Compute the intersection geometry
                var result = polygon.Intersection(testPolygon);

                // Only return if result is polygonal
                if (result is IPolygonal polygonalResult)
                    yield return (tile.Id, polygonalResult);
            }
        }
    }

from nettopologysuite.io.vectortiles.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.