Skip to main content
Question

How can I write or create a newline-delimited GeoJSON file


I'm currently exploring MapBox and their Tiling Service, which is currently in Beta and I'm trying to figure out how to create a line-delimited GeoJSON output so I can upload via their Tileset API. 

 

The data/file needs to take the format as per the example below:

 

Normal GeoJSON

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "name": "Melbourne"
            }, "geometry": {
                "type": "Point",
                "coordinates": [
                    144.9584,
                    -37.8173
                ]
            }
        }, {
            "type": "Feature",
            "properties": {
                "name": "Canberra"
            }, "geometry": {
                "type": "Point",
                "coordinates": [
                    149.1009,
                    -35.3039
                ]
            }
        }, {
            "type": "Feature",
            "properties": {
                "name": "Sydney"
            }, "geometry": {
                "type": "Point",
                "coordinates": [
                    151.2144,
                    -33.8766
                ]
            }
        }
    ]
}

Newline -delimited GeoJSON

{"type":"Feature","properties":{"name":"Melbourne"},"geometry":{"type":"Point","coordinates":[144.9584,-37.8173]}}
{"type":"Feature","properties":{"name":"Canberra"},"geometry":{"type":"Point","coordinates":[149.1009,-35.3039]}}
{"type":"Feature","properties":{"name":"Sydney"},"geometry":{"type":"Point","coordinates":[151.2144,-33.8766]}}

 

 I know it's possible using other tools such as GDAL, Tippecanoe etc, but I'm sure someone has already solved this problem using FME. 

 

2 replies

jovitaatsafe
Safer
Forum|alt.badge.img+11

Hi @daichisuba​,

This may not be the most elegant solution, and maybe you can build upon it or another community member may be able to suggest a better one, but I gave it a try on my end and got the new line delimited output in this way in case you want to give it a go:

 

  1. Read using the standard JSON (Javascript Object Notation) reader 
  2. ListExploder on features{}
  3. StringConcatenator set to New Attribute: text_line_data and String Expression below (you may want to delete the spaces if they are unwanted):
  4. Text File Writer, set the writer extension to .txt first and then go back to the Navigator to change the destination path so the extension is .json instead. 
{"type""@Value(type)""properties":{"name""@Value(properties.name)"},"geometry": {"type":"@Value(geometry.type)""coordinates":@Value(geometry.coordinates{0}), @Value(geometry.coordinates{1})}}

 


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • July 29, 2022

If you read the json as a block of text, JSONFragmenter using 

json["features"][*]

to get each feature, rename the json to text_line_data and then write using a regular text writer

image


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings