You will need to do some formatting of your data to make them into polygons. Merely labeling a field as WKT will not help. If you have a lot of files (which it sounds like you do), the most effective way will be to automate your solution by writing a script.
I was going to explain how when I decided that the simplest way would be to write an example script (apologies if I am teaching you to suck eggs!):
import os
csvFolder = r"C:\myFolder\mySubFolder"
#----------------------------------------
def writePolyToFile(outFile, polygon, polyId):
wkt = "POLYGON((" + ','.join(polygon) + "))\n"
outFile.write(str(polyId) + ';' + wkt)
def makePolys(inPath, outPath):
try:
with open(inPath,'r') as inFile:
contents = inFile.readlines()
polyId = 0
polygon = []
for line in contents:
line = line.rstrip('\n')
if polyId == 0:
if line != 'x,y':
print("Unexpected file contents detected in", inPath)
break
outFile = open(outPath,'w')
outFile.write("id;wkt\n")
polyId += 1
elif len(line) == 0:
writePolyToFile(outFile, polygon, polyId)
polygon = []
polyId += 1
else:
polygon.append(line.replace(',',' '))
writePolyToFile(outFile, polygon, polyId) #append the last polygon after EOF
outFile.close()
print('Conversion to WKT OK for', inPath)
except:
print('WARNING: conversion to WKT failed for', inPath)
def iterateFiles():
csvFiles = [each for each in os.listdir(csvFolder) if each.endswith('.csv')]
for file in csvFiles:
inPath = os.path.join(csvFolder, file)
newName = "WKT_" + file
outPath = os.path.join(csvFolder, newName)
makePolys(inPath, outPath)
#---------------------------------------------
if __name__ == "__main__":
iterateFiles()
This is a very simple Python script which will iterate over a folder of CSV files as a batch process. It does a crude logic check that the first line of the file follows your format of 'x,y'. It then collects all the points into an array until it finds a blank line and recasts the array as a WKT string which it writes to an output file of the same name as the original but prefixed by 'WKT_' (so 'firstFile.csv' exports to 'WKT_firstFile.csv' preserving the original file).
Change the following line csvFolder = r"C:\myFolder\mySubFolder" to point to a folder containing all the CSV files your want to convert (make sure you keep that 'r' at the start of the path!).
You can now open the resulting files using the normal 'Add vector layer' dialog instead of the 'Add delimited text' dialog.
EDIT
Here is a sample of my test:
Input:
x,y
10,10
20,20
20,30
10,10
5,5
5,6
6,5
5,5
15,15
30,30
30,40
15,15
Output:
id;wkt
1;POLYGON((10 10,20 20,20 30,10 10))
2;POLYGON((5 5,5 6,6 5,5 5))
3;POLYGON((15 15,30 30,30 40,15 15))