コード例 #1
0
        public void QueryShape(IGeometry pGeometry)
        {
            if (pGeometry == null)
            {
                return;
            }

            try
            {
                OSGeo.OGR.Geometry ogrGeometry = m_currentOGRFeature.GetGeometryRef();

                //export geometry from OGR to WKB
                int    wkbSize   = ogrGeometry.WkbSize();
                byte[] wkbBuffer = new byte[wkbSize];
                ogrGeometry.ExportToWkb(wkbBuffer);

                //import geometry from WKB to ESRI Shape
                IWkb pWKB = pGeometry as IWkb;
                pWKB.ImportFromWkb(wkbSize, ref wkbBuffer[0]);

                pGeometry.SpatialReference = m_pDataset.SpatialReference;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(" Error: " + ex.Message);
                pGeometry.SetEmpty();
            }
        }
コード例 #2
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);
        }
コード例 #3
0
        /// <summary>
        /// IFeature转换为DbGeometry
        /// </summary>
        /// <param name="feature"></param>
        /// <returns></returns>
        public static DbGeometry featureToDbGeometry(IFeature feature)
        {
            IWkb wkb = (IWkb)feature.Shape;

            byte[] wkb_bytes  = new byte[wkb.WkbSize];
            int    byte_count = wkb.WkbSize;

            wkb.ExportToWkb(ref byte_count, out wkb_bytes[0]);
            DbGeometry result = DbGeometry.FromBinary(wkb_bytes, SRID);

            return(result);
        }
コード例 #4
0
        private static string GetHexWkb(IGeometry geom)
        {
            string retval = "";

            try
            {
                IWkb   wkb       = geom as IWkb;
                int    byteCount = wkb.WkbSize;
                byte[] wkbBytes  = new byte[byteCount];
                wkb.ExportToWkb(ref byteCount, out wkbBytes[0]);
                retval = ByteArrayToString(wkbBytes, byteCount);
            }
            catch { }
            return(retval);
        }
コード例 #5
0
        public void QueryShape(IGeometry pGeometry)
        {
            if (pGeometry == null)
            {
                return;
            }

            try
            {
                OSGeo.OGR.Geometry ogrGeometry = m_currentOGRFeature.GetGeometryRef();

                // Flatten the geometry and ommit Z value until we add manual
                // Z-value zupport
                // See:
                // https://github.com/RBURHUM/arcgis-ogr/issues/11
                //
                //
                ogrGeometry.FlattenTo2D();

                //export geometry from OGR to WKB
                int    wkbSize   = ogrGeometry.WkbSize();
                byte[] wkbBuffer = new byte[wkbSize];
                ogrGeometry.ExportToWkb(wkbBuffer);

                //import geometry from WKB to ESRI Shape
                IWkb pWKB = pGeometry as IWkb;
                pWKB.ImportFromWkb(wkbSize, ref wkbBuffer[0]);

                pGeometry.SpatialReference = m_pDataset.SpatialReference;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(" Error: " + ex.Message);
                pGeometry.SetEmpty();
            }
        }