Exemple #1
0
        public static void FlashLine(IEnumerable <IPoint> points)
        {
            var activeView           = (ArcMap.Application.Document as IMxDocument)?.FocusMap as IActiveView;
            IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2;

            IPointCollection4 pPointColl = new PolylineClass();
            var aWKSPointBuffer          = new IPoint[points.Count()];

            var i = 0;

            foreach (var point in points)
            {
                aWKSPointBuffer[i] = point;
                i++;
            }
            pGeoBrg.SetPoints(pPointColl, ref aWKSPointBuffer);

            var polyline = pPointColl as IPolyline;

            IGeometryCollection theGeomColl = new GeometryBagClass();

            theGeomColl.AddGeometry(polyline);

            ITopologicalOperator theTopoOp = new PolylineClass();

            theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);

            IGeometry flashGeometry = theTopoOp as IGeometry;

            if (flashGeometry != null)
            {
                EsriTools.ZoomToGeometry(activeView, polyline);
                EsriTools.FlashGeometry(activeView.ScreenDisplay, new IGeometry[] { polyline });
            }
        }
Exemple #2
0
        public IPolygon BoundingPolygon(IList <IPoint> pList, ISpatialReference spatialrefrence)
        {
            try
            {
                IGeometryBridge2  pGeoBrg    = new GeometryEnvironment() as IGeometryBridge2;
                IPointCollection4 pPointColl = (IPointCollection4) new Multipoint(); // edited here

                int        numPoints       = pList.Count;
                WKSPoint[] aWKSPointBuffer = new WKSPoint[numPoints];
                for (int i = 0; i < pList.Count; i++)
                {
                    WKSPoint A = new WKSPoint();
                    A.X = pList[i].X;
                    A.Y = pList[i].Y;
                    aWKSPointBuffer[i] = A;
                }
                pGeoBrg.SetWKSPoints(pPointColl, ref aWKSPointBuffer);

                // edits here
                IGeometry pGeom = (IMultipoint)pPointColl;
                pGeom.SpatialReference = spatialrefrence;
                ITopologicalOperator pTopOp      = (ITopologicalOperator)pGeom;
                IPolygon             pPointColl2 = (IPolygon)pTopOp.ConvexHull();

                pPointColl2.SpatialReference = spatialrefrence;
                // OutputPolygon = pPointColl2; maybe you don't need this line as the object is not used
                return(pPointColl2);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemple #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //当确定按钮被点击时
            //连接数据库,路径规划
            //string sqlstr = "select ST_asbinary(ST_Union(geom)) as route from pgr_fromAtoB('whu_road_feature2line'::text,114.353,30.539,114.367,30.544) ;";
            string sqlstr = null;

            if ((startX * startY * endX * endY) != 0)
            {
                sqlstr = "select ST_asbinary(ST_Union(geom)) as route from pgr_fromAtoB('whu_road_feature2line'::text," + startX + "," + startY + "," + endX + "," + endY + ") ;";
            }
            else
            {
                MessageBox.Show("起始点或终止点不能为空");
                return;
            }
            Byte[]    routeWKB = DAO.executeRouteQuery(sqlstr);
            IGeometry geom;
            int       countin = routeWKB.GetLength(0);
            //地图容器,创建临时元素
            IMap               pMap               = mMapControl.Map;
            IActiveView        pActiveView        = pMap as IActiveView;
            IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;

            if (pElement != null)
            {
                pGraphicsContainer.DeleteElement(pElement);
            }
            //转换wkb为IGeometry
            IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3;

            factory.CreateGeometryFromWkbVariant(routeWKB, out geom, out countin);
            IPolyline pLine = (IPolyline)geom;

            //定义要素symbol
            ISimpleLineSymbol pLineSym = new SimpleLineSymbol();
            IRgbColor         pColor   = new RgbColor();

            pColor.Red     = 11;
            pColor.Green   = 120;
            pColor.Blue    = 233;
            pLineSym.Color = pColor;
            pLineSym.Style = esriSimpleLineStyle.esriSLSSolid;
            pLineSym.Width = 2;
            //线元素symbol绑定
            ILineElement pLineElement = new LineElementClass();

            pLineElement.Symbol = pLineSym;
            //添加geom
            pElement          = pLineElement as IElement;
            pElement.Geometry = pLine;
            //加入地图并刷新
            pGraphicsContainer.AddElement(pElement, 0);
            pActiveView.Refresh();
            //object symbol = pLineSym as object;
            //mMapControl.DrawShape(pLine, ref symbol);
        }
Exemple #4
0
        /// <summary>
        /// 将wkb对象转换为Geometry对象
        /// </summary>
        /// <param name="wkb"></param>
        /// <returns></returns>
        public static IGeometry ConvertWkbToGeometry(byte[] wkb)
        {
            IGeometry         geom;
            int               countin = wkb.GetLength(0);
            IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3;

            factory.CreateGeometryFromWkbVariant(wkb, out geom, out countin);
            return(geom);
        }
Exemple #5
0
        /// <summary>
        /// Converts the geometry to WKB.
        /// </summary>
        /// <param name="geometry">The geometry</param>
        /// <returns>WKB byte array</returns>
        private static byte[] ConvertGeometryToWKB(IGeometry geometry)
        {
            IWkb wkb = geometry as IWkb;
            ITopologicalOperator oper = geometry as ITopologicalOperator;

            oper.Simplify();

            IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3;

            byte[] b = factory.CreateWkbVariantFromGeometry(geometry) as byte[];
            return(b);
        }
        public void Export(ILayer layer, OIDList oids, int srid, int commitinterval)
        {
            IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3;

            IFeatureLayer featureLayer = (IFeatureLayer)layer;
            IDataset      dataset      = (IDataset)featureLayer.FeatureClass;

            GeoDataTableAdapter.GeoAdapter adapter = new GeoDataTableAdapter.GeoAdapter(dataset.Workspace);


            this.CommitInterval = commitinterval;
            int i = 0;

            string tableName = layer.Name.Replace(' ', '_');

            while (i < oids.Count)
            {
                int elementcount;

                if (i + this.CommitInterval > oids.Count)
                {
                    elementcount = oids.Count - i;
                }
                else
                {
                    elementcount = this.CommitInterval;
                }

                OIDList oidrange = oids.GetRange(i, elementcount);

                object[] vals = oidrange.ToObjectArray();

                DataTable table = adapter.GetAttributeTable(dataset.Name, featureLayer.FeatureClass.OIDFieldName, vals);
                table.AddWKBColumn();

                foreach (DataRow row in table.Rows)
                {
                    int      oid     = Convert.ToInt32(row[featureLayer.FeatureClass.OIDFieldName]);
                    IFeature feature = featureLayer.FeatureClass.GetFeature(oid);

                    byte[] wkbgeometry = (byte[])factory.CreateWkbVariantFromGeometry(feature.ShapeCopy);

                    row["WKB"] = wkbgeometry;
                }

                Write(table, tableName, srid, featureLayer.FeatureClass);

                i += this.CommitInterval;
            }
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dbGeometry"></param>
        /// <returns></returns>
        public static IGeometry dbGeometryToGeometry(DbGeometry dbGeometry)
        {
            if (dbGeometry == null)
            {
                return(null);
            }
            byte[]           wkb     = dbGeometry.AsBinary();
            IGeometry        geomOut = new GeometryBag();
            IGeometryFactory gf      = new GeometryEnvironment() as IGeometryFactory;
            int readCount            = 0;

            gf.CreateGeometryFromWkbVariant(wkb, out geomOut, out readCount);
            return(geomOut);
        }
Exemple #8
0
        /// <summary>
        /// 将ArcGIS中的Geometry转换成wkb
        /// </summary>
        /// <param name="geometry">ArcGIS中的Geometry对象</param>
        /// <returns></returns>
        public static byte[] ConvertGeometryToWkb(IGeometry geometry)
        {
            var wkb = geometry as IWkb;
            ITopologicalOperator oper = geometry as ITopologicalOperator;

            if (oper != null)
            {
                oper.Simplify();
            }

            IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3;

            if (factory != null)
            {
                byte[] b = factory.CreateWkbVariantFromGeometry(geometry) as byte[];
                return(b);
            }
            return(null);
        }
 public void MoveTo(IPoint ipoint_4)
 {
     if ((this.ipoint_2 == null ? false : this.ipoint_1 != null))
     {
         if (this.iscreenDisplay_0 != null)
         {
             Graphics graphic = Graphics.FromHwnd(new IntPtr(this.iscreenDisplay_0.hWnd));
             IntPtr   hdc     = graphic.GetHdc();
             if (this.ipoint_0 != null)
             {
                 this.method_1(this.double_0, hdc.ToInt32());
             }
             IConstructAngle geometryEnvironmentClass = new GeometryEnvironment() as IConstructAngle;
             this.double_0 = geometryEnvironmentClass.ConstructThreePoint(this.ipoint_2, this.ipoint_1, ipoint_4);
             this.method_1(this.double_0, hdc.ToInt32());
             graphic.ReleaseHdc(hdc);
             graphic.Dispose();
         }
         this.ipoint_0 = ipoint_4;
     }
 }
        /// <summary>Convert a GeoJSON Line geometry to Arcgis Geometry </summary>
        /// <param name="JSpoint">The deserialised GeoJson Object</param>
        /// <param name="epsg">The EPSG-code of the spatial reference, -1 is unknown</param>
        /// <returns>A Arcgis PolyLine goemetry</returns>
        public static IPolyline geojson2esriLine(datacontract.geojsonLine JSline, int epsg = -1)
        {
            Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
            System.Object obj = Activator.CreateInstance(factoryType);
            ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;

            IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2;

            ESRI.ArcGIS.esriSystem.WKSPoint[] aWKSPointBuffer = new ESRI.ArcGIS.esriSystem.WKSPoint[ JSline.coordinates.Count ];
            for (int n = 0; n < JSline.coordinates.Count; n++)
            {
                double[] xy = JSline.coordinates[n].ToArray();
                aWKSPointBuffer[n].X = xy[0];
                aWKSPointBuffer[n].Y = xy[1];
            }

            IPolyline esriLine = new PolylineClass();
            pGeoBrg.SetWKSPoints(esriLine as IPointCollection4, aWKSPointBuffer);

            if (epsg != -1)
            {
                ISpatialReference srs = spatialReferenceFactory.CreateSpatialReference(epsg);
                esriLine.SpatialReference = srs;
            }

            return esriLine;
        }
Exemple #11
0
        public static IMultiPatch Cylinder(IPoint ipoint_0, double double_0, double double_1, double double_2, double double_3, double double_4, bool bool_0, bool bool_1)
        {
            double              num                = 36.0;
            object              value              = Missing.Value;
            double              num2               = (double_2 - double_1) / num;
            double              num3               = double_2 - double_1;
            IMultiPatch         multiPatch         = new MultiPatch() as IMultiPatch;
            IGeometryCollection geometryCollection = multiPatch as IGeometryCollection;
            IPointCollection    pointCollection    = new TriangleStrip();
            IVector3D           vector3D           = new Vector3D() as IVector3D;
            IEncode3DProperties encode3DProperties = new GeometryEnvironment() as IEncode3DProperties;

            for (double num4 = double_2; num4 <= double_1; num4 += -num2)
            {
                double num5 = Utils3D.DegreesToRadians(num4);
                vector3D.PolarSet(-num5, 0.0, double_0);
                IPoint point = new Point();
                point.X = ipoint_0.X + vector3D.XComponent;
                point.Y = ipoint_0.Y + vector3D.YComponent;
                point.Z = double_3;
                double num6 = (num4 - double_1) / num3;
                if (bool_0)
                {
                    num6 = 1.0 + num6 * -1.0;
                }
                if (num6 <= 0.0)
                {
                    num6 = 0.001;
                }
                else if (num6 >= 1.0)
                {
                    num6 = 0.999;
                }
                double textureT;
                if (bool_1)
                {
                    textureT = 0.0;
                }
                else
                {
                    textureT = 1.0;
                }
                double m = 0.0;
                encode3DProperties.PackTexture2D(num6, textureT, out m);
                point.M = m;
                pointCollection.AddPoint(point, ref value, ref value);
                IClone clone  = point as IClone;
                IPoint point2 = clone.Clone() as IPoint;
                point2.Z = double_4;
                if (bool_1)
                {
                    textureT = 1.0;
                }
                else
                {
                    textureT = 0.0;
                }
                m = 0.0;
                encode3DProperties.PackTexture2D(num6, textureT, out m);
                point2.M = m;
                pointCollection.AddPoint(point2, ref value, ref value);
            }
            IGeometry2 inGeometry = pointCollection as IGeometry2;

            geometryCollection.AddGeometry(inGeometry, ref value, ref value);
            IZAware iZAware = multiPatch as IZAware;

            iZAware.ZAware = true;
            IMAware iMAware = multiPatch as IMAware;

            iMAware.MAware = true;
            return(multiPatch);
        }
Exemple #12
0
        private static void CreateFeatures(List<GdbFromKmlFeature> gdbFeaturesFromKML)
        {
            License lic = new License();
            IWorkspaceEdit wse = null;
            try
            {
                bool ok = lic.GetLicenses();
                IFeatureWorkspace fws = (IFeatureWorkspace)GetWorkspace(); // cast this as an IWorkspace
                wse = (IWorkspaceEdit)fws;
                wse.StartEditing(false);
                wse.StartEditOperation();
                IFeatureClass waypointFC = fws.OpenFeatureClass("WAYPOINT");
                IFeatureClass trailFC = fws.OpenFeatureClass("TRAIL");
                ISpatialReference spatRef = ((IGeoDataset)waypointFC.FeatureDataset).SpatialReference;
                int counter = 0;
                foreach (GdbFromKmlFeature gdbFe in gdbFeaturesFromKML)
                {

                    if (gdbFe.IsPoint)
                    {
                        /*var newWayPoint = waypointFC.CreateFeature();
                        newWayPoint.set_Value(newWayPoint.Fields.FindField("NAME"), gdbFe.Name);
                        newWayPoint.set_Value(newWayPoint.Fields.FindField("SHORTDESCRIPTION"), gdbFe.Description);
                        newWayPoint.set_Value(newWayPoint.Fields.FindField("SUBTYPE"), 4);
                        double lat = Convert.ToDouble(gdbFe.Coordinates[0][1]);
                        double lon = Convert.ToDouble(gdbFe.Coordinates[0][0]);
                        double elev = Convert.ToDouble(gdbFe.Coordinates[0][2]);
                        newWayPoint.set_Value(newWayPoint.Fields.FindField("LATITUDE"), lat);
                        newWayPoint.set_Value(newWayPoint.Fields.FindField("LONGITUDE"), lon);
                        newWayPoint.set_Value(newWayPoint.Fields.FindField("ELEVATION"), elev);
                        ToWebMercator(ref lon, ref lat);
                        IPoint pnt = new PointClass();
                        pnt.PutCoords(lon, lat);
                        pnt.SpatialReference = spatRef;
                        newWayPoint.Shape = pnt;
                        newWayPoint.Store();*/
                    }
                    else
                    {
                        Console.WriteLine(counter);
                        var newTrail = trailFC.CreateFeature();
                        newTrail.set_Value(newTrail.Fields.FindField("SEGMENT"), gdbFe.Name);
                        //newTrail.set_Value(newTrail.Fields.FindField("SHORTDESCRIPTION"), gdbFe.Description);
                        newTrail.set_Value(newTrail.Fields.FindField("SUBTYPE"), 1);
                        //Define shape
                        IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2;
                        IPointCollection4 pPointColl = new PolylineClass();
                        ((IGeometry)pPointColl).SpatialReference = spatRef;
                        int vertexCount = gdbFe.Coordinates.Count;
                        WKSPoint[] aWKSPointBuffer = new WKSPoint[vertexCount];
                        int i = 0;
                        foreach(string[] vertex in gdbFe.Coordinates)
                        {
                            double lat = Convert.ToDouble(vertex[1]);
                            double lon = Convert.ToDouble(vertex[0]);
                            double elev = Convert.ToDouble(vertex[2]);
                            ToWebMercator(ref lon, ref lat);
                            aWKSPointBuffer[i] = new WKSPoint() { X = lon, Y = lat };
                            i++;
                        }
                        pGeoBrg.SetWKSPoints(pPointColl, ref aWKSPointBuffer);
                        newTrail.Shape = (IGeometry) pPointColl;
                        newTrail.Store();

                    }
                    counter++;
                    if (counter % 100 == 0)
                    {
                        wse.StopEditOperation();
                        wse.StopEditing(true);
                        wse.StartEditing(false);
                        wse.StartEditOperation();
                    }
                }

            }
            finally
            {
                wse.StopEditOperation();
                wse.StopEditing(true);
                lic.ReleaseLicenses();
            }
        }
Exemple #13
0
        public static IGroupElement CreateRoadSurfaceFromPolygon(IFeature ifeature_0, IFeature3DProperties ifeature3DProperties_0, clsTextureGroup clsTextureGroup_0, ISurface isurface_0, string string_0, IPolygon ipolygon_0, bool bool_0)
        {
            IGroupElement groupElement = null;
            IGroupElement result;

            try
            {
                IEncode3DProperties encode3DProperties = new GeometryEnvironment() as IEncode3DProperties;
                IGroupElement       groupElement2      = new GroupElement() as IGroupElement;
                if (modFacades.m_limitAngle == 0.0)
                {
                    modFacades.m_limitAngle = 0.5235987666666666;
                }
                IGeometry geometry = null;
                if (ifeature_0 != null)
                {
                    if (ifeature3DProperties_0 != null && bool_0)
                    {
                        ifeature3DProperties_0.ApplyFeatureProperties(ifeature_0, out geometry, false);
                        modFacades.g_bFeaturePropertiesApplied = true;
                    }
                    else
                    {
                        geometry = ifeature_0.Shape;
                        modFacades.g_bFeaturePropertiesApplied = false;
                    }
                }
                else if (ipolygon_0 != null)
                {
                    geometry = ipolygon_0;
                }
                if (geometry == null)
                {
                    result = groupElement;
                    return(result);
                }
                if (!(geometry is IMultiPatch))
                {
                }
                IEnvelope envelope = geometry.Envelope;
                double    num      = envelope.ZMin;
                if (modFacades.IsNaN(num))
                {
                    num = 0.0;
                }
                double        num2          = 0.0;
                I3DProperties i3DProperties = ifeature3DProperties_0 as I3DProperties;
                if (i3DProperties.OffsetExpressionString.Length > 0)
                {
                    num2 = Convert.ToDouble(i3DProperties.OffsetExpressionString);
                }
                if (geometry is IPolygon)
                {
                    num += num2;
                }
                IGeometryCollection geometryCollection = geometry as IGeometryCollection;
                int geometryCount = geometryCollection.GeometryCount;
                int num3;
                if (geometry is IMultiPatch)
                {
                    geometryCount = geometryCollection.GeometryCount;
                    num3          = geometryCollection.GeometryCount * 2 / 3;
                    modFacades.m_extrusionHeight = geometry.Envelope.ZMax - geometry.Envelope.ZMin;
                }
                else
                {
                    num3          = 0;
                    geometryCount = geometryCollection.GeometryCount;
                }
                if (modFacades.m_extrusionHeight >= 1.0)
                {
                }
                for (int i = num3; i <= geometryCount - 1; i++)
                {
                    IGeometry        geometry2    = geometryCollection.get_Geometry(i);
                    esriGeometryType geometryType = geometry2.GeometryType;
                    if (geometryType == esriGeometryType.esriGeometryRing || geometryType == esriGeometryType.esriGeometryPolyline)
                    {
                    }
                    IPointCollection pointCollection = geometry2 as IPointCollection;
                    int pointCount = pointCollection.PointCount;
                    if (pointCount >= 2)
                    {
                    }
                    IVector3D vector3D = new Vector3D() as IVector3D;
                    vector3D.XComponent = 0.0;
                    vector3D.YComponent = 0.0;
                    vector3D.ZComponent = 1.0;
                    double m = 0.0;
                    encode3DProperties.PackNormal(vector3D, out m);
                    IPointCollection pointCollection2 = new Ring();
                    object           value            = Missing.Value;
                    short            num4             = 0;
                    while ((int)num4 <= pointCount - 1)
                    {
                        IPoint point = pointCollection.get_Point((int)num4);
                        point.Z = num;
                        point.M = m;
                        IClone clone = point as IClone;
                        pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value);
                        num4 += 1;
                    }
                    IRing ring = pointCollection2 as IRing;
                    ring.Close();
                    IMultiPatch         multiPatch          = new MultiPatch() as IMultiPatch;
                    IGeometryCollection geometryCollection2 = multiPatch as IGeometryCollection;
                    IZAware             iZAware             = multiPatch as IZAware;
                    iZAware.ZAware = true;
                    IMAware iMAware = multiPatch as IMAware;
                    iMAware.MAware = true;
                    geometryCollection2.AddGeometry(pointCollection2 as IGeometry, ref value, ref value);
                    multiPatch.PutRingType(pointCollection2 as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing);
                    IElement element = modFacades.CreateElement(multiPatch, clsTextureGroup_0.RoofSymbol, string_0 + ";ROOFCOLOR=" + clsTextureGroup_0.RoofColorRGB.ToString());
                    if (element != null)
                    {
                        groupElement2.AddElement(element);
                    }
                }
                if (groupElement2 != null)
                {
                    IElementProperties elementProperties = groupElement2 as IElementProperties;
                    elementProperties.Name = string_0;
                }
                groupElement = groupElement2;
                result       = groupElement;
                return(result);
            }
            catch
            {
            }
            result = groupElement;
            return(result);
        }
Exemple #14
0
        public static IGroupElement CreateFacadesFromPolygon(IFeature ifeature_0, IFeature3DProperties ifeature3DProperties_0, clsTextureGroup clsTextureGroup_0, ISurface isurface_0, string string_0, IPolygon ipolygon_0, bool bool_0)
        {
            IGroupElement groupElement = null;
            IGroupElement result;

            try
            {
                IEncode3DProperties encode3DProperties = new GeometryEnvironment() as IEncode3DProperties;
                IGroupElement       groupElement2      = new GroupElement() as IGroupElement;
                if (modFacades.m_limitAngle == 0.0)
                {
                    modFacades.m_limitAngle = 0.5235987666666666;
                }
                IGeometry geometry = null;
                if (ifeature_0 != null)
                {
                    if (ifeature3DProperties_0 != null && bool_0)
                    {
                        ifeature3DProperties_0.ApplyFeatureProperties(ifeature_0, out geometry, false);
                    }
                    else
                    {
                        geometry = ifeature_0.Shape;
                    }
                }
                else if (ipolygon_0 != null)
                {
                    geometry = ipolygon_0;
                }
                if (geometry == null)
                {
                    result = null;
                    return(result);
                }
                if (!(geometry is IMultiPatch))
                {
                }
                IEnvelope         envelope         = geometry.Envelope;
                double            num              = envelope.ZMin;
                ISpatialReference spatialReference = BuildingProperty.Scene.SpatialReference;
                geometry.Project(spatialReference);
                string a = num.ToString();
                if (a.Equals("非数字"))
                {
                    num = 0.0;
                }
                double num2 = 0.0;
                if (ifeature3DProperties_0 != null)
                {
                    I3DProperties i3DProperties = ifeature3DProperties_0 as I3DProperties;
                    if (i3DProperties.OffsetExpressionString.Length > 0)
                    {
                        try
                        {
                            num2 = Convert.ToDouble(i3DProperties.OffsetExpressionString);
                        }
                        catch
                        {
                        }
                    }
                    if (geometry is IPolygon)
                    {
                        num += num2;
                    }
                }
                IGeometryCollection geometryCollection = geometry as IGeometryCollection;
                int geometryCount = geometryCollection.GeometryCount;
                int num3;
                if (geometry is IMultiPatch)
                {
                    geometryCount = geometryCollection.GeometryCount;
                    num3          = geometryCollection.GeometryCount * 2 / 3;
                    modFacades.m_extrusionHeight = geometry.Envelope.ZMax - geometry.Envelope.ZMin;
                }
                else
                {
                    num3          = 0;
                    geometryCount = geometryCollection.GeometryCount;
                }
                if (modFacades.m_extrusionHeight < 1.0)
                {
                    modFacades.m_extrusionHeight = 1.0;
                }
                IPoint point = null;
                double num4  = 0.0;
                double num5  = 0.0;
                double num6  = 0.0;
                object value = Missing.Value;
                for (int i = num3; i < geometryCount; i++)
                {
                    IGeometry        geometry2    = geometryCollection.get_Geometry(i);
                    esriGeometryType geometryType = geometry2.GeometryType;
                    if (geometryType == esriGeometryType.esriGeometryRing || geometryType == esriGeometryType.esriGeometryPolyline)
                    {
                        IPointCollection pointCollection = geometry2 as IPointCollection;
                        int pointCount = pointCollection.PointCount;
                        if (pointCount >= 2)
                        {
                            int                 num7 = 0;
                            int                 num8 = 1;
                            bool                flag = false;
                            IPointCollection    pointCollection2;
                            double              m;
                            IMultiPatch         multiPatch;
                            IGeometryCollection geometryCollection2;
                            IZAware             iZAware;
                            IMAware             iMAware;
                            IElement            element;
                            while (!flag)
                            {
                                bool flag2 = false;
                                while (num8 < pointCount && !flag2)
                                {
                                    if (num8 - num7 == 1)
                                    {
                                        IPoint point2 = pointCollection.get_Point(num7);
                                        point = pointCollection.get_Point(num8);
                                        num5  = point.X - point2.X;
                                        num6  = point.Y - point2.Y;
                                        num4  = Math.Sqrt(num5 * num5 + num6 * num6);
                                        if (isurface_0 != null)
                                        {
                                            num  = isurface_0.get_Z(point.X, point.Y);
                                            num += num2;
                                        }
                                    }
                                    else
                                    {
                                        IPoint point2 = point;
                                        double num9   = num5;
                                        double num10  = num6;
                                        point = pointCollection.get_Point(num8);
                                        if (isurface_0 != null)
                                        {
                                            num  = isurface_0.get_Z(point.X, point.Y);
                                            num += num2;
                                        }
                                        num5 = point.X - point2.X;
                                        num6 = point.Y - point2.Y;
                                        double num11 = Math.Sqrt(num9 * num9 + num10 * num10);
                                        double num12 = Math.Sqrt(num5 * num5 + num6 * num6);
                                        double num13 = (num9 * num5 + num10 * num6) / (num11 * num12);
                                        if (num13 < Math.Cos(modFacades.m_limitAngle))
                                        {
                                            flag2 = true;
                                            break;
                                        }
                                        num4 += num12;
                                    }
                                    num8++;
                                }
                                if (flag2)
                                {
                                    num8--;
                                }
                                else
                                {
                                    num8--;
                                }
                                pointCollection2 = new TriangleStrip();
                                double num14 = 0.0;
                                for (int j = num7; j <= num8; j++)
                                {
                                    if (j > 0)
                                    {
                                        IPoint point2 = point;
                                        point  = pointCollection.get_Point(j);
                                        num5   = point.X - point2.Y;
                                        num6   = point.Y - point2.Y;
                                        num14 += Math.Sqrt(num5 * num5 + num6 * num6);
                                    }
                                    else
                                    {
                                        point = pointCollection.get_Point(j);
                                    }
                                    point.Z = num;
                                    m       = 0.0;
                                    encode3DProperties.PackTexture2D(num14 / num4, 0.0, out m);
                                    point.M = m;
                                    IClone clone = point as IClone;
                                    pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value);
                                    point.Z = num + modFacades.m_extrusionHeight;
                                    m       = 0.0;
                                    encode3DProperties.PackTexture2D(num14 / num4, -1.0, out m);
                                    point.M = m;
                                    pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value);
                                }
                                multiPatch          = new MultiPatch() as IMultiPatch;
                                geometryCollection2 = (multiPatch as IGeometryCollection);
                                iZAware             = (multiPatch as IZAware);
                                iZAware.ZAware      = true;
                                iMAware             = (multiPatch as IMAware);
                                iMAware.MAware      = true;
                                geometryCollection2.AddGeometry(pointCollection2 as IGeometry, ref value, ref value);
                                if (clsTextureGroup_0 != null)
                                {
                                    int index = modFacades.FindTextureByAspect(clsTextureGroup_0, num4 / modFacades.m_extrusionHeight);
                                    element = modFacades.CreateElement(multiPatch, clsTextureGroup_0.Symbols[index], string_0);
                                }
                                else
                                {
                                    element = modFacades.CreateElement(multiPatch, null, string_0);
                                }
                                if (element != null)
                                {
                                    groupElement2.AddElement(element);
                                }
                                num7 = num8;
                                num8 = num7 + 1;
                                if (num7 >= pointCount - 1)
                                {
                                    flag = true;
                                }
                            }
                            IVector3D vector3D = new Vector3D() as IVector3D;
                            vector3D.XComponent = 0.0;
                            vector3D.YComponent = 0.0;
                            vector3D.ZComponent = 1.0;
                            m = 0.0;
                            encode3DProperties.PackNormal(vector3D, out m);
                            pointCollection2 = new Ring();
                            for (int j = 0; j <= pointCount - 1; j++)
                            {
                                IPoint point3 = pointCollection.get_Point(j);
                                point3.Z = num + modFacades.m_extrusionHeight;
                                point3.M = 0.0;
                                IClone clone = point3 as IClone;
                                pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value);
                            }
                            IRing ring = pointCollection2 as IRing;
                            ring.Close();
                            multiPatch          = new MultiPatch() as IMultiPatch;
                            geometryCollection2 = (multiPatch as IGeometryCollection);
                            iZAware             = (multiPatch as IZAware);
                            iZAware.ZAware      = true;
                            iMAware             = (multiPatch as IMAware);
                            iMAware.MAware      = true;
                            geometryCollection2.AddGeometry(pointCollection2 as IGeometry, ref value, ref value);
                            multiPatch.PutRingType(pointCollection2 as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing);
                            if (clsTextureGroup_0 != null)
                            {
                                element = modFacades.CreateElement(multiPatch, clsTextureGroup_0.RoofSymbol, string_0 + ";ROOFCOLOR=" + clsTextureGroup_0.RoofColorRGB.ToString());
                            }
                            else
                            {
                                element = modFacades.CreateElement(multiPatch, null, string_0 + ";ROOFCOLOR=1");
                            }
                            if (element != null)
                            {
                                groupElement2.AddElement(element);
                            }
                        }
                    }
                }
                if (groupElement2 != null)
                {
                    IElementProperties elementProperties = groupElement2 as IElementProperties;
                    elementProperties.Name = string_0;
                }
                groupElement = groupElement2;
                result       = groupElement;
                return(result);
            }
            catch
            {
            }
            result = groupElement;
            return(result);
        }
