python 2.7 - How to reduce the coordinates decimal in a local kml file using pykml? -


I have a km file that has more than 1 million characters in cells I want to reduce the number of decimals in 12 to 3 I am I imported LXML and Picham.

pykml.helpers import import Piikl set_max_decimal_places file1 = open ( '\ United States divisions. Level 2 os import path #set_max_decimal_places (file1, max_decimals = {' longitude ': 3,' Latitude ': 3})

and I found this error:

  39 index_no = 0 # longitude is in first position 40 # modified & lt; latitude & gt; --- & gt; l. in doc.findall ( ".//{http://www.opengis.net/kml/2.2}longitude") 41: 42 new_val = round (float (Elktekst), Maks_disimals [Deta_prkar ]) 43 L.greatparent (). Longitude = K. Langueut (New_val)  

Specialty Enter: 'File' Objects There is no attribute 'Search' in

That's because you only need to Loading and it must be parsed first. From:

  In [29]: From the Picnic import parser ... in [40]: kml_file = path.join (\ .. a ..: '../src/pykml/test', \ ....: 'testfiles / google_kml_developers_guide', \ ....: 'in full_tour_example.kml') [44]: with open (kml_file) In the form f: ....: doc = parser.parse (F)  

Then you can call:

  ....: Set_max_decimal_places (doctor, max_decimals = {' Using the code, I think that it is the most important part of this code: 'latitude': 3, 'latitude': 3,})  

Update:

Should also work: ()

  file1 = open ('\ United States divisions. Level 2.kml ') doc = fromstring (file1.read (), schema = Schema ( "ogckml22.xsd")) set_max_decimal_places (doctor, Adiktm_disimals = 3)  

Update : 2

just drag the last code used by your comments:

  open ( "\ from set_max_decimal_places pykml import parser from Pykml.helpers import United Atry lxml import departments. level 2kkm L ') as f: doc = parser.parse (f) set_max_decimal_places (doc, max_decimals = {' longitude ': 3,' Latitude ': 3}) Print etree.tostring (doctor, pretty_print = true) outfile = file File.rstrip ('.py') + '. Kml ',' w ') outfile.write (etree.tostring (doctor, pretty_print = true))  

Comments