ArcGIS Server dynamically generates Cache

Source: Internet
Author: User

To improve browsing performance, ArcGIS Server is usually used for map caching (commonly referred to as "tile technology "). For example, mapabc and GoogleMap currently use this technology.
The so-called map cache technology refers to cutting a map into images of certain specifications and saving it to a computer hard disk according to certain mathematical rules. When a user accesses the map service through a client browser, the server directly returns the "tile" corresponding to the current map coordinate area, thus reducing the server load and improving the map browsing speed.
The map cache technology is generally used for relatively stable data, because after the map is switched to a tile, it exists as an image and changes the data (here it refers to the geometric shape change of the data) it cannot respond in a timely manner. This is the technical disadvantage of map caching. To reflect changes to a map in a timely manner, the map cache must be rebuilt. The rebuild map cache depends on the map's region range and cache scale, ranging from several minutes to dozens of hours. Therefore, Cache Management is a relatively troublesome task.
Map caching is generally not recommended for systems with high real-time requirements. However, the map cache provides a good performance experience. Therefore, some modifications can be made on this basis to adapt to the map update operation. Some WebGIS systems involve data editing, which results in a high frequency of data updates and does not apply to the publishing of cached data. Therefore, the real-time data is very good, however, the browsing and refresh performances of maps are very poor (the refresh performance is related to the data size and the rendering complexity of layers), occupying a large amount of server resources, and causing unstable servers when multiple users connect.
After repeated tests, lazy goat proposed the following solutions to solve the problems of frequent data changes and low map performance. The basic idea of the solution is to use the map caching technology to segment a map. When editing data, you can obtain the tiles (one or more) corresponding to the space data. You can calculate the MAP range of these tiles, then, the map images in this range are regenerated in the background, and the newly generated images are replaced with the old tiles.
The procedure is as follows:
1.
Create a non-pooled service and generate a map cache.
2.
Obtain the tile corresponding to the edited image. In general, if it is a vertex image, it corresponds to a tile. A line or surface image may fall on multiple tiles. You can use ESRI. ArcGIS. ADF. arcgisserver. tilecacheinfo to obtain information about the tile. However, if it falls into that tile, you must understand the principle of map slicing.
1) ArcGIS Server slicing principle and naming rules: Set an origin point as the starting point of map slicing (default: (400,-400). This is a coordinate of longitude and latitude, setting this value can connect data from other regions so that data of different services can be effectively spliced. If you are interested, you can study it ), the map is cut into several small pictures with a certain size (the pixel with a length of 2 to the power of N) and stored to a computer disk in a scientific way. The naming rule is that images of different scales are placed in a folder named LXX. the first scale folder is named l00, and the second scale is called L01, and so on. The scale folder (hereinafter referred to as the L folder) directory also contains folders starting with R, which indicates the row. each row of the current scale tile corresponds to a folder. The r folder is named by the row sequence of the tile (represented by rindex). The rindex is converted into an 8-bit hexadecimal format. If it is not enough, add 0 to the left, use the code formula to indicate Foldername = "R" + rindex. tostring ("X "). padleft (8, '0 '). The r folder stores tiles. the tile naming method is similar to the r folder naming method. It starts with the letter C and is followed by the column number of the tile in the row (indicated by cIndex, there is still an 8-bit hexadecimal filename = "C" + rindex. tostring ("X "). padleft (8, '0') + ". "+ format. tostring ()

2) Calculate the tile corresponding to the graph (taking the vertex as an example)
The following describes how to obtain the corresponding Tile of a vertex by adding a vertex element.
First, obtain information about the map service. The notpooledserviceurl is a string that corresponds to the URL of the current service. The map service has been sliced.

// Obtain service-related information

 

ESRI. ArcGIS. ADF. arcgisserver. mapserverproxy mapserver_dcom = new ESRI. ArcGIS. ADF. arcgisserver. mapserverproxy (notpooledserviceurl );

 

