protected void MakeTxtFileOfJSONElevationResponses()
        {
            //return;
            string trailName= "'GDT'";
            string sectionName = "'G'";
            string startWaypointOID = "1418";
            int distanceBetweenPoints = 10;
            IGeometryCollection geomCol = new GeometryBagClass();
            WebClient client = new WebClient();
            string path = "";
            string samples = "";
            IFeatureClass trailFC = null;
            IFeatureClass elevationFC = null;
            IFeatureClass waypointFC = null;
            GetFeatureClasses(ref trailFC, ref elevationFC, ref waypointFC);
            IQueryFilter qf = new QueryFilterClass();
            qf.WhereClause = "OBJECTID =  " + startWaypointOID;
            //qf.WhereClause = "NAME = " + trailName + " and SECTIONNAME = " + sectionName;
            IFeatureCursor feCur = waypointFC.Search(qf, false);
            IFeature startWaypoint = feCur.NextFeature();
            Marshal.FinalReleaseComObject(feCur);
            Queue<IFeature> waypointsToProcess = new Queue<IFeature>();
            waypointsToProcess.Enqueue(startWaypoint);
            HashSet<int> waypointsWeHaveSeen = new HashSet<int>();
            while(waypointsToProcess.Count > 0)
            {
                IFeature waypointFe = waypointsToProcess.Dequeue();
                waypointsWeHaveSeen.Add(waypointFe.OID);
                ISpatialFilter sf = new SpatialFilterClass();
                sf.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                sf.GeometryField = "SHAPE";
                sf.Geometry = waypointFe.Shape;
                feCur = trailFC.Search(sf, false);
                IFeature connectedTrail = feCur.NextFeature();
                while (connectedTrail != null)
                {

                    if (("'" + connectedTrail.get_Value(connectedTrail.Fields.FindField("NAME")) + "'" == trailName) && ("'" + connectedTrail.get_Value(connectedTrail.Fields.FindField("SECTIONNAME")) +"'" == sectionName))
                    {
                        File.AppendAllText(@"c:\temp\connectedSegs.txt", Environment.NewLine + connectedTrail.OID.ToString());
                        geomCol.AddGeometry(connectedTrail.ShapeCopy);
                        int fromID = Convert.ToInt16(connectedTrail.get_Value(connectedTrail.Fields.FindField("FROMWAYPOINT")));
                        int toID = Convert.ToInt16(connectedTrail.get_Value(connectedTrail.Fields.FindField("TOWAYPOINT")));
                        if (waypointsWeHaveSeen.Contains(fromID) == false)
                        {
                            waypointsToProcess.Enqueue(waypointFC.GetFeature(fromID));
                        }
                        if (waypointsWeHaveSeen.Contains(toID) == false)
                        {
                            waypointsToProcess.Enqueue(waypointFC.GetFeature(toID));
                        }
                    }

                    connectedTrail = feCur.NextFeature();
                }
                Marshal.FinalReleaseComObject(feCur);

            }

            //return;

            Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
            System.Object obj = Activator.CreateInstance(factoryType);
            ISpatialReferenceFactory spatialReferenceFactory = obj as ISpatialReferenceFactory;
            ISpatialReference spatRef = spatialReferenceFactory.CreateGeographicCoordinateSystem(4326);
            //ISpatialReference existingSpatRef = geomCol.get_Geometry(0).SpatialReference;
            ISpatialReference existingSpatRef = startWaypoint.ShapeCopy.SpatialReference;
            /*IFeature trailFe = feCur.NextFeature();
            ISpatialReference existingSpatRef = null;
            while (trailFe != null)
            {
                geomCol.AddGeometry(trailFe.ShapeCopy);
                if(existingSpatRef == null)
                {
                    existingSpatRef = trailFe.ShapeCopy.SpatialReference;
                }
                trailFe = feCur.NextFeature();
            }*/
            IPointCollection newPolyline = new PolylineClass();
            ((IGeometry)newPolyline).SpatialReference = startWaypoint.ShapeCopy.SpatialReference;
            HashSet<string> points = new HashSet<string>();
            for(int i = 0 ; i < geomCol.GeometryCount; i++)
            {
                IPointCollection geomPntCol = geomCol.get_Geometry(i) as IPointCollection;
                for (int j = 0; j < geomPntCol.PointCount; j++ )
                {
                    IPoint pnt = geomPntCol.get_Point(j);
                    string pntString = pnt.X + "," + pnt.Y;
                    if(points.Contains(pntString) == false)
                    {
                        points.Add(pntString);
                        pnt.SpatialReference = startWaypoint.ShapeCopy.SpatialReference;
                        newPolyline.AddPoint(pnt);
                    }
                }

            }
            IPolyline fullTrail = newPolyline as IPolyline;
            fullTrail.SpatialReference = startWaypoint.ShapeCopy.SpatialReference;
            //ITopologicalOperator unionedPolyline = new PolylineClass();
            //unionedPolyline.ConstructUnion(geomCol as IEnumGeometry);
            //IPolyline fullTrail = unionedPolyline as IPolyline;
            Marshal.FinalReleaseComObject(feCur);
            IFeature fromPoint = waypointFC.GetFeature(Convert.ToInt16( startWaypointOID));
            IProximityOperator proxOp = fromPoint.ShapeCopy as IProximityOperator;
            double fromPointDist = proxOp.ReturnDistance(fullTrail.FromPoint);
            if (proxOp.ReturnDistance(fullTrail.ToPoint) == 0)
            {
                fullTrail.ReverseOrientation();
            }
            int dividePointIndex = 1;
            List<IPoint> pointsOnTrail = new List<IPoint>();
            double totalDistance = 0;
            while(dividePointIndex * distanceBetweenPoints < fullTrail.Length)
            {
                IPoint outPoint = new PointClass();
                fullTrail.QueryPoint(esriSegmentExtension.esriNoExtension, dividePointIndex * distanceBetweenPoints, false, outPoint);
                outPoint.SpatialReference = existingSpatRef;
                outPoint.Project(spatRef);
                pointsOnTrail.Add(outPoint);
                dividePointIndex++;
            }
            StringBuilder sb = new StringBuilder();
            List<string> locationStrings = new List<string>();
            int locationPointsInStringBuilder = 0;
            for (int i = 0; i < pointsOnTrail.Count; i++)
            {
                if(sb.Length > 0)
                {
                    sb.Append("|");
                }
                sb.Append(pointsOnTrail[i].Y);
                sb.Append(",");
                sb.Append(pointsOnTrail[i].X);
                locationPointsInStringBuilder++;
                if (locationPointsInStringBuilder > 33)
                {
                    locationStrings.Add(sb.ToString());
                    sb = new StringBuilder();
                    locationPointsInStringBuilder = 0;
                }
            }
            locationStrings.Add(sb.ToString());
            //FileStream fsw = File.OpenWrite(@"c:\temp\SectionAElevations.txt");
            int counter = 0;
            foreach(string locString in locationStrings)
            {
                counter++;
                //FileStream fsw = File.OpenWrite(@"c:\temp\SectionAElevations.txt");
                string address = "https://maps.googleapis.com/maps/api/elevation/json?locations=" + locString + "&key=AIzaSyBJlaYSBeJkYl_G2tInjNJBYmjJhaSulLA";
                System.Threading.Thread.Sleep(1000);
                string reply = client.DownloadString(address);
                File.AppendAllText(@"c:\temp\Section" + sectionName + "Elevations.txt", reply + Environment.NewLine);
            }

            //        https://maps.googleapis.com/maps/api/elevation/json?locations=39.7391536,-104.9847034|36.455556,-116.866667&key=AIzaSyC2WxuR5N1TKk5rfFrFQSd_IwMlg3TvVnM
            //string address = @"https://maps.googleapis.com/maps/api/elevation/json?path=" + path +  "&samples=" + samples + "&key=AIzaSyC2WxuR5N1TKk5rfFrFQSd_IwMlg3TvVnM";
        }
