phayes / geoPHP

Advanced geometry operations in PHP
https://geophp.net
Other
861 stars 262 forks source link

Multiple coordinates on the same line throws fatal error #151

Open MappingSupport opened 6 years ago

MappingSupport commented 6 years ago

First, thank you for geoPHP. I am another Google map API dev that is converting to Leaflet. Alas, Leaflet lacks native support for KML/KMZ.

Once a day several KMZ files are produced and hosted on a federal FTP server. I need to display this data on a map in the browser. I manually converted one KMZ file to KML and then wrote a short PHP script to convert the KML to geoJSON using geoPHP. That conversion failed for the reason that coordinates.../coordinates is one looong csv string. Not a line break in sight.

It has been my experience that this way of presenting coordinates is quite common.

I modified the pentagon.kml file that comes with geoPHP so coordinates.../coordinates is one long csv string. Then I made a short script to demonstrate the error message.

File: https://mappingsupport.com/p/bug_report/pentagon_fail.kml

Script: https://mappingsupport.com/p/bug_report/simple_geophp_test.php

Error message: PHP Fatal error: Uncaught exception 'Exception' with message 'Cannot construct a LineString with a single point' in /home/mapping1/usr/geophp/lib/geometry/LineString.class.php:18

BathoryPeter commented 5 years ago

Your kml is invalid, coordinate tuples must not be separated with comma. https://developers.google.com/kml/documentation/kmlreference#coordinates Specification requires new line as separator, but I think geoPHP understands white spate too.