A Placemark is a Feature with associated Geometry. In Google Earth, a Placemark appears as a list item in the Places panel. A Placemark with a Point has an icon associated with it that marks a point on the earth in the 3D viewer. (In the Google Earth 3D viewer, a Point Placemark is the only object you can click or roll over. Other Geometry objects do not have an icon in the 3D viewer. To give the user something to click, you would need to add a Point to the Polygon.)
Inheritance: geFeature
コード例 #1
0
        public static geKML ToKML(IEnumerable<Location> locations)
        {
            geDocument doc = new geDocument();
            doc.Name = "Locations exported";
            foreach (var loc in locations)
            {
                gePlacemark pm = new gePlacemark();

                //Create some coordinates for the point at which
                //this placemark will sit. (Lat / Lon)
                geCoordinates coords = new geCoordinates(new geAngle90(loc.Latitude), new geAngle180(loc.Longitude));

                //Create a point with these new coordinates
                gePoint point = new gePoint(coords);

                //Assign the point to the Geometry property of the
                //placemark.
                pm.Geometry = point;

                //Now lets add some other properties to our placemark
                pm.Name = loc.Name;
                pm.Description = "Visit at: " + loc.Time.ToString();
                //Finally, add the placemark to the document
                doc.Features.Add(pm);
            }
            //Now that we have our document, lets create our KML
            geKML kml = new geKML(doc);
            return kml;
        }
コード例 #2
0
ファイル: Example2.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";

            // Create a new style to be added the doc
            geStyle myStyle = new geStyle("myStyle");

            //add a new IconStyle to the style
            myStyle.IconStyle = new geIconStyle();
            myStyle.IconStyle.Icon = new geIcon("Example2.png");
            myStyle.IconStyle.Scale = 2F; //or (float)2

            //Add the style
            doc.StyleSelectors.Add(myStyle);

            //Create a Placemark to put in the document
            //This placemark is going to be a point
            //but it could be anything in the Geometry class
            gePlacemark pm = new gePlacemark();

            //Create some coordinates for the point at which
            //this placemark will sit. (Lat / Lon)
            geCoordinates coords = new geCoordinates(
                new geAngle90(37.422067),
            new geAngle180(-122.084437));

            //Create a point with these new coordinates
            gePoint point = new gePoint(coords);

            //Assign the point to the Geometry property of the
            //placemark.
            pm.Geometry = point;

            //Set the placemark's style to the style we created above
            pm.StyleUrl = "#myStyle";

            //Now lets add some other properties to our placemark
            pm.Name = "My Placemark";
            pm.Snippet = "This is where I put my Placemark";
            pm.Description =
                "I wonder where this is...GOOGLE!";

            //Finally, add the placemark to the document
            doc.Features.Add(pm);

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

            //Add supporting files to the KMZ (assuming it's going to be rendered as KMZ
            byte[] myFile = File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "\\images\\Example2.png");
            kml.Files.Add("Example2.png", myFile);

            return kml;
        }
コード例 #3
0
    /// <summary>
    /// This kml will contain the data that will be refreshed according to what is defined in GetINIT()
    /// </summary>
    /// <returns></returns>
    public static geKML GetWebExample1Data()
    {
        geDocument doc = new geDocument();

        //you probably won't see this since the document is a child of a network link
        doc.Name = "WebExample1Data";
        doc.Snippet = "This data should auto refresh based on the RefreshInterval of our parent NetworkLink";

        gePlacemark pm = new gePlacemark();
        geCoordinates coord = new geCoordinates(new geAngle90(37.422067), new geAngle180(-122.084437));
        gePoint point = new gePoint(coord);

        //Just show the server dateTime so that we know it's updating as advertised.
        pm.Name = DateTime.Now.ToString();
        pm.Description = "This data will be automatically refreshed based on the parent NetworkLink";
        pm.Geometry = point;

        doc.Features.Add(pm);

        return new geKML(doc);
    }
コード例 #4
0
ファイル: Example1.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";

            //Create a Placemark to put in the document
            //This placemark is going to be a point
            //but it could be anything in the Geometry class
            gePlacemark pm = new gePlacemark();

            //Create some coordinates for the point at which
            //this placemark will sit. (Lat / Lon)
            geCoordinates coords = new geCoordinates(
                new geAngle90(37.422067),
            new geAngle180(-122.084437));

            //Create a point with these new coordinates
            gePoint point = new gePoint(coords);

            //Assign the point to the Geometry property of the
            //placemark.
            pm.Geometry = point;

            //Now lets add some other properties to our placemark
            pm.Name = "My Placemark";
            pm.Snippet = "This is where I put my Placemark";
            pm.Description =
                "I wonder where this is...";

            //Finally, add the placemark to the document
            doc.Features.Add(pm);

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

            return kml;
        }
