Beijing ArcGIS Server Development Training example (sorting)

Source: Internet
Author: User
Tags imap
Beijing ArcGIS Server Development Training example (sorting)

21:07:48 | category: Flex, ArcGIS | label: | large font size, small/medium subscription

Beijing ArcGIS Server Development Training example (organized)

Some time ago, I went to Beijing to attend ESRI's ArcGIS Server application development training. I found that the examples are basically the same as those in the arcgsi server development series above flyingis, except for the last two examples. Because the training Party does not provide source code, all test examples made during training cannot be copied. Alas, there is no way. After the training is completed, sort it out and put it up for future reference!

 

Examples include

1. Web ADF programming-Implementation of the query function

2. Graphics daTa sources-highlight implementation

3. ArcGIS Server daTa sources -- Implementation of the buffer function

4. Custom Tool

5. Custom tasks

6. Extended ArcGIS Server

 

As the previous five examples are described in detail in the flyingis blog, I will not introduce them here. Here we will mainly introduce the last example to expand ArcGIS Server.

 

Objectives:

Extended ArcGIS Server to obtain the province area based on the province name

Of course, this is just an example. You can make complicated extensions.

 

Preparations before the test:

1. Prepare map data for each province

2. Create a map document for Province

3. Publish a map service through the map document of Province

 

Test procedure:

1. Compile the class implementing iserverobjectextension, that is, the function you want to add, create a daansoe project, add a class file, and change the nameThe code for getarea. CS is as follows:

C # code
  1. <Span style = "color: #000000">UsingSystem;
  2. UsingSystem. Collections. Generic;
  3. UsingSystem. text;
  4. UsingSystem. incluiseservices;
  5. UsingESRI. ArcGIS. ADF. arcgisserver;
  6. UsingESRI. ArcGIS. server;
  7. UsingSystem. runtime. interopservices;
  8. UsingESRI. ArcGIS. CARTO;
  9. UsingESRI. ArcGIS. Geodatabase;
  10. UsingESRI. ArcGIS. geometry;
  11. NamespaceDaansoe
  12. {
  13. [GUID ("560680e2-1dfb-438c-ba66-27a144bece55")]
  14. Public InterfaceIactcarea
  15. {
  16. DoubleGetarea (StringSQL );
  17. }
  18. [Automationproxy (True), Classinterface (classinterfacetype. autodual), GUID ("68f301bc-7a2f-44ea-a8b1-0%31321719")]
  19. Public ClassSoeserver: servicedcomponent, iactcarea, iserverobjectextension
  20. {
  21. PrivateIserverobjecthelper m_soh;
  22.  
  23.  
  24. # Region iactcarea Member
  25. /* The method used for testing
  26. Public double getarea (Double X, Double Y)
  27. {
  28. Return X + Y;
  29. }
  30. */
  31. Public DoubleGetarea (StringSQL)
  32. {
  33. Imapserver mapserver = m_soh.serverobjectAsImapserver;
  34. Imapserverobjects mapserverobjs = mapserverAsImapserverobjects;
  35. IMAP map = mapserverobjs. get_map (mapserver. defaultmapname );
  36. Ifeaturelayer pflayer = map. get_layer (0)AsIfeaturelayer;
  37. Ifeatureclass PFC = pflayer. featureclass;
  38. Ispatialfilter PSF =NewSpatialfilterclass ();
  39. PSF. whereclause = SQL;
  40. PSF. spatialrel = ESRI. ArcGIS. Geodatabase. esrispatialrelenum. esrispatialrelintersects;
  41. Ifeaturecursor pfcursor = PFC. Search (PSFAsIqueryfilter,False);
  42. Ifeature pfeature = pfcursor. nextfeature ();
  43. If(Pfeature =Null)
  44. Return-2;
  45. Ipolympus Gon polygon = pfeature. ShapeAsIpolympus gon;
  46. Iarea parea = PolygonAsIarea;
  47. ReturnParea. area;
  48. }
  49.  
  50. # Endregion
  51.  
  52. # Region iserverobjectextension Member
  53. VoidIserverobjectextension. INIT (iserverobjecthelper psoh)
  54. {
  55. M_soh = psoh;
  56. }
  57. VoidIserverobjectextension. Shutdown ()
  58. {
  59. M_soh =Null;
  60. }
  61.  
  62. # Endregion
  63. }
  64. }
  65. </Span>