Example #2
0
        private void Btnok_Click(object sender, EventArgs e)
        {
            if (m_mapControl.Map.SelectionCount == 0)
            {
                MessageBox.Show("����ѡ�����ѯҪ�أ�");
                return;
            }
            IEnumFeature pEnumfeature;
            IFeature pFeature;
            IFeature newFeat;
            //ITopologicalOperator pToplogicalOper;
            //IPolygon pPolygon;
            double bufferDistence;

            if (m_mapControl.Map.SelectionCount == 0)
            {
                return;
            }
            bufferDistence = Convert.ToDouble(BufferText.Text);
            pEnumfeature = m_mapControl.Map.FeatureSelection as IEnumFeature;
            pEnumfeature.Reset();
            pFeature = pEnumfeature.Next();
            IFeatureClass pFeatureclass;
            FileInfo n = new FileInfo(textBox1.Text);
            string openpath = n.Directory.ToString();//ȡ·���ĸ�Ŀ¼���ڴ��µ�layer
            pFeatureclass = CreatNewShapefile(openpath, n.Name, m_mapControl.SpatialReference);

            //IFeatureBuffer pFeatureBuffer = pFeatureclass.CreateFeatureBuffer();
            //IFeatureCursor pFeatureCursor = pFeatureclass.Insert(true);
            int iFieldAttribute = pFeatureclass.FindField("Text");
            //while (pFeature != null)
            //{
            //    pToplogicalOper = pFeature.Shape as ITopologicalOperator;
            //    pPolygon = new PolygonClass();
            //    pPolygon = pToplogicalOper.Buffer(bufferDistence) as IPolygon;
            //    pFeatureBuffer.Shape = pPolygon;
            //    //pFeatureBuffer.set_Value(iFieldAttribute, pFeature.OID);
            //    pFeatureCursor.InsertFeature(pFeatureBuffer);
            //    pFeature = pEnumfeature.Next();
            //}
            //pFeatureCursor.Flush();

            //ML�޸Ĵ���
            IGeometryCollection inputGeom = new GeometryBagClass();
            IGeometryBag geomBag = inputGeom as IGeometryBag;
            object missing = Type.Missing;
            while (pFeature != null)
            {
                inputGeom.AddGeometry(pFeature.ShapeCopy, ref missing, ref missing);
                pFeature = pEnumfeature.Next();
            }

            IBufferConstruction bfCon = new BufferConstructionClass();
            IBufferConstructionProperties bfConProp = bfCon as IBufferConstructionProperties;
            ISpatialReferenceFactory spatialRefFac = new SpatialReferenceEnvironmentClass();
            bfConProp.EndOption = esriBufferConstructionEndEnum.esriBufferRound;
            bfConProp.SideOption = esriBufferConstructionSideEnum.esriBufferFull;
            bfConProp.ExplodeBuffers = false;
            bfConProp.OutsideOnly = false;
            bfConProp.GenerateCurves = true;
            bfConProp.UnionOverlappingBuffers = true;
            bfConProp.DensifyDeviation = -1;
            IGeometryCollection outGeom = new GeometryBagClass();
            bfCon.ConstructBuffers(inputGeom as IEnumGeometry, bufferDistence, outGeom);
            for (int i = 0; i < outGeom.GeometryCount; i++)
            {
                newFeat = pFeatureclass.CreateFeature();
                newFeat.Shape = outGeom.get_Geometry(i);
                newFeat.Store();
            }
            newFeat = null;
            //���ͼ���map
            IFeatureLayer pOutputFeatureLayer;
            pOutputFeatureLayer = new FeatureLayerClass();
            pOutputFeatureLayer.FeatureClass = pFeatureclass;
            pOutputFeatureLayer.Name = pFeatureclass.AliasName;
            m_mapControl.Map.AddLayer(pOutputFeatureLayer);

            this.Dispose();
        }
