walkerke / mapboxapi

R interface to Mapbox web services
https://walker-data.com/mapboxapi/
Other
109 stars 8 forks source link

Cannot replicate example in Creating and uploading Mapbox vector tilesets (tippecanoe has syntax error) #36

Closed xiaofanliang closed 11 months ago

xiaofanliang commented 1 year ago

Hi,

First, thanks so much for developing this package. This makes my life a lot easier. I am opening an issue to report errors I ran into when trying to recreate examples in here: https://walker-data.com/mapboxapi/articles/creating-tiles.html. I copied everything below as it is in the tutorial:

library(mapboxapi)
library(mapdeck)
library(httr)

# Get the Microsoft buildings data for Texas and unzip
GET("https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Texas.zip", write_disk("Texas.zip", overwrite = TRUE), progress())

unzip("Texas.zip")

# Use tippecanoe to make a dynamic .mbtiles file that visualizes large data appropriately
# at any zoom level.  sf objects can also be used as input!
# (requires installing tippecanoe on your machine separately first)
tippecanoe(input = "Texas.geojson",
           output = "Texas.mbtiles",
           layer_name = "texas_buildings")

And my Rstudio returned the following error message:

tippecanoe v2.23.0
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `tippecanoe -o /Users/xiaofanliang/Texas.mbtiles -zg -as -f -l texas_buildings Texas.geojson'

I also tried using my own data in the format of an sf object, but the same error persists. Any ideas of why? Seems like the error is related to syntax around token? I also made sure that my Mapbox token (both public and secrete is installed in the environment). I also checked all the boxes for token scopes when creating the secrete token. The proof is that when I run the following line, it will say:

> mb_access_token(token, install = TRUE)
Error: A MAPBOX_SECRET_TOKEN already exists. You can overwrite it with the argument overwrite=TRUE

Weirdly, if I run Sys.getenv, it will return me empty strings. Not sure how to proceed further.

> Sys.getenv("MAPBOX_SECRET_TOKEN")
[1] ""
yoowhyeeen commented 1 year ago

Hi @xiaofanliang,

One thing I noticed right away is when you said Sys.getenv("MAPBOX_SECRET_TOKEN") returned an empty string. Could you unset and then set your MAPBOX_SECRET_TOKEN using Sys.unsetenv("MAPBOX_SECRET_TOKEN") then Sys.setenv("MAPBOX_SECRET_TOKEN"="xyz"), where xyz is your public token from your Mapbox account? Make sure to enclose token in double quotation marks like I did in my example.

You might want to print out the token just to make sure it's not empty. I've attached my sample output below.

mb

After that, you can overwrite your old MAPBOX_SECRET_TOKEN with the one you've just reset with mb_access_token(Sys.getenv("MAPBOX_SECRET_TOKEN"), install = TRUE, overwrite = TRUE) and try the code again.

Hope that helps, UN

xiaofanliang commented 1 year ago

@yoowhyeeen Thanks for replying after so long. I followed your steps and do the following, but it still returns the same error. This time, my Sys.getenv("MAPBOX_SECRET_TOKEN") is returning my Mapbox public token fine.

token = "pk...." (my public mapbox token)
Sys.unsetenv("MAPBOX_SECRET_TOKEN")
Sys.setenv("MAPBOX_SECRET_TOKEN"=token)
mb_access_token(token, install = TRUE, overwrite = TRUE)

# Your original .Renviron will be backed up and stored in your R HOME directory if needed.
# Your access token has been stored in your .Renviron and can be accessed by Sys.getenv("MAPBOX_PUBLIC_TOKEN"). 
# To use now, restart R or run `readRenviron("~/.Renviron")`
# [1] "pk...."

Sys.getenv("MAPBOX_SECRET_TOKEN")
# [1] "pk...."

tippecanoe(input = "Texas.geojson",
           output = "Texas.mbtiles",
           layer_name = "texas_buildings")

# tippecanoe v2.23.0
# sh: -c: line 0: syntax error near unexpected token `('
# sh: -c: line 0: `tippecanoe -o /Users/xiaofanliang/Texas.mbtiles -zg -as -f -l texas_buildings Texas.geojson'
yoowhyeeen commented 1 year ago

@xiaofanliang The documentation for the example mentioned installing tippecanoe with the link attached, were you able to install that to your local machine? I've also linked the GitHub page here.

xiaofanliang commented 1 year ago

@yoowhyeeen I redownloaded tippecanoe through Homebrew (using MacOS). The error is the same, except that the version for tippecanoe has changed. Anyway... if this is too weird and not replicable.. l will leave it be for now. Thanks for your help though!

tippecanoe v2.26.0
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `tippecanoe -o /Users/xiaofanliang/Texas.mbtiles -zg -as -f -l texas_buildings Texas.geojson'
yoowhyeeen commented 1 year ago

@xiaofanliang Sure! I was able to get it to run, although I didn't wait to see complete output. Screenshot from 2023-05-10 15-45-45

walkerke commented 11 months ago

I just ran this code successfully. Perhaps try updating to the latest version of tippecanoe, which has now migrated to Felt? https://github.com/felt/tippecanoe