Gdal Database Study Notes (1): Seamless stitching of Google satellite images

Source: Internet
Author: User

Before starting the project, you should first understand the tile map. The tile map Pyramid Model is a multi-resolution hierarchical model. From the bottom layer of the tile pyramid to the top layer, the resolution is getting lower and lower, but the geographical range is unchanged. The implementation principle is to first determine the number of scaling levels n provided by the map service platform, and use the map images with the lowest scaling level and the largest map scale as the bottom layer of the pyramid, that is, layer 0th, it is segmented into square map tiles of the same size (such as 256x256 pixels) starting from the upper left corner of the map image, from left to right and from top to bottom, layer-4 tile matrix is formed. On the basis of the O-layer map image, a layer-2 map image is generated and segmented by merging every 2x2 pixels into a pixel, split into square map tiles of the same size as the next layer to form a 1st-layer tile matrix. A 2nd-layer tile matrix is generated using the same method ;...; Until the first layer of N constitutes the entire tile pyramid.

In Google Maps, map data is composed of a large number of square images. There is a two-level scaling ratio. Each map image has a coordinate value, which consists of X and Y values. The value range of proportional factor Zoom is (0-22 ). When the map slider displays a larger scale map, the number of images is split. The two modes differ significantly in the request and response speed. The response speed based on the map tile service framework is faster than that of the traditional WebGIS, and the load on the map server is also smaller.

Now we can start work. First, we can prepare a tile map. If it is used for research, we can use some third-party tools (of course we can write one ourselves) to capture the tile map from Google Maps and store it locally, for example, it is stored in the format of c: \ googlemas \ satelite \ x \ y.jpg, where x, y, and z represent the column, row, and zoom level of the tile respectively.

 

With these figures, we start to splice them.ArticleA lot. Now I mainly want to introduce how to use C # To splice Google Maps.Code:

Void Savebitmapbuffered (Dataset SRC, dataset DST, Int X, Int  Y ){  If (SRC. rastercount < 3  ) {System. environment. Exit ( - 1  );}  //  Get the gdal band objects from the dataset Band redband = SRC. getrasterband ( 1  ); Band greenband = SRC. getrasterband ( 2  ); Band blueband = SRC. getrasterband ( 3  );  //  Get the width and height of the raster      Int Width = Redband. xsize;  Int Height = Redband. ysize;  Byte [] R = New   Byte [Width *Height];  Byte [] G = New   Byte [Width * Height];  Byte [] B = New   Byte [Width * Height]; redband. readraster (  0 , 0 , Width, height, R, width, height, 0 , 0  ); Greenband. readraster ( 0 , 0 , Width, height, G, width, height, 0 , 0  ); Blueband. readraster (  0 , 0 , Width, height, B, width, height, 0 , 0  ); Band WRB = DST. getrasterband ( 1  ); WRB. writeraster (x * Width, y * height, width, height, R, width, height,0 , 0  ); Band wgb = DST. getrasterband ( 2  ); Wgb. writeraster (x * Width, y * height, width, height, G, width, height, 0 , 0  ); Band WBB = DST. getrasterband ( 3  ); WBB. writeraster (x * Width, y * height, width, height, B, width, height, 0 , 0 );}  ///   <Summary>  ///  Tiled tiles  ///   </Summary>  ///   <Param name = "tilesbounds"> </param>  ///   <Param name = "tilepath"> </param>  ///   <Param name = "outputfilename"> </param>  Public   Void Combinetiles (tilesbounds, String Tilepath, String  Outputfilename ){  If  (File. exists (outputfilename) {file. Delete (outputfilename );}  Int Imagewidth = 256 * (Tilesbounds. maxcol-tilesbounds. mincol + 1  );  Int Imageheight = 256 * (Tilesbounds. maxrow-tilesbounds. minrow +1  );  //  Register Driver (s ).  Gdal. allregister (); driver Driver = Gdal. getdriverbyname ( "  Gtiff  "  ); Dataset destdataset = Driver. Create (outputfilename, imagewidth, imageheight, 3 , Datatype. gdt_byte, Null  );

For ( Int Col = tilesbounds. mincol; Col <= tilesbounds. maxcol; Col ++ ){ For ( Int Row = tilesbounds. minrow; row <= tilesbounds. maxrow; row ++ ){ Try { String Sourcefilename = tilepath + tilesbounds. zoomlevel. tostring () + " \\ " + Col. tostring () + " \\ " + Row. tostring () + " . Jpg " ; If (File. exists (sourcefilename) {dataset sourcedataset = Gdal. Open (sourcefilename, access. ga_readonly ); If (Sourcedataset! = Null ) {Savebitmapbuffered (sourcedataset, destdataset, Col -Tilesbounds. mincol, row-Tilesbounds. minrow );}}} Catch (Exception ex) {MessageBox. Show (ex. tostring () ;}} destdataset. Dispose ();} // Call Tilesbounds = New Tilesbounds (); tilesbounds. mincol = 107901 ; Tilesbounds. maxcol = 107926 ; Tilesbounds. minrow =49652 ; Tilesbounds. maxrow = 49668 ; Tilesbounds. zoomlevel = 17 ; String Outputfilename = " C: \ Beijing satellite map " + Tilesbounds. zoomlevel. tostring () + " . Tif " ; String Tilepath = " C: \ googlemaps \ satelite \\ " ; Combinetiles (tilesbounds, tilepath, outputfilename );

OK. Let's take a look.

 

 

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.