ArcGIS Server dynamically generates cache and replaces tiles (c#+ae)

Source: Internet
Author: User

By using ArcGIS Server for map Publishing, the current more popular map caching techniques (popular as "tile technology") are usually used to enhance browsing performance. such as the current MAPABC and GoogleMap is precisely the use of this technology.

The so-called map caching technology, is according to a certain mathematical rules, the map into a certain size of the picture saved to the computer hard disk, when the user through the client browser access map services, the server directly return to the current map coordinate region corresponding to the "tile", so as to reduce the server burden, improve the speed of map browsing effect.

Map caching technology generally for relatively stable data, because the map cut into tiles, in the form of pictures, for the data changes (here refers to the changes in the geometry of the data) can not be timely response, this is the map cache technology deficiencies. To reflect the changes in the map in a timely manner, it is necessary to reconstruct the map cache. Rebuilding the map cache depends on the area of the map and the scale of the cache, which ranges from a few minutes to dozens of hours. Therefore, the management of caching is a relatively troublesome thing.

The use of map caching techniques is generally not recommended for systems with high real-time requirements. However, the performance of the map cache experience is very good, so you can make some changes on this basis, it is necessary to adapt to the map update operation. Some Webgis systems because of data editing, data update frequency is not suitable for the release of the cache, the real-time data is very good, but the map browsing and refreshing performance is very poor (refresh performance and the size of the data and layer rendering complexity), a large number of server resources, Multiple user connections cause server instability and so on.

After repeated experiments, according to the above requirements, the following scheme is proposed to solve the problem of frequent data fluctuation and poor map performance. The basic idea of the program: use map caching techniques to slice the map, and when editing the data, get the tile (one or several) of the space data, calculate the map range of the tile, and regenerate the map picture in the background, and replace the newly generated pictures with the old tiles.

The specific approach is as follows:

1. Create a non-pooled service and generate a map cache. This part of lazy sheep is not introduced.

2. Gets the tile that corresponds to the edited graphic. In general, if it is a point graph, corresponding to a tile, line, surface graphics a figure may fall on more than one tile above. You can use ESRI.ArcGIS.ADF.ArcGISServer.TileCacheInfo to get information about tiles, but when you fall into that tile, you must understand the principle of map slicing.

1) ArcGIS Server slicing principle and naming rules
Set a origin as the starting point of the map slice (default is (400,-400), this is a latitude and longitude coordinates, set this value can connect the data of other regions, so that the data of different services can be effectively spliced, interested colleagues can study it), The map is cut into a number of small pictures in a certain size (n-th-square pixels with a length of 2) and stored in a scientifically named computer disk. The name of the rule is the picture of each scale placed in the folder named LXX, the first scale folder named L00, the second scale of the question L01, so on. The scale folder (called L folder) also has a folder at the beginning of R, R for row, current scale tile for each row of a folder. The name of the R folder is the row sequence of tiles (expressed in rindex), the Rindex into 8-bit 16, insufficient on the left to fill 0, with a code formula to represent foldername = "R" +rindex.tostring ("X"). PadLeft (8, ' 0 '). R folder contains tiles, the name of the tile is similar to the name of the R folder, beginning with the letter C, followed by the tile in the row of the column number (with CIndex), the back is still a 8-bit 16 binary filename = "C" +rindex.tostring ("x" ). PadLeft (8, ' 0 ') + "." +format. ToString ()

2 compute the tile corresponding to the graph (take the point as an example)
The following is an example of adding a point element to illustrate how to get the tile corresponding to this point
First get information about the map service, where Notpooledserviceurl is a string, corresponding to the current service URL, map service has been sliced

Get information about the service
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. Getdefaultmapname ());
String defaultmapname = mapserver_dcom. Getdefaultmapname ();
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;

and get the tile information for this map service.

Gets the picture format of the tile
string cachetileformat = mapserver_dcom. Gettileimageinfo (Defaultmapname). Cachetileformat;
String imagetype = Cachetileformat.startswith ("PNG")? ". png": ". jpg";
Get information about tiles for
ESRI. ArcGIS.ADF.ArcGISServer.TileCacheInfo tcacheinfo = mapserver_dcom. Gettilecacheinfo (defaultmapname);
The origin of the tile (AGS default value is (-400,400), can be set when slicing this value)
pointn RIGINPT = Tcacheinfo.tileorigin as POINTN;

And then define other relevant information

Double Envcenterx = ppoint.x;  PPoint for the newly added point element of the graphic
double envcentery = ppoint.y;
ESRI. arcgis.adf.arcgisserver.lodinfo[] Lodinfos = Tcacheinfo.lodinfos;
int Tcolcenter, trowcenter;              PPoint the tiles corresponding to the column, row
double tilewidth, tileheight;            corresponding to the length and width of the tile (calculated as map unit)
double tilexmin, tileymin;               PPoint is located in the lower left corner of the tile coordinates
double tilexmax, Tileymax;               The upper-right corner coordinate of the tile where the ppoint resides

By calculating the path of the tiles that find the corresponding level of cache for this point (based on the above mentioned slicing principle and naming rules)

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)//respectively update the tiles under each scale, where PoolService is a
 A mapserverproxy}

The formula for calculating the row and column values of tiles can be derived by 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)

The last is to replace the original tile by generating a new picture to achieve the local update effect (i.e. the Updatetile function above). The idea is to define a envelope by passing in the coordinates of the corresponding four corners of the single tile, outputting the picture of the envelope area, and replacing the tiles for the corresponding URL.

ESRI. ArcGIS.ADF.ArcGISServer.MapServerInfo agssoapmapserverinfo = mapserver_dcom. Getserverinfo (mapserver_dcom.
Getdefaultmapname ()); 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 up plot area//set out picture format, dpi, long width, etc. 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;//The virtual path of the output picture string imgname = Httpurl.substring (httpurl.length-44, 44);//Extract the name of the picture s
Tring Source = imgname; 
The virtual path is converted to the physical path of the server disk drive, where Serviceoutputdir is the default output position of AGS source =serviceoutputdir + "\" + source;   System.IO.File.Copy (source, Tileurl, true); Copy to tile directory and replace it

1. A few places to notice

1 This method of updating tiles, design to modify the server-side file operation, so you must give the map cache in the folder where the IIS user can control permissions (NTFS disk format must be set)

2 here only the design point of the update operation, because a point in a certain proportion of only a tile, so, although there are more than 10 levels of caching, but only more than 10 pictures, the plot and replacement time is not long, do not occupy the server too long time to deal with (including the connection map service around 20s). Of course, programmers can also update tiles at different scales by setting the cache level, which is even more true. If you design to the line and surface of the update, that must limit the area, because the area is very large, processing time will be very long (if the user accidentally put a site similar to the area of the face of the update, which is equivalent to the entire city cache to do)

3 The above is used for pooling and non-pooling of two services (both services are published using the same mxd, this is noteworthy), it is estimated that some confusion. The difference between pooling and non-pooling services can refer to ESRI's documentation, which is not covered here. If you use a service that has already been cached to output a new image, the picture is not changed at all, as is the original tile, so you must create a pooled, not-cached service as a dedicated service, so that the update of the data can immediately be reflected in the service.

4 The cached update operation is performed after the element is added and saved. In order to improve the user experience, you can open a thread in the background to perform the update of the tile, the front-end using Graphicslayer to draw the elements. This allows the current operation user to see the current situation for the first time, when other users are connected, they see the latest map cache.

Turn from: http://www.cnblogs.com/ericgisser/archive/2009/10/13/gis_cache.html

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.