zoukankan      html  css  js  c++  java
  • ArcGIS Engine 几何对象和WKB的转换

    using System;
    using System.Collections.Generic;
    using System.Text;
    using GisSharpBlog.NetTopologySuite.IO;
    using ESRI.ArcGIS.Geometry;
    
    namespace Utils
    {
        /// <summary>
        /// This class is used to convert a GeoAPI Geometry to ESRI and vice-versa.
        /// It can also convert a ESRI Geometry to WKB/WKT and vice-versa.
        /// </summary>
        public static class Converters
        {
    
            public 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 static byte[] ConvertWKTToWKB(string wkt)
            {
                WKBWriter writer = new WKBWriter();
                WKTReader reader = new WKTReader();
                return writer.Write(reader.Read(wkt));
            }
    
            public static string ConvertWKBToWKT(byte[] wkb)
            {
                WKTWriter writer = new WKTWriter();
                WKBReader reader = new WKBReader();
                return writer.Write(reader.Read(wkb));
            }
    
            public static string ConvertGeometryToWKT(IGeometry geometry)
            {
                byte[] b = ConvertGeometryToWKB(geometry);
                WKBReader reader = new WKBReader();
                GeoAPI.Geometries.IGeometry g = reader.Read(b);
                WKTWriter writer = new WKTWriter();
                return writer.Write(g);
            }
    
            public static IGeometry ConvertWKTToGeometry(string wkt)
            {
                byte[] wkb = ConvertWKTToWKB(wkt);
                return ConvertWKBToGeometry(wkb);
            }
    
            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;
            }
    
    
            public static IGeometry ConvertGeoAPIToESRI(GeoAPI.Geometries.IGeometry geometry)
            {
                WKBWriter writer = new WKBWriter();
                byte[] bytes = writer.Write(geometry);
                return ConvertWKBToGeometry(bytes);
            }
    
            public static GeoAPI.Geometries.IGeometry ConvertESRIToGeoAPI(IGeometry geometry)
            {
                byte[] wkb = ConvertGeometryToWKB(geometry);
                WKBReader reader = new WKBReader();
                return reader.Read(wkb);
            }
        }
    }
  • 相关阅读:
    数据库创建索引后如何查看是否生效
    两种动态代理的区别
    zuul请求过滤
    intellij idea 中 Job Debug特别缓慢问题
    vue路由注册及创建
    vue.config.js配置文件
    TypeScript配置文件
    如何发布自己的npm安装包
    npm常见命令
    通过foreach的方式批量插入
  • 原文地址:https://www.cnblogs.com/zuiyirenjian/p/3410141.html
Copyright © 2011-2022 走看看