Generate contour lines for TIN in ArcEngine

Source: Internet
Author: User

The time is too late. directly add the source code:

/// <Summary> // TIN to generate a contour line /// </summary> /// <param name = "pInterval"> contour line spacing </param> public void Tin2Contour (string path _, string name _, double pInterval) {// obtain TIN ITinLayer pTinlayer = GetLayerByName (pScene, comboBox_TIN.Text) as ITinLayer; ITin pTin = pTinlayer. dataset as ITin; // create Contour shape IWorkspaceFactory pWSFac = new ShapefileWorkspaceFactoryClass (); IFeatureWorkspace pFeatureWS = pWSFac. openFromFile (path _, 0) as IFeatureWorkspace; if (System. IO. file. exists (path _ + "\" + name _ + ". shp ") {System. IO. file. delete (path _ + "\" + name _ + ". shp "); System. IO. file. delete (path _ + "\" + name _ + ". dbf "); System. IO. file. delete (path _ + "\" + name _ + ". shx ");} IFields pFields = CreateShapeFields (esriGeometryType. esriGeometryPolyline); pFeatureWS. createFeatureClass (name _, pFields, null, null, esriFeatureType. esriFTSimple, "Shape", null); IFeatureClass pContourFeatureClass = pFeatureWS. openFeatureClass (name _); // generate the contour line ITinSurface pTinSurface = pTin as ITinSurface; pTinSurface. contour (0, pInterval, pContourFeatureClass, "Contour", 0); // Add the Contour layer IFeatureLayer pFeatureLayer = new FeatureLayerClass (); pFeatureLayer. featureClass = pContourFeatureClass; IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer; pGeoFeatureLayer. displayAnnotation = true; pGeoFeatureLayer. displayField = "Contour"; pGeoFeatureLayer. name = pContourFeatureClass. aliasName + "_ Contour"; // set the line style ILineSymbol pLineSymbol = new SimpleLineSymbolClass (); pLineSymbol. color = GetRGBColor (32, 47,247); pLineSymbol. width = 2; ISimpleRenderer pRender = pGeoFeatureLayer. renderer as ISimpleRenderer; pRender. symbol = pLineSymbol as ISymbol; pScene. addLayer (pFeatureLayer as ILayer );}
# Region create a geometric field // <summary> // create a geometric field // </summary> // <param name = "p_esriGeotype"> </param>/ // <returns> </returns> public IFields CreateShapeFields (esriGeometryType p_esriGeotype) {IFields pFields = new FieldsClass (); IFieldsEdit pFieldsEdit = pFields as alias; IGeometryDef pGeoDef = new GeometryDefClass (); IGeometryDefEdit pGeoDefEdit = pGeoDef as alias; pGeoDefEdit. geometryType_2 = p_esriGeotype; pGeoDefEdit. spatialReference_2 = (ISpatialReference) new UnknownCoordinateSystem (); IField peld = new FieldClass (); IFieldEdit pFldEdit = pFld as IFieldEdit; pFldEdit. name_2 = "shape"; pFldEdit. isNullable_2 = false; pFldEdit. type_2 = esriFieldType. esriFieldTypeGeometry; pFldEdit. geometryDef_2 = pGeoDef; pFieldsEdit. addField (pfield); return pFields;} # endregion # region obtain the layer by name // obtain the layer public ILayer GetLayerByName (IScene scene, string strLayerName) {ILayer pLayer = null; for (int I = 0; I <scene. layerCount; I ++) {pLayer = scene. get_Layer (I); if (strLayerName = pLayer. name) {break ;}} return pLayer ;}# endregion

For more information about the Contour function, see the help documentation!

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.