Inheritance: geGeometry
コード例 #1
0
 geGeometry DoLineString(SqlGeography g)
 {
     List<geCoordinates> coor = new List<geCoordinates>();
     int points = 0;
     while (points < g.STNumPoints().Value)
     {
         coor.Add(new geCoordinates(new geAngle90(g.STPointN(points + 1).Lat.Value), new geAngle180(g.STPointN(points + 1).Long.Value)));
         points++;
     }
     geLineString ls = new geLineString(coor);
     return ls;
 }
コード例 #2
0
        private static geGeometry ToKMLPolyline(Polyline geometry)
        {
            geLineString kmlGeomtry;

              List<geCoordinates> points = new List<geCoordinates>();

              foreach(ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection in geometry.Paths)
              {
            foreach (MapPoint point in pointCollection)
            {
              points.Add(PointToCoordinate(point));
            }
              }
              kmlGeomtry = new geLineString(points);
              return kmlGeomtry;
        }
コード例 #3
0
ファイル: Example3.cs プロジェクト: rupeshkumar399/seemapcell
        public static geKML RunExample(string FileName)
        {
            // Use a Document as the root of the KML
            geDocument doc = new geDocument();
            doc.Name = "My Root Document";

            gePlacemark pm = new gePlacemark();

            //Always complete the boundary by adding an end point that matches your beginning point

            List<geCoordinates> outerCoords = new List<geCoordinates>();
            outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-114)));
            outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-108)));
            outerCoords.Add(new geCoordinates(new geAngle90(31), new geAngle180(-108)));
            outerCoords.Add(new geCoordinates(new geAngle90(31), new geAngle180(-114)));
            outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-114)));

            List<geCoordinates> innerCoords1 = new List<geCoordinates>();
            innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-113)));
            innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-112)));
            innerCoords1.Add(new geCoordinates(new geAngle90(35), new geAngle180(-112)));
            innerCoords1.Add(new geCoordinates(new geAngle90(35), new geAngle180(-113)));
            innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-113)));

            List<geCoordinates> innerCoords2 = new List<geCoordinates>();
            innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-113)));
            innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-112)));
            innerCoords2.Add(new geCoordinates(new geAngle90(33), new geAngle180(-112)));
            innerCoords2.Add(new geCoordinates(new geAngle90(33), new geAngle180(-113)));
            innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-113)));

            geOuterBoundaryIs outer = new geOuterBoundaryIs(new geLinearRing(outerCoords));

            gePolygon poly = new gePolygon(outer);

            geInnerBoundaryIs inner1 = new geInnerBoundaryIs(new geLinearRing(innerCoords1));
            geInnerBoundaryIs inner2 = new geInnerBoundaryIs(new geLinearRing(innerCoords2));
            poly.InnerBoundaries.Add(inner1);
            poly.InnerBoundaries.Add(inner2);

            pm.Geometry = poly;

            doc.Features.Add(pm);

            //Lets add a Line somewhere too...
            geStyle myLineStyle = new geStyle("myLineStyle");
            myLineStyle.LineStyle = new geLineStyle();
            myLineStyle.LineStyle.Color.SysColor = Color.Yellow;
            myLineStyle.LineStyle.Width = 4;  //This may or may not work, depends on the end user's video card

            doc.StyleSelectors.Add(myLineStyle);

            gePlacemark pmLine = new gePlacemark();
            pmLine.StyleUrl = "#myLineStyle";
            pmLine.Name = "Example Line";
            pmLine.Description = "Some description";

            List<geCoordinates> lineCoords = new List<geCoordinates>();
            lineCoords.Add(new geCoordinates(new geAngle90(35),new geAngle180(-117)));
            lineCoords.Add(new geCoordinates(new geAngle90(35),new geAngle180(-106)));

            geLineString line = new geLineString(lineCoords);

            pmLine.Geometry = line;

            doc.Features.Add(pmLine);

            //Now that we have our document, lets create our KML
            geKML kml = new geKML(doc);

            return kml;
        }
コード例 #4
0
        private void processPolyLineLayer(LayerProperties layerProps, geFolder folder)
        {
            //I have a polyline layer, and a kml folder :)
            IFeatureClass clasa = (layerProps.Layeru as IFeatureLayer).FeatureClass;
            //get acces to features
            IFeatureCursor featurele = clasa.Search(null, true);
            int nrFeature = clasa.FeatureCount(null);

            //if I have any features
            Polyline curba;
            IFeature currentFeature;

            while ((currentFeature = featurele.NextFeature()) != null)
            {
                curba = currentFeature.Shape as Polyline;
                //coordinates and vertices
                double coordLat;
                double coordLong;
                IEnumVertex colection = curba.EnumVertices;
                IPoint lineVertex;

                //create coord system WGS 84 (Google earth)
                IGeographicCoordinateSystem gcs;
                SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment();
                gcs = sre.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                //create spatial reference
                ISpatialReference pointToSpatialReference;
                pointToSpatialReference = gcs;

                #region add points to polyline
                //create a placemark for the line
                gePlacemark pmLine = new gePlacemark();
                pmLine.StyleUrl = "#Shape2KMLGeneratedStyle";

                List<geCoordinates> lineCoords = new List<geCoordinates>();
                int index1, index2;
                //iterate points...

                geLineString line = null;

                while (!colection.IsLastInPart())
                {
                    colection.Next(out lineVertex, out index1, out index2);
                    //project point and get coordinates
                    lineVertex.Project(pointToSpatialReference);
                    lineVertex.QueryCoords(out coordLong, out coordLat);

                    try
                    {
                    switch (layerProps.AltitudeMode)
                    {
                        case AltitudeMode.absolute:
                            if (layerProps.Field == "")
                            {
                                //add point to line
                                lineCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Altitude));
                            }
                            else
                            {
                                int altitude;
                                //if altitude is integer, this should work
                                    altitude = (int)currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.Field));

                                //add point to line
                                    lineCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Multiplier * altitude));

                            }
                            break;

                        case AltitudeMode.clampToGround:
                            //add point to line
                            lineCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong)));
                            break;

                        case AltitudeMode.relativeToGround:
                           if (layerProps.Field == "")
                            {
                              //add point to line
                            lineCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Altitude));
                        }
                        else
                        {
                            float altitude;
                             //if altitude is integer, this should work
                            altitude = (float)currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.Field));

                            //add point to line
                            lineCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Multiplier * altitude));

                        }

                        break;

                        default:
                            break;
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Altitude field is not a number value");
                    break;
                }
                }
                //create line from list of coords
                line = new geLineString(lineCoords);

                switch (layerProps.AltitudeMode)
                {
                    case AltitudeMode.absolute:
                        line.AltitudeMode = geAltitudeModeEnum.absolute;
                        break;
                    case AltitudeMode.clampToGround:
                        line.AltitudeMode = geAltitudeModeEnum.clampToGround;
                        break;
                    case AltitudeMode.relativeToGround:
                        line.AltitudeMode = geAltitudeModeEnum.relativeToGround;
                        break;
                    default:
                        break;
                }

                if (layerProps.DescField != "")
                    pmLine.Description = currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.DescField)).ToString();

                if (layerProps.NameField != "")
                    pmLine.Name = currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.NameField)).ToString();

                //and add it to document
                pmLine.Geometry = line;
                folder.Features.Add(pmLine);

                #endregion
            }
        }