Create a memory layer in arcengine-hl3292 comment

Source: Internet
Author: User

Link: http://gishuangjun.blog.sohu.com/139347305.html

Core tips:A new feature is added to arcengine9.2, allowing you to create a memory workspace.
A new feature is added to arcengine9.2, allowing you to create a memory workspace. When you need such a layer, the attribute data or geometric data of this layer needs to be updated frequently, without the need for efficiency issues, you can consider using the memory layer.
The memory layer is created in five steps:
1. Set attribute Fields
2. Set space reference and geometric Fields
3. Create a memory Workspace
4. Create a feature class in the memory Workspace
5. Create a feature layer and set the feature class created in the previous step to the feature class of the feature layer.

See the complete sample code below

/// <Summary>
/// Create a layer in memory
/// </Summary>
/// <Param name = "datasetname"> dataset name </param>
/// <Param name = "aliasename"> alias </param>
/// <Param name = "spatialref"> space reference </param>
/// <Param name = "geometrytype"> ry type </param>
/// <Param name = "propertyfields"> set of attribute fields </param>
/// <Returns> ifeaturelayer </returns>
Public static ifeaturelayer createfeaturelayerinmemeory (string datasetname, string aliasename, ispatialreference spatialref, esrigeometrytype geometrytype, ifields propertyfields)
{
Iworkspacefactory workspacefactory = new inmemoryworkspacefactoryclass ();
ESRI. ArcGIS. Geodatabase. iworkspacename workspacename = workspacefactory. Create ("", "myworkspace", null, 0 );
ESRI. ArcGIS. esrisystem. INAME name = (INAME) workspacename;
ESRI. ArcGIS. Geodatabase. iworkspace inmemwor = (iworkspace) name. open ();

Ifield ofield = new fieldclass ();
Ifields ofields = new fieldsclass ();
Ifieldsedit ofieldsedit = NULL;
Ifieldedit ofieldedit = NULL;
Ifeatureclass ofeatureclass = NULL;
Ifeaturelayer ofeaturelayer = NULL;

Try
{
Ofieldsedit = ofields as ifieldsedit;
Ofieldedit = ofield as ifieldedit;

For (INT I = 0; I <propertyfields. fieldcount; I ++)
{
Ofieldsedit. addfield (propertyfields. get_field (I ));
}

Igeometrydef geometrydef = new geometrydefclass ();

Igeometrydefedit geometrydefedit = (igeometrydefedit) geometrydef;
Geometrydefedit. avgnumpoints_2 = 5;
Geometrydefedit. geometrytype_2 = geometrytype;
Geometrydefedit. gridcount_2 = 1;
Geometrydefedit. hasm_2 = false;
Geometrydefedit. hasz_2 = false;
Geometrydefedit. spatialreference_2 = spatialref;

Ofieldedit. name_2 = "shape ";
Ofieldedit. type_2 = esrifieldtype. esrifieldtypegeometry;
Ofieldedit. geometrydef_2 = geometrydef;
Ofieldedit. isnullable_2 = true;
Ofieldedit. required_2 = true;
Ofieldsedit. addfield (ofield );

Ofeatureclass = (inmemwor as ifeatureworkspace). createfeatureclass (datasetname, ofields, null, null, esrifeaturetype. esriftsimple, "shape ","");

(Ofeatureclass as idataset). browsename = datasetname;

Ofeaturelayer = new featurelayerclass ();
Ofeaturelayer. Name = aliasename;
Ofeaturelayer. featureclass = ofeatureclass;
}
Catch
{
}
Finally
{
Try
{
System. runtime. interopservices. Marshal. releasecomobject (ofield );
System. runtime. interopservices. Marshal. releasecomobject (ofields );
System. runtime. interopservices. Marshal. releasecomobject (ofieldsedit );
System. runtime. interopservices. Marshal. releasecomobject (ofieldedit );
System. runtime. interopservices. Marshal. releasecomobject (name );
System. runtime. interopservices. Marshal. releasecomobject (workspacefactory );
System. runtime. interopservices. Marshal. releasecomobject (workspacename );
System. runtime. interopservices. Marshal. releasecomobject (inmemwor );
System. runtime. interopservices. Marshal. releasecomobject (ofeatureclass );
}
Catch {}

GC. Collect ();
}
Return ofeaturelayer;
}

 

 

The following figure shows how to create a point memory Layer Based on the collected coordinate points:

Ifeaturelayer pfeaturelayer = new featurelayerclass ();
Ifieldsedit curfileds = new fieldsclass ();
Ifieldedit curfield = new fieldclass ();
Curfield = new fieldclass ();
Curfield. name_2 = "name ";
Curfield. type_2 = esrifieldtype. esrifieldtypestring;
Curfileds. addfield (curfield );

Curfield = new fieldclass ();
Curfield. name_2 = "longitude ";
Curfield. type_2 = esrifieldtype. esrifieldtypedouble;
Curfileds. addfield (curfield );

Curfield = new fieldclass ();
Curfield. name_2 = "latitude ";
Curfield. type_2 = esrifieldtype. esrifieldtypedouble;
Curfileds. addfield (curfield );

Pfeaturelayer = createfeaturelayerinmemeory ("position", "collection point", new unknowncoordinatesystemclass (), esrigeometrytype. esrigeometrypoint, curfileds as ifields );
P_axmap.addlayer (pfeaturelayer as ilayer );
Ifeaturecursor featurecursor;
Ifeature pfeature;
Ifeatureclass pfeatureclass = pfeaturelayer. featureclass;
Pfeature = pfeatureclass. createfeature ();
Iqueryfilter pqueryfilter = new queryfilterclass ();
Featurecursor = pfeatureclass. Search (pqueryfilter, true );
Pqueryfilter. whereclause = NULL;
Pfeature = featurecursor. nextfeature ();
Pfeature. set_value (0, str1 );
Pfeature. set_value (1, x );
Pfeature. set_value (2, y );
Ienvelope penvelope = new envelopeclass ();

// If the double-click object is a vertex, it can be scaled to the vertex.
Penvelope. putcoords (0, 0, 0.3, 0.3); // determine the envelope size

Ipoint xpoint = new pointclass ();
Xpoint. putcoords (x, y );

Pfeature. Shape = xpoint;
Pfeature. Store ();

// Set the color
Irgbcolor pcolor = new rgbcolorclass ();

Pcolor. red= 255;

Pcolor. Green = 0;

Pcolor. Blue = 0;

// Set the image
Isimplemarkersymbol PSM = new simplemarkersymbolclass ();
PSM. Style = esrisimplemarkerstyle. esrismscircle;
PSM. size = 10;
PSM. Color = pcolor;

(Pfeaturelayer as ifeatureselection). selectionsymbol = (isymbol) PSM;
(Pfeaturelayer as ifeatureselection). setselectionsymbol = true;

(Pfeaturelayer as ifeatureselection). selectionset. Add (pfeature. OID );

Penvelope. centerat (xpoint); // scale the map to this point.
P_axmap.extent = penvelope;
P_axmap.activeview.partialrefresh (esriviewdrawphase. esriviewgeography, pfeaturelayer, null );
P_axmap.activeview.screendisplay.updatewindow ();

 

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.