Pergunta

I am trying to use Matlab to send commands to FWTools in order to project a bunch of .shp files.

I am able to start FWTools from Matlab but I cant figure out how to send it commands without my interaction.

So far FWTools starts and my matlab command window and acts like the FWTools shell. I type commands and it will run, but I want to be able to send them in my .m file. Once FWTools starts up, my script will not continue to the next line of code.

My code so far:

cmd = 'ogr2ogr -s_srs "EPSG:4326" -t_srs "EPSG:3006" out_sweref99tm.shp in_wgs84.shp';
system('C:\Windows\system32\cmd.exe \K "d:\FWTools2.4.7\setfw.bat" ')
sprintf('%s',cmd) % try to send cmd to matlab command window aka FWTools

I also tried to put the cmd into my system call but that returned an error since it appears that I am trying to call FWTools with a super long string afterwards :(

cmd = 'ogr2ogr -s_srs "EPSG:4326" -t_srs "EPSG:3006" out_sweref99tm.shp in_wgs84.shp';
system(['C:\Windows\system32\cmd.exe \K "d:\FWTools2.4.7\setfw.bat" ',cmd])

The reason I am using FWTools is that I am projecting from WGS84 to SWEREF99TM and (from my understanding) its not easy to get the final projection via Matlab's mapping toolbox. Please correct me if I am wrong as I would love to keep it to Matlab.

And if possible, I would like to stay in Matlab and not move to Python.

Thanks. Norris

Foi útil?

Solução

The call of C:\Windows\system32\cmd.exe is not necessary.

Try this:

cmd = 'ogr2ogr -s_srs "EPSG:4326" -t_srs "EPSG:3006" out_sweref99tm.shp in_wgs84.shp';
system(['d: && cd d:\FWTools2.4.7\ && setfw.bat ',cmd])

or if you actually need to pass your parameters after the first call and not with:

system(['d: && cd d:\FWTools2.4.7\ && setfw.bat && ',cmd])

Maybe you can post a screenshot of how it looks like when you do it manually.


requested explanation:

The && operator is implicating that the following command is executed "in the next line". It's like you press enter in the cmd window and then you have to type the next command.

For example cd d:\FWTools2.4.7\ does never work directly, as the default is usually "c:". So firstly have to type d: and in the next step you change to your folder cd d:\FWTools2.4.7\

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top