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

Simplify save_graph_xml output #915

Closed
3 tasks done
davidmurray opened this issue Jan 5, 2023 · 7 comments
Closed
3 tasks done

Simplify save_graph_xml output #915

davidmurray opened this issue Jan 5, 2023 · 7 comments

Comments

@davidmurray
Copy link
Contributor

davidmurray commented Jan 5, 2023

Do not delete the following template. Fill it out completely.

Is your feature proposal related to a problem?

The save_graph_xml function adds a lot of (unnecessary?) data to the resulting XML file:

osmnx/osmnx/osm_xml.py

Lines 207 to 212 in 586cf26

for table in (gdf_nodes, gdf_edges):
table["uid"] = "1"
table["user"] = "osmnx"
table["version"] = "1"
table["changeset"] = "1"
table["timestamp"] = "2017-01-01T00:00:00Z"

The resulting XML file has a lot of extra fields compared to regular OSM XML files :

<?xml version="1.0"?>
<osm version="0.6" generator="OSMnx">
  <node id="0" timestamp="2017-01-01T00:00:00Z" uid="1" user="osmnx" version="1" changeset="1" lat="45.5571316" lon="-73.5963673">
    <tag k="highway" v="nan"/>
  </node>
  <node id="1" timestamp="2017-01-01T00:00:00Z" uid="1" user="osmnx" version="1" changeset="1" lat="nan" lon="nan">
    <tag k="highway" v="nan"/>
  </node>
  <node id="2" timestamp="2017-01-01T00:00:00Z" uid="1" user="osmnx" version="1" changeset="1" lat="nan" lon="nan">
    <tag k="highway" v="nan"/>
  </node>
  <node id="3" timestamp="2017-01-01T00:00:00Z" uid="1" user="osmnx" version="1" changeset="1" lat="45.5575365" lon="-73.5889391">
    <tag k="highway" v="nan"/>
  </node>
  ...
</osm>

In addition, what's the point of the timestamp if it's always the same date in 2017?

Describe the solution you'd like to propose

Either:

  1. Adding a parameter to save_graph_xml to decide whether or not these extra fields should be added to the xml file, or:
  2. Removing this code altogether.

Thanks!

@davidmurray
Copy link
Contributor Author

In addition, it seems that the function adds tags even when the values do not exist:

<node id="2" timestamp="2017-01-01T00:00:00Z" uid="1" user="osmnx" version="1" changeset="1" lat="nan" lon="nan">
    <tag k="highway" v="nan"/>
  </node>

image

When the values are null/NaN, they shouldn't be written to the xml file in my opinion. Might be worth fixing this as well. :)

@gboeing
Copy link
Owner

gboeing commented Jan 5, 2023

Do the osm_xml_* values in the settings module not allow you to do this as you wish?

@davidmurray
Copy link
Contributor Author

davidmurray commented Jan 5, 2023

@gboeing Hi,

Yeah, it seems like it can. ox.settings.osm_xml_node_attrs allows be to specify which keys I want. However, it doesn't let me specify the values. I.e. it's always these:

table["uid"] = "1"
table["user"] = "osmnx"
table["version"] = "1"
table["changeset"] = "1"
table["timestamp"] = "2017-01-01T00:00:00Z"

Since I don't want those it's fine for my use-case, but it could be nice to add a way to set the values.

@gboeing
Copy link
Owner

gboeing commented Jan 5, 2023

@mxndrwgrdnr do you remember the reasoning behind these default values? Are they specified by the API somewhere?

@mxndrwgrdnr
Copy link
Contributor

mxndrwgrdnr commented Jan 5, 2023

I don't recall exactly, but I know that at the time I wrote this code I was using a command-line tool (Osmium?) for testing that my outputs were valid .osm files. I'm pretty sure that without these fields present I couldn't get my files to validate, or at least the validator would complain about it.

@gboeing
Copy link
Owner

gboeing commented May 24, 2023

Closed by #917

@gboeing gboeing closed this as completed May 24, 2023
@gboeing
Copy link
Owner

gboeing commented Mar 2, 2024

See enhancements in #1135

User can now specify custom values for each attribute by simply setting those attribute values on the graph nodes/edges before saving as XML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants