Exemple #1
0
        public SelectResult SelectLine(GISVertex vertex, List <GISFeature> features,
                                       GISView view, GISExtent MinSelectExtent)
        {
            Double distance = Double.MaxValue;
            int    id       = -1;

            for (int i = 0; i < features.Count; i++) //找最近的feature判断是否有效
            {
                if (MinSelectExtent.IntersectOrNot(features[i].spatialpart.extent) == false)
                {
                    continue;
                }
                GISLine line = (GISLine)(features[i].spatialpart);
                double  dist = line.Distance(vertex);
                //Console.WriteLine("dist:" + dist);
                if (dist < distance)//每次找到最小的距离并记录id号
                {
                    distance = dist;
                    id       = i;
                }
            }
            Console.WriteLine("id:" + id.ToString());//测试id是否存在
            //Console.WriteLine(distance);
            //精选
            if (id == -1)//经过遍历 没有与minsextent相交的点则跳出
            {
                SelectedFeature = null;
                return(SelectResult.TooFar);
            }
            else
            {
                double screendistance = view.ToScreenDistance(distance);
                if (screendistance < GISConst.MinScreenDistance)
                {
                    SelectedFeature = features[id];
                    return(SelectResult.OK);
                }
                else
                {
                    SelectedFeature = null;
                    return(SelectResult.TooFar);//即使在粗选相交 精选距离也超过了限制 则返回
                }
            }
        }
Exemple #2
0
 //输出图层所有GISFeatrue
 static void WriteFeatures(GISLayer layer, BinaryWriter bw)
 {
     for (int featureindex = 0; featureindex < layer.FeatureCount(); featureindex++)
     {
         GISFeature feature = layer.GetFeature(featureindex);
         if (layer.ShapeType == SHAPETYPE.point)
         {
             ((GISPoint)feature.spatialpart).centroid.WriteVertex(bw);
         }
         else if (layer.ShapeType == SHAPETYPE.line)
         {
             GISLine line = (GISLine)(feature.spatialpart);
             WriteMultipleVertexes(line.Vertexes, bw);
         }
         else if (layer.ShapeType == SHAPETYPE.polygon)
         {
             GISPolygon polygon = (GISPolygon)(feature.spatialpart);
             WriteMultipleVertexes(polygon.Vertexes, bw);
         }
         WriteAttributes(feature.attributepart, bw);
     }
 }