ESRI. ArcGIS. ADF. arcgisserver. mapserverinfo mapi = mapserver_dcom.getserverinfo (mapserver_dcom.getdefamapmapname ());

 

String defaultmapname = mapserver_dcom.getdefamapmapname ();

 

 

ESRI. ArcGIS. ADF. arcgisserver. mapdescription pmapdescription = mapi. defaultmapdescription;

 

ESRI. ArcGIS. ADF. arcgisserver. envelopen Mape = mapi. fullextent as ESRI. ArcGIS. ADF. arcgisserver. envelopen;

 

ESRI. ArcGIS. ADF. arcgisserver. envelopen mapiextent = (ESRI. ArcGIS. ADF. arcgisserver. envelopen) mapi. extent;

Then obtain the tile information of the map service.

// Obtain the image format of the tile.

 

String cachetileformat = mapserver_dcom.gettileimageinfo (defaultmapname). cachetileformat;

 

String imagetype = cachetileformat. startswith ("PNG ")? ". PNG": ". jpg ";

 

// Obtain information about the tile.

 

ESRI. ArcGIS. ADF. arcgisserver. tilecacheinfo tcacheinfo = mapserver_dcom.gettilecacheinfo (defaultmapname );

 

// Tile origin (the default value of AGS is (-400,400). This value can be set during slicing)

 

Pointn originpt = tcacheinfo. tileorigin as pointn;

 

Then define other related information

Double envcenterx = Ppoint. X;
// Ppoint indicates the new vertex element.

Double envcentery = Ppoint. Y;

ESRI. ArcGIS. ADF. arcgisserver. lodinfo [] lodinfos = tcacheinfo. lodinfos;

 

 

Int tcolcenter, trowcenter;
// Columns and rows corresponding to the tile where the Ppoint is located

 

Double tilewidth, tileheight;
// The length and width of the corresponding tile (calculated as the map Unit)

 

Double tilexmin, tileymin;
// Coordinates of the lower left corner of the tile where the Ppoint is located

 

Double tilexmax, tileymax;
// Coordinates of the upper right corner of the tile where the Ppoint is located

 

Find the path of cached tiles at all levels corresponding to this point through calculation (calculated based on the slice principle and naming rules mentioned above)

Foreach (ESRI. ArcGIS. ADF. arcgisserver. lodinfo Li in lodinfos)

 

{

 

Tilewidth = tcacheinfo. tilecols * Li. Resolution;

 

Tcolcenter = (INT) math. Floor (envcenterx-(double) originpt. X)/tilewidth );

 

Tilexmin = (double) originpt. x + (tcolcenter * tilewidth );

 

Tileheight = tcacheinfo. tilerows * Li. Resolution;

 

Trowcenter = (INT) math. Floor (double) originpt. Y-envcentery)/tileheight );

 

Tileymin = (double) originpt. Y-(trowcenter * tileheight)-tileheight;

 

Tilexmax = tilexmin + tilewidth;

 

Tileymax = tileymin + tileheight;

 

String Turl = cachedir + "\ Layers \ _ alllayers" + "\ L" + Li. levelid. tostring (). padleft (2, '0 ')

 

+ "\ R" + trowcenter. tostring ("X"). padleft (8, '0 ')

 

+ "\ C" + tcolcenter. tostring ("X"). padleft (8, '0 ')

 

+ Imagetype;

 

Updatetile (tilexmin, tileymin, tilexmax, tileymax, Turl, tcacheinfo, poolservice)

 

// Update the tiles at each scale. The poolservice is a mapserverproxy.

 

}

The formula for calculating the row and column values of a tile can be introduced based on the slicing principle.
Column = floor (point of interest X-tile origin X)/ground width of a tile)
Row = floor (tile origin y-point of interest y)/ground height of a tile)

Finally, the original tile is replaced by generating a new image to achieve local update (that is, the above updatetile function ). The idea is to define an envelope by passing in the coordinates of the four corners corresponding to a single tile, output the image of the envelope area, and replace the tile of the corresponding URL.

