create geotiff from jpg with jgw file using geotools? - geotools

i have an image in JPG also crated JGW file using Affine transformation now i want to convert this jpg file with jgw file into geotiff how can i do that?
thanks

First you'll need to make sure you have a dependency on gt-image and gt-geotiff:
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-image</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-geotiff</artifactId>
<version>${geotools.version}</version>
</dependency>
Then you can simply open the JPG with WLD file (or any other image based file) and write it out as a GeoTIFF.
AbstractGridFormat format = GridFormatFinder.findFormat(input);
Hints hints = null;
if (format instanceof GeoTiffFormat) {
hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
}
AbstractGridCoverage2DReader reader = format.getReader(input, hints);
GridCoverage2D grid = reader.read(null);
reader.dispose();
File out = new File("test.tif");
GeoTiffFormat outFormat = new GeoTiffFormat();
GridCoverageWriter writer = outFormat.getWriter(out, hints);
writer.write(grid, null);
writer.dispose();

Related

Google Drive upload file from localhost hardisk, OOM issues due to HttpPostedFile

This is web application, try to upload file in folder to Google Drive, I had done all the setting at Google console to get the credentials. It only work for smaller file, file size more than 200MB will hit OOM error. What should I do?
For the web config, I had set
<httpRuntime targetFramework="4.5" maxRequestLength="2000000000" executionTimeout="99999999" />
<gcAllowVeryLargeObjects enabled="true" />
After i get the Authorize from google at page load, i try to loop the directory to get the files.
protected string[] dirs = Directory.GetFiles(#"C:\Users\Yeep\Desktop\GoogleDrive");
After loop each of the file I will create FileStream / ReadAllBytes I had try 2 way.
foreach (string dir in dirs)
{
byte[] buffer = null;
using (FileStream fs = new FileStream(dir, FileMode.Open, FileAccess.Read))
{
buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int)fs.Length);
}
//byte[] fileData = System.IO.File.ReadAllBytes(dir); //or this way
}
After loop through the file, to read all the bytes, I will run this / this.
Session["File"] = ConstructHttpPostedFile(buffer, fileName);
When Create an HttpRawUploadedContent instance it hit OOM, how to solve or got any other method?

Simple Download with CloudRail fails

