Comments (2)
As a test case take the Russia boundary from OSM.
from nettopologysuite.io.vectortiles.
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)
- Installation and examples
- Is it possible to create a tileserver? HOT 1
- Is there an example of creating vector tiles from osm files HOT 2
- postgis support HOT 4
- Remove from this org HOT 3
- Lines and polygons are skipped HOT 4
- Migrate this to the NTS organization once stable HOT 1
- Better simplification at 'higher' levels
- Add support for writing all representable geometry types to a vector tile HOT 1
- Add support for reading [Mapbox|GeoJSON] vector tiles HOT 3
- Lots of questions... HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nettopologysuite.io.vectortiles.