Exemple #15
0
        private bool CREATEPOLYGONFEATURE(string sClassName, string sPoints, string sVars)
        {
            IFeatureClass pFC;
            IFeatureWorkspace pFWKS;
            IFeature pFeat;
            IPolygon pPolygon;
            IPoint[] pPts;
            IMxDocument pMXDoc;
            IGeometryBridge2 pGeoBrg;
            IPointCollection4 pPointColl;
            string[,] sVar;

            try
            {
                SW1.Reset();
                SW1.Start();
                pMXDoc = GetDoc();
                pPts = GetPoints(sPoints, pMXDoc.FocusMap.SpatialReference);
                if (pPts != null)
                {
                    if (pPts.GetUpperBound(0) > 0)
                    {
                        sVar = GetVars(sVars);
                        pGeoBrg = new GeometryEnvironment() as IGeometryBridge2;
                        pPointColl = new PolygonClass();
                        pGeoBrg.AddPoints(pPointColl, pPts);
                        pFWKS = (IFeatureWorkspace)Workspace;
                        pFC = pFWKS.OpenFeatureClass(sClassName);
                        if (pFC != null)
                        {
                            if (pEditor != null)
                            {
                                pEditor.StartOperation();
                                pFeat = pFC.CreateFeature();
                                pPolygon = (IPolygon)pPointColl;
                                pFeat.Shape = (IGeometry)pPolygon;
                                SetFields(pFeat, sVar);
                                pFeat.Store();
                                Logger.WriteLine("OID:" + pFeat.OID);
                                pEditor.StopOperation("Create Polygon");
                            }
                            else
                            {
                                Logger.WriteLine("Editor not found");
                            }
                        }
                        SW1.Stop();
                        RecordActionTime("CreatePOYGONFeature: " ,SW1.ElapsedMilliseconds);
                        return true;
                    }
                    else
                    {
                        Logger.WriteLine("Missing Geometry");
                        return false;
                    }
                }
                else
                {
                    Logger.WriteLine("Null Geometry");
                    return false;
                }
            }
            catch (COMException ComEX)
            {
                Logger.WriteLine("Error in CreatePOLYGONFeature: " + ComEX.ErrorCode + " :" + ComEX.Message + ":" + ComEX.StackTrace);
                return false;
            }
            catch (Exception EX)
            {
                Logger.WriteLine("Error in CreatePOLYGONFeature: " + EX.Message + ":" + EX.StackTrace);
                return false;
            }
        }
