Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCT Elevation Chart #16

Open
kylebarron opened this issue Jan 6, 2020 · 2 comments
Open

PCT Elevation Chart #16

kylebarron opened this issue Jan 6, 2020 · 2 comments

Comments

@kylebarron
Copy link
Member

kylebarron commented Jan 6, 2020

Updating elevation chart:

Tippecanoe only stores two dimensions when generating vector tiles. So if I take the 3d lines and convert them to vector tiles, I'll have no elevation data.

So my options are essentially:

  1. GeoJSON with 3 dimensions
  2. vector tiles of points with metadata on each point
  3. GeoJSON of points with metadata on each

I think 2 is the best, because I can also encode the trail mile in the data.

Note that a drawback of this is that it could simplify the geometry when zoomed out, and thus you wouldn't have an exact elevation chart at low zooms. You could only show at a higher zoom, and also there's probably a tippecanoe option to not simplify as much.

Given this drawback, alternatively, 3 might be the best because there would be no simplification. Then you could have the trail line be vector tile

Also to think about:

  • scale of the elevation chart could change while scrolling when there's differing lengths of trail on the screen.
  • what components to use to render the chart. Probably the victory library, because then I can use similar syntax within react native.
@kylebarron
Copy link
Member Author

Note that if you run map.queryRenderedFeatures with no geometry provided, by default it runs it for the current viewport. You can still pass a specific layer id, so that you only find elevation features.

@kylebarron
Copy link
Member Author

Code to generate geojson of points with elevation:

import geojson
import numpy as np
from shapely.geometry import LineString, Point
from shapely.ops import linemerge

import geom
from data_source import Halfmile

hm = Halfmile()
gdf = hm.trail_full(False)
l = linemerge(gdf.geometry.values)
l_repr = geom.reproject(l, geom.WGS84, geom.CA_ALBERS)
multiplier = 4282464 / l_repr.length

marginal_dists = []
for ind in range(len(l_repr.coords)):
    if ind == 0:
        marginal_dists.append(0.0)
        continue

    coord_next = l_repr.coords[ind]
    coord_prev = l_repr.coords[ind - 1]
    line = LineString([Point(coord_next), Point(coord_prev)])
    dist = line.length
    marginal_dists.append(dist)

dists_new = np.cumsum(marginal_dists)
# Adjust to actual PCT length
dists_new *= multiplier

features = []
for coord, dist in zip(l.coords, dists_new):
    p = Point(coord)
    attrs = {'mi': dist * 0.000621371, 'ele': coord[2]}
    f = geojson.Feature(geometry=p, properties=attrs)
    features.append(f)

fc = geojson.FeatureCollection(features)

with open('../hmpoints.geojson', 'w') as f:
    geojson.dump(fc, f)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant