All Projects → kylebarron → snap-to-tin

kylebarron / snap-to-tin

Licence: MIT License
Snap vector features to the faces of a triangulated irregular network (TIN)

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to snap-to-tin

roadifier
Open Source road mesh generator script for Unity
Stars: ✭ 30 (+66.67%)
Mutual labels:  terrain, mesh
Delatin
A fast JavaScript terrain mesh generation tool based on Delaunay triangulation
Stars: ✭ 207 (+1050%)
Mutual labels:  terrain, mesh
Vectiler
A vector tile, terrain and city 3d model builder and exporter
Stars: ✭ 394 (+2088.89%)
Mutual labels:  vector-tiles, terrain
Pts
Quantized Mesh Terrain Data Generator and Server for CesiumJS Library
Stars: ✭ 36 (+100%)
Mutual labels:  terrain, mesh
SimpleErosion
Simple C++ implementatoin of particle-based hydraulic erosion on a square grid
Stars: ✭ 64 (+255.56%)
Mutual labels:  terrain, terrain-rendering
femio
FEM I/O tool
Stars: ✭ 15 (-16.67%)
Mutual labels:  mesh
terrain
Create a 3d terrain with WebGL.
Stars: ✭ 43 (+138.89%)
Mutual labels:  terrain
aranya
Control all kinds of devices with Kubernetes
Stars: ✭ 16 (-11.11%)
Mutual labels:  mesh
osm-analytics-cruncher
Backend code for osm-analytics
Stars: ✭ 14 (-22.22%)
Mutual labels:  vector-tiles
currender
Currender: A CPU renderer for computer vision
Stars: ✭ 26 (+44.44%)
Mutual labels:  mesh
ipvpn
[WIP] Easy-to-use decentralized secure overlay private network (for any device)
Stars: ✭ 24 (+33.33%)
Mutual labels:  mesh
Thalatta
An open source terrain generation suite.
Stars: ✭ 37 (+105.56%)
Mutual labels:  terrain
pacman.store
Pacman Mirror via IPFS for ArchLinux, Endeavouros and Manjaro
Stars: ✭ 65 (+261.11%)
Mutual labels:  mesh
postile
Project migrated to: https://gitlab.com/Oslandia/postile
Stars: ✭ 67 (+272.22%)
Mutual labels:  vector-tiles
ComputeShaderBVHMeshHit
Unity ComputeShader implementation of BVH(Bounding Volume Hierarchy) based mesh hit checking.
Stars: ✭ 25 (+38.89%)
Mutual labels:  mesh
vector-tile-base
A very basic and low level library written in python for encoding and decoding Mapbox Vector Tiles
Stars: ✭ 42 (+133.33%)
Mutual labels:  vector-tiles
volumentations
Augmentation package for 3d data based on albumentaitons
Stars: ✭ 26 (+44.44%)
Mutual labels:  mesh
unity-plumber
A component to procedurally generate pipe-like meshes in Unity
Stars: ✭ 55 (+205.56%)
Mutual labels:  mesh
tilelive-postgis
Implements the tilelive API for generating vector tiles from PostGIS
Stars: ✭ 48 (+166.67%)
Mutual labels:  vector-tiles
yggmail
End-to-end encrypted email for the mesh networking age
Stars: ✭ 72 (+300%)
Mutual labels:  mesh

snap-to-tin

Build Status

Snap vector features to the faces of a triangulated irregular network (TIN).

Overview

Given a TIN representing a terrain mesh, this snaps 2D Point and LineString features to the faces of that mesh.

For Point features, this finds the triangle containing that point and linearly interpolates from the heights of the triangle's vertices to find the point's elevation.

For LineString features, this finds the elevation of every vertex using the same method as for Points, but also finds every intersection between each LineString segment and triangle edges. At each segment-edge intersection, a new vertex is added to the resulting LineString, so that every part of the LineString is attached to a face of the mesh.

Install

yarn add @kylebarron/snap-to-tin
# or
npm install @kylebarron/snap-to-tin

Usage

Note that the coordinates of the TIN and the vector features need to be in the same coordinate system.

import snapFeatures from '@kylebarron/snap-to-tin'
import {load} from '@loaders.gl/core';
import {TerrainLoader} from '@loaders.gl/terrain';

// Load and parse terrain mesh
const terrain = await load(terrainImage, TerrainLoader);

