cyang-kth / fmm

Fast map matching, an open source framework in C++
https://fmm-wiki.github.io/
Apache License 2.0
878 stars 205 forks source link

"Segmentation fault: 11" when reading in Network object from shapefile #171

Closed MathiasVersichele closed 3 years ago

MathiasVersichele commented 3 years ago

I just installed fmm on Mac (took some time making it work on python3), but I think the install went fine in the end. Running fmm_test.py finishes without any errors. However, when I try to read in a shapefile I made on my own, it throws a "Segmentation fault: 11":

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from fmm import Network,NetworkGraph,STMATCH,STMATCHConfig
>>> network = Network("/xxx/geouniq_nl_car_small.shp")
[2021-02-02 16:53:49.995] [info] [network.cpp:72] Read network from file /xxx/geouniq_nl_car_small.shp
Segmentation fault: 11

I think my shapefile has the correct structure: image

The geoms are in a projected coordinate system, but that shouldn't be the problem right ? I tried just reading in a smaller part of the network, but it still fails. I'm attaching the network I'm trying to load. small_network.zip

Any help would be much appreciated !

NicklasXYZ commented 3 years ago

I had no problem loading your network using python 2 and 3 running in docker.

So I image it is a problem with your environment and configuration.

There's a docker file here you can use to test things out with python 2: https://github.com/cyang-kth/fmm/tree/master/docker

If you want to test things out with python 3 you can use this docker file here I threw together:

# Pull alpine base image
FROM alpine:3.12.0

# Install required FMM dependencies
RUN apk update && \
    apk add --no-cache \
        alpine-sdk \
        g++ \
        gdal \ 
        gdal-dev \
        cmake \
        boost-dev \
        boost-serialization \
        libbz2 \
        expat-dev \
        swig \
        python3-dev

# Define a user and a wokring directory
ARG user=fmm
ARG home=/usr/src/$user

# Create the new working directory
RUN mkdir -p $home
# Set the current working directory.
WORKDIR $home

# Create a symbolic link for aliasing python3 as python 
RUN ln -s /usr/bin/python3 /usr/bin/python && \
    ln -s /usr/bin/pip3 /usr/bin/pip

# Clone the FMM github repository
RUN git clone https://github.com/cyang-kth/fmm.git && \
    cd fmm && \
    mkdir build && \
    cd build && \
    cmake .. -DPYTHON_LIBRARY=/usr/lib/libpython3.8.so -DPYTHON_INCLUDE_DIR=/usr/include/python3.8 && \
    make -j4 && \
    make install && \
    make clean

Then just build and run the image similar to how it was done with python 2 (since alpine linux is used as the base image you will probably have to run /bin/sh instead of /bin/bash).

MathiasVersichele commented 3 years ago

I just managed to load the file. To generate the shapefile I used st_snaptogrid(geom, 1) to round the geoms to 1m precision. When I don't simplify the geoms anymore, it loads fine. I guess the simplification makes some geoms (very short lines) collapse to NULL geometries. Weird that the attached file loads without issues for you though...

NicklasXYZ commented 3 years ago

Hmm, I see. I can't really give you any answers to that.
I only had a brief look at the library just now and looked through the issues :p

With both of the docker images I built and ran I got the trace:

[2021-02-02 18:17:56.585] [info] [network.cpp:72] Read network from file geouniq_nl_car_small.shp
[2021-02-02 18:17:56.672] [info] [network.cpp:170] Number of edges 4738 nodes 4021
[2021-02-02 18:17:56.672] [info] [network.cpp:171] Field index: id 0 source 1 target 2
[2021-02-02 18:17:56.675] [info] [network.cpp:174] Read network done

... after running the two commands you pasted in the original post.

MathiasVersichele commented 3 years ago

Ok, thanks for looking into it anyway! So, the issue for me is solved making sure no geometries collapse unto themselves by simplifying them.