jagodki / Offline-MapMatching

a QGIS-plugin for matching a trajectory with a network using a Hidden Markov Model and Viterbi algorithm
GNU General Public License v3.0
168 stars 51 forks source link

Applying for multiple line #43

Closed daymonj closed 3 years ago

daymonj commented 4 years ago

Hello, I'm Seongyeon. I'm trying to use this plugin for multiple lines which have unique id. But I think it doesn't provide grouping gps points by id. In my case to reduce computation time, clipping network is necessary before matching trajectory. I don't want to repeat these steps for every linestring in my dataset. So I tried to use pyqgis, but it seems quite difficult. How can I do in this case?

jagodki commented 4 years ago

Hello Seongyeon,

Could you provide a sample data of your trajectories? Than I could try to create a solution for your problem.

Sincerely, Christoph

daymonj commented 4 years ago

sample.zip

These are sample trajectory and network data. I'm using EPSG:5179. Trajectory sample data has four trajectories and each of them have use_id.

Thanks for your help:)

jagodki commented 3 years ago

Hi,

I am not sure, if there is a native PyQGIS function to get all unique values of a field. But it is possible with a bit python:

#init some vars
field_name = "use_id"
field_values = []

#get the selected layer
vl = iface.activeLayer()

#iterate over all features and read the values of the given field
for feature in vl.getFeatures():
    field_values.append(feature[field_name])

#get the unique values
unique_field_values = list(set(field_values))

#now iterate over all unique values and set each value as a filter argument
for unique_value in unique_field_values:
    vl.setSubsetString(field_name + " = " + str(unique_value))
    print("===")
    print(unique_value)
    print(vl.featureCount())

#remove any filter from the active layer
vl.setSubsetString("")

Explanation: The variable field_name is the name to separate your trajectory. In the second iteration a filter will be applied to the active layer (you should select the trajectory layer before running the script). After that I added some prints, which could be removed by calling my plugin via the processing framework.

You can run the script in the python console and in the python editor directly in QGIS. Please let me know, if this approach will fit your needs.

jagodki commented 3 years ago

closed because of inactivity, please reopen this issue if necessary