Browse Source

Dateien hochladen nach „“

master
parent
commit
a6cee62879
2 changed files with 58 additions and 0 deletions
  1. +3
    -0
      Sample CSV format.csv
  2. +55
    -0
      csv2kml.py

+ 3
- 0
Sample CSV format.csv View File

@ -0,0 +1,3 @@
Marca temporal,Lugar / Zona / Ubicación ,Sensor de presión,Modelo (sensor de presión),Arrancador,Modelo (arrancador),Caudalimetro ,Modelo (caudalimetro),Analizador de Potencia ,Modelo (analizador de Potencia),Interruptor de presión ,Modelo (interruptor de presión),RTU,Modelo (RTU),Modem,Modelo (Modem),Longitud,Latitud,ID del pozo,Sensor de nivel,Modelo (Sensor de nivel)
14/2/2023 9:41:44,Ciudad Universitaria ,"Si, funciona",Bdije7,No,NA,"Si, no funciona",Kdiu3,"Si, funciona",Jdjej7,No,Bejj3,"Si, funciona",Jdiy3,"Si, funciona",Jej28,19.72459,-101.18628,12345,"Si, no funciona",Djjeu3
14/2/2023 9:41:48,Santiaguito ,"Si, funciona",Nsjdk,"Si, funciona",Na,"Si, funciona",Na,"Si, funciona",Na,"Si, funciona",Na,"Si, funciona",12828,"Si, funciona",Jajdkkd,19.69028,-101.19635,257382,"Si, funciona",Jsjdk

+ 55
- 0
csv2kml.py View File

@ -0,0 +1,55 @@
import csv
import simplekml
def description(*argv):
"""Creates a description block with the arguments of the function"""
block = ''
check = 0
for arg in argv:
if arg == argv[0] and check == 0:
block = block + arg
check = 1
else:
block = block + '<BR>' + arg
return block
# Open the CSV file and read its contents
with open(r'D:\aleja\Downloads\cosa\Sample CSV format.csv', 'r') as file:
reader = csv.reader(file)
headers = next(reader)
# Create a KML document
kml = simplekml.Kml()
# Iterate over the rows in the CSV file
for row in reader:
# Extract the data for each field in the row
name = row[1]
pressure = "Sensor de presion: " + row[2] + " " + row[3]
starter = "Arrancador: " + row[4] + " " + row[5]
flow = "Caudalimetro: " + row[6] + " " + row[7]
power = "Analizador de potencia: " + row[8] + " " + row[9]
switch = "Interruptor de presion: " + row[10] + " " + row[11]
rtu = "RTU: " + row[12] + " " + row[13]
modem = "Modem: " + row[14] + " " + row[15]
ID = "ID: " + row[18]
level = "Sensor de nivel: " + row[19] + " " + row[20]
latitude = float(row[16])
longitude = float(row[17])
# Added function, arguments are data to be placed in description box
datos = description(name, ID, pressure, starter, flow, power, switch, rtu, modem, level)
# Add a new point to the KML document
point = kml.newpoint(name=name, description=datos, coords=[(longitude, latitude)])
point.style.labelstyle.scale = 1
point.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/water.png'
# Write the KML data to a file
print(kml.kml())
kml.save(r'D:\aleja\Downloads\cosa\Output.kml')

Loading…
Cancel
Save