I'm a beginner in Java and a geomatics student.
I would like to run the gdal unit from QGIS in the DOS command. I managed to open the executable in the command. But the command shows several types of sub folder.
C:\Program Files\QGISWien\bin>"C:\Program Files\QGISWien\bin\gdalwarp.exe"
Usage: gdalwarp [--help-general] [--formats]
[-s_srs srs_def] [-t_srs srs_def] [-to "NAME=VALUE"]
[-order n | -tps | -rpc | -geoloc] [-et err_threshold]
[-refine_gcps tolerance [minimum_gcps]]
[-te xmin ymin xmax ymax] [-tr xres yres] [-tap] [-ts width height]
[-wo "NAME=VALUE"] [-ot Byte/Int16/...] [-wt Byte/Int16]
[-srcnodata "value [value...]"] [-dstnodata "value [value...]"] -dstalpha
[-r resampling_method] [-wm memory_in_mb] [-multi] [-q]
[-cutline datasource] [-cl layer] [-cwhere expression]
[-csql statement] [-cblend dist_in_pixels] [-crop_to_cutline]
[-of format] [-co "NAME=VALUE"]* [-overwrite]
[-nomd] [-cvmd meta_conflict_value]
srcfile* dstfile
And I would like for example to open the [--help-general]
Any Ideas, how can I do that?
Thanks
hey with my knowledge if you have to open a file there is some basic tags you should follow
Opens an existing file and allows you to specify an editor.
"File.OpenFile filename [/e:editorname]"
Related
import PIL
img = PIL.Image.new("RGB", (100,100))
img.show()
The error message:
FSPathMakeRef(/Applications/Preview.app) failed with error -43.
Following from Sean True's answer, an even quicker but temporary fix is to simply make a symbolic link to Preview.app in the old location. In the terminal run
ln -s /System/Applications/Preview.app /Applications/Preview.app
This fixed the problem for me.
There's an official fix in github for Pillow 7, but I'm still on 6.
This appears to be a PIL ImageShow issue, with the PIL MacViewer using /Applications/Preview.app as an absolute path to the OSX Preview app.
It's not there in Catalina. I did a quick hack to ImageShow.py changing /Applications/Preview.app to just Preview.app and the issue went away. That might or might not still work on pre-Catalina OSX, but I don't have an easy way to test.
It has apparently moved to /System/Applications/Preview.app so a quick check at run time would probably cover both cases.
elif sys.platform == "darwin":
class MacViewer(Viewer):
format = "PNG"
options = {'compress_level': 1}
preview_locations = ["/System/Applications/Preview.app","/Applications/Preview.app"]
preview_location = None
def get_preview_application(self):
if self.preview_location is None:
for pl in self.preview_locations:
if os.path.exists(pl):
self.preview_location = pl
break
if self.preview_location is None:
raise RuntimeError("Can't find Preview.app in %s" % self.preview_locations)
return self.preview_location
def get_command(self, file, **options):
# on darwin open returns immediately resulting in the temp
# file removal while app is opening
pa = self.get_preview_application()
command = "open -a %s" % pa
command = "(%s %s; sleep 20; rm -f %s)&" % (command, quote(file),
quote(file))
return command
def show_file(self, file, **options):
"""Display given file"""
pa = self.get_preview_application()
fd, path = tempfile.mkstemp()
with os.fdopen(fd, 'w') as f:
f.write(file)
with open(path, "r") as f:
subprocess.Popen([
'im=$(cat);'
'open %s $im;'
'sleep 20;'
'rm -f $im' % pa
], shell=True, stdin=f)
os.remove(path)
return 1
I am trying to use mtimesx library on matlab 2016a, win 10 64bit, I compile this library and the following code runs in command window:
>> a=rand(2,4,2);
>> b=rand(4,5,2);
>> d=mtimesx(a,b)
d(:,:,1) =
0.5234 0.7756 0.6265 0.7531 0.6579
0.6256 0.3926 0.3557 0.7522 0.4804
d(:,:,2) =
0.6398 0.8713 0.8695 0.3040 0.6066
1.2157 1.0177 1.2590 0.5510 1.1960
but when I'm trying to run it as a script following error occurs:
Undefined function or variable 'mtimesx'.
Error in Untitled2 (line 25)
d=mtimesx(a,b);
and after that this function don't work in command window until I compile it again.
Thank you
the problem solved by making following changes in mtimesx_build.m:
1.changing mexopts = [prefdir '\mexopts.bat']; to ----> mexopts =[prefdir'\mex_C++_win64.xml'];
changing x = findstr(tline,'COMPILER=cl'); to ---> x = findstr(tline,'COMPILER="cl"');
I'm using Matlab to output a multi-page PS file:
print(figure, '-dpsc2', fullfile(folder, [file '.ps']), '-r600', '-append')
and then using Matlab to invoke Ghostscript to convert the resulting PS file to a PDF:
system(['"' gsPath '" -sDEVICE=pdfwrite \
-dDEVICEWIDTHPOINTS=' num2str(int32(width*72)) ' \
-dDEVICEHEIGHTPOINTS=' num2str(int32(height*72)) ' \
-dPDFFitPage \
-o "' fullfile(folder, [file '.pdf']) '" "' fullfile(folder, [file '.ps']) '"']);
which is just a really hard-to-read way of writing something along the lines of
gswin64c -sDEVICE=pdfwrite ^
-dDEVICEWIDTHPOINTS=100 ^
-dDEVICEHEIGHTPOINTS=100 ^
-dPDFFitPage ^
-o "C:\folder\output.pdf" "C:\folder\input.ps"
where I've put in example values for device dimensions and input/output paths. When I use this code to print a single figure (one page) to PDF, everything works perfectly. However, when printing multiple figures (multiple pages) to PDF, Ghostscript throws an error:
GPL Ghostscript 9.06 (2012-08-08)
Copyright (C) 2012 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
**** Unable to open the initial device, quitting.
Now, if I remove the -dDEVICEWIDTHPOINTS=100 -dDEVICEHEIGHTPOINTS=100 part of my Ghostscript command and again attempt to print multiple figures to a PDF, it works fine (except for the page size being different than what I want).
GPL Ghostscript 9.06 (2012-08-08)
Copyright (C) 2012 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Loading NimbusSanL-Regu font from %rom%Resource/Font/NimbusSanL-Regu... 4032872 2490784 2311720 1014184 2 done.
Has anyone else run into a similar problem and found a workaround for this issue? One of the keys here is that I need to be able to control the page size of the PDF produced. Thanks!
Below is an example that should run fine. First we create a multi-page PS file:
fname = 'test';
if exist([fname '.ps'], 'file'), delete([fname '.ps']); end
hfig = figure;
for i=1:10
plot(cumsum(rand(100,1)-0.5))
drawnow
print(hfig, '-dpsc2', '-append', [fname '.ps'])
end
close(hfig)
Next we convert it to PDF using Ghostscript, and properly crop the figures:
gs_path = 'C:\Program Files\gs\gs9.07\bin\gswin64c.exe';
gs_opts = '-dBATCH -dNOPAUSE -q';
% ps2pdf
cmd = sprintf('"%s" %s -sDEVICE=pdfwrite -dPDFFitPage -o %s %s', ...
gs_path, gs_opts, [fname '.pdf'], [fname '.ps']);
disp(cmd); system(cmd);
% get bbox
cmd = sprintf('"%s" %s -sDEVICE=bbox %s', ...
gs_path, gs_opts, [fname '.pdf']);
disp(cmd); [~,out] = system(cmd);
out = textscan(out, '%s', 'Delimiter','');
bbox = regexp(out{1}, '^%%BoundingBox: (\d+) (\d+) (\d+) (\d+)','tokens','once');
bbox = str2double(vertcat(bbox{:}));
bbox = [min(bbox(:,1:2)) max(bbox(:,3:4))];
% crop to bounding box
cmd = sprintf(['"%s" %s -o %s -sDEVICE=pdfwrite' ...
' -dDEVICEWIDTHPOINTS=%d -dDEVICEHEIGHTPOINTS=%d -dFIXEDMEDIA' ...
' -c "<</PageOffset [-%d -%d]>> setpagedevice" -f %s'], ...
gs_path, gs_opts, [fname '_cropped.pdf'], ...
bbox(3)-bbox(1), bbox(4)-bbox(2), bbox(1), bbox(2), [fname '.pdf']);
disp(cmd); system(cmd);
I'm working with the following script, run_test:
#!/bin/sh
temp=$1;
cat <<EOF | matlab
[status name] = unix('echo $temp');
disp(name);
% some Matlab code
test_complete = 1;
save(name)
exit
EOF
I want to pass a name to the script, run some code then save a .mat file with the name that was passed. However, there is a curious piece of behavior:
[energon2] ~ $ ./run_test 'run1'
Warning: No display specified. You will not be able to display graphics on the screen.
< M A T L A B (R) >
Copyright 1984-2010 The MathWorks, Inc.
Version 7.12.0.635 (R2011a) 64-bit (glnxa64)
March 18, 2011
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
>> >> >> >> run1
>> >> >> >> >>
[energon2] ~ $ ls *.mat
run1?.mat
There is a "?" at the end of the file name when it's saved, but not when displayed on command line. This is acceptable for my needs, but a bit irritating to not know why it's occurring. Any explanation would be appreciated.
Edits, solution:
Yuk was correct below in the underlying cause and the use of save('$temp'). I'm now using the following script
#!/bin/sh
temp=$1;
cat <<EOF | matlab
% some Matlab code
test_complete = 1;
save('$temp')
exit
EOF
Thanks for the help.
You name variable has end-of-line as the last character. When you run echo run1 in unix this command display run1 and then "hit enter". In your script all the output of echo are saved to the name variable.
You can confirm it with the following:
>> format compact
>> [status, name] = unix('echo run1')
status =
0
name =
run1
>> numel(name)
ans =
5
>> int8(name(end))
ans =
10
>> int8(sprintf('\n'))
ans =
10
Apparently this character can be a part of a file name in unix, but shell displays it as ?.
Can't you do save($temp) instead?
EDIT: See my comments below for correction and more explanation.
Is there any package to load .arff format file into matlab?
The .arff format is used in Weka for running machine learning algorithm.
Since Weka is a Java library, you can directly use the API it exposes to read ARFF files:
%## paths
WEKA_HOME = 'C:\Program Files\Weka-3-7';
javaaddpath([WEKA_HOME '\weka.jar']);
fName = [WEKA_HOME '\data\iris.arff'];
%## read file
loader = weka.core.converters.ArffLoader();
loader.setFile( java.io.File(fName) );
D = loader.getDataSet();
D.setClassIndex( D.numAttributes()-1 );
%## dataset
relationName = char(D.relationName);
numAttr = D.numAttributes;
numInst = D.numInstances;
%## attributes
%# attribute names
attributeNames = arrayfun(#(k) char(D.attribute(k).name), 0:numAttr-1, 'Uni',false);
%# attribute types
types = {'numeric' 'nominal' 'string' 'date' 'relational'};
attributeTypes = arrayfun(#(k) D.attribute(k-1).type, 1:numAttr);
attributeTypes = types(attributeTypes+1);
%# nominal attribute values
nominalValues = cell(numAttr,1);
for i=1:numAttr
if strcmpi(attributeTypes{i},'nominal')
nominalValues{i} = arrayfun(#(k) char(D.attribute(i-1).value(k-1)), 1:D.attribute(i-1).numValues, 'Uni',false);
end
end
%## instances
data = zeros(numInst,numAttr);
for i=1:numAttr
data(:,i) = D.attributeToDoubleArray(i-1);
end
%## visualize data
parallelcoords(data(:,1:end-1), ...
'Group',nominalValues{end}(data(:,end)+1), ...
'Labels',attributeNames(1:end-1))
title(relationName)
You can even directly use its functionality from MATLAB. An example:
%## classification
classifier = weka.classifiers.trees.J48();
classifier.buildClassifier( D );
fprintf('Classifier: %s %s\n%s', ...
char(classifier.getClass().getName()), ...
char(weka.core.Utils.joinOptions(classifier.getOptions())), ...
char(classifier.toString()) )
The output C4.5 decision tree:
Classifier: weka.classifiers.trees.J48 -C 0.25 -M 2
J48 pruned tree
------------------
petalwidth <= 0.6: Iris-setosa (50.0)
petalwidth > 0.6
| petalwidth <= 1.7
| | petallength <= 4.9: Iris-versicolor (48.0/1.0)
| | petallength > 4.9
| | | petalwidth <= 1.5: Iris-virginica (3.0)
| | | petalwidth > 1.5: Iris-versicolor (3.0/1.0)
| petalwidth > 1.7: Iris-virginica (46.0/1.0)
Number of Leaves : 5
Size of the tree : 9
Yes, there are a few MATLAB interfaces for WEKA files on MATLAB File Exchange, I normally use this one: http://www.mathworks.com/matlabcentral/fileexchange/21204-matlab-weka-interface where you have a saveARFF() and a loadARFF() functions.
If you only want to load a file stored in "arff" format into Matlab, and don't need any other functionality from Weka, just remove the header part of your "arff" file (those attribute definitions), and save the file as csv format (you should replace class values with a numeric equivalences), and then use the built-in "csvread" function of Matlab. This way there is no need to find a third party package.
M = importdata('filename.arff');
very slow for large files, but it works (tested in MATLAB 2010b)
Searching the MATLAB Central File Exchange reveals some possibilities. In particular, the results from Durga Lal Shrestha and Gerald Augusto Corzo Perez look promising, though I haven't tried either.
If the methods mentioned above do not work, and header information is required, load the arff file in weka, then select save as option and save the data using csv file format.