public PolygonFeature(
			string name, 
			World parentWorld, 
			LinearRing outerRing,
			LinearRing[] innerRings,
			System.Drawing.Color polygonColor) : base(name, parentWorld)
		{
			RenderPriority = WorldWind.Renderable.RenderPriority.LinePaths;
			m_outerRing = outerRing;
			m_innerRings = innerRings;
			m_polygonColor = polygonColor;

			double minY = double.MaxValue;
			double maxY = double.MinValue;
			double minX = double.MaxValue;
			double maxX = double.MinValue;
			double minZ = double.MaxValue;
			double maxZ = double.MinValue;

			for(int i = 0; i < m_outerRing.Points.Length; i++)
			{
				if(m_outerRing.Points[i].X < minX)
					minX = m_outerRing.Points[i].X;
				if(m_outerRing.Points[i].X > maxX)
					maxX = m_outerRing.Points[i].X;

				if(m_outerRing.Points[i].Y < minY)
					minY = m_outerRing.Points[i].Y;
				if(m_outerRing.Points[i].Y > maxY)
					maxY = m_outerRing.Points[i].Y;

				if(m_outerRing.Points[i].Z < minZ)
					minZ = m_outerRing.Points[i].Z;
				if(m_outerRing.Points[i].Z > maxZ)
					maxZ = m_outerRing.Points[i].Z;
			}
			
			// set a uniform Z for all the points
			for(int i = 0; i < m_outerRing.Points.Length; i++)
			{
				if(m_outerRing.Points[i].Z != maxZ)
					m_outerRing.Points[i].Z = maxZ;
			}

			if(m_innerRings != null && m_innerRings.Length > 0)
			{
				for(int n = 0; n < m_innerRings.Length; n++)
				{
					for(int i = 0; i < m_innerRings[n].Points.Length; i++)
					{
						if(m_innerRings[n].Points[i].Z != maxZ)
							m_innerRings[n].Points[i].Z = maxZ;
					}
				}
			}

			m_geographicBoundingBox = new GeographicBoundingBox(maxY, minY, minX, maxX, minZ, maxZ);

			minZ += parentWorld.EquatorialRadius;
			maxZ += parentWorld.EquatorialRadius;

			BoundingBox = new BoundingBox(
				(float)minY, (float)maxY, (float)minX, (float)maxX, (float)minZ, (float)maxZ);
		}
        public PolygonFeature(
            string name,
            World parentWorld,
            LinearRing outerRing,
            LinearRing[] innerRings,
            System.Drawing.Color polygonColor) : base(name, parentWorld)
        {
            RenderPriority = WorldWind.Renderable.RenderPriority.LinePaths;
            m_outerRing    = outerRing;
            m_innerRings   = innerRings;
            m_polygonColor = polygonColor;

            double minY = double.MaxValue;
            double maxY = double.MinValue;
            double minX = double.MaxValue;
            double maxX = double.MinValue;
            double minZ = double.MaxValue;
            double maxZ = double.MinValue;

            for (int i = 0; i < m_outerRing.Points.Length; i++)
            {
                if (m_outerRing.Points[i].X < minX)
                {
                    minX = m_outerRing.Points[i].X;
                }
                if (m_outerRing.Points[i].X > maxX)
                {
                    maxX = m_outerRing.Points[i].X;
                }

                if (m_outerRing.Points[i].Y < minY)
                {
                    minY = m_outerRing.Points[i].Y;
                }
                if (m_outerRing.Points[i].Y > maxY)
                {
                    maxY = m_outerRing.Points[i].Y;
                }

                if (m_outerRing.Points[i].Z < minZ)
                {
                    minZ = m_outerRing.Points[i].Z;
                }
                if (m_outerRing.Points[i].Z > maxZ)
                {
                    maxZ = m_outerRing.Points[i].Z;
                }
            }

            // set a uniform Z for all the points
            for (int i = 0; i < m_outerRing.Points.Length; i++)
            {
                if (m_outerRing.Points[i].Z != maxZ)
                {
                    m_outerRing.Points[i].Z = maxZ;
                }
            }

            if (m_innerRings != null && m_innerRings.Length > 0)
            {
                for (int n = 0; n < m_innerRings.Length; n++)
                {
                    for (int i = 0; i < m_innerRings[n].Points.Length; i++)
                    {
                        if (m_innerRings[n].Points[i].Z != maxZ)
                        {
                            m_innerRings[n].Points[i].Z = maxZ;
                        }
                    }
                }
            }

            m_geographicBoundingBox = new GeographicBoundingBox(maxY, minY, minX, maxX, minZ, maxZ);

            minZ += parentWorld.EquatorialRadius;
            maxZ += parentWorld.EquatorialRadius;

            BoundingBox = new BoundingBox(
                (float)minY, (float)maxY, (float)minX, (float)maxX, (float)minZ, (float)maxZ);
        }
		private static void addPolygonFeature(XPathNodeIterator iter, World parentWorld, RenderableObjectList parentRenderable)
		{
			if(iter.Count > 0)
			{
				while(iter.MoveNext())
				{
					string name = getInnerTextFromFirstChild(iter.Current.Select("Name"));
					
					string distanceAboveSurfaceString = getInnerTextFromFirstChild(iter.Current.Select("DistanceAboveSurface"));
					string minimumDisplayAltitudeString = getInnerTextFromFirstChild(iter.Current.Select("MinimumDisplayAltitude"));
					string maximumDisplayAltitudeString = getInnerTextFromFirstChild(iter.Current.Select("MaximumDisplayAltitude"));
					string opacityString = getInnerTextFromFirstChild(iter.Current.Select("Opacity"));
					string extrudeHeightString = getInnerTextFromFirstChild(iter.Current.Select("ExtrudeHeight"));
					string extrudeUpwardsString = getInnerTextFromFirstChild(iter.Current.Select("ExtrudeUpwards"));
					string imageUri = getInnerTextFromFirstChild(iter.Current.Select("ImageUri"));
					string outlineString = getInnerTextFromFirstChild(iter.Current.Select("Outline"));

					XPathNodeIterator posListIter = iter.Current.Select("exterior/LinearRing/posList");
					posListIter.MoveNext();

					string lineString = getInnerTextFromFirstChild(posListIter);
					
					string[] lineParts = lineString.Split(' ');
					Point3d[] points = new Point3d[lineParts.Length];
					
					for(int i = 0; i < lineParts.Length; i++)
					{
						string[] pointParts = lineParts[i].Split(',');
						points[i] = new Point3d();
						points[i].X = ParseDouble(pointParts[0]);
						points[i].Y = ParseDouble(pointParts[1]);
						
						if(pointParts.Length > 2)
							points[i].Z = ParseDouble(pointParts[2]);

					}

					System.Drawing.Color c = System.Drawing.Color.Black;
					System.Drawing.Color outlineColor = System.Drawing.Color.Black;
					
					if(iter.Current.Select("FeatureColor").Count > 0)
					{
						c =	getColor(iter.Current.Select("FeatureColor"));
					}

					if(iter.Current.Select("OutlineColor").Count > 0)
					{
						outlineColor =	getColor(iter.Current.Select("OutlineColor"));
					}

					PolygonFeature pf = null;
					
					LinearRing outerRing = new LinearRing();
					outerRing.Points = points;

					pf = new PolygonFeature(name, parentWorld, outerRing, null, c);

					pf.OutlineColor = outlineColor;

					if(outlineString != null && outlineString.Length > 0)
						pf.Outline = ParseBool(outlineString);

					if(opacityString != null && opacityString.Length > 0)
						pf.Opacity = byte.Parse(opacityString);

					if(distanceAboveSurfaceString != null && distanceAboveSurfaceString.Length > 0)
						pf.DistanceAboveSurface = ParseDouble(distanceAboveSurfaceString);

					if(minimumDisplayAltitudeString != null && minimumDisplayAltitudeString.Length > 0)
						pf.MinimumDisplayAltitude = ParseDouble(minimumDisplayAltitudeString);

					if(maximumDisplayAltitudeString != null && maximumDisplayAltitudeString.Length > 0)
						pf.MaximumDisplayAltitude = ParseDouble(maximumDisplayAltitudeString);

					string description = getInnerTextFromFirstChild(iter.Current.Select("Description"));
					if(description != null && description.Length > 0)
						pf.Description = description;

					addExtendedInformation(iter.Current.Select("ExtendedInformation"), pf);

					string infoUri = iter.Current.GetAttribute("InfoUri", "");

					if(infoUri != null && infoUri.Length > 0)
					{
						if(pf.MetaData.Contains("InfoUri"))
						{
							pf.MetaData["InfoUri"] = infoUri;
						}
						else
						{
							pf.MetaData.Add("InfoUri", infoUri);
						}
					}

					pf.MetaData.Add("XmlSource", (string)parentRenderable.MetaData["XmlSource"]);
					pf.ParentList = parentRenderable;

					if(World.Settings.useDefaultLayerStates)
					{
						pf.IsOn = ParseBool(iter.Current.GetAttribute("ShowAtStartup", ""));
					}
					else
					{
						pf.IsOn = IsLayerOn(pf);
					}
					parentRenderable.ChildObjects.Add(
						pf
						);

					parentRenderable.RenderPriority = RenderPriority.LinePaths;
					
				}
			}
		}
        public override void Initialize(DrawArgs drawArgs)
        {

            if (m_polygonFeature == null)
            {

                double offset = 0.02;

                Point3d[] points = new Point3d[4];



                points[0] = new Point3d(

                    m_longitude - offset,

                    m_latitude - offset,

                    200000);



                points[1] = new Point3d(

                    m_longitude - offset,

                    m_latitude + offset,

                    200000);



                points[2] = new Point3d(

                    m_longitude + offset,

                    m_latitude + offset,

                    200000);



                points[3] = new Point3d(

                    m_longitude + offset,

                    m_latitude - offset,

                    200000);



                LinearRing outerRing = new LinearRing();

                outerRing.Points = points;



                m_polygonFeature = new PolygonFeature(

                    name,

                    World,

                    outerRing,

                    null,

                    System.Drawing.Color.Chocolate);



                m_polygonFeature.AltitudeMode = AltitudeMode.Absolute;

                m_polygonFeature.Extrude = true;

                m_polygonFeature.Outline = true;

                m_polygonFeature.OutlineColor = System.Drawing.Color.Chocolate;



            }



            FileInfo savedFlagFile = new FileInfo(SavedImagePath);

            FileInfo placeHolderFile = new FileInfo(SavedImagePath + ".blk");



            if (savedFlagFile.Exists)
            {

                try
                {

                    m_texture = ImageHelper.LoadTexture(

                        savedFlagFile.FullName,

                        System.Drawing.Color.Black.ToArgb());

                }

                catch
                {

                    savedFlagFile.Delete();

                    savedFlagFile.Refresh();

                }

            }



            if (!savedFlagFile.Exists && !placeHolderFile.Exists)
            {

                if (!savedFlagFile.Directory.Exists)

                    savedFlagFile.Directory.Create();



                try
                {

                    WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(m_imageUri);

                    download.DownloadFile(savedFlagFile.FullName);

                    download.Dispose();



                    savedFlagFile.Refresh();

                }

                catch
                {

                    FileStream fs = placeHolderFile.Create();

                    fs.Close();

                    fs = null;



                    placeHolderFile.Refresh();

                }



                if (savedFlagFile.Exists)
                {

                    m_texture = ImageHelper.LoadTexture(

                        savedFlagFile.FullName,

                        System.Drawing.Color.Black.ToArgb());

                }

            }



            UpdateVertices();

            isInitialized = true;

        }
