Пример #1
0
        /// <summary>
        /// PointToSegmentColl - takes a point collection and returns a collection of segments.
        /// </summary>
        /// <param name="pntColl"></param>
        /// <returns>SegmentCollection</returns>
        internal static ESRI.ArcGIS.Geometry.ISegmentCollection PointsToSegmentColl(ESRI.ArcGIS.Geometry.IPointCollection pntColl)
        {
            ESRI.ArcGIS.Geometry.ISegmentCollection segcoll = new ESRI.ArcGIS.Geometry.PolylineClass() as ESRI.ArcGIS.Geometry.ISegmentCollection;
            ESRI.ArcGIS.Geometry.ISegment           segment;
            ESRI.ArcGIS.Geometry.IPoint             frompoint = null;
            ESRI.ArcGIS.Geometry.IPoint             topoint   = null;

            for (int i = 0; i < pntColl.PointCount; i++)
            {
                if (frompoint == null)
                {
                    frompoint = pntColl.get_Point(i);
                    if (pntColl.PointCount >= (i + 1))
                    {
                        topoint = pntColl.get_Point((i + 1));
                        segment = PointsToSegment(frompoint, topoint);
                        segcoll.AddSegment(segment, Type.Missing, Type.Missing);
                    }
                }
                else
                {
                    // to point becomes frompoint after each iteration
                    frompoint = topoint;
                    if (pntColl.PointCount > (i + 1))
                    {
                        topoint = pntColl.get_Point((i + 1));
                        segment = PointsToSegment(frompoint, topoint);
                        segcoll.AddSegment(segment, Type.Missing, Type.Missing);
                    }
                }
            }

            return(segcoll);
        }
Пример #2
0
        public void CreateLineFeature(IFeatureClass featureClass, IFeature sourceF, ESRI.ArcGIS.Geometry.IGeometry shape, string value1, string value2, string value3, string value4, string value5)
        {
            try
            {
                double angle = Convert.ToDouble(ConfigUtil.GetConfigValue("Angle"));
                // Build the feature.
                ESRI.ArcGIS.Geometry.IPoint pOriginPoint = shape as ESRI.ArcGIS.Geometry.IPoint;
                double dbPi = 4 * Math.Atan(1);
                ESRI.ArcGIS.Geometry.IPoint pEndPoint = new ESRI.ArcGIS.Geometry.PointClass();
                //MessageBox.Show(pOriginPoint.X.ToString() + pOriginPoint.Y.ToString());
                pEndPoint.X = pOriginPoint.X - (Math.Cos(((angle) * (dbPi / 180))) * 6);
                pEndPoint.Y = pOriginPoint.Y - (Math.Sin(((angle) * (dbPi / 180))) * 6);


                ESRI.ArcGIS.Geometry.IPointCollection pCollection = new ESRI.ArcGIS.Geometry.PolylineClass();
                pCollection.AddPoint(pOriginPoint);
                pCollection.AddPoint(pEndPoint);

                IFeature feature = featureClass.CreateFeature();
                feature.Shape = pCollection as ESRI.ArcGIS.Geometry.IPolyline;

                // Update the value on a string field that indicates who installed the feature.
                int contractorFieldIndex = featureClass.FindField("DIAMETER");
                feature.set_Value(contractorFieldIndex, Convert.ToInt16(value2));

                int diaFieldIndex = featureClass.FindField("OWNEDBY");
                feature.set_Value(diaFieldIndex, value4);

                int matFieldIndex = featureClass.FindField("SERVICELENGTHBAND");
                feature.set_Value(matFieldIndex, value3);


                int ownedbyFieldIndex = featureClass.FindField("SERVICESIDE");
                feature.set_Value(ownedbyFieldIndex, value1);

                int JBPFieldIndex = featureClass.FindField("JPNUM");
                feature.set_Value(featureClass.FindField("LENGTH"), 6);
                feature.set_Value(JBPFieldIndex, value5);
                feature.set_Value(featureClass.FindField("LOCATION"), sourceF.get_Value(sourceF.Fields.FindField(ConfigUtil.GetConfigValue("LOCATION"))));
                feature.set_Value(featureClass.FindField("LOCATIONDESCRIPTION"), ConfigUtil.GetConfigValue("LOCATIONDESCRIPTION"));
                feature.set_Value(featureClass.FindField("FACILITYID"), GenerateID(ConfigUtil.GetConfigValue("GenIDNWL")));


                // Commit the new feature to the geodatabase.
                feature.Store();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + e.StackTrace);
            }
        }