// Construct class
const snap = new SnapFeatures({
  // triples of position indices that make up the faces of the terrain
  indices: terrain.indices.value,
  // x, y, z positions in space of each index
  positions: terrain.attributes.POSITION.value,
  // Optional bounding box to clip features to
  bounds: [0, 0, 1, 1]
})

// array of GeoJSON features
const features = [...]
const snappedFeatures = snap.snapFeatures({features})

API

The default export is a class: SnapFeatures.

SnapFeatures constructor

Admits an object with the following keys:

  • indices: a flat TypedArray with triples of indices referring to positions of the triangles that make up the TIN. Each triple refers to a triangle face. So [1, 3, 4, ...] would mean that the second, fourth, and fifth (since zero-indexed) set of coordinates in positions constitute a triangle face.

  • positions: a flat TypedArray with x, y, z coordinates of the triangles. So [0.25, 0.5, 625, ...] would mean that the first position, i.e. 0 in indices, has position x=0.25, y=0.5, z=625 in the given coordinate space.

  • bounds: (optional) an array of [minX, minY, maxX, maxY] to be used for clipping features. This is used to clip vector features, since heights cannot be found for positions outside the extent defined by the positions array. If provided, bounds will be intersected with the maximal bounds from the positions array. Default: maximum extent of positions

    This is especially useful with features generated from vector tiles, since vector tiles usually have buffer outside the geographic extent it represents.

SnapFeatures.snapFeatures()

Snap GeoJSON Point and LineString features to the TIN. Admits an object with the following keys:

  • features: an array of GeoJSON Features, containing 2D Point and LineString geometries. Other geometry types will be silently skipped.

Returns new GeoJSON features with 3D coordinates.

SnapFeatures.snapPoints()

Snap a TypedArray of points to the TIN.

  • positions: a flat TypedArray with positions of 2D Point geometries.

    Note that this is different from the positions given to the constructor, which are the positions of the triangles of the TIN. These are the positions of Points on the TIN.

  • featureIds: Optional, a flat TypedArray with featureIds, one per vertex. If provided, a similar TypedArray will be returned. Since some input points can be omitted from the output (e.g. if outside the bounds of the TIN), this helps to keep track of which snapped point has which properties. This must be the same length as the number of vertices within positions. So if positions holds five 2D coordinates, the length of positions should be 10 and the length of featureIds should be 5.

Returns:

{
  // A flat TypedArray containing 3D coordinates for each point
  positions: TypedArray,
  // If provided as input, a mutated featureIds array for each snapped vertex
  featureIds: TypedArray,
}

SnapFeatures.snapLines()

Snap a TypedArray of lines to the TIN.

  • positions: a flat TypedArray with positions of 2D LineString geometries.

    Note that this is different from the positions given to the constructor, which are the positions of the triangles of the TIN. These are the positions of LineStrings on the TIN.

  • pathIndices: a flat TypedArray with indices of where each individual LineString starts. For example, if there are 3 paths of 2, 3, and 4 vertices each, pathIndices should be [0, 2, 5, 9]. Note, this must have length n + 1, where n is the number of vertices. If not provided, assumed the entire positions array constitutes a single LineString.

  • featureIds: Optional, a flat TypedArray with featureIds, one per vertex. If provided, a similar TypedArray will be returned. Since some input lines can be omitted from the output (e.g. if outside the bounds of the TIN), this helps to keep track of which snapped vertex has which properties. This must be the same length as the number of vertices within positions. So if positions holds five 2D coordinates, the length of positions should be 10 and the length of featureIds should be 5.

Returns:

{
  // A flat TypedArray containing 3D coordinates for each point
  positions: TypedArray,
  // A flat TypedArray with indices of where each snapped `LineString` starts
  pathIndices: TypedArray,
  // If provided as input, a mutated featureIds array for each snapped vertex
  featureIds: TypedArray,
}

Use with TypedArrays

This library is designed to support TypedArrays (through the snapPoints and snapLines methods) in order to achieve maximum performance. When using web workers, passing TypedArrays is most efficient because it allows for bypassing serialization and deserialization of the data. In the next release, loaders.gl will have support for reading Mapbox Vector Tiles directly into TypedArrays. Deck.gl also supports passing binary TypedArrays as data to its layers. So the process of

  1. Loading vector geometries
  2. Snapping features to the TIN
  3. Passing to deck.gl layers

should be quite fast, and additionally there would be little main-thread performance cost to doing #2 on a worker thread.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].