Beispiel #5
0
        private static LinearRing[] GetInnerBoundaries(KMLPolygon oCastSource)
        {
            LinearRing[] result = new LinearRing[oCastSource.InnerBoundaries.Count];

            for (int count = 0; count < oCastSource.InnerBoundaries.Count; count++)
            {
                result[count] = new LinearRing(GetPoints(oCastSource.InnerBoundaries[count]));
            }

            return result;
        }
Beispiel #6
0
		/// <summary>
		/// Parses Multi Polygons
		/// </summary>
		/// <param name="inNode">The node containing Polygons</param>
		/// <param name="layer">The layer to add the resulting Polygons to</param>
		private void ParseMultiGeometry(XmlNode inNode, RIcons layer)
		{
			// Parse all Placemarks that have a name and Polygon
			XmlNodeList placemarkNodes = inNode.SelectNodes("Placemark[name and MultiGeometry]");
			Random rand = new Random((int)DateTime.Now.Ticks);

			foreach(XmlNode placemarkNode in placemarkNodes)
			{
				XmlNode nameNode = placemarkNode.SelectSingleNode("name");
				string name = nameNode.InnerText;

				// change this to something that unifies the geometry into a single object instead of a user-accessible list
				RIcons multiGeometryList = new RIcons(name);

				Style style = null;

				// get StyleUrl
				XmlNode styleUrlNode = placemarkNode.SelectSingleNode("styleUrl");
				if(styleUrlNode != null)
				{
					string styleUrlKey = styleUrlNode.InnerText.Trim();
					if(styleUrlKey.StartsWith("#"))
						styleUrlKey = styleUrlKey.Substring(1, styleUrlKey.Length - 1);

					style = (Style)iconStyles[styleUrlKey];
				}
				else
				{
					XmlNode styleNode = placemarkNode.SelectSingleNode("Style");
					if(styleNode != null)
						style = GetStyle( styleNode, new Style(), "");
				}

				if(style == null)
					style = new Style();
				
				if(style.LineStyle == null)
					style.LineStyle = new LineStyle();

				if(style.PolyStyle == null)
					style.PolyStyle = new PolyStyle();

				XmlNodeList lineStringNodes = placemarkNode.SelectNodes("MultiGeometry/LineString");
				foreach(XmlNode lineStringNode in lineStringNodes)
				{
					bool extrude = false;
					XmlNode extrudeNode = lineStringNode.SelectSingleNode("extrude");
					if (extrudeNode != null)
						extrude = Convert.ToBoolean(Convert.ToInt16(extrudeNode.InnerText));

					XmlNode coordinateNode = lineStringNode.SelectSingleNode("coordinates");
					Point3d[] points = ParseCoordinates(coordinateNode);

					XmlNode altitudeModeNode = lineStringNode.SelectSingleNode("altitudeMode");
					AltitudeMode altitudeMode = GetAltitudeMode(altitudeModeNode);

					if(points != null && points.Length > 0)
					{
						LineFeature line = new LineFeature(
							name, 
							m_world, 
							points,
							System.Drawing.Color.FromArgb(style.LineStyle.Color.Color)
							);

						line.AltitudeMode = altitudeMode;
						if(style.PolyStyle.Color != null)
							line.PolygonColor = System.Drawing.Color.FromArgb(style.PolyStyle.Color.Color);
						
						line.LineWidth = (float)style.LineStyle.Width.Value;
						line.Extrude = extrude;

						multiGeometryList.Add(line);
					}
				}

				XmlNodeList polygonNodes = placemarkNode.SelectNodes("MultiGeometry/Polygon");
				foreach(XmlNode polygonNode in polygonNodes)
				{
					bool extrude = false;
					XmlNode extrudeNode = polygonNode.SelectSingleNode("extrude");
					if (extrudeNode != null)
						extrude = Convert.ToBoolean(Convert.ToInt16(extrudeNode.InnerText));

					XmlNode altitudeModeNode = polygonNode.SelectSingleNode("altitudeMode");
					AltitudeMode altitudeMode = GetAltitudeMode(altitudeModeNode);

					LinearRing outerRing = null;
					LinearRing[] innerRings = null;

					// Parse Outer Ring
					XmlNode outerRingNode = polygonNode.SelectSingleNode("outerBoundaryIs/LinearRing/coordinates");
					if (outerRingNode != null)
					{
						Point3d[] points = ParseCoordinates(outerRingNode);
						
						outerRing = new LinearRing();
						outerRing.Points = points;
					}
					
					// Parse Inner Ring
					XmlNodeList innerRingNodes = polygonNode.SelectNodes("innerBoundaryIs");
					if (innerRingNodes != null)
					{
						innerRings = new LinearRing[innerRingNodes.Count];
						for(int i = 0; i < innerRingNodes.Count; i++)
						{
							Point3d[] points = ParseCoordinates(innerRingNodes[i]);

							innerRings[i] = new LinearRing();
							innerRings[i].Points = points;
						}
					}

					if(outerRing != null)
					{
						PolygonFeature polygonFeature = new PolygonFeature(
							name, 
							m_world,
							outerRing,
							innerRings,
							(style.PolyStyle.Color != null ? System.Drawing.Color.FromArgb(style.PolyStyle.Color.Color) : System.Drawing.Color.Yellow)
							);

						polygonFeature.Extrude = extrude;
						polygonFeature.AltitudeMode = altitudeMode;
						polygonFeature.Outline = style.PolyStyle.Outline;
						if(style.LineStyle.Color != null)
							polygonFeature.OutlineColor = System.Drawing.Color.FromArgb(style.LineStyle.Color.Color);

						multiGeometryList.Add(polygonFeature);
					}
				}

				XmlNode visibilityNode = placemarkNode.SelectSingleNode("visibility");
				if(visibilityNode != null)
					multiGeometryList.IsOn = (visibilityNode.InnerText == "1" ? true : false);

				layer.Add(multiGeometryList);
			}
		}
