(defun convert-loc-to-kml (patch-file flag poligon-color /  list-all-points list-current-point list-file list-strings coordinates coordinates-str description)
  
  (if patch-file
    (progn
      
      (setq list-file (file_read_to_list patch-file))
      (setq list-file (reverse (cddddr (reverse (cddddr list-file)))))
      (repeat (/(length list-file)14)
	(setq list-current-point (append list-current-point (list (get-record-id-loc-point (car list-file)))))
	(setq list-file (cdr list-file))
	(repeat 12
	  (setq list-current-point (append list-current-point (list (get-record-value-loc-point (car list-file)))))
	  (setq list-file (cdr list-file))
	  )
	(setq list-all-points (append list-all-points (list list-current-point)))
	(setq list-current-point nil)
	(setq list-file (cdr list-file))
	)
      (setq description "<![CDATA[имя план высота H<br>")
      (foreach x list-all-points
	(setq description (strcat
			    description
			    (strcat (get-item-by-name-in-list x "Description")" "
				    (get-item-by-name-in-list x "Use_Horizontal")" "
				    (get-item-by-name-in-list x "Use_Vertical")" "
				    (get-item-by-name-in-list x "Local_Z")"<br>")))
	)
      (setq description (strcat description "]]>"))
      (foreach y list-all-points
	(setq coordinates (append coordinates (list (list (atof (get-item-by-name-in-list y "Lon")) (atof (get-item-by-name-in-list y "Lat")) ))))
	)
      (setq coordinates (convert-list-points-to-poligon coordinates))
      (setq coordinates-str "")
      (foreach z coordinates
	(setq coordinates-str (strcat coordinates-str (rtos (nth 0 z) 2 13)"," (rtos (nth 1 z) 2 13) ",0 "))
	)
      (setq list-strings (list
			   "<?xml version=\"1.0\" encoding=\"windows-1251\"?>"
			   "<kml xmlns=\"http://earth.google.com/kml/2.2\">"
			   "<Document>"
			   "<Placemark>"
			   (strcat "<name>" (vl-filename-base patch-file)"</name>")
			   (strcat "<description>"description"</description>")
			   "<Style>"
			   "<LineStyle>"
			   (strcat "<color>" "A60000FF" "</color>")
			   "<width>2</width>"
			   "</LineStyle>"
			   "<PolyStyle>"
			   (strcat "<color>" poligon-color "</color>")
			   "<fill>1</fill>"
			   "</PolyStyle>"
			   "</Style>"
			   "<Polygon>"
			   "<extrude>1</extrude>"
			   "<outerBoundaryIs>"
			   "<LinearRing>"
			   (strcat "<coordinates>" coordinates-str "</coordinates>")
			   "</LinearRing>"
			   "</outerBoundaryIs>"
			   "</Polygon>"
			   "</Placemark>"
			   "</Document>"
			   "</kml>"
			   )
	    )
      
      (if flag
	(setq patch-file (getfiled "Имя сохраняемого файла..." (strcat (vl-filename-directory patch-file)"\\"(vl-filename-base patch-file)) "kml" 1))
	(setq patch-file (strcat (vl-filename-directory patch-file)"\\"(vl-filename-base patch-file)".kml")))
      (if patch-file(file_write_list_to_file patch-file list-strings))
      )
    )
  (princ)
  )