Exemple #16
0
        public void Export(string spatialiteDatabasePath, int srid, ILayer layer)
        {
            try
            {
                this.DatabasePath = spatialiteDatabasePath;

                if (srid > 0)
                {
                    IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3;

                    IFeatureLayer featureLayer = (IFeatureLayer)layer;

                    IDataset dataset = (IDataset)featureLayer.FeatureClass;

                    GeoDataTableAdapter.GeoAdapter adapter = new GeoDataTableAdapter.GeoAdapter(dataset.Workspace);

                    DataTable table        = null;
                    ITable    featureTable = (ITable)featureLayer.FeatureClass;

                    if (this.Extent != null)
                    {
                        ISpatialFilter filter = new SpatialFilterClass();
                        filter.Geometry   = this.Extent;
                        filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                        filter.SubFields = featureLayer.FeatureClass.OIDFieldName;

                        IFeatureCursor cursor = featureLayer.FeatureClass.Search(filter, true);

                        IFeature feature = null;
                        object[] vals    = new object[featureLayer.FeatureClass.FeatureCount(filter)];

                        int w = 0;

                        while ((feature = cursor.NextFeature()) != null)
                        {
                            vals[w++] = feature.OID;
                        }

                        table = adapter.GetAttributeTable(dataset.Name, featureLayer.FeatureClass.OIDFieldName, vals);
                    }
                    else
                    {
                        // no events for the adapter, so just 1 step for now.
                        // TODO: update GeoDataTableAdapter w/ events.
                        this.OnAttributeReadProgress(0, 1);
                        table = adapter.GetAttributeTable(featureTable, dataset.Name.Replace('.', '_'));
                        this.OnAttributeReadProgress(1, 1);
                    }

                    DataColumn wkbcolumn = new DataColumn("WKB", typeof(byte[]));
                    table.Columns.Add(wkbcolumn);

                    int totalRows = table.Rows.Count;
                    int i         = 0;
                    this.OnGeometryReadProgress(i, totalRows);

                    foreach (DataRow row in table.Rows)
                    {
                        this.OnGeometryReadProgress(++i, totalRows);

                        int oid = Convert.ToInt32(row[featureLayer.FeatureClass.OIDFieldName]);

                        IFeature feature = featureLayer.FeatureClass.GetFeature(oid);

                        byte[] wkbgeometry = (byte[])factory.CreateWkbVariantFromGeometry(feature.ShapeCopy);

                        row["WKB"] = wkbgeometry;
                    }

                    WriteTable(this.SpatialiteDatabase, srid, table, featureLayer.FeatureClass);
                }
                else
                {
                }

                // this.SpatialiteDatabase.Close();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
                throw;
            }
        }