Example #3
0
        private void Btnok_Click(object sender, EventArgs e)
        {
            if (m_mapControl.Map.SelectionCount == 0)
            {
                MessageBox.Show("请先选择待查询要素!");
                return;
            }
            IEnumFeature pEnumfeature;
            IFeature     pFeature;
            IFeature     newFeat;
            //ITopologicalOperator pToplogicalOper;
            //IPolygon pPolygon;
            double bufferDistence;

            if (m_mapControl.Map.SelectionCount == 0)
            {
                return;
            }
            bufferDistence = Convert.ToDouble(BufferText.Text);
            pEnumfeature   = m_mapControl.Map.FeatureSelection as IEnumFeature;
            pEnumfeature.Reset();
            pFeature = pEnumfeature.Next();
            IFeatureClass pFeatureclass;
            FileInfo      n        = new FileInfo(textBox1.Text);
            string        openpath = n.Directory.ToString();//取路径的父目录用于存新的layer

            pFeatureclass = CreatNewShapefile(openpath, n.Name, m_mapControl.SpatialReference);

            //IFeatureBuffer pFeatureBuffer = pFeatureclass.CreateFeatureBuffer();
            //IFeatureCursor pFeatureCursor = pFeatureclass.Insert(true);
            int iFieldAttribute = pFeatureclass.FindField("Text");
            //while (pFeature != null)
            //{
            //    pToplogicalOper = pFeature.Shape as ITopologicalOperator;
            //    pPolygon = new PolygonClass();
            //    pPolygon = pToplogicalOper.Buffer(bufferDistence) as IPolygon;
            //    pFeatureBuffer.Shape = pPolygon;
            //    //pFeatureBuffer.set_Value(iFieldAttribute, pFeature.OID);
            //    pFeatureCursor.InsertFeature(pFeatureBuffer);
            //    pFeature = pEnumfeature.Next();
            //}
            //pFeatureCursor.Flush();

            //ML修改代码
            IGeometryCollection inputGeom = new GeometryBagClass();
            IGeometryBag        geomBag   = inputGeom as IGeometryBag;
            object missing = Type.Missing;

            while (pFeature != null)
            {
                inputGeom.AddGeometry(pFeature.ShapeCopy, ref missing, ref missing);
                pFeature = pEnumfeature.Next();
            }



            IBufferConstruction           bfCon         = new BufferConstructionClass();
            IBufferConstructionProperties bfConProp     = bfCon as IBufferConstructionProperties;
            ISpatialReferenceFactory      spatialRefFac = new SpatialReferenceEnvironmentClass();

            bfConProp.EndOption               = esriBufferConstructionEndEnum.esriBufferRound;
            bfConProp.SideOption              = esriBufferConstructionSideEnum.esriBufferFull;
            bfConProp.ExplodeBuffers          = false;
            bfConProp.OutsideOnly             = false;
            bfConProp.GenerateCurves          = true;
            bfConProp.UnionOverlappingBuffers = true;
            bfConProp.DensifyDeviation        = -1;
            IGeometryCollection outGeom = new GeometryBagClass();

            bfCon.ConstructBuffers(inputGeom as IEnumGeometry, bufferDistence, outGeom);
            for (int i = 0; i < outGeom.GeometryCount; i++)
            {
                newFeat       = pFeatureclass.CreateFeature();
                newFeat.Shape = outGeom.get_Geometry(i);
                newFeat.Store();
            }
            newFeat = null;
            //添加图层进map
            IFeatureLayer pOutputFeatureLayer;

            pOutputFeatureLayer = new FeatureLayerClass();
            pOutputFeatureLayer.FeatureClass = pFeatureclass;
            pOutputFeatureLayer.Name         = pFeatureclass.AliasName;
            m_mapControl.Map.AddLayer(pOutputFeatureLayer);


            this.Dispose();
        }