private Geometry GetKml(TPolygon polygon) { if (polygon.Rings.Count == 0) { return(null); } var outher = polygon.GetOuterBoundary(); if (outher == null) { return(GetKml(polygon.AsCollection())); } var outherKml = new OuterBoundary { LinearRing = GetRingKml(outher) }; var kml = new Polygon { OuterBoundary = outherKml }; foreach (var ring in polygon.Rings) { if (ring == outher) { continue; } var inner = new InnerBoundary() { LinearRing = GetRingKml(ring) }; var _ = kml.InnerBoundary.Append(inner); } return(kml); }
public string Write(Guid listGuid) { string kml = string.Empty; Serializer serializer = new Serializer(); Kml _kml = new Kml(); Folder folder = new Folder(); UseWeb(spWeb => { SPList list = spWeb.Lists.GetList(listGuid, true); SPField field = list.GetGeoField(); if (field != null) { foreach (SPListItem item in list.Items) { string wkt = item[field.Id] as string; SimpleWKTReader wktReader = new SimpleWKTReader(); var simpleGeometry = wktReader.Parse(wkt); if (simpleGeometry.GeometryType == GeometryTypes.Point) { var _point = (OpenSMIL.Server.SimpleFeature.GeomtryTypes.Point)simpleGeometry; SharpKml.Dom.Point point = new SharpKml.Dom.Point(); point.Coordinate = new Vector(_point.Lat, _point.Lon); Placemark placemark = CreatePlaceMark(item.Title, point); folder.AddFeature(placemark); } else if (simpleGeometry.GeometryType == GeometryTypes.LineString) { var _lineString = (OpenSMIL.Server.SimpleFeature.GeomtryTypes.LineString)simpleGeometry; SharpKml.Dom.LineString line = new SharpKml.Dom.LineString(); line.Coordinates = CreateCoordinateCollection(_lineString.Points); Placemark placeMark = CreatePlaceMark(item.Title, line); folder.AddFeature(placeMark); } else if (simpleGeometry.GeometryType == GeometryTypes.Polygon) { var _polygon = (OpenSMIL.Server.SimpleFeature.GeomtryTypes.Polygon)simpleGeometry; OuterBoundary outerBoundary = new OuterBoundary(); outerBoundary.LinearRing = new LinearRing(); outerBoundary.LinearRing.Coordinates = CreateCoordinateCollection(_polygon.Points); SharpKml.Dom.Polygon polygon = new SharpKml.Dom.Polygon(); polygon.OuterBoundary = outerBoundary; polygon.Extrude = true; Placemark placeMark = CreatePlaceMark(item.Title, polygon); folder.AddFeature(placeMark); } } _kml.Feature = folder; } }); serializer.Serialize(_kml); return(serializer.Xml); }
protected override void setJSON(JObject obj, BaseClassIfc host, HashSet <int> processed) { base.setJSON(obj, host, processed); obj["OuterBoundary"] = OuterBoundary.getJson(this, processed); if (mInnerBoundaries.Count > 0) { obj["InnerBoundaries"] = new JArray(InnerBoundaries.ToList().ConvertAll(x => x.getJson(this, processed))); } }
public override string GetStepParameters() { var parameters = new List <string>(); parameters.Add(OuterBoundary != null ? OuterBoundary.ToStepValue() : "$"); parameters.Add(InnerBoundaries != null ? InnerBoundaries.ToStepValue() : "$"); return(string.Join(", ", parameters.ToArray())); }
protected override void setJSON(JObject obj, BaseClassIfc host, SetJsonOptions options) { base.setJSON(obj, host, options); obj["OuterBoundary"] = OuterBoundary.getJson(this, options); if (mInnerBoundaries.Count > 0) { obj["InnerBoundaries"] = new JArray(InnerBoundaries.ToList().ConvertAll(x => x.getJson(this, options))); } }
protected override void setJSON(JObject obj, BaseClassIfc host, SetJsonOptions options) { base.setJSON(obj, host, options); obj["BasisSurface"] = BasisSurface.getJson(this, options); obj["OuterBoundary"] = OuterBoundary.getJson(this, options); if (mInnerBoundaries.Count > 0) { obj["InnerBoundaries"] = new JArray(InnerBoundaries.Select(x => x.getJson(this, options))); } }
internal override void SetXML(XmlElement xml, BaseClassIfc host, Dictionary<string, XmlElement> processed) { base.SetXML(xml, host, processed); xml.AppendChild(OuterBoundary.GetXML(xml.OwnerDocument, "OuterBoundary", this, processed)); if (mInnerBoundaries.Count > 0) { XmlElement element = xml.OwnerDocument.CreateElement("InnerBoundaries", mDatabase.mXmlNamespace); xml.AppendChild(element); foreach (IfcCurve c in InnerBoundaries) element.AppendChild(c.GetXML(xml.OwnerDocument, "", this, processed)); } }
internal override void SetXML(XmlElement xml, BaseClassIfc host, HashSet <int> processed) { base.SetXML(xml, host, processed); xml.AppendChild(OuterBoundary.GetXML(xml.OwnerDocument, "OuterBoundary", this, processed)); if (mInnerBoundaries.Count > 0) { XmlElement element = xml.OwnerDocument.CreateElement("InnerBoundaries"); xml.AppendChild(element); foreach (IfcCurve c in InnerBoundaries) { element.AppendChild(c.GetXML(xml.OwnerDocument, "", this, processed)); } } }
public SharpKml.Dom.Polygon makeSimplePolygon(List <Vector> lstVct, AltitudeMode altMode) { var pg = new SharpKml.Dom.Polygon(); pg.Tessellate = true; pg.Extrude = true; pg.AltitudeMode = altMode; var linring = new LinearRing(); OuterBoundary obdr = new OuterBoundary(); linring.Coordinates = new CoordinateCollection(lstVct); obdr.LinearRing = linring; obdr.LinearRing.CalculateBounds(); pg.OuterBoundary = obdr; return(pg); }
/// <summary>Получить полигон</summary> /// <param name="polygon"></param> /// <param name="projection"></param> /// <returns></returns> public static Polygon GetKml(this TPolygon polygon, ProjectionInfo projection) { if (projection == null) { return(null); } if (polygon.Rings.Count == 0) { return(null); } var outher = new OuterBoundary { LinearRing = polygon.Rings[0].GetRingKml(projection) }; var kml = new Polygon { OuterBoundary = outher }; return(kml); }
public SharpKml.Dom.Polygon makeSimplePolygon(SharpKml.Dom.LineString lineString, AltitudeMode altMode) { List <Vector> lstVct = new List <Vector>(); lstVct.AddRange(lineString.Coordinates); lstVct.Add(lineString.Coordinates.First()); var pg = new SharpKml.Dom.Polygon(); pg.Extrude = true; pg.AltitudeMode = altMode; var linring = new LinearRing(); OuterBoundary obdr = new OuterBoundary(); linring.Coordinates = new CoordinateCollection(lstVct); obdr.LinearRing = linring; obdr.LinearRing.CalculateBounds(); pg.OuterBoundary = obdr; return(pg); }
private void btnOutputKML_Click(object sender, EventArgs e) { LinkedList <WayPoints> wp_list = _path.waypoints; int pcount = 0; int point_count = wp_list.Count; if (point_count > 0) { //double lat_center = Convert.ToDouble(txtCenterLat.Text); //double lon_center = Convert.ToDouble(txtCenterLon.Text); double lat, new_lat, start_lat; double lon, new_lon, start_lon; double image_len; double image_wid; image_len = (Math.Tan(GPS.DegreesToRadians(_options.focal_angle_hor / 2)) * 30.0); image_wid = (Math.Tan(GPS.DegreesToRadians(_options.focal_angle_ver / 2)) * 30.0); double alt; double bear; string location_name = txtKMLPath.Text; string filename = txtKMLFilePath.Text; Kml kml = new Kml(); Folder folder = new Folder(); SharpKml.Dom.Placemark placemark = new SharpKml.Dom.Placemark(); LineString linestring = new LineString(); var vector = new Vector(); CoordinateCollection coordinates = new CoordinateCollection(); Style path_style = new Style(); path_style.Polygon = new PolygonStyle(); path_style.Line = new LineStyle(); // Color32( alpha, blue, green, red path_style.Polygon.Color = new Color32(128, 255, 255, 0); path_style.Line.Color = new Color32(255, 255, 255, 0); linestring.AltitudeMode = AltitudeMode.RelativeToGround; linestring.Extrude = true; WayPoints point = new WayPoints(); do { point = wp_list.ElementAt(pcount); lat = point.lat; lon = point.lon; alt = point.alt; if (!_options.units_metric) { alt = GPS.FeetToMeters(alt); } vector = new Vector(lat, lon, alt); coordinates.Add(vector); pcount++; } while (pcount < point_count); linestring.Coordinates = coordinates; placemark.Geometry = linestring; placemark.AddStyle(path_style); placemark.Name = location_name; folder.AddFeature(placemark); // kml.Feature = placemark; /* Generate camera rectangles */ if (chkGenCamRect.Checked) { //image_len = 25; //image_wid = 50; double diag_ang = GPS.RadiansToDegrees(Math.Atan(image_len / image_wid)); double diag_len = Math.Sqrt((image_len * image_len) + (image_wid * image_wid)); double gps_radius; for (int i = 0; i < wp_list.Count; i++) { Style poly_style = new Style(); poly_style.Polygon = new PolygonStyle(); poly_style.Line = new LineStyle(); // Color32( alpha, blue, green, red poly_style.Polygon.Color = new Color32(128, 0, 255, 255); poly_style.Line.Color = new Color32(255, 0, 255, 255); Kml kml_rect = new Kml(); SharpKml.Dom.Placemark rect_placemark = new SharpKml.Dom.Placemark(); Polygon poly = new Polygon(); OuterBoundary outer = new OuterBoundary(); LinearRing line = new LinearRing(); CoordinateCollection coor = new CoordinateCollection(); poly.AltitudeMode = AltitudeMode.RelativeToGround; poly.Extrude = false; point = wp_list.ElementAt(i); lat = point.lat; lon = point.lon; alt = point.alt; gps_radius = _options.earth_radius + _options.def_elevation + alt; alt = 2; bear = point.head; coor.Clear(); new_lat = GPS.GPS_Lat_BearDist(lat, lon, diag_ang + bear, diag_len, gps_radius); new_lon = GPS.GPS_Lon_BearDist(lat, lon, new_lat, diag_ang + bear, diag_len, gps_radius); start_lat = new_lat; start_lon = new_lon; vector = new Vector(new_lat, new_lon, alt); coor.Add(vector); new_lat = GPS.GPS_Lat_BearDist(lat, lon, 180 - diag_ang + bear, diag_len, gps_radius); new_lon = GPS.GPS_Lon_BearDist(lat, lon, new_lat, 180 - diag_ang + bear, diag_len, gps_radius); vector = new Vector(new_lat, new_lon, alt); coor.Add(vector); new_lat = GPS.GPS_Lat_BearDist(lat, lon, 180 + diag_ang + bear, diag_len, gps_radius); new_lon = GPS.GPS_Lon_BearDist(lat, lon, new_lat, 180 + diag_ang + bear, diag_len, gps_radius); vector = new Vector(new_lat, new_lon, alt); coor.Add(vector); new_lat = GPS.GPS_Lat_BearDist(lat, lon, 360 - diag_ang + bear, diag_len, gps_radius); new_lon = GPS.GPS_Lon_BearDist(lat, lon, new_lat, 360 - diag_ang + bear, diag_len, gps_radius); vector = new Vector(new_lat, new_lon, alt); coor.Add(vector); vector = new Vector(start_lat, start_lon, alt); coor.Add(vector); line.Coordinates = coor; outer.LinearRing = line; poly.OuterBoundary = outer; rect_placemark.Geometry = poly; rect_placemark.AddStyle(poly_style); rect_placemark.Name = "WP " + Convert.ToString(i); folder.AddFeature(rect_placemark); } } kml.Feature = folder; Serializer serializer = new Serializer(); serializer.Serialize(kml); System.IO.File.WriteAllText(filename, serializer.Xml); } this.Close(); }