ArcGIS Server Web GIS development experience (4)

Source: Internet
Author: User
Tags ipoint
This section focuses on code calculation. Let's take a look at the implementation of some simple functions through the code. I am about to have a holiday, so I can't write well without having to worry about it. It may be better to paste the code.

1. Get all layers

ESRI. ArcGIS. server. webcontrols. webmap = map1.createwebmap ();
Try
{
ESRI. ArcGIS. Carto. imapdescription descr = webmap. mapdescription;
Ddllayers. Items. Clear ();
Int ID;
For (INT I = 0; I <= descr. layerdescriptions. Count-1; I ++)
{
Id = descr. layerdescriptions. get_element (I). ID;
Ddllayers. Items. Add (Id. tostring () + "," + webmap. layernamefromid (ID); // ddllayers is a dropdownlist Control
}
If (ddllayers. Items. Count> 0)
{
Ddllayers. selectedindex = 0;
}

}
Finally
{
Webmap. Dispose ();
}

2. Get the layer object through the layer ID

Private ifeaturelayer getfeaturelayer (INT lyid)
{
Webmap = map1.createwebmap ();
Try
{
Ilayer layer = (webmap. mapserver as imapserverobjects). get_layer (webmap. dataframe, lyid );
If (layer = NULL)
Return NULL;
Else
{
Return (layer as ifeaturelayer );
}
}
Finally
{
Webmap. Dispose ();
}

}

3. Create a polygon

Private void map1_polygon (Object sender, ESRI. ArcGIS. server. webcontrols. polygoneventargs ARGs)
{
If (ARGs. toolname = "newpolygon ")
{
Ifeaturelayer flayer = getcurfeaturelayer (); // you can call the getfeaturelayer (INT lyid) function to obtain the function of the current active layer.
If (flayer = NULL) return;

If (flayer. featureclass. shapetype! = ESRI. ArcGIS. Geometry. esrigeometrytype. esrigeometrypolygon)
{
String SC;
SC = "<script language = JavaScript> alert ('the current layer type is incorrect! ') </SCRIPT> ";
Page. registerclientscriptblock ("shapetypeerror", SC );
Return;
}

// Generate a polygon
ESRI. ArcGIS. server. iservercontext context;
ESRI. ArcGIS. server. webcontrols. webmap = map1.createwebmap ();
Webmap. managelifetime (flayer );
Context = webmap. servercontext;
ESRI. ArcGIS. Geometry. ipolympus Gon poly = context. Createobject ("esrigeometry. Polygon") as ESRI. ArcGIS. Geometry. ipolympus gon; // 'new AG. polygonclass ();
Webmap. managelifetime (poly );
ESRI. ArcGIS. Geometry. ipoint pt;
ESRI. ArcGIS. Geometry. igeometrycollection ringcol = context. Createobject ("esrigeometry. Polygon") as ESRI. ArcGIS. Geometry. igeometrycollection; // new polygonclass ();
Webmap. managelifetime (ringcol );
ESRI. ArcGIS. Geometry. ipointcollection ptcol = context. Createobject ("esrigeometry. Ring") as ESRI. ArcGIS. Geometry. ipointcollection; // new ringclass ();
Webmap. managelifetime (ptcol );
Object OBJ = type. missing;
For (INT I = 0; I <= args. vectors. Length-1; I ++)
{
PT = webmap. tomappoint (ARGs. vectors [I]. X, argS. vectors [I]. y );
Ptcol. addpoint (PT, ref OBJ, ref OBJ );
}
Ringcol. addgeometry (ptcol as igeometry, ref OBJ, ref OBJ );
Poly = ringcol as ipolympus gon;

// Write the Polygon into the layer.
ESRI. ArcGIS. Geodatabase. ifeature feature = flayer. featureclass. createfeature ();
Feature. Shape = POLY as igeometry;
Feature. Store ();
Webmap. Refresh ();

Webmap. Dispose ();
}
}

4. Select a rectangle to obtain the selection set and display the selected object on the map. (This function takes more than a day .)

Private void map1_dragrectangle (Object sender, ESRI. ArcGIS. server. webcontrols. tooleventargs ARGs)
{
String strtool = args. toolname. tolower ();
If (strtool = "rectsel ")
{
// Obtain the current Layer
If (ddllayers. selectedvalue = "")
Return;
Ifeaturelayer flayer = getcurfeaturelayer ();
If (flayer = NULL) return;

// Obtain the selection set
Int T1 = environment. tickcount;
ESRI. ArcGIS. server. webcontrols. webmap = map1.createwebmap ();
ESRI. ArcGIS. server. iservercontext CTX = webmap. servercontext;
Webmap. managelifetime (CTX );
ESRI. ArcGIS. Geodatabase. iworkspace Ws = (flayer. featureclass as ESRI. ArcGIS. Geodatabase. idataset). workspace;
ESRI. ArcGIS. Geometry. ienvelope Env = CTX. Createobject ("esrigeometry. Envelope") as ESRI. ArcGIS. Geometry. ienvelope;
Webmap. managelifetime (WS );
Webmap. managelifetime (ENV );
Ipoint Pt = webmap. tomappoint (convert. toint32 (request. Params. Get ("Maxx"), convert. toint32 (request. Params. Get ("Maxy ")));
Env. xmax = pt. X;
Env. ymin = pt. Y;
PT = webmap. tomappoint (convert. toint32 (request. Params. Get ("Minx"), convert. toint32 (request. Params. Get ("miny ")));
Env. xmin = pt. X;
Env. Ymax = pt. Y;
ESRI. ArcGIS. Geodatabase. ispatialfilter filter = CTX. Createobject ("esrigeodatabase. spatialfilter") as ESRI. ArcGIS. Geodatabase. ispatialfilter;
Webmap. managelifetime (filter );
Filter. spatialrel = ESRI. ArcGIS. Geodatabase. esrispatialrelenum. esrispatialrelintersects;
Filter. Geometry = env as ESRI. ArcGIS. Geometry. igeometry;
Filter. geometryfield = flayer. featureclass. shapefieldname;
ESRI. ArcGIS. Geodatabase. iselectionset sset = flayer. featureclass. Select (filter, ESRI. ArcGIS. Geodatabase. esriselectiontype. Optional, ESRI. ArcGIS. Geodatabase. esriselectionoption. esriselectionoptionnormal, WS );

Int t2 = environment. tickcount;
Int T3 = t2-t1; // T3 is the query response time, can be used to test the performance, huh, huh

// Display the selection set
Int ID;
ESRI. ArcGIS. Geodatabase. ienumids;
IDS = sset. IDS;
Webmap. managelifetime (IDS );
IDs. Reset ();
ESRI. ArcGIS. Geodatabase. ifidset fidset = CTX. Createobject ("esrigeodatabase. fidset") as ESRI. ArcGIS. Geodatabase. ifidset;
Id = IDs. Next ();
While (ID> = 0)
{
Fidset. Add (ID );
Id = IDs. Next ();
}
Imapdescription DESC = webmap. mapdescription as imapdescription;
Webmap. managelifetime (DESC );
Ilayerdescription ldesc = DESC. layerdescriptions. get_element (flyid );
Webmap. managelifetime (ldesc );
Ldesc. selectionfeatures = fidset;

// Save the selection information in the session
Session ["selection"] = sset;
Session ["layerid"] = flyid;

Webmap. Refresh ();

Webmap. Dispose ();

}

}

5. Delete the selected object

Private void deletesel ()
{
If (session ["layerid"] = NULL) return;
If (session ["selection"] = NULL) return;

Int layerid = (INT) session ["layerid"];
If (layerid =-1) return;
ESRI. ArcGIS. Geodatabase. iselectionset sset = session ["selection"] as ESRI. ArcGIS. Geodatabase. iselectionset;
If (sset = NULL) return;

Webmap = map1.createwebmap ();
Ifeaturelayer layer = getfeaturelayer (layerid );
If (layer = NULL) return;
Webmap. managelifetime (layer );
Webmap. managelifetime (sset );
ESRI. ArcGIS. Geodatabase. ienumids IDs = sset. IDS;
Webmap. managelifetime (IDS );
IDs. Reset ();
Int ID;
Id = IDs. Next ();
ESRI. ArcGIS. Geodatabase. ifeature feature;
ESRI. ArcGIS. server. iservercontext CTX = webmap. servercontext;
Webmap. managelifetime (CTX );
// Convert selectionset to featurecursor object
ESRI. ArcGIS. Geodatabase. ifeaturecursor fcursor;
ESRI. ArcGIS. Geodatabase. icursor cursor;
Sset. Search (null, false, out cursor );
Fcursor = cursor as ESRI. ArcGIS. Geodatabase. ifeaturecursor;
ESRI. ArcGIS. esrisystem. Iset pdeleteset = CTX. Createobject ("esrisystem. Set") as ESRI. ArcGIS. esrisystem. Set;
Webmap. managelifetime (pdeleteset );

// Set the Iset object
Feature = fcursor. nextfeature ();
While (feature! = NULL)
{
Pdeleteset. Add (feature );
Feature = fcursor. nextfeature ();
}

ESRI. ArcGIS. Geodatabase. ifeatureedit fedit;
Pdeleteset. Reset ();
Fedit = pdeleteset. Next () as ESRI. ArcGIS. Geodatabase. ifeatureedit;
While (fedit! = NULL)
{
Fedit. deleteset (pdeleteset );
Fedit = pdeleteset. Next () as ESRI. ArcGIS. Geodatabase. ifeatureedit;
}

Session. Remove ("layerid ");
Session. Remove ("selection ");

Webmap. Refresh ();

Webmap. Dispose ();
}

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.