Challenge: Encoded Polyline Algorithm

Challenge: Encoded Polyline Algorithm

CodeDing
Mentor Mentor
480 Views
3 Replies
Message 1 of 4

Challenge: Encoded Polyline Algorithm

CodeDing
Mentor
Mentor

Looking for a challenge?

 

Try to create this Encoded Polyline Algorithm in AutoLISP:

https://developers.google.com/maps/documentation/utilities/polylinealgorithm 

 

Example:

 

 

(setq ptList '((38.5 -120.2) (40.7 -120.95) (43.252 -126.453)))
(EncodePolyline ptList)
_p~iF~ps|U_ulLnnqC_mqNvxq`@   <<--- The correct output string

 

 

 

Why is this relevant?

Many mapping APIs can't afford the extreme overhead of very lengthy polyline coordinate arrays that get provided as parameters; and they don't always need to keep the full precision of a polyline when they're merely overlaying a vector line on a map image. So there needed to be a way to effectively reduce the amount of input data while still outputting the desired product (even if a little precision was lost in the process, it shouldn't be noticeable in the end result).

 

Attached is my go at it

 

Happy Coding!

~DD

481 Views
3 Replies
Replies (3)
Message 2 of 4

daniel_cadext
Advisor
Advisor

That’s pretty cool, the compression is really good!

could be really handy as a cad utility

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 3 of 4

CodeDing
Mentor
Mentor

@daniel_cadext ,

 

Well, it's a Lossy Compression, so idk if that's ideal for CAD software 🤔

can't think of where to apply it

0 Likes
Message 4 of 4

daniel_cadext
Advisor
Advisor

lossy because its rounding to single precision

I think if you can encode/decode XYZ coordinates, that could be useful.

Probably the same encoding, if you think of it as an array of floats

Could be used to store points in database blobs or maybe a spreadsheet  

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx