Search, insert, delete, and update GIS data (arcengine)

Source: Internet
Author: User

1,Search for Data

1) Use featurcursor for Spatial Query

// Use the constructed envelope (rectangular box) to find the Element Set of featureclass at the intersection of Envelope

// The result data is obtained by repeating featurecursor. nextfeature.

Ienvelope envelope = new envelopeclass ();

Envelope. putcoords (508786,681 196, 513033,684 341 );

// Spatial Query

Ispatialfilter spatialfilter = new spatialfilterclass ();

Spatialfilter. Geometry = envelope;

String shpfld = featureclass. shapefieldname;

Spatialfilter. geometryfield = shpfield;

Spatialfilter. spatialrel = esrispatialrelenum. esrispatialrelintersects; // Intersection

Iqueryfilter queryfilter = new queryfilterclass ();

Queryfilter = (iqueryfilter) spatialfilter;

Ifeaturecursor searchcursor = featureclass. Search (queryfilter, true );

Ifeature feature = searchcursor. nextfeature ();

Int n = 0;

While (feature! = NULL ){

N ++;

Feature = basecursor. nextfeature ();

}

2) use featurecursor to query in the selection set

Ifeatureselection pfeatureselectio = pfeaturelayer as ifeatureselection;

Icursor ppcursor;
Pfeatureselectio. selectionset. Search (null, false, out ppcursor );

Ifeaturecursor pfeaturecursor = ppcursor as ifeaturecursor;

Ifeature pfeature = pfeaturecursor. nextfeature ();

3) Use featurecursor to query attributes

Iqueryfilter pqueryfilter = new queryfilterclass ();

Pqueryfilter. whereclause = "projectcode = '" + this. projectnumtextbox. Text. Trim () + "'";

Ifeaturecursor pfeaturecursor = linefeaclass. Search (pqueryfilter, false );

Ifeature pfeatureifexit = pfeaturecursor. nextfeature ();

 

2,Insert data

1) Use Insert cursors andFeaturebuffer

 
Ifeaturebuffer featurebuffer = featureclass. createfeaturebuffer ();
 
Ifeaturecursor featurecursor = featureclass. insert (True);
 
ObjectFeatureoid;
Featurebuffer. set_value (featurebuffer. Fields. findfield ("instby"), "B Pierce ");
 
For(IntIc = 0; IC <99; IC ++)
 
 
Featurebuffer. Shape = geometry;
 
Featureoid = featurecursor. insertfeature (featurebuffer );
 
}
Featurebuffer. set_value (featurebuffer. Fields. findfield ("instby"), "K Johnston ");
 
For(IntIc = 0; IC <99; IC ++)
 
{
 
Featurebuffer. Shape = Geometry
 
 Featureoid = featurecursor. insertfeature (featurebuffer );
 
}
 
Featurecursor. Flush ();

2) insert data directly (feature. Store Method)

Ifeature newlinefeature = linefeaclass. createfeature ();

Newlinefeature. Shape = pfeature. shape;
Int II = newlinefeature. Fields. findfield (areazonalname );

If (II> 0)

{

Newlinefeature. set_value (II, this. analysareacombobox. Text. Trim ());
}

Newlinefeature. Store ();

3,Data deletionDelete

Ifeatureclass featureclass = featureworkspace. openfeatureclass ("parcels ");

Iqueryfilter queryfilter = new queryfilterclass ();

Queryfilter. whereclause = "zoning_s = 'r '";

Ifeaturecursor updatecursor = featureclass. Update (queryfilter, false );

Ifeature feature = updatecursor. nextfeature ();

Int m = 0;

While (feature! = NULL)

{

M ++;

Updatecursor. deletefeature (feature );

Feature = updatecursor. nextfeature ();

}

4,Data Update Update

Ifeatureclass featureclass = featureworkspace. openfeatureclass ("parcels ");

// Query attributes

Iqueryfilter queryfilter = new queryfilterclass ();

Queryfilter. whereclause = "zoning_s = 'U '";

// Use featurecursor to update data

Ifeaturecursor updatecursor = featureclass. Update (queryfilter, false );

Int fieldindex = featureclass. findfield ("zoning_s ");

Ifeature feature = updatecursor. nextfeature ();

Int m = 0;

While (feature! = NULL)

{

M ++;

Feature. set_value (fieldindex, "x ");

Updatecursor. updatefeature (feature );

Feature = updatecursor. nextfeature ();

}

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.