Пример #3
0
        // FeatureDataTablet to shapefile
        private void WriteFeatureDataTable2shp(GeometryType gtype, FeatureDataTable ftable, IFeatureClass fc, String shapefilePath)
        {
            int rowCount = ftable.Rows.Count;
            int colCount = ftable.Columns.Count;
            int geometryColIndex = ftable.GeometryColumnIndex;
            //GeometryType gtype = selLayer.GeometryType;
            toolStripProgressBar1.Maximum = rowCount;
            toolStripProgressBar1.Value = 0;
            toolStripProgressBar1.Visible = true;

            // for each selected features
            for (int i = 0; i < rowCount; i++)
            {
                toolStripProgressBar1.Value = i + 1;
                selectionStripStatusLabel1.Text = toolStripProgressBar1.Value.ToString() + "/" + rowCount.ToString() + " features exported .";
                toolStripStatusLabel2.Text = shapefilePath;
                Application.DoEvents();

                // create a new feature
                IFeature feature = fc.CreateFeature();
                DataRow arow = ftable.Rows[i];
                string globalid;
                if (arow.Table.Columns.Contains("GlobalID"))
                {
                    globalid = arow["GlobalID"].ToString();
                }
                else
                {
                    globalid = arow["OBJECTID"].ToString();
                }

                // geometry
                ESRI.ArcGIS.Mobile.Geometries.Geometry mobileGeometry = arow[geometryColIndex] as ESRI.ArcGIS.Mobile.Geometries.Geometry;
                byte[] mobileGeometryByteArray = mobileGeometry.ExportToEsriShape();
                int len = mobileGeometryByteArray.Length;
                switch (gtype)
                {
                    case GeometryType.Point:
                        ESRI.ArcGIS.Geometry.IPoint aoShape = new ESRI.ArcGIS.Geometry.PointClass();
                        ((ESRI.ArcGIS.Geometry.IESRIShape)aoShape).ImportFromESRIShape(ref len, ref mobileGeometryByteArray[0]);
                        feature.Shape = aoShape;
                        break;

                    case GeometryType.Multipoint:
                        ESRI.ArcGIS.Geometry.IMultipoint aoShape2 = new ESRI.ArcGIS.Geometry.MultipointClass();
                        ((ESRI.ArcGIS.Geometry.IESRIShape)aoShape2).ImportFromESRIShape(ref len, ref mobileGeometryByteArray[0]);
                        feature.Shape = aoShape2;
                        break;

                    case GeometryType.Polyline:
                        ESRI.ArcGIS.Geometry.IPolyline aoShape3 = new ESRI.ArcGIS.Geometry.PolylineClass();
                        ((ESRI.ArcGIS.Geometry.IESRIShape)aoShape3).ImportFromESRIShape(ref len, ref mobileGeometryByteArray[0]);
                        feature.Shape = aoShape3;
                        break;

                    case GeometryType.Polygon:
                        ESRI.ArcGIS.Geometry.IPolygon aoShape4 = new ESRI.ArcGIS.Geometry.PolygonClass();
                        ((ESRI.ArcGIS.Geometry.IESRIShape)aoShape4).ImportFromESRIShape(ref len, ref mobileGeometryByteArray[0]);
                        feature.Shape = aoShape4;
                        break;
                }

                // insert other attributes
                // in mobile cache, the last col is for geometry
                // in shapefile, fid and shape fields are first two, for other fields index = +2
                for (int col = 0; col < colCount - 1; col++)
                {
                    // type
                    DataColumn dc = ftable.Columns[col];
                    Type dt = dc.DataType;

                    // guid or globalid, change to string
                    if (dt == typeof(Guid) || (dt == typeof(ESRI.ArcGIS.Mobile.GlobalId)))
                    {
                        feature.set_Value(col + 2, arow[col].ToString());
                        //feature.Store();
                        continue;
                    }

                    // if blob field, write to file
                    if (dt == typeof(Byte[]))
                    {
                        continue;
                    }
                    // raster field, write to jpg files
                    if (dt == typeof(Bitmap))
                    {
                        string photofoldername = shapefilePath + "\\" + dc.ColumnName;
                        if (!Directory.Exists(photofoldername))
                            continue;

                        // get bitmap from a raster field, save to ImageSource
                        System.Windows.Media.ImageSource imgsrc = null;
                        Bitmap bitmap = arow[col] as Bitmap;
                        if (bitmap == null)
                            continue;

                        System.Windows.Int32Rect rect = new System.Windows.Int32Rect(0, 0, bitmap.Width, bitmap.Height);
                        IntPtr hBitmap = IntPtr.Zero;
                        try
                        {
                            hBitmap = bitmap.GetHbitmap();
                            imgsrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                                     hBitmap, IntPtr.Zero, rect, BitmapSizeOptions.FromEmptyOptions());

                            // write the ImageSource to jpg
                            if (imgsrc == null)
                                continue;
                            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                            encoder.Frames.Add(BitmapFrame.Create(imgsrc as BitmapSource));
                            string fileName = photofoldername + "\\" + globalid + ".jpg";
                            using (System.IO.FileStream file = File.OpenWrite(fileName))
                            {
                                encoder.Save(file);
                            }

                            continue;

                        }
                        finally
                        {
                            if (hBitmap != IntPtr.Zero)
                                DeleteObject(hBitmap);
                        }
                    }  // end of bitmap

                    // other data types, just set the value
                    if (arow[col].ToString() != "")
                        feature.set_Value(col + 2, arow[col]);
                    else
                        feature.set_Value(col + 2, 0);

                }

                feature.Store();
            }

            //MessageBox.Show(rowCount.ToString() + " features saved into a shapefile at: " + shapefilePath);
            toolStripProgressBar1.Value = 0;
            selectionStripStatusLabel1.Text = "";
            toolStripProgressBar1.Visible = false;

            return;
        }