SOLVED: see my answer below
I am trying to open .tif, .img, and .dat Raster files to a new layer in ArcMap.
I have tried all the methods I have found in the documentation and a few implementations on StackOverflow.
This is the current code:
File file = new File(output);
IWorkspaceFactory wsFactory = (IWorkspaceFactory)new RasterWorkspaceFactory();
IRasterWorkspace2 rasterWS = (IRasterWorkspace2)wsFactory.openFromFile(file.getParentFile().getAbsolutePath(),0);
IRasterDataset rds = rasterWS.openRasterDataset(output);
IRasterLayer rasterLayer = new RasterLayer();
rasterLayer.createFromDataset(rds);
IActiveView activeView = mxDocument.getActiveView();
IMap _map = activeView.getFocusMap();
_map.addLayer(rasterLayer);
This code throws no error messages, but it does not open the layer. Previous implementations that I took from sample programs and documentation for arcObjects 10.2 throw exceptions on this line:
RasterDataset rasterDataset = (RasterDataset) rasterWorkspace.openRasterDataset(file.getAbsolutePath());
The only lead I have right now is the ControlsAddDataCommand class to possibly call the command for opening the files and give the filepath as input. Build a custom command to open the file?
Note: The files open fine by clicking the addData option on the Layer menu.
SOLVED
IRasterLayer rasterLayer = new RasterLayer();
rasterLayer.createFromFilePath(output);
mxDocument.addLayer(rasterLayer);
Found this code by browsing the JavaDoc Tooltips in Eclipse.
Just type in the object and a "." Eclipse will show all the options available.
I'm amazed this code snippet wasn't listed anywhere online (that I found in about 8 hours of searching). Anyways, that's the simple 3 line solution!
Related
I have been trying to utilize the Android SDK from Maffen:
https://github.com/mrmaffen/vlc-android-sdk/ in order to stream RTSP.
So I found the following stack overflow thread:
vlc-android-sdk - cannot view RTSP live video
Which has a number of answers of how to do this.
However, the problem I am having is that when I try to set the options for LibVLC it will not allow me to do so.
For example:
ArrayList<String> options = new ArrayList<String>();
options.add("--no-drop-late-frames");
options.add("--no-skip-frames");
options.add("--rtsp-tcp");
options.add("-vvv");
videoVlc = new LibVLC(options)
When I try to run this I get the following error message in Android Studio:
"error: incompatible types: ArrayList cannot be converted to Context"
Also if I hover over the "LibVLC(options)" section of the code it comes up with the following message:
"LibVLC (android.content.Context) in LibVLC cannot be applied to (java.util.ArrayList)
I'm no Java expert, so perhaps this is an easy fix but I have been trying different sample codes from around the internet all day and every single one sets those options and I can't do it.
Any help would be much appreciated. Thank you!
EDIT:
This problem was solved using the following:
videoVlc = new LibVLC(this, options);
I had simply forgot about including the context part of the LibVLC.
I forgot to go back and edit this once I had arrived at a solution.
maffen vlc android sdk. the constructor LibVLC takes two params. context and options. option can be null. and options should be the second one. the older version may only takes one param option
I want to create a plugin that adds a video on the current slide in an open instance of Open Office Impress by specifying the location of the video automatically. I have successfully added shapes to the slide. But I cannot find a way to embed a video.
Using the .uno:InsertAVMedia I can take user input to choose a file and it works. How do I want to specify the location of the file programmatically?
CONCLUSION:
This is not supported by the API. Images and audio can be inserted without user intervention but videos cannot be done this way. Hope this feature is released in subsequent versions.
You requested information about an extension, even though the code you are using is quite different, using a file stream reader and POI.
If you really do want to develop an extension, then start with one of the Java samples. An example that uses Impress is https://wiki.openoffice.org/wiki/File:SDraw.zip.
Inserting videos into an Impress presentation can be difficult. First be sure you can get it to work manually. The most obvious way to do that seems to be Insert -> Media -> Audio or Video. However many people use links to files instead of actually embedding the file. See also https://ask.libreoffice.org/en/question/1898/how-to-embed-video-into-impress-presentation/.
If embedding is working for your needs and you want to automate the embedding by using an extension (which seems to be what your question is asking), then there is a dispatcher method called InsertAVMedia that does this.
I do not know offhand what the parameters are for the call. See https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=61127 for how to look up parameters for dispatcher calls.
EDIT
Here is some Basic code that inserts a video.
sub insert_video
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:InsertAVMedia", "", 0, Array())
end sub
From looking at InsertAVMedia in sfx.sdi, it seems that this call does not take any parameters.
EDIT 2
Sorry but InsertVideo and InsertImage do not take parameters either. From svx.sdi it looks like the following calls take parameters of some sort: InsertGalleryPic, InsertGraphic, InsertObject, InsertPlugin, AVMediaToolBox.
However according to https://wiki.openoffice.org/wiki/Documentation/OOoAuthors_User_Manual/Getting_Started/Sometimes_the_macro_recorder_fails, it is not possible to specify a file for InsertObject. That documentation also mentions that you never know what will work until you try it.
InsertGraphic takes a FileName parameter, so I would think that should work.
It is possible to add an XPlayer on the current slide. It looks like this will allow you to play a video, and you can specify the file's URL automatically.
Here is an example using createPlayer: https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=57699.
EDIT:
This Basic code works on my system. To play the video, simply call the routine.
sub play_video
If Video_flag = 0 Then
video =converttoURL( _
"C:\Users\JimStandard\Downloads\H264_test1_Talkinghead_avi_480x360.avi")
Video_flag = 1
'for windows:
oManager = CreateUnoService("com.sun.star.media.Manager_DirectX")
' for Linux
' oManager = CreateUnoService("com.sun.star.media.Manager_GStreamer")
oPlayer = oManager.createPlayer( video )
' oPlayer.CreatePlayerwindow(array()) ' crashes?
'oPlayer.setRate(1.1)
oPlayer.setPlaybackLoop(False)
oPlayer.setMediaTime(0.0)
oPlayer.setVolumeDB(GetSoundVolume())
oPlayer.start() ' Lecture
Player_flag = 1
Else
oPlayer.start() ' Lecture
Player_flag = 1
End If
End Sub
I have 2 .m files. One is the function and the other one (read.m) reads then function and exports the results into an excel file. I have a java program that makes some changes to the .m files. After the changes I want to automate the execution/running of the .m files. I have downloaded the matlabcontrol.jar and I am looking for a way to use it to invoke and run the read.m file that then reads the function.
Can anyone help me with the code? Thanks
I have tried this code but it does not work.
public static void tomatlab() throws MatlabConnectionException, MatlabInvocationException {
MatlabProxyFactoryOptions options =
new MatlabProxyFactoryOptions.Builder()
.setUsePreviouslyControlledSession(true)
.build();
MatlabProxyFactory factory = new MatlabProxyFactory(options);
MatlabProxy proxy = factory.getProxy();
proxy.eval("addpath('C:\\path_to_read.m')");
proxy.feval("read");
proxy.eval("rmpath('C:\\path_to_read.m')");
// close connection
proxy.disconnect();
}
Based on the official tutorial in the Wiki of the project, it seems quite straightforward to start with this API.
The path-manipulation might be a bit tricky, but I would give a try to loading the whole script into a string and passing it to eval (please note I have no prior experience with this specific Matlab library). That could be done quite easily (with joining Files.readAllLines() for example).
Hope that helps something.
I am trying to get PDF417 barcode reading to be enabled in ZXing (Zebra Crossing). I did a pull from the github repo and built the library according to the wiki. The ant build output seems to indicate that the PDF417 submodule is being built. I tried to test everything according to the wiki using these images but I get a "no barcode found" error.
kscottz#kscottz-laptop:~/barcode/zxing$ java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner Sample_PDF417.png
file:/home/kscottz/barcode/zxing/Sample_PDF417.png: No barcode found
kscottz#kscottz-laptop:~/barcode/zxing$ java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner bc.png
file:/home/kscottz/barcode/zxing/bc.png: No barcode found
kscottz#kscottz-laptop:~/barcode/zxing$ java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner sanitycheck.jpg
file:/home/kscottz/barcode/zxing/sanitycheck.jpg (format: QR_CODE, type: TEXT):
Raw result:
<-- SNIP -->
What gives? Am I missing a flag to enable PDF417? Where would one look to set these sorts of configuration options? I am regularly a Python/C/C++ developer so I may be missing something pretty basic.
Try --try_harder, otherwise it's in the mode suitable for mobile devices, instead of using more CPU to scan the image more. --pure_barcode will probably work too since these are synthetic images.
In general. These don't seem to decode though. I can't access the first image, and the second isn't found even in the online decoder (which you can always use as a check): http://zxing.elasticbeanstalk.com/w/decode.jspx
I don't know why since I presume it's valid. You can run through the debugger to see exactly what goes wrong.
So I ran the ZXing test script on the test barcodes and they do pass, so I am going to assume it is enabled. It appears that when zxing says alpha they really mean alpha. =(
Basically to detect only PDF417 barcode using ZXING library, you need to pass in the hints asking ZXING to only look for PDF417 type.
try below,
hints.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.of(BarcodeFormat.PDF_417));
Checkout the below example,
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
hints.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.of(BarcodeFormat.PDF_417));
//hints.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.allOf(BarcodeFormat.class));
hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
hints.put(DecodeHintType.TRY_HARDER, true);
Result result = new MultiFormatReader().decode(bitmap, hints);
Using Eclipse jdt facilities, you can traverse the AST of java code snippets as follows:
ASTParser ASTparser = ASTParser.newParser(AST.JLS3);
ASTparser.setSource("package x;class X{}".toCharArray());
ASTparser.createAST(null).accept(...);
But when trying to perform code complete & code selection it seems that I have to do it in a plug-in application since I have to write codes like
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(somePath));
ICodeAssist i = JavaCore.createCompilationUnitFrom(f);
i.codeComplete/codeSelect(...)
Is there anyway that I can finally get a stand-alone java application which incorporates the jdt code complete/select facilities?
thx a lot!
shi kui
I have noticed it that using org.eclipse.jdt.internal.codeassist.complete.CompletionParser
I can parse a code snippet as well.
CompletionParser parser =new CompletionParser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
new CompilerOptions(null),
new DefaultProblemFactory(Locale.getDefault())),
false);
org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit =
new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(
"class T{f(){new T().=1;} \nint j;}".toCharArray(), "testName", null);
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration unit = parser.dietParse(sourceUnit, compilationResult, 25);
But I have 2 questions:
1. How to retrive the assist information?
2. How can I specify class path or source path for the compiler to look up type/method/field information?
I don't think so, unless you provide your own implementation of ICodeAssist.
As the Performing code assist on Java code mentions, Elements that allow this manipulation should implement ICodeAssist.
There are two kinds of manipulation:
Code completion - compute the completion of a Java token.
Code selection - answer the Java element indicated by the selected text of a given offset and length.
In the Java model there are two elements that implement this interface: IClassFile and ICompilationUnit.
Code completion and code selection only answer results for a class file if it has attached source.
You could try opening a File outside of any workspace (like this FAQ), but the result wouldn't implement ICodeAssist.
So the IFile most of the time comes from a workspace location.