I am trying to implement an application that includes downloading files from Dropbox. It looks like there is a simple straightforward framework that does that (CloudRail). But the codes crashes when I try to work with the file downloaded (in this case an image), here is the example:
self.dropboxInstance = [[Dropbox alloc] initWithClientId:self.authDic[#“————“] clientSecret:self.authDic[#“————“]];
id returnObject = [self.dropboxInstance downloadWithFilePath:#“/pictures/001.png“];
UIImage * image = [UIImage imageWithData:object]; // CRASH HERE
I checked the network and disk activity through Xcode tools and the download is performed correctly, so I believe it has something to do with the return of the download function.
First of all, the return type of the method is an NSInputStream, that can be used to read the contents of the file you downloaded.
The reason why the code is not working is because you are treating it as an NSData type.
So the solution would be to first read all the content from the stream received as return, store it in an NSData object and then create an UIImage from the data.
self.dropboxInstance = [[Dropbox alloc] initWithClientId:self.authDic[#“————“] clientSecret:self.authDic[#“————“]];
id returnObject = [self.dropboxInstance downloadWithFilePath:#“/pictures/001.png“];
//NEW CODE
NSInputStream * inputStream = returnObject;
[inputStream open];
NSInteger result;
uint8_t buffer[1024]; // buffer of 1kB
while((result = [inputStream read:buffer maxLength:1024]) != 0) {
if(result > 0) {
// buffer contains result bytes of data to be handled
[data appendBytes:buffer length:result];
} else {
// The stream had an error. You can get an NSError object using [iStream streamError]
if (result<0) {
[NSException raise:#"STREAM_ERROR" format:#"%#", [inputStream streamError]];
}
}
}
//END NEWCODE
UIImage * image = [UIImage imageWithData:data]; // NO CRASH ANYMORE :)
The above code is used to read from the stream in a procedural way (will block the thread). To read from the stream asynchronously refer to this other answer (Stream to Get Data - NSInputStream). Hope this helped.

WinRT: How to read images from the pictures library via an URI?

Trying to read an image that is stored in the pictures library via an URI the image is never displayed (in an Image control). Reading the same image via a stream works (assuming the app hat the Picture Library capability declared of course). Reading images from the application's data folder via an URI works.
Does someone know what could be wrong?
Here is how I (unsucessfully) try to read an image via an URI:
var imageFile = (await KnownFolders.PicturesLibrary.GetFilesAsync()).FirstOrDefault();
string imagePath = imageFile.Path;
Uri uriSource = new Uri(imagePath);
var bitmap = new BitmapImage(uriSource);
this.Image.Source = bitmap;
Here is how I sucessfully read the same image via a stream:
var imageFile = (await KnownFolders.PicturesLibrary.GetFilesAsync()).FirstOrDefault();
BitmapImage bitmap;
using (var stream = await imageFile.OpenReadAsync())
{
bitmap = new BitmapImage();
await bitmap.SetSourceAsync(stream);
}
this.Image.Source = bitmap;
I need to read the image via URI because this is the fastest way to read images and is async by nature, working perfectly with data binding.
There is no URI for the pictures library. You'll need to get the StorageFile and stream it in.
The file URI you use doesn't work because the app doesn't have direct access to the PicturesLibrary and so cannot reference items there by path. The StorageFile object provides brokered access to locations that the app doesn't natively have permissions to.

How to create NEW txt file using Adobe AIR

How to create a REALY NEW text file (.txt) using AS3 adobe AIR. Most articles are writing to EXISTING text file (text file already exist).
like this one:
How to create new File txt by using Adobe Air
Thank you.
//create a reference to the file in the applicationStorage Directory
//(for more directories, look at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html
var fileToCreate:File = File.applicationStorageDirectory;
fileToCreate = fileToCreate.resolvePath("myfile.txt");
//create a filestream to write to the file
//the write and/or creating the file is done with the FileMode in the open() function
//look at the table that describes what FileMode does what here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileMode.html
var fileStream:FileStream = new FileStream();
fileStream.open(fileToCreate, FileMode.WRITE);
//write some string to the file
fileStream.writeUTF('this is a string to write to the file');
//finally, close the filestream
fileStream.close();
EDIT: changed filemode from READ to WRITE. READ does not create the file ofcourse :)

image in local html couldn't be loaded into webview in windows8

I want to load local html file which in the local folder to the webview, but WebView doesn't support 'ms-aspx:///' protocal, I found a solution to read the html file to stream, and then convert it to string, using NavigateToString method to load the html, it works well. But, If there's an image in the html file, the image couldn't display, anyone can help?
I have solved.
Solution:
Convert the image file to base64 string
StorageFolder appFolder = ApplicationData.Current.LocalFolder;
StorageFile file = await appFolder.GetFileAsync("SplashScreen.png");
using (var stream = await file.OpenAsync(FileAccessMode.Read))
{
var reader = new DataReader(stream.GetInputStreamAt(0));
var bytes = new byte[stream.Size];
await reader.LoadAsync((uint)stream.Size);
reader.ReadBytes(bytes);
base64 = Convert.ToBase64String(bytes);
}
Use StringBuilder to create the html string
sb.Append("<html><head><title>Image test</title></head><body><p>This is a test app!</p><img src=\"data:image/png;base64,");
sb.Append(base64);
sb.Append("\" /></body></html>");
TestWebView.NavigateToString(sb.ToString());
Try using the ms-appx-web:// scheme instead of ms-aspx:// to load html from a WebView. If that doesn't work, you may need to use the ms-appdata:// scheme to access the image if it's in your application data folder.
Some further resources that might help:
How to load a local HTML-File into Webview
URI schemes
How to reference content