问题
I need to convert a shapefile/ kml to encoded polyline format for a certain project. Does anyone know of a simple conversion tool or code that achieves the same ?
回答1:
You'll first want to convert your KML/SHP to a list of lat/long pairs. For KML, you can simply open the KML file in an editor to get the lat/long pairs. For SHP, you can first use shp2kml to convert to KML.
Then, use the encoding library in the Maps API, or you can write your own encoder using the algorithm.
回答2:
Your term shapefile/kml is confusing. If you want to convert from an ESRI shapefile to a kml file, the utility ogr2ogr works like this:
ogr2ogr -f "KML" outputfile.kml sourcefile.shp.
For downloads, ogr2ogr is part of the GDAL distribution: http://www.gdal.org/
来源:https://stackoverflow.com/questions/9242988/how-to-generate-encoded-polylines-from-shapefile-kml