本帖最后由 记忆碎片 于 2012-8-28 16:13 编辑
沉寂了一阵子,工作实在太忙。抱歉
最近研究,meteoInfo确实很强大。分享进步共同学习如下
希望实现功能:用户输入经纬度,判断经纬度所在省市区。
效果图如下:
代码如下
- public class AdjustLocationClass
- {
- public static Location AdjustLocation(double longitude, double latitude)
- {
- Location location=new Location();
- string aFile = Environment.CurrentDirectory + @"\CHN_adm3.shp";
- MapLayer aLayer = MapDataManage.OpenLayer(aFile);
- VectorLayer cityLayer = (VectorLayer)aLayer;
- var extent = new MeteoInfoC.Global.Extent();
- for (int i = 0; i < cityLayer.ShapeList.Count; i++)
- {
- extent = cityLayer.ShapeList.Extent;
- if (longitude >= extent.minX && longitude <= extent.maxX && latitude >= extent.minY && latitude <= extent.maxY)
- {
- location.Province = cityLayer.GetCellValue(4, i).ToString();
- location.City = cityLayer.GetCellValue(6, i).ToString();
- location.Distinct = cityLayer.GetCellValue(8,i).ToString();
- }
- }
- return location;
- }
- }
- public struct Location
- {
- string province;
- string city;
- string distinct;
- string locationString;
- public string LocationString
- {
- get
- {
- processLocationString();
- return locationString;
- }
- set { locationString = value; }
- }
- public string Distinct
- {
- get { return distinct; }
- set { distinct = value; }
- }
- public string City
- {
- get { return city; }
- set { city = value; }
- }
- public string Province
- {
- get
- {
- return province;
- }
- set
- {
- province = value;
- }
- }
- private void processLocationString()
- {
- locationString = "该位置位于:" + province + "省" + city + "市" + distinct + "区";
- }
- }
使用方法:新建项目,引用meteoInfoC 的dll,并且把对应的shp地图拷到dll相同的文件夹下。即可使用。很方便
经过管理员“MeteoInfo”指出:每个shape的Extent是该shape的最小外接矩形,比shape的真实边界要大,点在一个shape的Extent内未必就在该shape内。
恳请指导如何解决这个问题?
|