mapbox / carto

fast CSS-like map stylesheets
https://cartocss.readthedocs.io/
Apache License 2.0
652 stars 129 forks source link

Does carto support relative pathes? #497

Closed mattmeye closed 5 years ago

mattmeye commented 5 years ago

Hello,

im struggling with an serverless + mapnik + carto + osm-bright implementation for aws lambda. I believe that it exists a problem with relative pathes.

error

error Error: Shape Plugin: shapefile 'shp/simplified-land-polygons-complete-3857/simplified_land_polygons.shp' does not exist  encountered during parsing of layer 'land-low' in Layer
    at Error (native)

My development environment is aws cloud9.

    .build # build folder of serverless
    ├── handler.js
    ├── carto
    │   └── build # Build folder of configured osm-bright
    │       └── ... # assets folders (fonts images res)
    │       └── shp # also shp/simplified-land-polygons-complete-3857/simplified_land_polygons.shp exists
    │       └── project.mml

project.mml

{
  "Layer": [
    {
      "Datasource": {
        "dbname": "osm", 
        "extent": "-20037508.34 -20037508.34 20037508.34 20037508.34", 
        "file": "shp/simplified-land-polygons-complete-3857/simplified_land_polygons.shp", 
        "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over", 
        "type": "shape"
      }, 
....

Usage of carto

const fetchMapFile = async () => {

  const configName = path.join(__dirname, './carto/build/project.mml') # /home/ec2-user/environment/cloud9TileTest/.build/carto/build/project.mml
  const configDirName = path.dirname(configName) # /home/ec2-user/environment/cloud9TileTest/.build/carto/build

  const data = readFileSync(configName, 'utf8');
  const mml = new carto.MML({});

  return new Promise((resolve, reject) => {
    mml.load(configDirName, data, (err, data) => {

I believe that the osm-bright is correctly builded: i copied this folder in my local windows tilemill project folder and see that the tiles can correctly generated.

What have I done wrong?

nebulon42 commented 5 years ago

If I remember correctly then carto does nothing with the shapefile datasource but presents it to Mapnik as is. So, yes, carto does support relative paths - for stylesheet files. In your case I think Mapnik would have to know how to resolve the path for the datasource. You can verify this if you look at the content of the data structure that carto outputs. It should contain your shapefile file path in one form or the other. You can also post or link that here and we can look together at it.

Disclaimer: It has been quite a while since I last worked with carto so I could be wrong.

mattmeye commented 5 years ago

Hey nebulon,

thank you for you comment. You were right. I fixed the problem to the shp-pathes, but i get another file not find error: "Error: file could not be found: 'img/marsh-16.png'"

the only reference to this file is in the base.mss inside the carto folder. inside the same directory there is a img folder with the image. do i need to configure this path too? maybe this setting in the configure.py of osm-brigth is wrong: config["path"] = path.expanduser("~/environment/cloud9TileTest/carto") ?

mattmeye commented 5 years ago

if i change the path manually from "img/marsh-16.png" to "carto/build/img/marsh-16.png" i get the error at the next reference (marsh-32). do you know how i can set a prefix for all resources?

mattmeye commented 5 years ago

@nebulon42 I found the solution. The build of osm-brigth was okay. The solution is to set a base path in the following mapnik function map.fromString(xml, { base: 'xyz' }, (err, map) => { ... })

Thank you for you help!