Using system; using system. collections. generic; using system. text; using system. enterpriseservices; using ESRI. arcGIS. ADF. arcgisserver; using ESRI. arcGIS. server; using system. runtime. interopservices; using ESRI. arcGIS. CARTO; using ESRI. arcGIS. geodatabase; using ESRI. arcGIS. geometry; namespace daansoe {[GUID ("560680e2-1dfb-438c-ba66-27a144bece55")] public interface iactcarea {double getarea (string SQL);} [automationproxy (true), classinterface (classinterfacetype. autodual), GUID ("68f301bc-7a2f-44ea-a8b1-0%31321719")] public class soeserver: servicedcomponent, iactcarea, iserverobjectextension {private iserverobjecthelper Soh; # region iactcarea Member/* method used for testing public double getarea (Double X, Double Y) {return X + Y;} */Public double getarea (string SQL) {imapserver mapserver = m_soh.serverobject as imapserver; imapserverobjects mapserverobjs = mapserver as imapserverobjects; IMAP map = mapserverobjs. get_map (mapserver. defaultmapname); ifeaturelayer pflayer = map. get_layer (0) as ifeaturelayer; ifeatureclass PFC = pflayer. featureclass; ispatialfilter PSF = new spatialfilterclass (); PSF. whereclause = SQL; PSF. spatialrel = ESRI. arcGIS. geodatabase. esrispatialrelenum. esrispatialrelintersects; ifeaturecursor pfcursor = PFC. search (PSF as iqueryfilter, false); ifeature pfeature = pfcursor. nextfeature (); If (pfeature = NULL) Return-2; ipolympus Gon polygon = pfeature. shape as ipolympus gon; iarea parea = polygon as iarea; return parea. area ;}# endregion # region iserverobjectextension member void iserverobjectextension. init (iserverobjecthelper psoh) {m_soh = psoh;} void iserverobjectextension. shutdown () {m_soh = NULL;} # endregion }}

 

2. Use regasm to Register Server Object Extension

Enter the command prompt box in vs2005:

E: \ Program Files \ Microsoft Visual Studio 8 \ Vc>

 

Switch the current directory to the directory where the above DLL is located:

E: \ project \ Beijing training \ beijingtraining \ exercise11 \ daansoe \ bin \ debug>

 

Run the following command for registration:

Regasm/TLB: daansoe. TLB/codebase daansoe. dll

 

After execution, you can go to the dll Directory to verify whether the corresponding. TLB is generated.

 

(If you want to cancel registration, use the regasm/u daansoe. dll/TLB daansoe. TLB/codebase command)

 

3. Register Server Object extension to GIS server

We will use a piece of code to register the server object extension to the GIS server.

Create a console project with the command registertogisserver. Add the following code in the main method:

C # code
  1. <Span style = "color: #000000"> identity =NewIdentity ("username", "888888", "Domain ");
  2. Agsserverconnection connection =NewAgsserverconnection ("fmc-pca187", identity );
  3. Connection. Connect ();
  4. Iserverobjectadmin2 SOA = connection. serverobjectadminAsIserverobjectadmin2;
  5. Iserverobjectextensiontype SOE = soa. createextensiontype ();
  6. Soe. CLSID = "daansoe. soeserver ";
  7. Soe. Name = "soeserver ";
  8. Soe. Description = "test application ";
  9. SOA. addextensiontype ("mapserver", SoE); </span>
Identity identity = new Identity("username", "888888", "domain");            AGSServerConnection connection = new AGSServerConnection("fmc-pca187", identity);            connection.Connect();            IServerObjectAdmin2 soa = connection.ServerObjectAdmin as IServerObjectAdmin2;            IServerObjectExtensionType soe = soa.CreateExtensionType();            soe.CLSID = "DAANSOE.SOEServer";            soe.Name = "SOEServer";            soe.Description = "Test Application";            soa.AddExtensionType("MapServer", soe);

Run this code. After execution, go to <ArcGIS Server install location> \ Server \ system folder to open servertypesext. dat for verification.

 

4. Stop the province service, right-click the Service Properties capabilities, hook the soeserver, and restart the province service.

 

5. Use Server Object Extension

Create a new web application, create a new ASPX page, change it to useextensiongisserver. aspx, and add the corresponding controls. In the Click Event of the button, implement the following code:

C # code
  1. <Span style = "color: #000000"> identity =NewIdentity ("username", "888888", "Domain ");
  2. Agsserverconnection connection =NewAgsserverconnection ("fmc-pca187", identity );
  3. Connection. Connect ();
  4. Iserverobjectmanager som = connection. serverobjectmanagerAsIserverobjectmanager;
  5. Iservercontext servercontext = som. createservercontext ("Province", "mapserver ");
  6. Iserverobjectextensionmanager soem = servercontext. serverobjectAsIserverobjectextensionmanager;
  7. Iserverobjectextension SOE = soem. findextensionbytypename ("soeserver ");
  8. Iactcarea paear = SoeAsIactcarea;
  9. DoubleArea = paear. getarea (textbox1.text. tostring ());
  10. Servercontext. releasecontext ();
  11. Response. Write ("<SCRIPT> alert (" + area. tostring () + "); </SCRIPT>"); </span>
Identity identity = new Identity("username", "888888", "domain");        AGSServerConnection connection = new AGSServerConnection("fmc-pca187", identity);        connection.Connect();        IServerObjectManager som = connection.ServerObjectManager as IServerObjectManager;        IServerContext serverContext = som.CreateServerContext("province", "MapServer");        IServerObjectExtensionManager soem = serverContext.ServerObject as IServerObjectExtensionManager;        IServerObjectExtension soe = soem.FindExtensionByTypeName("SOEServer");        IActcArea pAear = soe as IActcArea;        double area = pAear.GetArea(TextBox1.Text.ToString());        serverContext.ReleaseContext();        Response.Write("<script>alert(" + area.ToString() + ");</script>");

The preview effect is as follows:

 

Now, if everything goes well, the entire function is complete. Click OK to bring up the area of Sichuan Province.

 

Note:

If the server object extension is registered with ArcGIS Server and the Province service is started again, if daansoe is to be generated again, stop province. Otherwise, an error will occur, then use regasm to register the modified DLL.

 

Finally, I uploaded the entire project of the above examples as an attachment. These examples are all debugged on the local machine. You need to modify the identity parameter after downloading, any questions can be raised here!

From: http://feng10251225.blog.163.com/blog/static/63122798200991997484/

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.