I have a csv file
input.csv
1,[103.85,1.28992],[103.89,1.294],[103.83,1.216]
2,[103.5,1.292],[103.9,1.4],[103.3,1.21]
3,[103.6,1.291],[103.6,1.39],[103.3,1.29]
From this I need to convert it into
{
"type": "LineString",
"coordinates": [[103.85,1.28992],[103.89,1.294],[103.83,1.216]]
"properties": {
"id": "1"
}
},
{
"type": "LineString",
"properties": {
"id": "2"
},
"coordinates": [[103.5,1.292],[103.9,1.4],[103.3,1.21]]
},{
"type": "LineString",
"properties": {
"id": "3"
},
"coordinates": [[103.6,1.291],[103.6,1.39],[103.3,1.29]]
}
I am now trying to do it in java.So I read the csv file with open csv
try (CSVReader reader = new CSVReader(new FileReader(fileName))) {
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
for (String e: nextLine) {
// System.out.format("%s ", e);
System.out.println( e.split(",",1));
}
}
But I am having problem while spliting the line.If you look at the first line then I want to have
1 as a part and the rest [103.85,1.28992],[103.89,1.294],[103.83,1.216] as another part.So that I can build the String
String s="{\"type\": \"LineString\", \"coordinates\": "+s[1]+"
\"properties\": { \"id\":"+s[0]+"} }";
Any help is appreciated