Comments (8)
@zhuang-hao-ming
This is a good question. What I expect for a python interface is something that can be tested interactively on the fly. It would be convenient if different components of the program can be designed with Python interface.
The program is like
from fmm import ubodt, network, mm_app
app = mm_app()
table = ubodt.read("ubodt.txt")
net = network.read("network.shp")
app.register_ubodt(table)
app.register_network(net)
app.register_config({r:200,k:8,pf:100})
# Some functions
print table.query_dist(12,23)
print table.query_path(12,23)
print net.search_candidate(point, k = 5, r= 200)
print app.match_wkt("Linestring ...")
With the python interface above, it would also be easy to design a map matching web service in Python using lightweight server such as flask.
https://github.com/BVLC/caffe/tree/master/examples/web_demo
I have very few experience with writing Python interface for C program. Perhaps that would be quite a lot of work.
from fmm.
Hello @cyang-kth .
I am not very familiar with Caffe.
I want to know what your definition of python interface is.
I just implemented a python interface.
It look like this.
>>> import fmm
>>> fmm.fmm("fmm_config.xml")
------------ Fast map matching (FMM) ------------
------------ Author: Can Yang ------------
------------ Version: 2018.03.09 ------------
------------ Applicaton: fmm ------------
Validating configuration for map match application:
Warning, overwrite existing result file.mr.txt
And the code look like this.
#include <boost/python.hpp>
#include <string>
using namespace std;
#include <app/fmm.cpp>
void fmm(string config_file_name) {
char* argvs[] = { "fmm" , const_cast<char*>(config_file_name.c_str()) };
main(2, argvs);
}
BOOST_PYTHON_MODULE(fmm)
{
using namespace boost::python;
def("fmm", fmm);
}
I think there is no difference between such a python interface and the command line.
So I think you might have some suggestions on the design of python interfaces.
Thank.
from fmm.
There seems to be several ways to write python wrapper for c++.
- Boost python https://www.boost.org/doc/libs/1_69_0/libs/python/doc/html/index.html
- SWIG http://www.swig.org/tutorial.html
- Cython https://cython.org/
Other popular libraries
- tensorflow : swig https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/pywrap_dlopen_global_flags.py#L31
- caffe: Cython
- GDAL: swig
- Numpy: swig
from fmm.
A Python API has been added in the latest commit.
from fmm.
Thanks @cyang-kth for the great work with this code!
Do you have plans to make the API available in python3?
Would be great, especially since python 2.7 reached end of life in 2020.
from fmm.
The current Python API is built using Swig, which supports Python 3.0 according to the documentation.
http://www.swig.org/Doc3.0/SWIGDocumentation.html#Python_python3support
If you want to build the Python 3 API you can just add a line to this cmake file before this line
Line 68 in dafe913
set_property(TARGET fmm PROPERTY SWIG_COMPILE_OPTIONS -py3)
Then you should have the Python 3 binding installed.
Currently I have no time to test the Python 3 binding but in the future it can be added as one option to the cmake command line to enable python 3 support.
from fmm.
Thanks for the quick reply! And thanks for the hint, I now managed to compile to python3.8, and the fmm_test.py
completes successfully. Also my first test on my own data looks promising.
I had to do some more modifications in the CMakeLists.txt
:
Require right python version:
find_package(PythonLibs 3.8 REQUIRED)
And I think the target is called pyfmm
, not fmm
:
set_property(TARGET pyfmm PROPERTY SWIG_COMPILE_OPTIONS -py3)
from fmm.
Thank you for correcting this problem. The current Swig built with cmake majorly copies from online resources so there exist some out of date commands and errors.
I will update the master branch when I have time.
from fmm.
Related Issues (20)
- Installation error
- Could we get (Matched edge index,indices) via command line approach
- can NOT run command "make .." under miniconda3 virtual environment
- Unable to perform python fmm_test.py on Win10 Home (64bit) with cygwin environment HOT 9
- error HOT 1
- Error when trying to execute GPS track / GPS points in CSV file HOT 3
- codes of python (fmm_example.ipynb) cannot output file with ogeom information since the result_config.output_config has no attribute of "write_ogeom"
- cpath and mgeom unmatched HOT 3
- Import error when running fmm_test.py
- make error HOT 2
- How to output duration
- Segmentation fault (core dumped) when constructing Network
- Build Error HOT 3
- cpath has multiple paths
- Strange Matching Results with Circles or Multiple Routes
- cmake报错
- Python API ImportError fmm related
- typedef std::conditional_t HOT 1
- "Cannot find proj.db" issue HOT 1
- build issue - make HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fmm.