简体   繁体   中英

How to find overlapping percentage of two polyline stored in mongodb?

I am using google maps API to get directions from one place to another. Google maps returns a polyline that looks something like this

o`kpBywaaMQs@y@{Ag@LUJEKUsFyATeE|@i@@{B?w@@iBLkC\}APoBP{BPyAJuBCqAJeAHkAB{@Bs@JcAVyCv@yBlBl@i@JoAPuB?}@@UB]NWRq@^yBdAaB~@IBEr@MpBK~A@RDLLFxBf@hAVb@P`Bz@bErB

First query

I want to know if I store this polyline in the mongo database or do I convert it to a list of points and store it as a LineString ?

Converting the polyline to points returns something like this

[
 (18.5756, 73.74221),
 (18.57569, 73.74247),
 (18.57598, 73.74239),
 (18.57601, 73.74237),
 (18.57603, 73.74238),
 (18.57605, 73.7424),
 (18.57622, 73.74286),
 (18.57642, 73.74279),
 (18.57653, 73.74273),
 (18.57656, 73.74279),
 (18.57667, 73.74401),
 (18.57712, 73.7439),
 (18.57811, 73.74359),
 (18.57832, 73.74358),
]

Second question

I will have to work with multiple such polylines and I need to find if two or more polylines overlap each other (and by what percentage if possible).

This relates to the first question as I would assume that executing a query for my above requirement would need the polyline to be stored in one of the two formats for eaiser (or successful) query execution.

yes you have to store it has a GeoJSON object, if you want to use the geospatial queries of mongodb. LineString seems indeed the best for you here

You can check if two GeoJSON object overlap each other with $geoIntersects Or you can check if an object is inside another with $geoWithin

But it doesn't seems that you can have the percentage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM