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

errors in GeoJSON to JSON conversion #83

Open
stevesong opened this issue Apr 9, 2024 · 4 comments
Open

errors in GeoJSON to JSON conversion #83

stevesong opened this issue Apr 9, 2024 · 4 comments

Comments

@stevesong
Copy link

lib-cove-ofds installs fine and I am able to use the command-line version of it to convert GeoJSON nodes and spans files into a single valid JSON file. However, when I attempt to use it in a python script, I run into problems. The sample code which suggests the following line triggers an error.

worker.process_data(nodes_data, spans_data)

process_data doesn't appear to accept two arguments. I am able to run it sequentially i.e.

worker.process_data(nodes_data)
worker.process_data(spans_data)

The result produces a valid JSON file but not valid OFDS. It produces spans with node references that cannot be resolved. Temporary link to COVE output. I am not sure what I am doing wrong.

@odscjames
Copy link
Collaborator

Firstly acknowledging the sample code is wrong - it wasn't updated when we changed our thinking about multiple files. I think it should be (not tested):

from libcoveofds.geojson import GeoJSONToJSONConverter, GeoJSONAssumeFeatureType
...
worker.process_data(nodes_data, assumed_feature_type=GeoJSONAssumeFeatureType.NODE)
worker.process_data(spans_data, assumed_feature_type=GeoJSONAssumeFeatureType.SPAN)

@odscjames
Copy link
Collaborator

Ah, I don't have access to the original GeoJSON data but looking at the outputted JSON I can make a guess.

In the first span it's

  "start": "{\"id\": \"..........\", \"name\": \".........\", \"location\": {\"type\": \"Point\", \"coordinates\": [......,.........]}}",

Note, the value for the start key is not a dict - it's a string of the JSON representation of a dict! Has the value somehow been accidentally string-ifyed in the input data?

This is maybe something we could try and catch and fix in the converter, if this is a common problem

@stevesong
Copy link
Author

stevesong commented Apr 10, 2024

That was the hint I needed, thank you! I was using json.loads instead of json.load.

Your revised sample code works for me. :-)

@odscjames
Copy link
Collaborator

We should fix our docs - can we leave this issue open to track that task?

@odscjames odscjames reopened this Apr 10, 2024
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

2 participants