Select to view content in your preferred language

Merge multiple RasterDataset

3223
17
Jump to solution
03-28-2013 02:32 AM
oyleiste
Regular Contributor
Hello

I can get Linear Line of Sight from a single DTED file; which had beed opened by:
IWorkspaceFactory wsf = new RasterWorkspaceFactoryClass(); IRasterWorkspace rasterWS = (IRasterWorkspace)wsf.OpenFromFile(foldername, 0); IRasterDataset rasterDS = rasterWS.OpenRasterDataset("n42.dt0"); //DTED Level 0 file

Single DTED file means that both observer and target are in the DTED file's area.

Well, the problem occurs when I load more than one DTED files and want to use these functions:
IRaster raster = rasterDS.CreateDefaultRaster(); RasterSurfaceClass rsc = new RasterSurfaceClass(); rsc.PutRaster(raster); [INDENT]rsc.GetElevation(point);[/INDENT] [INDENT]rsc.GetLineOfSight(blah, blah, blah);
[/INDENT]

If observer is in a DTED file and target is in another DTED file, GetLineOfSight function fails obviously.
How can I merge two RasterDataset to give rsc.PutRaster() function one single raster?
Or
How can I put more than one raster in RasterSurfaceClass?

Thank you
Sincerely
0 Kudos
17 Replies
JasonPike
Frequent Contributor
Yes,   CreateDefaultRaster returns   IRaster; not   IRasterDataset. But keep in mind that   IRasterDatasetEdit.Mosaic gets   IRaster as first parameter, not   IRasterDataset. That's why I use   rasterDS[0].CreateDefaultRaster() function; to get   IRaster and pass it to   Mosaic function. 

The link; creates a   IRasterDataset for a image (map). Because it copies   pixels into it. My   IRastarDataset's format is   "DTED Level 0", not map nor image. So, I think I can't use it. 

I need more tea 😄 

I get   IRasterDataset like this: 
IWorkspaceFactory wsf = new RasterWorkspaceFactoryClass();
IRasterWorkspace rasterWS = (IRasterWorkspace)wsf.OpenFromFile(foldername, 0);
List<IRasterDataset> rasterDS = new List<IRasterDataset>();
rasterDS.Add(rasterWS.OpenRasterDataset(DTED_filename)); //"n34.dt0" for ex.

Yes, the documentation just says it's datatype: double 😐


I would be surprised if DTEDs (any level) weren't supported--they are very common raster types. I'll keep digging as I have time. Please keep the forum up-to-date on your progress.
0 Kudos
JasonPike
Frequent Contributor
I would be surprised if DTEDs (any level) weren't supported--they are very common raster types. I'll keep digging as I have time. Please keep the forum up-to-date on your progress.


Well, I guess I'm wrong:
http://downloads.esri.com/support/ProjectCenter/Raster_Data_Management_-_Introduction_to_ArcGIS_Rast...

Here is a presentation from 2004. I don't know if it is still relevant, but DTED 1 & 2 and supported, but DTED 0 isn't included in the list. I still haven't found a list of supported types in the 10.1 documentation.
0 Kudos
oyleiste
Regular Contributor
I just found this link that displays Raster formats for saving. There is no DTED in it.

I tried to copy my all DTED RasterDatasets to IRasterCollection using Append function, and save it using ISaveAs2.SaveAsRasterDataset, and then, load it from file again, but I couldn't save datasets as DTED. Code for this:
IRasterCollection rc = (IRasterCollection) new MosaicRasterClass();
rc.Append(rasterDS[0]);
rc.Append(rasterDS[1]);
ISaveAs save = (ISaveAs) rc;
IRasterStorageDef store = new RasterStorageDefClass();
store.CompressionType = esriRasterCompressionType.esriRasterCompressionUncompressed; //no idea!
save.SaveAsRasterDataset("ResultDTED", _workspace_, "X?", store);


You mean, if my DTEDs was level 1 or 2, Mosaic function wouldn't fail?

Thank you
0 Kudos
JasonPike
Frequent Contributor
I just found this link that displays Raster formats for saving. There is no DTED in it.

