• ArcGIS 基于AO 实现的经纬度定位


    原文地址:http://www.cnblogs.com/binlee/archive/2011/04/28/2032160.html

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using System.Web;
    using ESRI.ArcGIS.Geometry;
    using ESRI.ArcGIS.Carto;
    using ESRI.ArcGIS.Geodatabase;
    using ESRI.ArcGIS.DataSourcesGDB;
    using ESRI.ArcGIS.DataSourcesFile;
    using System.IO;
    using ESRI.ArcGIS.Server;

    // 注意: 如果更改此处的类名“Service”,也必须更新 Web.config 和关联的 .svc 文件中对“Service”的引用。
    public class AddressReverse: IAddressReverse
    {   
      IPoint pPoint;
        public string AddressRevServer(double iLongtitude, double iLatitude)
        {
            //ArcGis Server的身份验证,服务是需要验证的
            ESRI.ArcGIS.ADF.Identity identity = new ESRI.ArcGIS.ADF.Identity("ArcGISWebServices""1""sse12a2db84c65");
            ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection gisServerConnection;
            gisServerConnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection("sse12a2db84c65", identity);
            gisServerConnection.Connect();
            IServerObjectManager4 serverObjectManager = (IServerObjectManager4)gisServerConnection.ServerObjectManager;
            IServerContext serverContext = serverObjectManager.CreateServerContext("""");//创建一个空的服务器上下文
            string result = string.Empty;//保存最终的地址

                    IFeatureWorkspace pFeatureWorkspace;
                    IFeatureLayer pFeatureLayer;
                    IFeatureClass cityfeatureClass;
                    IFeatureClass xiangfeatureClass;
                    IFeatureClass cunfeatureClass;
       
                    string cityfilePath = @"E:\fjWGS1984"//数据目录
                    string cityfileName = @"city_Project.shp"//市图层
                    string xiangfilename = @"xiang_region_town_Project.shp";//乡镇图层
                    string cunfilename = @"xiang_region_county_Project.shp";//村图层

                    IWorkspaceFactory factory = (IWorkspaceFactory)serverContext.CreateObject("esriDataSourcesFile.ShapefileWorkspaceFactory");

                    //创建point,服务里面涉及到com组件的不能用new,只能用CreateObject
                    pPoint = serverContext.CreateObject("esriGeometry.Point"as IPoint;
                    //给point赋经纬度值
                    pPoint.PutCoords(iLongtitude, iLatitude);
          //打开工作空间
                    pFeatureWorkspace = (IFeatureWorkspace)factory.OpenFromFile(cityfilePath, 0);
                    pFeatureLayer = new FeatureLayerClass();
                    pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(cityfileName);
                    pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
                    cityfeatureClass = pFeatureWorkspace.OpenFeatureClass(cityfileName);
          //创建spatialFilter,用于空间查询
                    ISpatialFilter spatialFilter = serverContext.CreateObject("esriGeoDatabase.SpatialFilter"as ESRI.ArcGIS.Geodatabase.SpatialFilter;
                    spatialFilter.Geometry = pPoint;
                    spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;// 空间关系是相交
                    spatialFilter.GeometryField = cityfeatureClass.ShapeFieldName;
                    
                    //获取与点相交的市图层中的feature
                    IFeatureCursor featureCursor = cityfeatureClass.Search(spatialFilter, false);
                    IFeature resultFeature = featureCursor.NextFeature();
                    if (resultFeature != null)
                    {
                        result+=resultFeature.get_Value(resultFeature.Fields.FindField("SNAME")).ToString();//获取城市名称
                    }


               //获取县名称
                    pFeatureWorkspace = (IFeatureWorkspace)factory.OpenFromFile(cityfilePath, 0);
                    pFeatureLayer = new FeatureLayerClass();
                    pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(cunfilename);
                    pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
                    cunfeatureClass = pFeatureWorkspace.OpenFeatureClass(cunfilename);

                    IFeatureCursor featureCursorcun = cunfeatureClass.Search(spatialFilter, false);
                    IFeature resultFeaturecun = featureCursorcun.NextFeature();
                    if (resultFeaturecun != null)
                    {
                        result += resultFeaturecun.get_Value(resultFeaturecun.Fields.FindField("XNAME")).ToString();
                    }

                    //获取乡镇名称
                    pFeatureWorkspace = (IFeatureWorkspace)factory.OpenFromFile(cityfilePath, 0);
                    pFeatureLayer = new FeatureLayerClass();
                    pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(xiangfilename);
                    pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
                    xiangfeatureClass = pFeatureWorkspace.OpenFeatureClass(xiangfilename);

                    IFeatureCursor featureCursortown = xiangfeatureClass.Search(spatialFilter, false);
                    IFeature resultFeaturetown = featureCursortown.NextFeature();
                    if (resultFeaturetown != null)
                    {
                        result += resultFeaturetown.get_Value(resultFeaturetown.Fields.FindField("ZNAME")).ToString();
                    }

                    return result;
        }

  • 相关阅读:
    《Java并发编程的艺术》 第9章 Java中的线程池
    《Java并发编程的艺术》第6/7/8章 Java并发容器与框架/13个原子操作/并发工具类
    java锁总结
    《Java并发编程的艺术》第5章 Java中的锁 ——学习笔记
    《Java并发编程的艺术》第4章 Java并发编程基础 ——学习笔记
    Java并发编程的艺术(一、二章) ——学习笔记
    redis缓存使用SpringDataRedis
    商城06——solr索引库搭建&solr搜索功能实现&图片显示问题解决
    商城05——首页轮播图显示实现&Redis环境搭建&Redis实现缓存
    商城04——门户网站介绍&商城首页搭建&内容系统创建&CMS实现
  • 原文地址:https://www.cnblogs.com/merray/p/2534614.html
Copyright © 2020-2023  润新知