0

I'm trying to read a .csv file with the following format using MAC:

;lon;lat
0;55,245594;25,066697
1;55,135613;25,070419
2;55,275683;25,203425

What I am doing so far is:

$call csv2gdx coords.csv id=d index=1 values=2..lastCol useHeader=y

sets
  i 
  c /x,y/
;

parameters
  dloc(i,c) 'locations'
;

$gdxin clients_csv.gdx
$load ___ ?

What I want to do is read the lat,lon coordinates in the parameter dloc so as for each i to have a pair of coords c, i.e. lat, lon.

Example output:

           x           y

i1      17.175      84.327
azal
  • 1,210
  • 6
  • 23
  • 43

1 Answers1

0

Running your code produces an error from csv2gdx:

*** ErrNr = 15 Msg = Values(s) column number exceeds column count; Index = 2, ColCnt = 1

Per default, csv2gdx expects the entries separated by commas, which you do not have in your data. You could also define semicolon or tab as separator by means of an option, but if the data has really the format you posted, you do not need to call csv2gdx at all. You could just include the data directly like this:

Sets
  i 
  c
;

Table dloc(i<,c<) 'locations'
$include coords.csv
;

Display dloc;

EDIT after change of input data format:

The error message is still the same. And also the reason is the same: You use a different field separator than the default one. If you switch that using the option fieldSep=semiColon, you will realize that also your decimal separator is non-default for csv2gdx. But this can be changed as well. Here is the whole code (with adjusted csv2gdx call and adjustments for data loading). Note that sets i and c get implicitly defined when loading dloc with the < syntax in the declaration of dloc.

$call csv2gdx coords.csv id=d index=1 values=2..lastCol useHeader=y fieldSep=semiColon  decimalSep=comma

Sets
  i 
  c
;

parameters
  dloc(i<,c<) 'locations'
;

$gdxin coords.gdx
$load dloc=d

Display dloc;
$exit\
Lutz
  • 2,197
  • 1
  • 10
  • 12
  • pleas see the edit. The data are comma separated values. – azal Dec 17 '20 at 11:09
  • thanks for the answer. Do you maybe have an idea on how I can convert all those lat lon coordinates to x,y after I load them in a single pass? – azal Dec 17 '20 at 15:12
  • Not sure, if I got that right: You just want that the labels are called x/y instead of lat/lon? – Lutz Dec 17 '20 at 15:44
  • after loading with the above mentioned piece of code my coordinates, I want to convert them to x,y cartesian coordinates instead of lat, lon being loaded. – azal Dec 17 '20 at 15:53
  • What about this? https://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates – Lutz Dec 18 '20 at 05:54