ArcGIS engine generates Contour lines (C #)

Source: Internet
Author: User

Original: ArcGIS engine generates Contour lines (C #)

This article describes a C # write method that uses ArcGIS engine to generate contours.

C # writes The function of the rainfall contour in accordance with the rainfall value of the rainfall station. Make a few notes:
To generate contours from discrete points:
(1) Determine if the contour shapefile layer temporary storage path exists, if not exist then create, if there is not empty then delete the rebuild;
(2) Add "Rainfall" field and assign value, generate contour line and delete the added field;
(3) Based on the selected field using IDW interpolation to generate raster, and then set the spacing generated contour and annotated.

---------------------------------The following is the source code----------------------------------

private void Button1_Click (object sender, EventArgs e)
Define contour temporary shapefile layer storage path
String Ls_tempsavepath = @" c:\hnyttemp";
if (! Directory.Exists (Ls_tempsavepath))//If the directory does not exist, create
Directory.CreateDirectory (Ls_tempsavepath);
DirectoryInfo di = new DirectoryInfo (Ls_tempsavepath);
Fileinfo[] fi = null;
fi = di. GetFiles ();
if (FI. Length! = 0)//If the directory is not empty, delete the directory and then rebuild
Directory.delete (Ls_tempsavepath, true);
Directory.CreateDirectory (Ls_tempsavepath);
IMap pMap =;
Iinterpolationop Pinterpolationop = new Rasterinterpolationopclass ();

Create the input Point object
Igeodataset Pinputdataset;
Rainfall station layer "point"
Ifeaturelayer pfeatlayer = Axmapcontrol1.get_layer (0) as Ifeaturelayer;
Calls function to open the point dataset from disk

Ifeatureclass PFEATCLA = Pfeatlayer.featureclass;

IFeature pfeature;
Ifield Pfield = new Fieldclass ();
Ifieldedit Pfieldedit = Pfield as Ifieldedit;

Pfieldedit. name_2 = " Rainfall ";
pfieldedit.type_2 = esrifieldtype.esrifieldtypedouble;
pfieldedit.length_2 = 12;
Pfieldedit.isnullable_2 = false;
pfieldedit.defaultvalue_2 = 1111;
Pfeatcla.addfield (Pfieldedit); Add the field that you want to use.
for (int ii=0;ii<pfeatcla.featurecount (NULL)-1;ii++)
Pfeature = Pfeatcla.getfeature (ii);
Pfeature.set_value (PFeature.Fields.FindField (" rainfall "), 22+1999/(ii+2));
Feature field assignment, here is the value of their own arbitrarily assigned, only for testing ();
Pinputdataset = Pfeatlayer as Igeodataset;
Define the search Radius
Irasterradius Pradius = new Rasterradiusclass ();

Object Missing = Type.Missing;
Pradius.setvariable (ref Missing);
Create featureclassdescriptor using a value field
Ifeatureclassdescriptor pfcdescriptor = new Featureclassdescriptorclass ();
Pfcdescriptor.create (Pfeatlayer.featureclass, NULL, " rainfall ");
Set cellsize for output raster in the environment
Object cellsizeprovider = 20;

Irasteranalysisenvironment penv = Pinterpolationop as irasteranalysisenvironment;
Penv.setcellsize (Esrirasterenvsettingenum.esrirasterenvvalue, ref cellsizeprovider);

Perform the interpolation
Iraster poutraster = PINTERPOLATIONOP.IDW (Pfcdescriptor as Igeodataset, 2, Pradius, ref Missing) as Iraster;

ADD output into ArcMap as a raster layer
Rasterlayer Poutraslayer = new Rasterlayerclass ();
Poutraslayer.createfromraster (Poutraster); = " Grid ";
Pmap.addlayer (Poutraslayer);

Igeodataset Pgeodataset = Poutraster as Igeodataset;
Iworkspacefactory pworkspacefactory = new Shapefileworkspacefactory ();
Iworkspace pshpworkspace = pworkspacefactory.openfromfile (ls_tempsavepath, 0);
ISURFACEOP2 pSurfaceOp2 = new Rastersurfaceopclass ();
Irasteranalysisenvironment prasteranalysisenvironment = pSurfaceOp2 as irasteranalysisenvironment;
Prasteranalysisenvironment.reset ();
Prasteranalysisenvironment.setcellsize (Esrirasterenvsettingenum.esrirasterenvvalue, ref cellSizeProvider);
Prasteranalysisenvironment.outworkspace = Pshpworkspace;
Double dinterval = 5; Spacing
Igeodataset Poutputdataset = Psurfaceop2.contour (Pgeodataset, Dinterval,ref missing,ref Missing);
Ifeatureclass pfeatureclass= Poutputdataset as Ifeatureclass;
Ifeaturelayer Pfeaturelayer = new Featurelayerclass ();
Pfeaturelayer.featureclass = Pfeatureclass;
Igeofeaturelayer Pgeofeaturelayer = Pfeaturelayer as Igeofeaturelayer;
Pgeofeaturelayer.displayannotation = true;
Pgeofeaturelayer.displayfield = " contour"; = " rainfall Contour Line ";
Pmap.addlayer (Pgeofeaturelayer);
Axmapcontrol1.refresh ();

Delete the Rainfall field
Ifields pfields = Pfeatcla.fields;
int lfieldnumber = Pfields.findfield (" rainfall ");
Ifield pField1 = Pfields.get_field (Lfieldnumber);
Pfeatcla.deletefield (Pfield);

ArcGIS engine generates Contour lines (C #)

Related Article

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: 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.