Batch create quick views for Embedded Datasets

Source: Internet
Author: User

Mosaic dataset is a new spatial data model launched in ArcGIS 10.0. It is used to manage massive image data. We often need to access the Quick View of image data. This article will show you how to create quick view files for Embedded datasets in batches.

Environment Description: In this example, file geodatabase is used to store embedded datasets. ArcObjects is used for development and is deployed in ArcMap using ArcGIS add-in, as a command tool. Yestool Interface Design:


It can be seen that the implementation of the tool requires several key steps:

1. Click the select button to open the folder browsing dialog box and select file Geodatabase;

2. The program automatically accesses file Geodatabase, obtains all mosaic dataset, and puts them in the drop-down list for users to choose from;

3. Set other output parameters: Quick View storage path, DPI, and image compression ratio;

4. Click the "start to generate" button to create quick view tasks in batches;

5. The program prompts the currently created content, displays the progress, and then prompts the user.

The most important thing is the operation after you click the start generate button, including accessing the embedded dataset, traversing each scene of the image data, and creating a quick view for it.

The following code is executed by clicking the button:

Private void btncreate_click (Object sender, eventargs e) {If (txtgdbpath. text. trim () = "" | directory. exists (txtgdbpath. text) = false | txtpreviewpath. text. trim () = "" | directory. exists (txtpreviewpath. text) = false) {MessageBox. show ("Please select the correct space database and quick view directory! "); Return;} txtlog. Text + =" Start: detailed progress information is written to the log file. \ R \ n "; long start = datetime. now. ticks; loghelper. addmessage (string. format ("{0} start to execute the quick view generation operation... ", datetime. now. tolongtimestring (); // open the embedded dataset imosaicdataset MD = gdbhelper. openmosaicdataset (_ workspace, cmbdatasets. selecteditem. tostring (); If (MD = NULL) {txtlog. text + = "error: No mosaic dataset is obtained. view the log for details. \ R \ n "; return;} short quality = (short) numquality. value; int DPI = (INT) numdpi. value; // create quick view gdbhelper in batches. createpreview (MD, _ activeview, cmbdatasets. selecteditem. tostring (), txtpreviewpath. text, quality, DPI); long end = datetime. now. ticks; int totaltime = (INT) (end-Start)/timespan. tickspersecond); loghelper. addmessage (string. format ("{0} the quick view generation operation is complete. The total time is {1} seconds. ", Datetime. Now. tolongtimestring (), totaltime); loghelper. writetologfile (); txtlog. Text + =" complete: view the log for details. ";}

The following code traverses an embedded Dataset:

Public static void createpreview (imosaicdataset mosaicdataset, iactiveview view, string mdname, string dirpreview, short quality, int outres) {itable ptable = publish (mosaicdataset); If (ptable = NULL) return; int indexname = ptable. findfield ("name"); int indexoid = ptable. findfield ("objectid"); int indexraster = ptable. findfield ("raster"); icursor pcursor = ptable. search (null, Fals E); irow prow = pcursor. nextrow (); int COUNT = 1; while (prow! = NULL) {string rastername = convert. tostring (prow. get_value (indexname); string OID = convert. tostring (prow. get_value (indexoid); string picname = string. format ("1_01__1_12.16.jpg", mdname, OID); picname = system. io. path. combine (dirpreview, picname); loghelper. addmessage (string. format ("Creating Fast view {0}: {1 }... ", Count, picname); If (file. exists (picname) {loghelper. addmessage (string. format ("{0} already exists. Skip... ", picname);} else {try {irastercatalogitem prastercatalogitem = (irastercatalogitem) prow; irasterdataset prasterdataset = prastercatalogitem. rasterdataset; irasterlayer prasterlayer = new rasterlayerclass (); prasterlayer. createfromdataset (prasterdataset); iraster praster = prasterlayer. raster; irasterprops prasterpro = praster as irasterprops; If (view. focusmap. layercount> 0) {view. focusmap. clearlayers ();} view. focusmap. addlayer (prasterlayer as ilayer); iarea parea = prasterpro. extent. envelope as iarea; view. fullextent = prasterpro. extent; view. fullextent. centerat (parea. centroid); view. refresh (); view. focusmap. recalcfullextent (); exportactiveview (view, picname, prasterpro. extent, quality, outres);} catch (exception ex) {loghelper. addmessage (string. format ("failed to create quick view for {0}:", Ex. message) ;}} prow = pcursor. nextrow (); count ++; If (count % 100 = 0) {loghelper. writetologfile (); GC. collect (); // if the memory is not cleared, the memory usage will be too large. When the x64 system reaches about GB, the program has no response} marshal. releasecomobject (pcursor); view. clear ();}

The following code creates a Quick View:

Private Static void exportactiveview (ESRI. ArcGIS. Carto. iactiveview pactiveview, system. String picname, ienvelope pen, short quality, int outres) {If (pactiveview = NULL |! (Picname. endswith (". jpg ") return; ESRI. arcGIS. output. iexport export = new ESRI. arcGIS. output. export;class (); export. exportfilename = picname; export. resolution = outres; // output resolution, that is, DPI. The default value is 96 iexportjpeg pexg = export as iexportjpeg; pexg. quality = Quality; // image quality, 0 ~ 100,100 indicates not compressing tagrect exportrect; // This is a structure exportrect. right = pactiveview. exportframe. right; exportrect. bottom = pactiveview. exportframe. bottom; exportrect = pactiveview. exportframe; idisplaytransformation pdisplaytransformation = pactiveview. screendisplay. displaytransformation; pdisplaytransformation. transformrect (pen, ref exportrect, 8); exportrect. left = 0; exportrect. top = 0; // ISC // set up the pixelbounds envelope to match the exportrect ESRI. arcGIS. geometry. ienvelope envelope = new ESRI. arcGIS. geometry. envelopeclass (); envelope. putcoords (exportrect. left, exportrect. top, exportrect. right, exportrect. bottom); export. pixelbounds = envelope; system. int32 HDC = export. startexporting (); pactiveview. output (HDC, (system. int16) export. resolution, ref exportrect, pen, null); // explicit cast and 'ref 'keyword needed export. finishexporting (); export. cleanup (); pactiveview. clear (); marshal. releasecomobject (pexg); marshal. releasecomobject (export); pexg = NULL; export = NULL ;}

The above is the key code for creating a quick view in batches for the embedded dataset. If you need the complete code, please leave the email address in the comments. If you have any questions, please submit them in the comments.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.