예제 #1
0
        /**
         * 官网示例
         * */
        public void IFeatureClass_CreateFeature_Example(IFeatureClass featureClass)
        {
            //Function is designed to work with polyline data
            if (featureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
            {
                return;
            }
            //create a geometry for the features shape
            ESRI.ArcGIS.Geometry.IPolyline polyline = new ESRI.ArcGIS.Geometry.PolylineClass();
            ESRI.ArcGIS.Geometry.IPoint    point    = new ESRI.ArcGIS.Geometry.PointClass();
            point.X            = 0; point.Y = 0;
            polyline.FromPoint = point;
            point   = new ESRI.ArcGIS.Geometry.PointClass();
            point.X = 10; point.Y = 10; polyline.ToPoint = point;
            IFeature feature = featureClass.CreateFeature();

            //Apply the constructed shape to the new features shape
            feature.Shape = polyline;
            ISubtypes    subtypes    = (ISubtypes)featureClass;
            IRowSubtypes rowSubtypes = (IRowSubtypes)feature;

            if (subtypes.HasSubtype)         // does the feature class have subtypes?
            {
                rowSubtypes.SubtypeCode = 1; //in this example 1 represents the Primary Pipeline subtype
            }
            // initalize any default values that the feature has
            rowSubtypes.InitDefaultValues();
            //Commit the default values in the feature to the database
            feature.Store();
            //update the value on a string field that indicates who installed the feature.
            feature.set_Value(feature.Fields.FindField("InstalledBy"), "K Johnston");
            //Commit the updated values in the feature to the database
            feature.Store();
        }
예제 #2
0
        private Bitmap DrawToPictureBox(ISymbol pSym, PictureBox pBox)
        {
            IPoint    pPoint    = null;
            IGeometry pGeometry = null;
            int       hDC;

            System.Drawing.Graphics pGraphics = null;
            pGraphics = System.Drawing.Graphics.FromHwnd(pBox.Handle);
            //clear drawing canvas
            pGraphics.FillRectangle(System.Drawing.Brushes.White, pBox.ClientRectangle);
            if (pSym is IMarkerSymbol)
            {
                pPoint = new PointClass();                         //the geometry of a MarkerSymbol
                pPoint.PutCoords(pBox.Width / 2, pBox.Height / 2); //center in middle of pBox
                pGeometry = pPoint;
            }
            if (pSym is ILineSymbol)
            {
                ISegmentCollection polyline  = new ESRI.ArcGIS.Geometry.PolylineClass();
                ISegment           line      = new ESRI.ArcGIS.Geometry.LineClass();
                IPoint             fromPoint = new PointClass();
                fromPoint.PutCoords(pBox.Left, pBox.Bottom);
                IPoint toPoint = new PointClass();
                toPoint.PutCoords(pBox.Right, pBox.Top);
                line.FromPoint = fromPoint;
                line.ToPoint   = toPoint;
                object missing = Type.Missing;
                polyline.AddSegment(line, ref missing, ref missing);
                pGeometry = polyline as IGeometry;
            }
            if (pSym is IFillSymbol)
            {
                IEnvelope pEnvelope = new EnvelopeClass();
                pEnvelope.PutCoords(pBox.Left, pBox.Top, pBox.Right, pBox.Bottom);
                pGeometry = pEnvelope;
            }

            hDC = GetDC(pBox.Handle.ToInt32());
            pSym.SetupDC(hDC, null);
            pSym.ROP2 = esriRasterOpCode.esriROPCopyPen;
            pSym.Draw(pGeometry);
            pSym.ResetDC();

            Bitmap   image = new Bitmap(pBox.Width, pBox.Height, pGraphics);
            Graphics g2    = Graphics.FromImage(image);
            //获得屏幕的句柄
            IntPtr dc3 = pGraphics.GetHdc();
            //获得位图的句柄
            IntPtr dc2 = g2.GetHdc();

            BitBlt(dc2, 0, 0, pBox.Width, pBox.Height, dc3, 0, 0, SRCCOPY);
            pGraphics.ReleaseHdc(dc3); //释放屏幕句柄
            g2.ReleaseHdc(dc2);        //释放位图句柄
            //image.Save("c:\\MyJpeg.Icon", ImageFormat.Bmp);
            return(image);
        }
예제 #3
0
        private void DrawToTarget(ISymbol pSym, PictureBox pBox)
        {
            IPoint    pPoint    = null;
            IGeometry pGeometry = null;

            IDisplayTransformation pDisplayTrans = null;

            if (pSym is IMarkerSymbol)
            {
                pPoint = new PointClass();                         //the geometry of a MarkerSymbol
                pPoint.PutCoords(pBox.Width / 2, pBox.Height / 2); //center in middle of pBox
                pGeometry = pPoint;
            }
            if (pSym is ILineSymbol)
            {
                ISegmentCollection polyline  = new ESRI.ArcGIS.Geometry.PolylineClass();
                ISegment           line      = new ESRI.ArcGIS.Geometry.LineClass();
                IPoint             fromPoint = new PointClass();
                fromPoint.PutCoords(pBox.Left, pBox.Bottom);
                IPoint toPoint = new PointClass();
                toPoint.PutCoords(pBox.Right, pBox.Top);
                line.FromPoint = fromPoint;
                line.ToPoint   = toPoint;
                object missing = Type.Missing;
                polyline.AddSegment(line, ref missing, ref missing);
                pGeometry = polyline as IGeometry;
            }
            if (pSym is IFillSymbol)
            {
                IEnvelope pEnvelope = new EnvelopeClass();
                pEnvelope.PutCoords(pBox.Left, pBox.Top, pBox.Right, pBox.Bottom);
                pGeometry = pEnvelope;
            }
            pDisplayTrans = getTransformation(pBox) as IDisplayTransformation;
            pSym.SetupDC(pBox.Handle.ToInt32(), null);
            pSym.ROP2 = esriRasterOpCode.esriROPCopyPen;
            pSym.Draw(pGeometry);
            pSym.ResetDC();
        }
예제 #4
0
파일: Form1.cs 프로젝트: eglrp/Excercise
        void CreateShape()
        {
            string   strFolder = @"F:\arcMap";
            string   strFile   = "newpath" + ".shp";
            FileInfo fFile     = new FileInfo(strFolder + @"\" + strFile);

            string            shapeFullName     = strFolder + @"\" + strFile;
            IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(strFolder, 0);

            IFeatureClass pFeatureClass;

            //创建不同类型的字段
            int    i;
            double tmpLongitude;
            double tmpLatitude;
            IPoint pPoint;

            IFields     pFields     = new Fields();
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
            IField      pFiled      = new Field();
            IFieldEdit  pFieldEdit  = (IFieldEdit)pFiled;

            //设置坐标系并定义几何类型
            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironment();
            //IGeographicCoordinateSystem pGCS;
            //pGCS = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            IProjectedCoordinateSystem pPrj;

            pPrj = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type.esriSRProjCS_Beijing1954_3_Degree_GK_Zone_38);
            pFieldEdit.Name_2 = "SHAPE";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            #region 点创建
            //IGeometryDef pGeoDef = new GeometryDef();
            //IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;
            //pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;

            //pGeoDefEdit.SpatialReference_2 = pGCS;
            //pFieldEdit.GeometryDef_2 = pGeoDef;
            //pFieldsEdit.AddField(pFiled);

            //pFiled = new Field();
            //pFieldEdit = (IFieldEdit)pFiled;
            //pFieldEdit.Name_2 = "经度";
            //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
            //pFieldsEdit.AddField(pFiled);
            ////创建shp
            //pFeatureClass = pFeatureWorkspace.CreateFeatureClass(strFile, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");

            //tmpLongitude = 11616.61347551;
            //tmpLatitude = 3956.63814757;
            //pPoint = new ESRI.ArcGIS.Geometry.Point();
            //pPoint.X = tmpLongitude;
            //pPoint.Y = tmpLatitude;
            //IFeature pFeature = pFeatureClass.CreateFeature();
            //pFeature.Shape = pPoint;
            //pFeature.Store();

            //pPoint = new ESRI.ArcGIS.Geometry.Point();
            //pPoint.X = tmpLongitude - 100;
            //pPoint.Y = tmpLatitude - 100;
            //pFeature = pFeatureClass.CreateFeature();
            //pFeature.Shape = pPoint;
            //pFeature.set_Value(pFeature.Fields.FindField("经度"), tmpLongitude.ToString("F4"));

            //pFeature.Store();
            #endregion

            #region 线创建
            IGeometryDef     pGeoDef     = new GeometryDef();
            IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;
            pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;

            pGeoDefEdit.SpatialReference_2 = pPrj;
            pFieldEdit.GeometryDef_2       = pGeoDef;
            pFieldsEdit.AddField(pFiled);

            //创建shp
            pFeatureClass = pFeatureWorkspace.CreateFeatureClass(strFile, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");

            ILine pLine = new LineClass();

            pPoint = new ESRI.ArcGIS.Geometry.Point();
            pPoint.PutCoords(38708267.3691335, 4452391.75361639);

            //定义一个多义线对象
            IPolyline pPolyline = new ESRI.ArcGIS.Geometry.PolylineClass();
            //定义一个点的集合
            IPointCollection ptclo = pPolyline as IPointCollection;
            //定义一系列要添加到多义线上的点对象,并赋初始值

            ptclo.AddPoint(pPoint);

            pPoint = new ESRI.ArcGIS.Geometry.Point();
            pPoint.PutCoords(38708297.23653, 4452391.79756713);


            ptclo.AddPoint(pPoint);

            IFeature pFeature = pFeatureClass.CreateFeature();
            pFeature.Shape = pPolyline as IPolyline;
            pFeature.Store();
            #endregion

            #region 面创建
            //IGeometryDef pGeoDef = new GeometryDef();
            //IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;
            //pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;

            //pGeoDefEdit.SpatialReference_2 = pGCS;
            //pFieldEdit.GeometryDef_2 = pGeoDef;
            //pFieldsEdit.AddField(pFiled);

            //pFiled = new Field();
            //pFieldEdit = (IFieldEdit)pFiled;
            //pFieldEdit.Name_2 = "名称";
            //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            //pFieldsEdit.AddField(pFiled);
            ////创建shp
            //pFeatureClass = pFeatureWorkspace.CreateFeatureClass(strFile, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");

            //IPointCollection pointPolygon = new PolygonClass();
            //pPoint = new PointClass();
            //pPoint.PutCoords(116.445171, 40.187373);
            //pointPolygon.AddPoint(pPoint);
            //pPoint = new PointClass();
            //pPoint.PutCoords(116.445698, 40.187436);
            //pointPolygon.AddPoint(pPoint);
            //pPoint = new PointClass();
            //pPoint.PutCoords(116.446457, 40.184014);
            //pointPolygon.AddPoint(pPoint);
            //pPoint = new PointClass();
            //pPoint.PutCoords(116.445927, 40.183817);
            //pointPolygon.AddPoint(pPoint);

            //IFeature pFeature = pFeatureClass.CreateFeature();
            //pFeature.Shape = pointPolygon as IGeometry;
            //pFeature.set_Value(pFeature.Fields.FindField("名称"), "地块1");
            //pFeature.Store();

            //pointPolygon = new PolygonClass();
            //pPoint = new PointClass();
            //pPoint.PutCoords(116.445698, 40.187436);
            //pointPolygon.AddPoint(pPoint);
            //pPoint = new PointClass();
            //pPoint.PutCoords(116.446257, 40.187502);
            //pointPolygon.AddPoint(pPoint);
            //pPoint = new PointClass();
            //pPoint.PutCoords(116.446967, 40.184236);
            //pointPolygon.AddPoint(pPoint);
            //pPoint = new PointClass();
            //pPoint.PutCoords(116.446457, 40.184014);
            //pointPolygon.AddPoint(pPoint);

            //pFeature = pFeatureClass.CreateFeature();
            //pFeature.Shape = pointPolygon as IGeometry;
            //pFeature.set_Value(pFeature.Fields.FindField("名称"), "地块2");
            //pFeature.Store();

            #endregion

            //IGeometry polyline;
            //polyline = axMapControl1.TrackLine();
        }
예제 #5
-1
        private void DrawToTarget(ISymbol pSym, PictureBox pBox)
        {
            IPoint pPoint = null;
            IGeometry pGeometry = null;

            IDisplayTransformation pDisplayTrans = null;

            if (pSym is IMarkerSymbol)
            {
                pPoint = new PointClass();      //the geometry of a MarkerSymbol
                pPoint.PutCoords(pBox.Width / 2, pBox.Height / 2);       //center in middle of pBox
                pGeometry = pPoint;
            }
            if (pSym is ILineSymbol)
            {
                ISegmentCollection polyline = new ESRI.ArcGIS.Geometry.PolylineClass();
                ISegment line = new ESRI.ArcGIS.Geometry.LineClass();
                IPoint fromPoint = new PointClass();
                fromPoint.PutCoords(pBox.Left, pBox.Bottom);
                IPoint toPoint = new PointClass();
                toPoint.PutCoords(pBox.Right, pBox.Top);
                line.FromPoint = fromPoint;
                line.ToPoint = toPoint;
                object missing = Type.Missing;
                polyline.AddSegment(line, ref missing, ref missing);
                pGeometry = polyline as IGeometry;
            }
            if (pSym is IFillSymbol)
            {
                IEnvelope pEnvelope = new EnvelopeClass();
                pEnvelope.PutCoords(pBox.Left, pBox.Top, pBox.Right, pBox.Bottom);
                pGeometry = pEnvelope;
            }
            pDisplayTrans = getTransformation(pBox) as IDisplayTransformation;
            pSym.SetupDC(pBox.Handle.ToInt32(), null);
            pSym.ROP2 = esriRasterOpCode.esriROPCopyPen;
            pSym.Draw(pGeometry);
            pSym.ResetDC();
        }
예제 #6
-1
        private Bitmap DrawToPictureBox(ISymbol pSym, PictureBox pBox)
        {
            IPoint pPoint = null;
            IGeometry pGeometry = null;
            int hDC;
            System.Drawing.Graphics pGraphics = null;
            pGraphics = System.Drawing.Graphics.FromHwnd(pBox.Handle);
            //clear drawing canvas
            pGraphics.FillRectangle(System.Drawing.Brushes.White, pBox.ClientRectangle);
            if (pSym is IMarkerSymbol)
            {
                pPoint = new PointClass();      //the geometry of a MarkerSymbol
                pPoint.PutCoords(pBox.Width / 2, pBox.Height / 2);       //center in middle of pBox
                pGeometry = pPoint;
            }
            if (pSym is ILineSymbol)
            {
                ISegmentCollection polyline = new ESRI.ArcGIS.Geometry.PolylineClass();
                ISegment line = new ESRI.ArcGIS.Geometry.LineClass();
                IPoint fromPoint = new PointClass();
                fromPoint.PutCoords(pBox.Left, pBox.Bottom);
                IPoint toPoint = new PointClass();
                toPoint.PutCoords(pBox.Right, pBox.Top);
                line.FromPoint = fromPoint;
                line.ToPoint = toPoint;
                object missing = Type.Missing;
                polyline.AddSegment(line, ref missing, ref missing);
                pGeometry = polyline as IGeometry;
            }
            if (pSym is IFillSymbol)
            {
                IEnvelope pEnvelope = new EnvelopeClass();
                pEnvelope.PutCoords(pBox.Left, pBox.Top, pBox.Right, pBox.Bottom);
                pGeometry = pEnvelope;
            }

            hDC = GetDC(pBox.Handle.ToInt32());
            pSym.SetupDC(hDC, null);
            pSym.ROP2 = esriRasterOpCode.esriROPCopyPen;
            pSym.Draw(pGeometry);
            pSym.ResetDC();

            Bitmap image = new Bitmap(pBox.Width, pBox.Height, pGraphics);
            Graphics g2 = Graphics.FromImage(image);
            //获得屏幕的句柄
            IntPtr dc3 = pGraphics.GetHdc();
            //获得位图的句柄
            IntPtr dc2 = g2.GetHdc();
            BitBlt(dc2, 0, 0, pBox.Width, pBox.Height, dc3, 0, 0, SRCCOPY);
            pGraphics.ReleaseHdc(dc3);//释放屏幕句柄
            g2.ReleaseHdc(dc2);//释放位图句柄
            //image.Save("c:\\MyJpeg.Icon", ImageFormat.Bmp);
            return image;
        }