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

Value Error when downloading Data from OSM #13

Closed
MustaphaAhmedALy opened this issue Jan 11, 2021 · 8 comments
Closed

Value Error when downloading Data from OSM #13

MustaphaAhmedALy opened this issue Jan 11, 2021 · 8 comments

Comments

@MustaphaAhmedALy
Copy link

MustaphaAhmedALy commented Jan 11, 2021

I am trying to use the code to download the routable data from osmnx it produce#

Error

(
File "import.py", line 32, in
save_graph_shapefile_directional(G, filepath='stockholm')
File "import.py", line 26, in save_graph_shapefile_directional
gdf_edges.to_file(filepath_edges, encoding=encoding)
File "/home/mustafa/.local/lib/python3.8/site-packages/geopandas/geodataframe.py", line 746, in to_file
_to_file(self, filename, driver, schema, index, **kwargs)
File "/home/mustafa/.local/lib/python3.8/site-packages/geopandas/io/file.py", line 257, in _to_file
colxn.writerecords(df.iterfeatures())
File "/home/mustafa/.local/lib/python3.8/site-packages/fiona/collection.py", line 361, in writerecords
self.session.writerecs(records, self)
File "fiona/ogrext.pyx", line 1291, in fiona.ogrext.WritingSession.writerecs
File "fiona/ogrext.pyx", line 466, in fiona.ogrext.OGRFeatureBuilder.build
ValueError: Invalid field type <class 'tuple'>

)

"code for error reproduction"

(import osmnx as ox
import time
from shapely.geometry import Polygon
import os

def save_graph_shapefile_directional(G, filepath=None, encoding="utf-8"):
  # default filepath if none was provided
  if filepath is None:
      filepath = os.path.join(ox.settings.data_folder, "graph_shapefile")

  # if save folder does not already exist, create it (shapefiles
  # get saved as set of files)
  if not filepath == "" and not os.path.exists(filepath):
      os.makedirs(filepath)
  filepath_nodes = os.path.join(filepath, "nodes.shp")
  filepath_edges = os.path.join(filepath, "edges.shp")

  # convert undirected graph to gdfs and stringify non-numeric columns
  gdf_nodes, gdf_edges = ox.utils_graph.graph_to_gdfs(G)
  gdf_nodes = ox.io._stringify_nonnumeric_cols(gdf_nodes)
  gdf_edges = ox.io._stringify_nonnumeric_cols(gdf_edges)
  # We need an unique ID for each edge
  gdf_edges["fid"] = gdf_edges.index
  # save the nodes and edges as separate ESRI shapefiles
  gdf_nodes.to_file(filepath_nodes, encoding=encoding)
  gdf_edges.to_file(filepath_edges, encoding=encoding)

print("osmnx version",ox.__version__)

place ="Stockholm, Sweden"
G = ox.graph_from_place(place, network_type='drive', which_result=2)
save_graph_shapefile_directional(G, filepath='stockholm')
)
#
@MustaphaAhmedALy
Copy link
Author

I have tried on 2 different Machine and the same error , maybe I am doing something wrong as I am new to python?

@cyang-kth
Copy link
Owner

Your error seems to be related with fiona

File "fiona/ogrext.pyx", line 466, in fiona.ogrext.OGRFeatureBuilder.build
ValueError: Invalid field type <class 'tuple'>

It seems that some fields of the dataframe has value of tuple that cannot be saved by fiona.
Try to google the answer or check the geodataframe to delete columns causing this issue.

@Mohammed-9089
Copy link

@cyang-kth
The problem because "fid" column is contain tuples, so how can we remove it, while the fmm using this filed. (fmm/example/osmnx_example/map_matching.ipynb) here using this filed.
Read network and graph
network = Network("stockholm/edges.shp","fid", "u", "v")

@MustaphaAhmedALy
Copy link
Author

Solved using an older version of the osmnx library

@mapperosm
Copy link

Hi I face the same problem can you tell which version of osmnx should be used?

@MustaphaAhmedALy
Copy link
Author

the version it worked with is " 0.15.0 "

@mapperosm
Copy link

Thank you. Now I face onother problem osmnx pulls the data from nominatim.openstreetmap.org and this service seems to be down. Does anyone know a different possibility?

@mapperosm
Copy link

now it works!

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

4 participants