Skip to main content

My goal is to create a JSON file that matches the following template. I've been struggling getting the coordinates in the linestring geometry property properly formatted. Note the addition of the "tippecanoe" property.

{
    "type" : "Feature",
    "tippecanoe" : { "maxzoom" : 9, "minzoom" : 4 },
    "properties" : { "FULLNAME" : "N Vasco Rd" },
    "geometry" : {
        "type" : "LineString",
        "coordinates" : Â { -121.733350, 37.767671 ], " -121.733600, 37.767483 ],  Â -121.733131, 37.766952 ] ]
    }
}

Things I tried:

  • Basic geojson writer - Writes the maxoom/minzoom property under "properties" instead of "tippecanoe".
  • JSONTemplater - 
concat('mi',geom:get-points('xy', ', ', '],e'),']]')

This method works, but feels hackish; it adds quotation marks (") which I remove later. 

geom:get-text-data(geom:get-name())

The second method returns null values. I give the geometry a name with the GeometryPropertySetter, but still returns a null value. If someone can post a working example, I can go from there. The documentation is little light. Thank you!

Hi @justinmatis, you can use the GeometryExtractor (GeometryEncoding: GeoJSON) to translate the feature geometry to a geometry string '{"type": <geometry type>, "coordinates": <coordinates array>}' in the GeoJSON format and store it in a feature attribute.
Assuming the geometry string is stored in an attribute named "_geometry", this template expression should generate your desired JSON document.

{
    "type" : "Feature",
    "tippecanoe" : {
        "maxzoom" : fme:get-attribute("maxzooom"),
        "minzoom" : fme:get-attribute("minzoom")
    },
    "properties" : {
        "FULLNAME" : fme:get-attribute("FULLNAME")
    },
    "geometry" : fme:get-json-attribute("_geometry")
}

Hi @justinmatis, you can use the GeometryExtractor (GeometryEncoding: GeoJSON) to translate the feature geometry to a geometry string '{"type": <geometry type>, "coordinates": <coordinates array>}' in the GeoJSON format and store it in a feature attribute.
Assuming the geometry string is stored in an attribute named "_geometry", this template expression should generate your desired JSON document.

{
    "type" : "Feature",
    "tippecanoe" : {
        "maxzoom" : fme:get-attribute("maxzooom"),
        "minzoom" : fme:get-attribute("minzoom")
    },
    "properties" : {
        "FULLNAME" : fme:get-attribute("FULLNAME")
    },
    "geometry" : fme:get-json-attribute("_geometry")
}
I'd recommend you to use the GeometryExtractor as I suggested above, but if it cannot be used for some reason, this expression would be available instead.

 

{
    "type" : "Feature",
    "tippecanoe" : {
        "maxzoom" : fme:get-attribute("maxzooom"),
        "minzoom" : fme:get-attribute("minzoom")
    },
    "properties" : {
        "FULLNAME" : fme:get-attribute("FULLNAME")
    },
    "geometry" : {
        "type" : "LineString",
        "coordinates" :  
            for $coord in tokenize(geom:get-points("xy"), '\s')
            return /
                for $v in tokenize($coord, ',')
                return xs:double($v)
            ]
        ]
    }
} 

Hi @justinmatis, you can use the GeometryExtractor (GeometryEncoding: GeoJSON) to translate the feature geometry to a geometry string '{"type": <geometry type>, "coordinates": <coordinates array>}' in the GeoJSON format and store it in a feature attribute.
Assuming the geometry string is stored in an attribute named "_geometry", this template expression should generate your desired JSON document.

{
    "type" : "Feature",
    "tippecanoe" : {
        "maxzoom" : fme:get-attribute("maxzooom"),
        "minzoom" : fme:get-attribute("minzoom")
    },
    "properties" : {
        "FULLNAME" : fme:get-attribute("FULLNAME")
    },
    "geometry" : fme:get-json-attribute("_geometry")
}
And, if you need to get geometry name in the expression, just call the "geom:get-name" function. as in:

 

{
    ....
    "properties" : {
        "FULLNAME" : fme:get-attribute("FULLNAME"),
        "GeometryName": geom:get-name()
    },
    ...
}

Hi @justinmatis, you can use the GeometryExtractor (GeometryEncoding: GeoJSON) to translate the feature geometry to a geometry string '{"type": <geometry type>, "coordinates": <coordinates array>}' in the GeoJSON format and store it in a feature attribute.
Assuming the geometry string is stored in an attribute named "_geometry", this template expression should generate your desired JSON document.

{
    "type" : "Feature",
    "tippecanoe" : {
        "maxzoom" : fme:get-attribute("maxzooom"),
        "minzoom" : fme:get-attribute("minzoom")
    },
    "properties" : {
        "FULLNAME" : fme:get-attribute("FULLNAME")
    },
    "geometry" : fme:get-json-attribute("_geometry")
}

 

Great answer. I noticed this converted my linestring to xyz data where I had no z data. Threw in a 2DForcer to correct this.

Reply