I'm a bit confused, what would be the best practice to not insert duplicate data in a table, I have the following code.
cnn = pyodbc.connect ( 'Driver={SQL Server};Server=**;Database=**;uid=**;pwd=**',autocommit=True )
sqlcmd = ("Select GEOM.STX as lng,GEOM.STY as lat,a.Codigo from Cie a \
inner join Inmueble b on a.idInmueble = b.idInmueble \
inner join DiviPolitica c on c.idDiviPolitica = b.idDiviPolitica \
inner join Dire d on d.idDivisionPolitica = c.idDivisionPolitica where d.geom is not null")
read = fiona.open(r"\geo-pre\data\ViasActivos.shp")
base = cnn.cursor()
base.execute(sqlcmd)
for feature in read:
coord = feature['geometry']['coordinates'][0]
name = feature['properties']['Name']
linea = feature['properties']['LINEA']
ramal = feature['properties']['RAMAL']
cabecera = feature['properties']['CABECERAS']
for r in base:
longVias = coord[0]
latVias = coord[1]
cordenadas = '\''+str(longVias)+','+str(latVias)+'\''
center_point = [{'lat': latCIE, 'lng': lngCIE}]
test_point = [{'lat': latVias, 'lng': longVias}]
lat1 = center_point[0]['lat']
lon1 = center_point[0]['lng']
lat2 = test_point[0]['lat']
lon2 = test_point[0]['lng']
radius = 5.00 # radio en kilometros
a = haversine(lon1, lat1, lon2, lat2)
insertVia = ("INSERT INTO [dbo].[atributosCapas] \
(idCapaOrigen,[idTipo] \
,[idOrigen] \
,[GeomTipo] \
,[Geom] \
,[Fecha] \
,[Nombre] \
,[Direccion] \
,[Localidad] \
,[Provincia],descripcion,cadena)\
VALUES (null,3,2,'Punto',null,GETDATE(),'%s',null,null,null,null,'Ramal:%s,Linea:%s,cabecera:%s','%s')" % \
(name,ramal,linea,cabecera,cordenadas))
base.execute(insertVia)
The first for goes through a shapefile, the second for goes through an MSSQL query that I later insert into a table, now the only field I have to ask if that data already exists in the table [dbo]. [attributesCapas] is by the name (name), which would be the best practice for not inserting duplicates
Edit: I add to the question that I would like to avoid techniques like NOT IN or EXIST