I tried to copy my all DTED RasterDatasets to IRasterCollection using Append function, and save it using ISaveAs2.SaveAsRasterDataset, and then, load it from file again, but I couldn't save datasets as DTED. Code for this:
IRasterCollection rc = (IRasterCollection) new MosaicRasterClass();
rc.Append(rasterDS[0]);
rc.Append(rasterDS[1]);
ISaveAs save = (ISaveAs) rc;
IRasterStorageDef store = new RasterStorageDefClass();
store.CompressionType = esriRasterCompressionType.esriRasterCompressionUncompressed; //no idea!
save.SaveAsRasterDataset("ResultDTED", _workspace_, "X?", store);


You mean, if my DTEDs was level 1 or 2, Mosaic function wouldn't fail?

Thank you


Well, I'm speculating that a DTED level 1 or 2 would work--I can't find anything definitive. In the PDF I linked in my last post, it indicated that DTEDs were read-only, so that is probably why you can't save. Could you save it to a different format and use it?
0 Kudos
oyleiste
Regular Contributor
Unfortunately Mosaic function fails for DTED Level 2 too.
I created 2 DTED Level 2 files, with made-up data, loaded successfully in Arcmap but Mosaic function failed again.
Could you save it to a different format and use it?

What format? I tried some formats and all failed.
Maybe I should change my strategy!

By the way, I found this link that says DTED 0, 1 and 2 are supported (for ver. 10.1)
0 Kudos
oyleiste
Regular Contributor
I tried this code for save mosaicked DTEDs:
IRasterCollection rc = new MosaicRasterClass();
rc.Insert(0, rasterDS[0].CreateDeafultRaster());
rc.Insert(1, rasterDS[1].CreateDeafultRaster());
ISaveAs2 save = (ISaveAs2)rc;
IRasterStorageDef st = new RasterStorageDefClass();
save.SaveAsRasterDataset("MosaicResult", (IWorkspace)_rasterworkspace_, "DTED", st);

The result file is 2.76 MByte and it's full of 0 elevation (full blue); and it's size is one of DTED's size, not twice (if mosaic was successful, result's size would be twice as one of DTEDs).

Any idea will be appreciated
Thanks
0 Kudos
oyleiste
Regular Contributor
I found out an interesting fact:
SaveAsRasterDataset returns IRasterDataset. As input, I gave SaveAsRasterDataset 2 DTED Level 0 in IRasterCollection.
So, I decided to store SaveAsRasterDataset's return data and explore it's contents. Returned IRasterDataset was DTED Level 1 !!
0 Kudos
oyleiste
Regular Contributor
Well, after a lot of struggling with this stuff, I solved the problem :cool: I'll share the code and explain it, so people can use it easily.

If you want to merge/mosaic some IRasterDataset, you can use my code:
IRasterCollection rc = (IRasterCollection) new MosaicRasterClass();

#region Add some IRasterDataset to the rc (IRasterCollection)
rc.Insert(0, rasterDataset0);
rc.Insert(1, rasterDataset1);
rc.Insert(2, rasterDataset2);
rc.Insert(3, rasterDataset3);
#endregion

ISaveAs2 save = (ISaveAs2) rc;
IRasterStorageDef st = new RasterStorageDefClass();
IRasterStorageDef3 store = (IRasterStorageDef3)st;
store.CompressionType = esriRasterCompressionType.esriRasterCompressionUncompressed;
store.Tiled = false;
IRasterDataset resultDataset = save.SaveAsRasterDataset("ResultDTED.dt0", _workspace_, "DEM", store);

First, you should create a IRasterCollection and add some IRasterDataset into it. Then you should create ISaveAs2 and cast rc to it. Then create IRasterStorageDef stuff. Finally, use ISaveAs2's SaveAsRasterDataset function to save merged/mosaicked RasterDataset to file and use it's return value as IRasterDataset. resultDataset contains the merged dataset.

Thank everyone for replying, specially Jason.
Sincerely
0 Kudos