Esempio n. 1
0
 public static void CreateLineFeature(IFeatureLayer featureLayer, IPolyline polyline)
 {
     try
     {
         bool             hasZ            = FeatureClassUtil.CheckHasZ(featureLayer.FeatureClass);
         bool             hasM            = FeatureClassUtil.CheckHasM(featureLayer.FeatureClass);
         IPointCollection pointCollection = polyline as IPointCollection;
         if (pointCollection == null)
         {
             return;
         }
         for (int i = 1; i < pointCollection.PointCount; i++)
         {
             IPoint   fromPoint = pointCollection.Point[i - 1];
             IPoint   toPoint   = pointCollection.Point[i];
             IFeature feature   = featureLayer.FeatureClass.CreateFeature();
             feature.Shape = GeometryHelper.CreatePointCollection(fromPoint, toPoint, hasZ, hasM) as IPolyline;
             feature.Store();
         }
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
Esempio n. 2
0
 public static void CreatePointFeatures(IFeatureLayer featureLayer, IPolyline polyline, bool hasFromPoint, bool hasTurningPoint, bool hasToPoint)
 {
     try
     {
         bool             hasZ            = FeatureClassUtil.CheckHasZ(featureLayer.FeatureClass);
         bool             hasM            = FeatureClassUtil.CheckHasM(featureLayer.FeatureClass);
         IPointCollection pointCollection = polyline as IPointCollection;
         if (pointCollection == null)
         {
             return;
         }
         for (int i = 0; i < pointCollection.PointCount; i++)
         {
             if (hasFromPoint == false && i == 0)
             {
                 continue;
             }
             if (hasTurningPoint == false && i > 0 && i < pointCollection.PointCount - 1)
             {
                 continue;
             }
             if (hasToPoint == false && i == pointCollection.PointCount - 1)
             {
                 continue;
             }
             IPoint   point   = pointCollection.Point[i];
             IFeature feature = featureLayer.FeatureClass.CreateFeature();
             feature.Shape = GeometryHelper.CreatePoint(point.X, point.Y,
                                                        point.Z, point.M, hasZ, hasM);
             feature.Store();
         }
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
Esempio n. 3
0
        public static IFeature CutOffPolylineByPoint(IFeatureClass featureClass, IFeature polylineFeature,
                                                     IFeature pointFeature, string keyValue, string sKeyValue, string eKeyValue)
        {
            int idxKeyField  = pointFeature.Fields.FindField(keyValue);
            int idxSKeyField = polylineFeature.Fields.FindField(sKeyValue);
            int idxEKeyField = polylineFeature.Fields.FindField(eKeyValue);

            if (idxKeyField == -1 || idxSKeyField == -1 || idxEKeyField == -1)
            {
                return(null);
            }
            bool   hasZ  = FeatureClassUtil.CheckHasZ(featureClass);
            bool   hasM  = FeatureClassUtil.CheckHasM(featureClass);
            IPoint point = pointFeature.Shape as IPoint;

            if (point == null)
            {
                return(null);
            }
            IPolyline polyline1 = polylineFeature.ShapeCopy as IPolyline;

            if (polyline1 == null)
            {
                return(null);
            }
            IPolyline firstPolyline = new PolylineClass
            {
                FromPoint = GeometryHelper.CreatePoint(polyline1.FromPoint.X, polyline1.FromPoint.Y, polyline1.FromPoint.Z, polyline1.FromPoint.M, hasZ, hasM),
                ToPoint   = GeometryHelper.CreatePoint(point.X, point.Y, point.Z, point.M, hasZ, hasM)
            };

            if (hasZ)
            {
                IZAware pZAware = firstPolyline as IZAware;
                pZAware.ZAware = true;
            }
            if (hasM)
            {
                IMAware pMAware = firstPolyline as IMAware;
                pMAware.MAware = true;
            }
            polylineFeature.Shape = firstPolyline;
            polylineFeature.Store();
            IFeature  secondFeature  = featureClass.CreateFeature();
            IPolyline secondPolyline = new PolylineClass
            {
                FromPoint = GeometryHelper.CreatePoint(point.X, point.Y, point.Z, point.M, hasZ, hasM),
                ToPoint   = GeometryHelper.CreatePoint(polyline1.ToPoint.X, polyline1.ToPoint.Y, polyline1.ToPoint.Z, polyline1.ToPoint.M, hasZ, hasM),
            };

            if (hasZ)
            {
                IZAware pZAware = secondPolyline as IZAware;
                pZAware.ZAware = true;
            }
            if (hasM)
            {
                IMAware pMAware = secondPolyline as IMAware;
                pMAware.MAware = true;
            }
            secondFeature.Shape = secondPolyline;
            IField pField;

            for (int i = 0; i < featureClass.Fields.FieldCount; i++)
            {
                pField = featureClass.Fields.Field[i];
                if (pField.Type == esriFieldType.esriFieldTypeGeometry)
                {
                    continue;
                }
                int idx = secondFeature.Fields.FindField(pField.Name);
                if (pField.Editable && idx != -1)
                {
                    secondFeature.Value[idx] = polylineFeature.Value[idx];
                }
            }
            secondFeature.Store();

            polylineFeature.Value[idxEKeyField] = pointFeature.Value[idxKeyField];
            polylineFeature.Store();
            secondFeature.Value[idxSKeyField] = pointFeature.Value[idxKeyField];
            secondFeature.Store();
            return(secondFeature);
        }