ESRI. ArcGIS. ADF. arcgisserver. mapserverinfo agssoapmapserverinfo = mapserver_dcom.getserverinfo (mapserver_dcom.getdefamapmapname ());

 

ESRI. ArcGIS. ADF. arcgisserver. mapdescription agssoapmapdescription = agssoapmapserverinfo. defaultmapdescription;

 

SRI. ArcGIS. ADF. arcgisserver. envelopen penv = new ESRI. ArcGIS. ADF. arcgisserver. envelopen ();

 

Penv. xmin = xmin;

 

Penv. ymin = ymin;

 

Penv. xmax = xmax;

 

Penv. Ymax = Ymax;

 

Agssoapmapdescription. maparea. extent = penv;

// Set the plotting Area

 

 

// Set the format, DPI, length, and width of the image.

 

ESRI. ArcGIS. ADF. arcgisserver. imagedescription agsimagedes = new ESRI. ArcGIS. ADF. arcgisserver. imagedescription ();

 

ESRI. ArcGIS. ADF. arcgisserver. imagetype agsimagetype = new ESRI. ArcGIS. ADF. arcgisserver. imagetype ();

 

Agsimagetype. imageformat = ESRI. ArcGIS. ADF. arcgisserver. esriimageformat. esriimagepng;

 

Agsimagetype. imagereturntype = ESRI. ArcGIS. ADF. arcgisserver. esriimagereturntype. esriimagereturnurl;

 

ESRI. ArcGIS. ADF. arcgisserver. imagedisplay agsimagedis = new ESRI. ArcGIS. ADF. arcgisserver. imagedisplay ();

 

Agsimagedis. imagedpi = tcacheinfo. DPI;

 

Agsimagedis. imageheight = tcacheinfo. tilecols;

 

Agsimagedis. imagewidth = tcacheinfo. tilerows;

 

Agsimagedes. imagetype = agsimagetype;

 

Agsimagedes. imagedisplay = agsimagedis;

 

 

// Plot and replace tiles

 

ESRI. ArcGIS. ADF. arcgisserver. mapimage agsmapimage = mapserver_dcom.exportmapimage (agssoapmapdescription, agsimagedes );

 

String httpurl = agsmapimage. imageurl; // virtual path of the output image

 

String imgname = httpurl. substring (httpurl. Length-44, 44); // extract the image name

 

String source = imgname;

 

// Convert the virtual path to the physical path corresponding to the server disk drive. serviceoutputdir is the default output location of AGS.

 

Source = serviceoutputdir + "\" + source;

 

 

System. Io. file. Copy (source, tileurl, true );
// Copy to the corresponding directory of the tile and replace it

 

 

1.
Notes
1)
This method is used to update the tiles and design operations to modify the files on the server. Therefore, you must set the permissions that the IIS users can control for the folder where the map cache is located (which must be set under the NTFS disk format)
2)
Here, only update operations are designed. Because a point corresponds to only one tile under a certain proportion, even if there are more than a dozen cached images, the time for plotting and replacement is not long, and it does not take too long for the server to process (including connecting to the map service for about 20 s ). Of course, programmers can also update the tiles at different scales by setting the cache level, which is more practical. If the design is updated to the line and plane, it is necessary to limit the area range, because the area range is large, processing takes a long time (for example, if users submit and update a plane in a region similar to the city, this is equivalent to caching the whole city)
3)
The above two services are pooled and non-pooled (both services use the same mxd for release, which is worth noting). It may be confusing. For more information about the differences between pooling and non-pooling services, see ESRI instructions. If a cache service is used to output new images, the images are not changed at all. The original image is the original tile, therefore, you must create a pooled service without cache as a dedicated service for plotting, so that data updates can be immediately reflected in the service.
4)
Cache update operations are performed after elements are added and saved. To improve the user experience, you can open a thread in the background to execute the tile update program. The front end uses graphicslayer to draw the elements. In this way, the current user can see the current status immediately. When other users connect, the latest map cache is displayed.

 

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.