コード例 #5
0
        public geFolder SqlGeogCommandToKmlFolder(string connstr, string cmdstr, string fldname)
        {
            geFolder fld = new geFolder();
            fld.Name = fldname;

            using (SqlConnection conn = new SqlConnection(connstr))
            using (SqlCommand cmd = new SqlCommand(cmdstr, conn))
            {
                try
                {
                    conn.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        SqlGeography geog = (SqlGeography)rdr.GetValue(0);
                        if (!IsNullOrEmpty(geog))
                        {
                            gePlacemark pm = new gePlacemark();

                            if (rdr.FieldCount == 3)
                                pm = SqlGeogToKmlPlacemark(geog,
                                                        rdr.GetString(1),
                                                        rdr.GetString(2));
                            else
                                pm = SqlGeogToKmlPlacemark(geog,
                                                        rdr.GetString(1),
                                                        rdr.GetString(1));
                            fld.Features.Add(pm);
                        }
                    }
                }
                catch
                {
                    return null;
                }
            }

            return fld;
        }
コード例 #6
0
        public gePlacemark SqlGeogToKmlPlacemark(SqlGeography geog, string pname, string description )
        {
            if (IsNullOrEmpty(geog))
                return null;

            gePlacemark pm = new gePlacemark();
            pm.Description = description;
            pm.Name = pname;

            switch (geog.STGeometryType().Value)
            {
                case "Point":
                    pm.Geometry = DoPoint(geog);
                    break;
                case "LineString":
                    pm.Geometry = DoLineString(geog);
                    break;
                case "Polygon":
                    pm.Geometry = DoPolygon(geog);
                    break;
                case "MultiPoint":
                case "MultiLineString":
                case "MultiPolygon":
                case "GeometryCollection":
                    pm.Geometry = DoMulti(geog);
                    break;
                default:
                    break;
            }

            return pm;
        }
コード例 #7
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;
        }