Exemple #17
0
        /// <summary>
        /// 删除几何形状指定的顶点。
        /// 顶点的会与几何形状的顶点进行IPoint::Compare比较,
        /// 因此顶点必须是通过几何形状的顶点获取,才能成功删除。
        /// 如果删除的结果导致几何形状为空,则几何形状接口不为空,只是setEmpty。
        /// </summary>
        /// <param name="geometry">需要删除顶点的ESRI几何形状接口</param>
        /// <param name="point">指定要删除的顶点ESRI点接口</param>
        /// <returns>是否成功删除</returns>
        public static bool GeometryRemoveVertex(IGeometry geometry, IPoint point)
        {
            bool deleted = false;

            if (IsValidGeometry(geometry) && IsValidGeometry(point))
            {
                switch (geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryPoint:

                    #region 点几何形状

                    if (geometry is IPoint)
                    {
                        if ((geometry as IPoint).Compare(point) == 0)
                        {
                            geometry.SetEmpty();
                            deleted = true;
                        }
                    }

                    #endregion

                    break;

                case esriGeometryType.esriGeometryMultipoint:

                    #region 多点几何形状

                    if (geometry is IPointCollection)
                    {
                        for (int i = 0; i <= (geometry as IPointCollection).PointCount - 1; i++)
                        {
                            if ((geometry as IPointCollection).get_Point(i).Compare(point) == 0)
                            {
                                (geometry as IPointCollection).RemovePoints(i, 1);
                                deleted = true;
                                break;
                            }
                        }
                    }

                    #endregion

                    break;

                case esriGeometryType.esriGeometryPolyline:

                    #region 多义线几何形状

                    if (geometry is IPointCollection)
                    {
                        for (int i = 0; i <= (geometry as IPointCollection).PointCount - 1; i++)
                        {
                            if ((geometry as IPointCollection).get_Point(i).Compare(point) == 0)
                            {
                                (geometry as IPointCollection).RemovePoints(i, 1);
                                deleted = true;
                                break;
                            }
                        }
                    }

                    #endregion

                    break;

                case esriGeometryType.esriGeometryPolygon:

                    #region 面几何形状

                    if (geometry is IGeometryCollection)
                    {
                        bool removed = false;
                        for (int i = 0; i <= (geometry as IGeometryCollection).GeometryCount - 1; i++)
                        {
                            IGeometry partGeom = (geometry as IGeometryCollection).get_Geometry(i);
                            if (IsValidGeometry(partGeom) && partGeom is IRing && partGeom is IPointCollection)
                            {
                                if ((partGeom as IRing).IsClosed)
                                {
                                    #region 闭合的环(在编辑草图中存在)

                                    if ((partGeom as IRing).FromPoint.Compare(point) == 0 ||
                                        (partGeom as IRing).ToPoint.Compare(point) == 0)
                                    {
                                        if ((partGeom as IPointCollection).PointCount <= 2)
                                        {
                                            partGeom = null;
                                            removed  = true;
                                        }
                                        else
                                        {
                                            IPoint startPoint = (partGeom as IPointCollection).get_Point(1);
                                            (partGeom as IPointCollection).RemovePoints(
                                                (partGeom as IPointCollection).PointCount - 1, 1);
                                            (partGeom as IPointCollection).RemovePoints(0, 1);
                                            //(partGeom as IRing).FromPoint = startPoint;
                                            (partGeom as IRing).Close();
                                            removed = true;
                                        }
                                    }
                                    else
                                    {
                                        for (int j = 0; j <= (partGeom as IPointCollection).PointCount - 1; j++)
                                        {
                                            if ((partGeom as IPointCollection).get_Point(j).Compare(point) == 0)
                                            {
                                                (partGeom as IPointCollection).RemovePoints(j, 1);
                                                removed = true;
                                                break;
                                            }
                                        }
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region 非闭合的环(在编辑草图中应该不存在)

                                    for (int j = 0; j <= (partGeom as IPointCollection).PointCount - 1; j++)
                                    {
                                        if ((partGeom as IPointCollection).get_Point(j).Compare(point) == 0)
                                        {
                                            (partGeom as IPointCollection).RemovePoints(j, 1);
                                            removed = true;
                                            break;
                                        }
                                    }

                                    #endregion
                                }
                            }
                            if (removed)
                            {
                                (geometry as IGeometryCollection).RemoveGeometries(i, 1);
                                if (IsValidGeometry(partGeom))
                                {
                                    IGeometryCollection geometryCollection = new Multipoint() as IGeometryCollection;
                                    IGeometryBridge     geometryBridge     = new GeometryEnvironment() as IGeometryBridge;
                                    IGeometry[]         geometryArray      = { partGeom };
                                    geometryBridge.InsertGeometries((IGeometryCollection)geometry, i,
                                                                    ref geometryArray);
                                }
                                deleted = true;
                                break;
                            }
                        }
                    }

                    #endregion

                    break;

                default:
                    break;
                }
            }
            return(deleted);
        }
        /// <summary>Convert a GeoJSON Polygon geometry to Arcgis Geometry </summary>
        /// <param name="JSpoint">The deserialised GeoJson Object</param>
        /// <param name="epsg">The EPSG-code of the spatial reference, -1 is unknown</param>
        /// <returns>A Arcgis Polygon goemetry</returns>
        public static IPolygon geojson2esriPolygon(datacontract.geojsonPolygon JSPolygon, int epsg = -1)
        {
            Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
            System.Object obj = Activator.CreateInstance(factoryType);
            ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;

            IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2;

            IGeometryCollection esriGeometryCol = new PolygonClass();

            for (int n = 0; n < JSPolygon.coordinates.Count; n++)
            {
                List<List<double>> JSring = JSPolygon.coordinates[n];
                IPointCollection4 ring = new RingClass();
                ESRI.ArcGIS.esriSystem.WKSPoint[] aWKSPointBuffer = new ESRI.ArcGIS.esriSystem.WKSPoint[JSring.Count];
                for (int i = 0; i < JSring.Count; i++)
                {
                    double[] xy = JSring[i].ToArray();
                    aWKSPointBuffer[i].X = xy[0];
                    aWKSPointBuffer[i].Y = xy[1];
                }
                pGeoBrg.SetWKSPoints(ring , aWKSPointBuffer);
                esriGeometryCol.AddGeometry(ring as IGeometry, Type.Missing, Type.Missing);
            }

            IPolygon esriPolygon = esriGeometryCol as IPolygon;

            if (epsg != -1)
            {
                ISpatialReference srs = spatialReferenceFactory.CreateSpatialReference(epsg);
                esriPolygon.SpatialReference = srs;
            }
            return esriPolygon;
        }
Exemple #19
0
        private void LoadFeatureclass(IFeatureClass featureclass)
        {
            try
            {
                SpatialLiteDB db = new SpatialLiteDB(this.DatabasePath);
                db.Open();

                string sql = "SELECT AsBinary(" + Table.GeometryColumnName + ") as wkb,* FROM " + this.TableName;

                using (SQLiteCommand command = new SQLiteCommand(sql, db.SQLiteDatabaseConn))
                {
                    using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(command))
                    {
                        System.Data.DataTable table = new System.Data.DataTable();
                        adapter.Fill(table);

                        IFeatureCursor cursor = featureclass.Insert(true);

                        foreach (DataRow row in table.Rows)
                        {
                            IFeatureBuffer feature = featureclass.CreateFeatureBuffer();

                            for (int i = 0; i < feature.Fields.FieldCount; i++)
                            {
                                IField field = feature.Fields.get_Field(i);
                                Debug.WriteLine("FieldName=" + field.Name);
                                if (field.Type != esriFieldType.esriFieldTypeGeometry
                                    & !field.Name.Equals("wkb", StringComparison.CurrentCultureIgnoreCase)
                                    & !field.Name.Equals("name", StringComparison.CurrentCultureIgnoreCase)
                                    & !field.Name.Equals(featureclass.OIDFieldName, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    try
                                    {
                                        Debug.WriteLine("Spatialite Field Value: " + row[field.Name].ToString());
                                        feature.set_Value(i, row[field.Name]);
                                    }
                                    catch (Exception ex)
                                    {
                                        Trace.WriteLine(ex.StackTrace);
                                    }
                                }
                                else if (field.Type == esriFieldType.esriFieldTypeGeometry)
                                {
                                    byte[]    wkb = (byte[])row["wkb"];
                                    int       bytesRead;
                                    object    missing = Type.Missing;
                                    IGeometry outGeometry;


                                    object byteArrayObject = row["wkb"];

                                    IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3;

                                    factory.CreateGeometryFromWkbVariant(byteArrayObject, out outGeometry, out bytesRead);

                                    if (outGeometry != null)
                                    {
                                        try
                                        {
                                            feature.Shape = outGeometry;
                                        }
                                        catch (Exception ex)
                                        {
                                            Trace.WriteLine(ex.StackTrace);
                                        }
                                    }
                                }
                            }

                            cursor.InsertFeature(feature);
                        }
                    }
                }
                db.Close();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.StackTrace);
                throw;
            }
        }