Пример #1
0
        /// <summary>
        /// 创建Dataset
        /// </summary>
        /// <param name="wsTarget"></param>
        /// <param name="pSpatialRef"></param>
        /// <returns></returns>
        protected virtual IFeatureDataset CreateFeatureDataset(IWorkspace wsTarget, ISpatialReference pSpatialRef)
        {
            if (wsTarget == null)
            {
                return(null);
            }
            try
            {
                if (pSpatialRef == null)
                {
                    pSpatialRef = new UnknownCoordinateSystemClass();

                    ISpatialReferenceTolerance pSpatialTolerance = pSpatialRef as ISpatialReferenceTolerance;
                    double dXYTolerance = pSpatialTolerance.XYTolerance;
                    double dZTolerance  = pSpatialTolerance.ZTolerance;
                    ISpatialReferenceResolution pSpatialRefResolution = pSpatialRef as ISpatialReferenceResolution;

                    pSpatialRefResolution.set_XYResolution(true, dXYTolerance * 0.1);
                    pSpatialRefResolution.set_ZResolution(true, dZTolerance * 0.1);
                    pSpatialRefResolution.MResolution = pSpatialTolerance.MTolerance * 0.1;
                }

                return(((IFeatureWorkspace)wsTarget).CreateFeatureDataset(COMMONCONST.Dataset_Name, pSpatialRef));
            }
            catch (Exception ex)
            {
                SendMessage(enumMessageType.Exception, string.Format("创建Dataset时出错,信息:{0}", ex.Message));

                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// 根据某一图层的范围,创建mdb文件中的featuredataset及其空间范围
        /// </summary>
        /// <param name="motherWs">要创建featuredataset的工作空间</param>
        /// <param name="pGeoDataset">featuredataset所要依据的空间参考和空间范围</param>
        /// 这个函数要改!!
        public static void CreateDatasetInWs(IWorkspace motherWs, IGeoDataset pGeoDataset, string datasetName)
        {
            try
            {
                ISpatialReference pSpatialRef = null;
                IFeatureDataset   pFtDs       = null;


                if (pGeoDataset != null)
                {
                    pSpatialRef = pGeoDataset.SpatialReference;

                    IControlPrecision2 controlPrecision2 = pSpatialRef as IControlPrecision2;
                    if (!controlPrecision2.IsHighPrecision)
                    {
                        controlPrecision2.IsHighPrecision = true;
                    }

                    IEnvelope pEnv = pGeoDataset.Extent;
                    pEnv.Expand(1.5, 1.5, true);
                    pSpatialRef.SetDomain(pEnv.XMin, pEnv.XMax, pEnv.YMin, pEnv.YMax);

                    ISpatialReferenceTolerance pSpatialTolerance = (ISpatialReferenceTolerance)pSpatialRef;
                    double dXYTolerance = pSpatialTolerance.XYTolerance;
                    double dZTolerance  = pSpatialTolerance.ZTolerance;
                    ISpatialReferenceResolution pSpatialRefResolution = (ISpatialReferenceResolution)pSpatialRef;
                    pSpatialRefResolution.set_XYResolution(true, dXYTolerance * 0.1);
                    pSpatialRefResolution.set_ZResolution(true, dZTolerance * 0.1);
                    pSpatialRefResolution.MResolution = pSpatialTolerance.MTolerance * 0.1;

                    pFtDs = ((IFeatureWorkspace)motherWs).CreateFeatureDataset(datasetName, pSpatialRef);
                }
                else
                {
                    pSpatialRef = new UnknownCoordinateSystemClass();

                    ISpatialReferenceTolerance pSpatialTolerance = (ISpatialReferenceTolerance)pSpatialRef;
                    double dXYTolerance = pSpatialTolerance.XYTolerance;
                    double dZTolerance  = pSpatialTolerance.ZTolerance;
                    ISpatialReferenceResolution pSpatialRefResolution = (ISpatialReferenceResolution)pSpatialRef;
                    pSpatialRefResolution.set_XYResolution(true, dXYTolerance * 0.1);
                    pSpatialRefResolution.set_ZResolution(true, dZTolerance * 0.1);
                    pSpatialRefResolution.MResolution = pSpatialTolerance.MTolerance * 0.1;

                    pFtDs = ((IFeatureWorkspace)motherWs).CreateFeatureDataset(datasetName, pSpatialRef);
                }
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());
            }
        }
Пример #3
0
        /// <summary>
        /// 创建空间参考
        /// </summary>
        /// <param name="headNode">VCT头节点</param>
        private ISpatialReference CreateProjection(HeadNode headNode)
        {
            try
            {
                string sPrjInfo = "";
                //根据投影参数中的长半轴值,来判断是什么坐标系统(北京54,西安80,WGS-84,其他地方坐标系)
                //北京54
                double dMajorAxis = headNode.MajorMax.Y;

                //读取参考椭球的名称 (名称,长半轴,扁率的倒数)
                string sProjection = headNode.Spheroid.Split(',')[0];
                dMajorAxis = Math.Abs(dMajorAxis - 6378245);
                //if (fabs( m_dSemiMajorAxis - 6378245) < 0.0001)
                if (dMajorAxis < 0.0001)
                {
                    sPrjInfo = string.Format("PROJCS[\"{0}\",GEOGCS[\"GCS_Beijing_1954\",DATUM[\"D_Beijing_1954\""
                        + ",SPHEROID[\"{1}\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],"
                    + "PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",{2}],PARAMETER[\"False_Northing\",0.0],"
                    + "PARAMETER[\"Central_Meridian\",{3}],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],"
                    + "UNIT[\"Meter\",1.0]]", sProjection, "Gauss-Krueger", headNode.Excursion, headNode.Parametetor.OriginLongtitude);

                }
                //西安80
                else
                {
                    // sPrjInfo = string.Format("PROJCS["%s\",GEOGCS[\"GCS_Xian_1980\",DATUM[\"D_Xian_1980\",SPHEROID[\"%s\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",%s],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",%f],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]", m_strProjection, m_strSpheroid, sPianYi, m_lMeridian);
                    sPrjInfo = string.Format("PROJCS[\"{0}\",GEOGCS[\"GCS_Xian_1980\",DATUM[\"D_Xian_1980\","
                    + "SPHEROID[\"{1}\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],"
                    + "PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",{2}],PARAMETER[\"False_Northing\",0.0],"
                    + "PARAMETER[\"Central_Meridian\",{3}],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],"
                    + "UNIT[\"Meter\",1.0]]", sProjection, "Gauss-Krueger", headNode.Parametetor.EastOffset, headNode.Parametetor.OriginLongtitude);
                }
                //将坐标信息写入到Prj文件
                string sPrjFilename = Application.StartupPath + "tempPrj.prj";
                FileStream fs = File.Create(sPrjFilename);
                StreamWriter sw = new StreamWriter(fs);
                sw.Write(sPrjInfo);
                sw.Close();
                fs.Close();

                //根据Prj文件生成空间参考
                ISpatialReferenceFactory ipSpatialFactory = new SpatialReferenceEnvironmentClass();
                ISpatialReference pSpatialReference = ipSpatialFactory.CreateESRISpatialReferenceFromPRJFile(sPrjFilename);
                pSpatialReference.SetDomain(headNode.MajorMin.X,headNode.MajorMax.X,headNode.MajorMin.Y,headNode.MajorMax.Y);//
                //设置精度,防止cut失败
                //设置六位小数精度。以保证导出时也是六位
                ISpatialReferenceTolerance ipSrTolerance = pSpatialReference as ISpatialReferenceTolerance;

                ipSrTolerance.XYTolerance = 0.000001;
                ipSrTolerance.MTolerance = 0.001;
                ipSrTolerance.ZTolerance = 0.001;

                ISpatialReferenceResolution ipSrResolution = pSpatialReference as ISpatialReferenceResolution;
                ipSrResolution.MResolution = 0.001;
                ipSrResolution.set_XYResolution(true, 0.000001);
                ipSrResolution.set_ZResolution(true, 0.001);

                //删除生成的Prj文件
                File.Delete(sPrjFilename);


                //ISpatialReference pSpatialReference;
                //ISpatialReferenceFactory pSpatialreferenceFactory;
                //pSpatialreferenceFactory = new SpatialReferenceEnvironmentClass();
                //IGeographicCoordinateSystem pGeographicCoordinateSystem;
                //pGeographicCoordinateSystem = pSpatialreferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCS3Type.esriSRGeoCS_Xian1980);
                //pSpatialReference = pGeographicCoordinateSystem as ISpatialReference;
                //pSpatialReference.SetFalseOriginAndUnits(-180, -90, 1000000);//

                return pSpatialReference;
            }
            catch (Exception ex)
            {
                LogAPI.WriteLog("创建空间参考失败,系统默认创建空的空间参考!\r\n");
                LogAPI.WriteErrorLog(ex);
                ISpatialReference pSpatialReference = new UnknownCoordinateSystemClass();
                pSpatialReference.SetDomain(headNode.MajorMin.X, headNode.MajorMax.X, headNode.MajorMin.Y, headNode.MajorMax.Y);//
                return pSpatialReference;
            }
        }