コード例 #8
0
        private gePlacemark CreateKMLPlacemark(Graphic graphic)
        {
            gePlacemark placemark;
              geSchemaData schemaData;
              string placemarkNameColumn;

              placemark = new gePlacemark();

              placemarkNameColumn = GetPlacemarkName(graphic);

              if(placemarkNameColumn != string.Empty)
              {
            placemark.Name = graphic.Attributes[placemarkNameColumn].ToString();
              }

              if(graphic.Symbol != null)
              {
            placemark.StyleUrl = "#" + graphic.Symbol.GetHashCode().ToString();
              }
              else
              {
            placemark.StyleUrl = "#" + mStyleName;
              }

              placemark.Snippet = CreateKMLSnippet(graphic);
              placemark.Description = CreateKMLPlacemarkDescription(graphic);

              placemark.Geometry = ToKMLGeometry(graphic.Geometry);
              placemark.ExtendedData = new geExtendedData();

              schemaData = new geSchemaData();
              schemaData.SchemaUrl = "#" + mSchemaName;

              foreach(KeyValuePair<string, object> attributeKVP in graphic.Attributes)
              {
            if(attributeKVP.Key.ToUpper() != "SHAPE" && attributeKVP.Key != "FID")
            {
              geSimpleData simpleData;

              simpleData = new geSimpleData();
              simpleData.Name = attributeKVP.Key;
              if(graphic.Attributes[attributeKVP.Key] == null)
              {
            simpleData.Value = string.Empty;
              }
              else
              {
            simpleData.Value = graphic.Attributes[attributeKVP.Key].ToString();
              }
              schemaData.SimpleData.Add(simpleData);
            }
              }

              return placemark;
        }
        // This method is to be called once all the targets
        // are loaded via AddNewTarget. Once KML is created the list
        // will be emptied.
        public void BuildKML()
        {
            string exampleFileName = "";
            string exampleFileExt = "kmz";
            string file_name = "ASTX_TO_KML";

            // Use a Document as the root of the KML
            geDocument doc = new geDocument();
            doc.Name = "Asterix to KML";

            // Create a new style to be added the doc
            geStyle myStyle = new geStyle("myStyle");

            //add a new IconStyle to the style
            myStyle.IconStyle = new geIconStyle();
            myStyle.IconStyle.Icon = new geIcon("ac_image.png");
            myStyle.IconStyle.Scale = 1.0F; //or (float)1

            myStyle.LabelStyle = new geLabelStyle();
            myStyle.LabelStyle.Color.SysColor = Color.White;

            myStyle.LineStyle = new geLineStyle();
            myStyle.LineStyle.Color.SysColor = Color.Black;
            myStyle.LineStyle.Width = 4;

            //Add the style
            doc.StyleSelectors.Add(myStyle);

            foreach (DynamicDisplayBuilder.TargetType Target in TargetList)
            {
                //Create a Placemark to put in the document
                //This placemark is going to be a point
                //but it could be anything in the Geometry class
                gePlacemark pm = new gePlacemark();

                //Create some coordinates for the point at which
                //this placemark will sit. (Lat / Lon)
                geCoordinates coords = new geCoordinates(
                    new geAngle90(Target.Lat),
                new geAngle180(Target.Lon));

                double LevelInMeeters = 0.0;

                // Assign the altitude
                if (Target.ModeC != null)
                {
                    if (Target.ModeC != "---")
                        LevelInMeeters = (double.Parse(Target.ModeC) * 100.00) * SharedData.FeetToMeeters;
                }

                coords.Altitude = (float)LevelInMeeters;

                //Create a point with these new coordinates
                gePoint point = new gePoint(coords);
                point.AltitudeMode = geAltitudeModeEnum.absolute;
                point.Extrude = true;

                //Assign the point to the Geometry property of the
                //placemark.
                pm.Geometry = point;

                //Set the placemark's style to the style we created above
                pm.StyleUrl = "#myStyle";

                if (Properties.Settings.Default.GE_Show_ModeA)
                    pm.Name = Target.ModeA;

                if (Properties.Settings.Default.GE_Show_ModeC)
                {
                    if (Properties.Settings.Default.Show_ModeC_as_FL)
                        pm.Name = pm.Name + "  " + "FL:" + Target.ModeC;
                    else
                        pm.Name = pm.Name + "  " + LevelInMeeters.ToString() + "m";
                }

                if (Properties.Settings.Default.GE_Show_ModeC)
                {
                    pm.Name = pm.Name + " " + Target.ACID_Mode_S;
                }

                pm.Snippet = "Snipet Test";
                pm.Description = "Blaa Bla Blaaaa";

                //Finally, add the placemark to the document
                doc.Features.Add(pm);
            }

            geKML kml = new geKML(doc);

            //Add supporting files to the KMZ (assuming it's going to be rendered as KMZ
            byte[] myFile = File.ReadAllBytes(@"C:\ASTERIX\GE\ac_image.png");
            kml.Files.Add("ac_image.png", myFile);

            exampleFileName = Properties.Settings.Default.GE_Dest_Path + "\\" + file_name + "." + exampleFileExt;
            File.WriteAllBytes(exampleFileName, kml.ToKMZ());

            // Clear the list
            TargetList.Clear();
        }
コード例 #10
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
            }
        }
コード例 #11
0
        private void processPointLayer(LayerProperties layerProps, geFolder folder)
        {
            //I have a point layer, and a kml folder :)
            IFeatureClass clasa = (layerProps.Layeru as IFeatureLayer).FeatureClass;
            //get acces to features
            IFeatureCursor featurele = clasa.Search(null, true);

            //if I have any features
            Point punct;
            IFeature currentFeature;

            //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
            while ((currentFeature = featurele.NextFeature()) != null)
            {
                punct = currentFeature.Shape as Point;
                //coordinates and vertices
                double coordLat;
                double coordLong;

                //create a placemark for the point
                gePlacemark pmPoint = new gePlacemark();
                pmPoint.StyleUrl = "#Shape2KMLGeneratedStyle";

                //project point and get coordinates
                punct.Project(pointToSpatialReference);
                punct.QueryCoords(out coordLong, out coordLat);
                //add point

                geCoordinates coords;
                gePoint point;

                switch (layerProps.AltitudeMode)
                {
                    case AltitudeMode.absolute:

                        if (layerProps.Field == "")
                        {
                            //add point
                            coords = 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
                            coords = new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Multiplier * altitude);

                        }
                        point = new gePoint(coords);
                        point.AltitudeMode = geAltitudeModeEnum.absolute;
                        break;
                    case AltitudeMode.clampToGround:
                        coords = new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong));
                        point = new gePoint(coords);
                        point.AltitudeMode = geAltitudeModeEnum.clampToGround;
                        break;
                    case AltitudeMode.relativeToGround:
                        if (layerProps.Field == "")
                        {
                            //add point
                            coords = 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
                            coords = new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Multiplier * altitude);

                        }
                        point = new gePoint(coords);
                        point.AltitudeMode = geAltitudeModeEnum.relativeToGround;
                        break;
                    default:
                        point = null;
                        break;
                }

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

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

                pmPoint.Geometry = point;
                folder.Features.Add(pmPoint);
            #endregion
            }
        }