Beispiel #7
0
		/// <summary>
		/// Parses Polygons
		/// </summary>
		/// <param name="inNode">The node containing Polygons</param>
		/// <param name="layer">The layer to add the resulting Polygons to</param>
		private void ParsePolygons(XmlNode inNode, RIcons layer)
		{
			// Parse all Placemarks that have a name and Polygon
			XmlNodeList polygons = inNode.SelectNodes("Placemark[name and Polygon]");
			Random rand = new Random((int)DateTime.Now.Ticks);

			foreach (XmlNode node in polygons)
			{
				// Extract the name from this node
				XmlNode nameNode = node.SelectSingleNode("name");
				string name = nameNode.InnerText;
				
				Style style = null;

				// get StyleUrl
				XmlNode styleUrlNode = node.SelectSingleNode("styleUrl");
				if(styleUrlNode != null)
				{
					string styleUrlKey = styleUrlNode.InnerText.Trim();
					if(styleUrlKey.StartsWith("#"))
						styleUrlKey = styleUrlKey.Substring(1, styleUrlKey.Length - 1);

					style = (Style)iconStyles[styleUrlKey];
				}
				else
				{
					XmlNode styleNode = node.SelectSingleNode("Style");
					if(styleNode != null)
						style = GetStyle( styleNode, new Style(), "");
				}

				if(style == null)
					style = new Style();
				
				if(style.LineStyle == null)
					style.LineStyle = new LineStyle();

				if(style.PolyStyle == null)
					style.PolyStyle = new PolyStyle();

				// See if this LineString has to be extruded to the ground
				bool extrude = false;
				
				XmlNode extrudeNode = node.SelectSingleNode("Polygon/extrude");
				if (extrudeNode != null)
					extrude = Convert.ToBoolean(Convert.ToInt16(extrudeNode.InnerText));

				XmlNode altitudeModeNode = node.SelectSingleNode("Polygon/altitudeMode");
				AltitudeMode altitudeMode = GetAltitudeMode(altitudeModeNode);

				LinearRing outerRing = null;
				LinearRing[] innerRings = null;

				// Parse Outer Ring
				XmlNode outerRingNode = node.SelectSingleNode("Polygon/outerBoundaryIs/LinearRing/coordinates");
				if (outerRingNode != null)
				{
					Point3d[] points = ParseCoordinates(outerRingNode);
					Console.WriteLine(points.Length);

					outerRing = new LinearRing();
					outerRing.Points = points;
				}

				// Parse Inner Ring
				XmlNodeList innerRingNodes = node.SelectNodes("Polygon/innerBoundaryIs");
				if (innerRingNodes != null)
				{
					innerRings = new LinearRing[innerRingNodes.Count];
					for(int i = 0; i < innerRingNodes.Count; i++)
					{
						Point3d[] points = ParseCoordinates(innerRingNodes[i]);
						innerRings[i] = new LinearRing();
						innerRings[i].Points = points;
					}
				}

				if(outerRing != null)
				{
					PolygonFeature polygonFeature = new PolygonFeature(
						name, m_world,
						outerRing,
						innerRings,
						System.Drawing.Color.FromArgb(style.PolyStyle.Color.Color));

					polygonFeature.Extrude = extrude;
					polygonFeature.AltitudeMode = altitudeMode;
					polygonFeature.Outline = style.PolyStyle.Outline;
					if(style.LineStyle.Color != null)
						polygonFeature.OutlineColor = System.Drawing.Color.FromArgb(style.LineStyle.Color.Color);

					XmlNode visibilityNode = node.SelectSingleNode("visibility");
					if(visibilityNode != null)
						polygonFeature.IsOn = (visibilityNode.InnerText == "1" ? true : false);

					layer.Add(polygonFeature);
				}
			}
		}