In order to use the offline electronic map in AE program, the idea is as follows:
Download the map slices using the download tool, then use C # to slice the tiles into one image, then georeferencing them using arcmap and publish them to the ArcGIS Server slicing service for the program to use.
Today's talk about how to use C # splicing slices.
1. Slice download tool URL : Open source Map Downloader
The downloader is not very good, but compared to the charge trial version is still possible, the download interface is as follows:
2, data preparation, download good data such as :
3. Button click event
Private voidButton1_Click (Objectsender, EventArgs e) { //called TilesboundsTilesbounds =New tilesbounds(); Tilesbounds.mincol=109173; Tilesbounds.maxcol=109256; Tilesbounds.minrow=53284; Tilesbounds.maxrow=53363; //calculate the number of slices intnum = (tilesbounds.maxcol-tilesbounds.mincol) * (Tilesbounds.maxrow-Tilesbounds.minrow); Progressbar1.maximum= num *2; Progressbar1.step=1; Label3. Text=Num. ToString (); Tilesbounds.zoomlevel= -; stringOutputFileName ="F:\\18.png"; stringTilepath =@"C:\data\titledata\"; Combinetiles (Tilesbounds, Tilepath, OutputFileName); MessageBox. Show ("Stitching Complete"); }
4. Assign the pixel value of a single slice to the image after stitching
intA =0; //To display the progress bar ////Assign the pixel value of a single slice to the stitched image Private voidSavebitmapbuffered (BitmapMainbit,stringBmppath,intXinty) {a++; progressBar1.Value=A; X= x * the; Y= y * the; Label4. Text=a.tostring (); Application.doevents (); Bitmap bt=New Bitmap(Bmppath); for(inti =0; I < the; i++) { for(intj =0; J < the; J + +) {mainbit. SetPixel (x+ I, Y +J, Bt. GetPixel (i,j)); } } }
5, traverse the tile and save the picture after stitching
/// <summary> ///Traversing Tiles/// </summary> Private voidCombinetiles (Tilesbounds tilesbounds,stringTilepath,stringoutputfilename) { if(File. Exists (OutputFileName)) { File. Delete (OutputFileName); } intImageWidth = the* (Tilesbounds.maxcol-tilesbounds.mincol +1); intImageHeight = the* (Tilesbounds.maxrow-tilesbounds.minrow +1); Bitmap memoryimg=New Bitmap(ImageWidth, ImageHeight);//set the image size after stitching, note: If the picture is large, you need to set the program to 64-bit for(intcol = Tilesbounds.mincol; Col <= Tilesbounds.maxcol; col++) { for(introw = Tilesbounds.minrow; Row <= Tilesbounds.maxrow; row++) { Try { stringsourceFileName = Tilepath + tilesBounds.zoomLevel.ToString () +"\\"+ Col. ToString () +"\\"+ row. ToString () +". PNG"; if(File.exists (sourceFileName)) {savebitmapbuffered (memoryimg, SOURC Efilename, Col-Tilesbounds.mincol, Row-Tilesbounds.minrow); } Else{Console.WriteLine ("does not exist:"+sourceFileName); } } Catch(Exception ex) { MessageBox. Show (ex. ToString ()); }}} memoryimg. Save (outputfilename);//Save the merged picturememoryimg. Dispose (); }
6, Tilesbounds class
classTilesbounds { Public intMincol {Get;Set; } Public intMaxcol {Get;Set; } Public intMinrow {Get;Set; } Public intMaxRow {Get;Set; } Public intZoomlevel {Get;Set; } }
7. The stitching effect is as follows:
8, the source code is as follows, test data included:
Http://pan.baidu.com/s/1jIJgJX0
C # tiled Map tiles