PK$MGttgeojson2fromto/__init__.py""" Python module to convert GeoJSON to the 'from-to' format used by deck.gl's LineLayer """ __version__ = '0.2.9' PK $M;͑geojson2fromto/__main__.py""" Main entry file for the geojson2fromto module. """ from library import geojson2fromto if __name__ == '__main__': geojson2fromto.main() PK $M"geojson2fromto/library/__init__.pyPK$MA (geojson2fromto/library/geojson2fromto.py""" Module for converting geojson to from-to json. """ import sys from functools import reduce import simplejson as json import geopandas def get_geometries(input_file_path): """ Reads a GeoJSON input file and ouputs a geopandas.GeoSeries object with geometries. """ data_frame = geopandas.read_file(input_file_path) return data_frame['geometry'] def get_fromtos_line(linestring_coords): """ Converts a list of linestring coordinates to a list of 'from-to' dictionaries. """ line_coordinates_list_froms = linestring_coords[:-1] line_coordinates_list_tos = linestring_coords[1:] i = 0 fromtos = [] for i, val in enumerate(line_coordinates_list_froms): fromto_dict = {} fromto_dict['from'] = val fromto_dict['to'] = line_coordinates_list_tos[i] fromtos.append(fromto_dict) return fromtos def get_fromtos_multi(multi_linestring): """ Converts a GeoSeries with MuiltiLineStrings to a list of 'from-to' dictionaries. """ multi_linestring_coords = list(map( lambda linestring: list(linestring.coords), list(multi_linestring.geoms) )) return reduce( (lambda fromtos, linestring: fromtos + get_fromtos_line(linestring)), multi_linestring_coords, [] ) def get_fromtos(geometry): """ Converts a LineString or MultiLineString geometry to a list of 'from-to' dictionaries. """ if geometry is None: return [] geom_type = geometry.geom_type if geom_type == 'LineString': return get_fromtos_line(geometry.coords) if geom_type == 'MultiLineString': return get_fromtos_multi(geometry) return [] def convert(input_file_path): """ Converts a GeoJSON file to a list with dictionaries containing from and to fields. """ geometries = get_geometries(input_file_path) return reduce( (lambda fromtos, geometry: fromtos + get_fromtos(geometry)), geometries, [] ) def main(argv=sys.argv): # pylint: disable=dangerous-default-value """ Exposes the CLI of geojson2fromto """ json.encoder.FLOAT_REPR = lambda x: format(x, '.15f') try: inputfile_path = str(argv[1]) except IndexError: sys.stdout.write("Please provide a path to the input geojson file as the first argument") return False try: outputfile_path = str(argv[2]) except IndexError: outputfile_path = None fromto = convert(inputfile_path) if outputfile_path is not None: with open(outputfile_path, 'w') as outfile: json.dump(fromto, outfile) else: sys.stdout.write(json.dumps(fromto)) return True PK!H$7M/geojson2fromto-0.2.9.dist-info/entry_points.txtN+I/N.,()JO*3J+-ɷEd&%U [&fqqPKLL--&geojson2fromto-0.2.9.dist-info/LICENSEMIT License Copyright (c) 2018 Weasel & Fox Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HJVSa$geojson2fromto-0.2.9.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,rzd&Y)r$[)T&UD"PK!Hk!mM'geojson2fromto-0.2.9.dist-info/METADATATێF }Cm "4A ٺev.EQf%ڞ]iFKh>Oɗ#7%(:̥8fy}ӈ>ĪAhBM*:u$ztN-r&7DLgC5k~$Iȵ5K+\%^f߰ʧ?Je}V:k_8z:h܊5iJ1#e9T0.3RFAv*AIŞ2Lqlo:'vl>ը;| ǃɼ;c` -d(z}$6&IL@މM~׺yoXcHˀEILIfO 13Tdz{$Rf>ǧeVb?C| lNE PK!Hrѻ%geojson2fromto-0.2.9.dist-info/RECORDK0}`,h mn6*BDMYY5mM۳x9t՜)AWfwRXZ؈T&ʠ5qDś$I{+:#|JYI /e{O`j,T@$E}f #ʄ4vꍠf~ե߸=-7PB6Ea(;Kxys5v^P* Nlr"=vLF(&?:[Yؤr{-}*]Dv |U-#M~1Gbԇy?.3#ѩf/(6Fl<`Imoe]E(-).$x5HΝ wj AI\sPK$MGttgeojson2fromto/__init__.pyPK $M;͑geojson2fromto/__main__.pyPK $M"ugeojson2fromto/library/__init__.pyPK$MA (geojson2fromto/library/geojson2fromto.pyPK!H$7M/ geojson2fromto-0.2.9.dist-info/entry_points.txtPKLL--&< geojson2fromto-0.2.9.dist-info/LICENSEPK!HJVSa$geojson2fromto-0.2.9.dist-info/WHEELPK!Hk!mM'Bgeojson2fromto-0.2.9.dist-info/METADATAPK!Hrѻ%geojson2fromto-0.2.9.dist-info/RECORDPK