static public Stream ToKml(IFeatureCursor cursor, int maxFeatures) { KmlType kml = new KmlType(); DocumentType document = new DocumentType(); kml.Item = document; int counter = 0; IFeature feature = null; List <PlacemarkType> placemarks = new List <PlacemarkType>(); while ((feature = cursor.NextFeature) != null) { if (feature.Shape == null) { continue; } PlacemarkType placemark = new PlacemarkType(); placemark.Item_ = ToKml(feature.Shape); placemarks.Add(placemark); counter++; if (counter >= maxFeatures) { break; } } document.Items_ = placemarks.ToArray(); #region Serialize System.Xml.Serialization.XmlSerializerNamespaces namespaces = new System.Xml.Serialization.XmlSerializerNamespaces(); //namespaces.Add("wps", "http://www.opengis.net/wps/1.0.0"); //namespaces.Add("ows", "http://www.opengis.net/ows/1.1"); //namespaces.Add("xlink", "http://www.w3.org/1999/xlink"); //namespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance"); MemoryStream ms = new MemoryStream(); XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(kml.GetType()); ser.Serialize(ms, kml, namespaces); ms.Position = 0; return(ms); //byte[] bytes = new byte[ms.Length]; //ms.Position = 0; //ms.Read(bytes, 0, (int)ms.Length); //return System.Text.Encoding.UTF8.GetString(bytes); #endregion }
private void AddPlaceMark(string p_strPlaceMarkName, string p_strPlaceMarkDesc, string p_strCoordinates, bool p_blnLine) { /* * <Placemark> * <name>Location 3</name> * <description>This is location 3</description> * <Point> * <coordinates>-122.063,37.4063228</coordinates> * </Point> * </Placemark> * * <Placemark> * <name>Yahoo! Inc.</name> * <description><![CDATA[ * Yahoo! Inc.<br /> * 701 First Avenue<br /> * Sunnyvale, CA 94089<br /> * Tel: (408) 349-3300<br /> * Fax: (408) 349-3301<br /> * <p>Home page: <a href="http://yahoo.com">http://yahoo.com</a></p> * ]]> * </description> * <Point> * <coordinates>-122.0250403,37.4163228</coordinates> * </Point> * </Placemark> * * <Placemark> * <name /> * <description>[15-Aug-10 16:26:39] [264.26 km] [36.5 mph] [END]</description> * <styleUrl>#PointStyle</styleUrl> * <Point> * <coordinates>-2.15337666666667,55.5678933333333</coordinates> * </Point> * </Placemark> * * <Placemark> * <name>GPSTEST01 15-Aug-10 09:48:20</name> * <description /> * <LineString> * <coordinates>-1.63345833333333,55.0660283333333 -1.63354,55.06615 -1.633455,55.0660683333333 -1.633465,55.0661516666667 -1.63344833333333,55.0662333333333 -1.63348333333333,55.066285 -1.63337,55.0662833333333 -1.633315,55.0663133333333 -1.633295,55.066355 -1.63326833333333,55.06632 </coordinates> * </LineString> * </Placemark> * * */ PlacemarkType pm = new PlacemarkType(); pm.name = p_strPlaceMarkName; pm.description = p_strPlaceMarkDesc; if (p_blnLine) { LineStringType line = new LineStringType(); pm.Item1 = line; line.coordinates = p_strCoordinates; // pm.styleUrl ="#LineStyle"; } else { PointType point = new PointType(); pm.Item1 = point; point.coordinates = p_strCoordinates; pm.styleUrl = "#PointStyle"; } m_lPlaceMarks.Add(pm); }
private void ConvertPlacemark(PlacemarkType placemark) { this.ConvertGeometry(placemark.Item1); }