Beispiel #1
0
 private void drawLineString(LineString lineString, Graphics g, GeographicBoundingBox dstBB, Size imageSize)
 {
     using (Pen p = new Pen(lineString.Color, lineString.LineWidth))
     {
         g.DrawLines(p, this.getScreenPoints(lineString.Coordinates, 0, lineString.Coordinates.Length, dstBB, imageSize));
     }
 }
Beispiel #2
0
        private bool isShapeRecordInBounds(GeographicBoundingBox geoBB, ShapeRecord record)
        {
            if (record.Point != null)
            {
                if (record.Point.X < geoBB.West || record.Point.X > geoBB.East ||
                    record.Point.Y > geoBB.North || record.Point.Y < geoBB.South)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else if (record.MultiPoint != null)
            {
                if (record.MultiPoint.BoundingBox.North <= geoBB.South ||
                    record.MultiPoint.BoundingBox.South >= geoBB.North ||
                    record.MultiPoint.BoundingBox.West >= geoBB.East ||
                    record.MultiPoint.BoundingBox.East <= geoBB.West)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else if (record.PolyLine != null)
            {
                if (record.PolyLine.BoundingBox.North <= geoBB.South ||
                    record.PolyLine.BoundingBox.South >= geoBB.North ||
                    record.PolyLine.BoundingBox.West >= geoBB.East ||
                    record.PolyLine.BoundingBox.East <= geoBB.West)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else if (record.Polygon != null)
            {
                if (record.Polygon.BoundingBox.North <= geoBB.South ||
                    record.Polygon.BoundingBox.South >= geoBB.North ||
                    record.Polygon.BoundingBox.West >= geoBB.East ||
                    record.Polygon.BoundingBox.East <= geoBB.West)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
        public ProjectedVectorTile(
            GeographicBoundingBox geographicBoundingBox,
            ProjectedVectorRenderer parentLayer
            )
        {
            m_geographicBoundingBox = geographicBoundingBox;
            m_parentProjectedLayer  = parentLayer;

            BoundingBox = new BoundingBox((float)geographicBoundingBox.South, (float)geographicBoundingBox.North, (float)geographicBoundingBox.West, (float)geographicBoundingBox.East,
                                          (float)(parentLayer.World.EquatorialRadius + geographicBoundingBox.MinimumAltitude), (float)(parentLayer.World.EquatorialRadius + geographicBoundingBox.MaximumAltitude + 300000f));
        }
Beispiel #4
0
        public ShapeTile(
            GeographicBoundingBox geoBB,
            ShapeTileArgs shapeTileArgs
            )
        {
            m_GeoBB         = geoBB;
            m_ShapeTileArgs = shapeTileArgs;

            BoundingBox = new BoundingBox((float)geoBB.South, (float)geoBB.North, (float)geoBB.West, (float)geoBB.East,
                                          (float)m_ShapeTileArgs.LayerRadius, (float)m_ShapeTileArgs.LayerRadius + 300000f);
        }
        internal ProjectedVectorTile(
            GeographicBoundingBox geographicBoundingBox,
            ProjectedVectorRenderer parentLayer
            )
        {
            m_geographicBoundingBox = geographicBoundingBox;
            m_parentProjectedLayer = parentLayer;

            BoundingBox = new BoundingBox( (float)geographicBoundingBox.South, (float)geographicBoundingBox.North, (float)geographicBoundingBox.West, (float)geographicBoundingBox.East,
                (float)(parentLayer.World.EquatorialRadius + geographicBoundingBox.MinimumAltitude), (float)(parentLayer.World.EquatorialRadius + geographicBoundingBox.MaximumAltitude + 300000f));
        }
Beispiel #6
0
		public ShapeTile(
			GeographicBoundingBox geoBB,
			ShapeTileArgs shapeTileArgs
			)
		{
			m_GeoBB = geoBB;
			m_ShapeTileArgs = shapeTileArgs;

			BoundingBox = new BoundingBox( (float)geoBB.South, (float)geoBB.North, (float)geoBB.West, (float)geoBB.East, 
				(float)m_ShapeTileArgs.LayerRadius, (float)m_ShapeTileArgs.LayerRadius + 300000f);
		}
Beispiel #7
0
        internal ArcIMSLayerModelNode(DappleModel oModel, String strTitle, String strID, GeographicBoundingBox oBounds, double dMinScale, double dMaxScale, CultureInfo oCultureInfo)
            : base(oModel)
        {
            m_strTitle = strTitle;
            m_strID = strID;
            m_oBounds = oBounds;
            m_dMinScale = dMinScale;
            m_dMaxScale = dMaxScale;
            m_oCultureInfo = oCultureInfo;

            MarkLoaded();
        }
        private void drawPolygon(Polygon polygon, Graphics g, GeographicBoundingBox dstBB, Size imageSize)
        {
            if (polygon.innerBoundaries != null && polygon.innerBoundaries.Length > 0)
            {
                if (polygon.Fill)
                {
                    using (SolidBrush brush = new SolidBrush(polygon.PolgonColor))
                    {
                        g.FillPolygon(brush, getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }

                if (polygon.Outline)
                {
                    using (Pen p = new Pen(polygon.OutlineColor, polygon.LineWidth))
                    {
                        g.DrawPolygon(p,
                                      getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }

                if (polygon.Fill)
                {
                    using (SolidBrush brush = new SolidBrush(System.Drawing.Color.Black))
                    {
                        for (int i = 0; i < polygon.innerBoundaries.Length; i++)
                        {
                            g.FillPolygon(brush,
                                          getScreenPoints(polygon.innerBoundaries[i].Points, 0, polygon.innerBoundaries[i].Points.Length, dstBB, imageSize)
                                          );
                        }
                    }
                }
            }
            else
            {
                if (polygon.Fill)
                {
                    using (SolidBrush brush = new SolidBrush(polygon.PolgonColor))
                    {
                        g.FillPolygon(brush, getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }

                if (polygon.Outline)
                {
                    using (Pen p = new Pen(polygon.OutlineColor, polygon.LineWidth))
                    {
                        g.DrawPolygon(p, getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }
            }
        }
Beispiel #9
0
        internal int iGetLayerCount(bool bInterSect, WorldWind.GeographicBoundingBox extents, string strText)
        {
            int iCount = 0;

            if (strText == null)
            {
                strText = String.Empty;
            }

            GetLayerCount(bInterSect, extents, strText, ref iCount);

            return(iCount);
        }
Beispiel #10
0
 public bool Intersects(GeographicBoundingBox boundingBox)
 {
     if (North <= boundingBox.South ||
         South >= boundingBox.North ||
         West >= boundingBox.East ||
         East <= boundingBox.West)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
		public bool Intersects(GeographicBoundingBox boundingBox)
		{
			if(North <= boundingBox.South ||
				South >= boundingBox.North ||
				West >= boundingBox.East ||
				East <= boundingBox.West)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
Beispiel #12
0
        internal ImageTileLayerModelNode(DappleModel oModel, String strName, Uri oUri, String strExtension, double dLZTS, String strDataset, int iLevels, GeographicBoundingBox oBounds, int iDistanceAboveSurface, int iTextureSize)
            : base(oModel)
        {
            m_strName = strName;
            m_oUri = oUri;
            m_strExtension = strExtension;
            m_dLZTS = dLZTS;
            m_strDataset = strDataset;
            m_iLevels = iLevels;
            m_oBounds = oBounds;
            m_iDistanceAboveSurface = iDistanceAboveSurface;
            m_iTextureSize = iTextureSize;

            MarkLoaded();
        }
Beispiel #13
0
        /// <summary>
        /// Constructor.
        /// </summary>
        internal ServerList()
        {
            InitializeComponent();

            c_lvLayers.SmallImageList = Dapple.MainForm.DataTypeImageList;
            c_lvLayers.LargeImageList = Dapple.MainForm.DataTypeImageList;

            c_oPageNavigator.PageBack += BackPage;
            c_oPageNavigator.PageForward += ForwardPage;

            m_strSearchString = String.Empty;
            m_oSearchBox = null;

            m_oDragDropStartPoint = Point.Empty;

            SetNoServer();
        }
Beispiel #14
0
        private void GetLayerCount(bool bInterSect, WorldWind.GeographicBoundingBox extents, string strText, ref int iCount)
        {
            if (strText == null)
            {
                throw new ArgumentNullException("strText");
            }

            foreach (IBuilder builder in SubList)
            {
                (builder as BuilderDirectory).GetLayerCount(bInterSect, extents, strText, ref iCount);
            }
            foreach (LayerBuilder builder in LayerBuilders)
            {
                if ((strText != string.Empty && builder.Title.IndexOf(strText, 0, StringComparison.InvariantCultureIgnoreCase) == -1) ||
                    (extents != null && bInterSect && !extents.Intersects(builder.Extents) && !extents.Contains(builder.Extents)))
                {
                    continue;
                }

                iCount++;
            }
        }
Beispiel #15
0
        private void drawPolyLine(Shapefile_PolyLine polyLine, Graphics g, Color c, GeographicBoundingBox dstBB, Size imageSize)
        {
            using (Pen p = new Pen(c, m_ShapeTileArgs.LineWidth))
            {
                p.Color = c;
                if (polyLine.Parts.Length > 1)
                {
                    for (int partsItr = 0; partsItr < polyLine.Parts.Length - 1; partsItr++)
                    {
                        g.DrawLines(p,
                                    getScreenPoints(polyLine.Points, polyLine.Parts[partsItr], polyLine.Parts[partsItr + 1] - polyLine.Parts[partsItr], dstBB, imageSize));
                    }

                    g.DrawLines(p,
                                getScreenPoints(polyLine.Points, polyLine.Parts[polyLine.Parts.Length - 1],
                                                polyLine.Points.Length - polyLine.Parts[polyLine.Parts.Length - 1], dstBB, imageSize));
                }
                else
                {
                    g.DrawLines(p, getScreenPoints(polyLine.Points, 0, polyLine.Points.Length, dstBB, imageSize));
                }
            }
        }
Beispiel #16
0
		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);
        }
Beispiel #18
0
        private void drawPolygon(Polygon polygon, Graphics g, GeographicBoundingBox dstBB, Size imageSize)
        {
            if(polygon.innerBoundaries != null && polygon.innerBoundaries.Length > 0)
            {
                if(polygon.Fill)
                {
                    using(SolidBrush brush = new SolidBrush(polygon.PolgonColor))
                    {
                        g.FillPolygon(brush, getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }

                if(polygon.Outline)
                {
                    using(Pen p = new Pen(polygon.OutlineColor, polygon.LineWidth))
                    {
                        g.DrawPolygon(p,
                                getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }

                if(polygon.Fill)
                {
                    using(SolidBrush brush = new SolidBrush(System.Drawing.Color.Black))
                    {
                        for(int i = 0; i < polygon.innerBoundaries.Length; i++)
                        {
                            g.FillPolygon(brush,
                                getScreenPoints(polygon.innerBoundaries[i].Points, 0, polygon.innerBoundaries[i].Points.Length, dstBB, imageSize)
                                );
                        }
                    }
                }
            }
            else
            {
                if(polygon.Fill)
                {
                    using(SolidBrush brush = new SolidBrush(polygon.PolgonColor))
                    {
                        g.FillPolygon(brush, getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }

                if(polygon.Outline)
                {
                    using(Pen p = new Pen(polygon.OutlineColor, polygon.LineWidth))
                    {
                        g.DrawPolygon(p, getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }
            }
        }
Beispiel #19
0
        private Renderable.ImageLayer CreateImageLayer(double north, double south, double west, double east, DrawArgs drawArgs, string imagePath)
        {
            Bitmap   b = null;
            Graphics g = null;

            Renderable.ImageLayer imageLayer = null;
            GeographicBoundingBox geoBB      = new GeographicBoundingBox(north, south, west, east);

            int numberPolygonsInTile = 0;

            FileInfo imageFile    = new FileInfo(imagePath);
            FileInfo shapeFile    = new FileInfo(m_ShapeTileArgs.ParentShapeFileLayer.ShapeFilePath);
            FileInfo shapeXmlFile = null;

            if (m_ShapeTileArgs.ParentShapeFileLayer.MetaData.Contains("SourceXml"))
            {
                string sourceXml = (string)m_ShapeTileArgs.ParentShapeFileLayer.MetaData["SourceXml"];
                if (!sourceXml.ToLower().StartsWith("http://"))
                {
                    shapeXmlFile = new FileInfo(sourceXml);
                }
            }

            if (!m_ShapeTileArgs.ParentShapeFileLayer.EnableCaching ||
                !imageFile.Exists ||
                shapeXmlFile == null ||
                shapeXmlFile.LastWriteTimeUtc > imageFile.LastWriteTimeUtc ||
                shapeFile.LastWriteTimeUtc > imageFile.LastWriteTimeUtc
                )
            {
                for (int i = 0; i < m_ShapeTileArgs.ShapeRecords.Count; i++)
                {
                    ShapeRecord currentRecord = (ShapeRecord)m_ShapeTileArgs.ShapeRecords[i];

                    if (currentRecord.Null != null ||
                        currentRecord.Point != null ||
                        currentRecord.MultiPoint != null ||
                        !isShapeRecordInBounds(geoBB, currentRecord))
                    {
                        continue;
                    }
                    else
                    {
                        if (b == null)
                        {
                            b = new Bitmap(m_ShapeTileArgs.TilePixelSize.Width,
                                           m_ShapeTileArgs.TilePixelSize.Height,
                                           System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                        }

                        if (g == null)
                        {
                            g = Graphics.FromImage(b);
                        }

                        System.Drawing.Color color = m_ShapeTileArgs.PolygonColor;

                        //Fix Black Tiles
                        g.DrawLine(new Pen(color), 0, 0, 1, 1);


                        if (m_ShapeTileArgs.UseScalar && m_ShapeTileArgs.ScaleColors)
                        {
                            double red   = 1.0;
                            double green = 1.0;
                            double blue  = 1.0;

                            try
                            {
                                //TODO: make this a function and abstract to allow multiple gradient mappings
                                double dv;

                                double curScalar = double.Parse(currentRecord.Value.ToString());

                                if (curScalar < m_ShapeTileArgs.ScaleMin)
                                {
                                    curScalar = m_ShapeTileArgs.ScaleMin;
                                }
                                if (curScalar > m_ShapeTileArgs.ScaleMax)
                                {
                                    curScalar = m_ShapeTileArgs.ScaleMax;
                                }

                                dv = m_ShapeTileArgs.ScaleMax - m_ShapeTileArgs.ScaleMin;

                                if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.25 * dv))
                                {
                                    red   = 0;
                                    green = 4 * (curScalar - m_ShapeTileArgs.ScaleMin) / dv;
                                }
                                else if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.5 * dv))
                                {
                                    red  = 0;
                                    blue = 1 + 4 * (m_ShapeTileArgs.ScaleMin + 0.25 * dv - curScalar) / dv;
                                }
                                else if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.75 * dv))
                                {
                                    red  = 4 * (curScalar - m_ShapeTileArgs.ScaleMin - 0.5 * dv) / dv;
                                    blue = 0;
                                }
                                else
                                {
                                    green = 1 + 4 * (m_ShapeTileArgs.ScaleMin + 0.75 * dv - curScalar) / dv;
                                    blue  = 0;
                                }

                                color = System.Drawing.Color.FromArgb((int)(255 * red), (int)(255 * green), (int)(255 * blue));
                            }
                            catch (Exception)
                            {
                                //	Utility.Log.Write((string)currentPoly.ScalarHash[m_ShapeTileArgs.ColorKey]);
                                //	Utility.Log.Write(String.Format("Min: {0}, Max: {1}", m_ShapeTileArgs.ScaleMin, m_ShapeTileArgs.ScaleMax));
                                //	Utility.Log.Write(String.Format("{0},{1},{2}", red, green, blue));
                                //	Utility.Log.Write(ex);
                            }
                        }
                        else
                        {
                            if (m_ShapeTileArgs.ColorAssignments.Count > 0 && m_ShapeTileArgs.ScaleColors)
                            {
                                try
                                {
                                    string colorAssignmentKey = (string)currentRecord.Value;
                                    foreach (string cak in m_ShapeTileArgs.ColorAssignments.Keys)
                                    {
                                        if (String.Compare(cak, colorAssignmentKey, true) == 0)
                                        {
                                            color = (System.Drawing.Color)m_ShapeTileArgs.ColorAssignments[cak];
                                            break;
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }

                        if (currentRecord.Polygon != null)
                        {
                            drawPolygon(currentRecord.Polygon,
                                        g,
                                        color,
                                        geoBB,
                                        b.Size);
                        }

                        if (m_ShapeTileArgs.ColorAssignments.Count == 0 ||
                            !m_ShapeTileArgs.ScaleColors)
                        {
                            color = m_ShapeTileArgs.LineColor;
                        }

                        if (currentRecord.PolyLine != null)
                        {
                            drawPolyLine(currentRecord.PolyLine,
                                         g,
                                         color,
                                         geoBB,
                                         b.Size);
                        }
                        numberPolygonsInTile++;
                    }
                }
            }

            if (!m_ShapeTileArgs.ParentShapeFileLayer.EnableCaching)
            {
                string id = System.DateTime.Now.Ticks.ToString();

                if (b != null)
                {
                    MemoryStream ms = new MemoryStream();

                    //must copy original stream into new stream, if not, error occurs, not sure why
                    m_ImageStream = new MemoryStream(ms.GetBuffer());

                    imageLayer = new WorldWind.Renderable.ImageLayer(
                        id,
                        m_ShapeTileArgs.ParentWorld,
                        0,
                        m_ImageStream,
                        System.Drawing.Color.Black.ToArgb(),
                        (float)south,
                        (float)north,
                        (float)west,
                        (float)east,
                        (float)m_ShapeTileArgs.ParentShapeFileLayer.Opacity / 255.0f,
                        m_ShapeTileArgs.ParentWorld.TerrainAccessor);

                    ms.Close();
                }
            }
            else if (imageFile.Exists || numberPolygonsInTile > 0)
            {
                string id = System.DateTime.Now.Ticks.ToString();

                if (b != null)
                {
                    MemoryStream ms = new MemoryStream();
                    b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                    if (!imageFile.Directory.Exists)
                    {
                        imageFile.Directory.Create();
                    }

                    //must copy original stream into new stream, if not, error occurs, not sure why
                    m_ImageStream = new MemoryStream(ms.GetBuffer());
                    ImageHelper.ConvertToDxt3(m_ImageStream, imageFile.FullName);

                    ms.Close();
                }

                imageLayer = new WorldWind.Renderable.ImageLayer(
                    id,
                    m_ShapeTileArgs.ParentWorld,
                    0,                    // should be distance above surface
                    imageFile.FullName,   //m_ImageStream,
                    //0,//System.Drawing.Color.Black.ToArgb(),
                    (float)south,
                    (float)north,
                    (float)west,
                    (float)east,
                    (float)m_ShapeTileArgs.ParentShapeFileLayer.Opacity / 255.0f,
                    m_ShapeTileArgs.ParentWorld.TerrainAccessor);
            }

            if (b != null)
            {
                b.Dispose();
            }
            if (g != null)
            {
                g.Dispose();
            }

            b = null;
            g = null;

            //might not be necessary
            //GC.Collect();

            return(imageLayer);
        }
Beispiel #20
0
        internal ArcIMSLayerUri ToLayerUri(String strServiceName, GeographicBoundingBox oBox)
        {
            String strUri = base.ToString()
                + (base.ToString().IndexOf("?") > 0 ? "&" : "?")
                + "ServiceName=" + strServiceName
                + "&minx=" + oBox.West
                + "&miny=" + oBox.South
                + "&maxx=" + oBox.East
                + "&maxy=" + oBox.North;

            return new ArcIMSLayerUri(strUri);
        }
 public void Union(GeographicBoundingBox other)
 {
     this.North = Math.Max(this.North, other.North);
     this.South = Math.Min(this.South, other.South);
     this.East = Math.Max(this.East, other.East);
     this.West = Math.Min(this.West, other.West);
     this.MaximumAltitude = Math.Max(this.MaximumAltitude, other.MaximumAltitude);
     this.MinimumAltitude = Math.Min(this.MinimumAltitude, other.MinimumAltitude);
 }
 public bool Equivalent(GeographicBoundingBox other, double tolerance)
 {
     return this.North - other.North < tolerance && this.East - other.East < tolerance && this.South - other.South < tolerance && this.West - other.West < tolerance;
 }
        /*public byte Opacity
         * {
         *      get
         *      {
         *              return m_parentProjectedLayer.Opacity;
         *      }
         *      set
         *      {
         *              if(m_NwImageLayer != null)
         *              {
         *                      m_NwImageLayer.Opacity = value;
         *              }
         *              if(m_NeImageLayer != null)
         *              {
         *                      m_NeImageLayer.Opacity = value;
         *              }
         *              if(m_SwImageLayer != null)
         *              {
         *                      m_SwImageLayer.Opacity = value;
         *              }
         *              if(m_SeImageLayer != null)
         *              {
         *                      m_SeImageLayer.Opacity = value;
         *              }
         *
         *              if(m_NorthWestChild != null)
         *              {
         *                      m_NorthWestChild.Opacity = value;
         *              }
         *              if(m_NorthEastChild != null)
         *              {
         *                      m_NorthEastChild.Opacity = value;
         *              }
         *              if(m_SouthWestChild != null)
         *              {
         *                      m_SouthWestChild.Opacity = value;
         *              }
         *              if(m_SouthEastChild != null)
         *              {
         *                      m_SouthEastChild.Opacity = value;
         *              }
         *      }
         * }*/

        private Renderable.ImageLayer CreateImageLayer(double north, double south, double west, double east, DrawArgs drawArgs, string imagePath)
        {
            Bitmap   b = null;
            Graphics g = null;

            Renderable.ImageLayer imageLayer = null;
            GeographicBoundingBox geoBB      = new GeographicBoundingBox(north, south, west, east);
            int numberPolygonsInTile         = 0;

            FileInfo imageFile = new FileInfo(imagePath);

            if (!m_parentProjectedLayer.EnableCaching ||
                !imageFile.Exists
                )
            {
                if (m_parentProjectedLayer.LineStrings != null)
                {
                    for (int i = 0; i < m_parentProjectedLayer.LineStrings.Length; i++)
                    {
                        if (!m_parentProjectedLayer.LineStrings[i].Visible)
                        {
                            continue;
                        }

                        GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.LineStrings[i].GetGeographicBoundingBox();

                        if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB))
                        {
                            continue;
                        }
                        else
                        {
                            if (b == null)
                            {
                                b = new Bitmap(
                                    m_parentProjectedLayer.TileSize.Width,
                                    m_parentProjectedLayer.TileSize.Height,
                                    System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            }

                            if (g == null)
                            {
                                g = Graphics.FromImage(b);
                            }

                            drawLineString(
                                m_parentProjectedLayer.LineStrings[i],
                                g,
                                geoBB,
                                b.Size
                                );

                            numberPolygonsInTile++;
                        }
                    }
                }

                if (m_parentProjectedLayer.Polygons != null)
                {
                    for (int i = 0; i < m_parentProjectedLayer.Polygons.Length; i++)
                    {
                        if (!m_parentProjectedLayer.Polygons[i].Visible)
                        {
                            continue;
                        }

                        GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.Polygons[i].GetGeographicBoundingBox();

                        if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB))
                        {
                            continue;
                        }
                        else
                        {
                            if (b == null)
                            {
                                b = new Bitmap(
                                    m_parentProjectedLayer.TileSize.Width,
                                    m_parentProjectedLayer.TileSize.Height,
                                    System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            }

                            if (g == null)
                            {
                                g = Graphics.FromImage(b);
                            }
                            drawPolygon(
                                m_parentProjectedLayer.Polygons[i],
                                g,
                                geoBB,
                                b.Size);

                            numberPolygonsInTile++;
                        }
                    }
                }
            }

            if (b != null)
            {
                System.Drawing.Imaging.BitmapData srcInfo = b.LockBits(new Rectangle(0, 0,
                                                                                     b.Width, b.Height),
                                                                       System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                                                       System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                bool isBlank = true;
                unsafe
                {
                    int *srcPointer = (int *)srcInfo.Scan0;
                    for (int i = 0; i < b.Height; i++)
                    {
                        for (int j = 0; j < b.Width; j++)
                        {
                            int color = *srcPointer++;

                            if (((color >> 24) & 0xff) > 0)
                            {
                                isBlank = false;
                                break;
                            }
                        }

                        srcPointer += (srcInfo.Stride >> 2) - b.Width;
                    }
                }

                b.UnlockBits(srcInfo);
                if (isBlank)
                {
                    numberPolygonsInTile = 0;
                }
            }

            //	if(!m_parentProjectedLayer.EnableCaching)
            //	{
            string id = System.DateTime.Now.Ticks.ToString();

            if (b != null && numberPolygonsInTile > 0)
            {
                MemoryStream ms = new MemoryStream();
                b.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                //must copy original stream into new stream, if not, error occurs, not sure why
                m_ImageStream = new MemoryStream(ms.GetBuffer());

                imageLayer = new WorldWind.Renderable.ImageLayer(
                    id,
                    m_parentProjectedLayer.World,
                    0,
                    m_ImageStream,
                    System.Drawing.Color.Black.ToArgb(),
                    (float)south,
                    (float)north,
                    (float)west,
                    (float)east,
                    1.0f                            //(float)m_parentProjectedLayer.Opacity / 255.0f
                    ,
                    m_parentProjectedLayer.World.TerrainAccessor);

                ms.Close();
            }

            /*	}
             *      else if(imageFile.Exists || numberPolygonsInTile > 0)
             *      {
             *              string id = System.DateTime.Now.Ticks.ToString();
             *
             *              if(b != null)
             *              {
             *                      MemoryStream ms = new MemoryStream();
             *                      b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
             *                      if(!imageFile.Directory.Exists)
             *                              imageFile.Directory.Create();
             *
             *                      //must copy original stream into new stream, if not, error occurs, not sure why
             *                      m_ImageStream = new MemoryStream(ms.GetBuffer());
             *                      ImageHelper.ConvertToDxt3(m_ImageStream, imageFile.FullName);
             *
             *                      ms.Close();
             *              }
             *
             *              imageLayer = new WorldWind.Renderable.ImageLayer(
             *                      id,
             *                      m_parentProjectedLayer.World,
             *                      0,
             *                      imageFile.FullName,
             *                      //System.Drawing.Color.Black.ToArgb(),
             *                      (float)south,
             *                      (float)north,
             *                      (float)west,
             *                      (float)east,
             *                      1.0f,//(float)m_parentProjectedLayer.Opacity / 255.0f,
             *                      m_parentProjectedLayer.World.TerrainAccessor);
             *
             *              imageLayer.TransparentColor = System.Drawing.Color.Black.ToArgb();
             *      }
             */
            if (b != null)
            {
                b.Dispose();
            }
            if (g != null)
            {
                g.Dispose();
            }

            b = null;
            g = null;

            //might not be necessary
            //GC.Collect();

            return(imageLayer);
        }
Beispiel #24
0
        private void butNext_Click(object sender, EventArgs e)
        {
            if (ValidateChildren(ValidationConstraints.Enabled) && Validate())
             {
            // if there are screens to go to....
            if (butNext.Text.StartsWith("&N"))
            {
               tabCtl.TabPages.Clear();
               tabCtl.TabPages.Add(m_tabPages[m_intCurrentTab]);
            }
            // otherwise
            else
            {
               // Make result available and close
               if (m_intCurrentTab == 3)
               {
                  m_oServer = null;
                  m_oTileServer = null;
                  m_WmsURL = txtWmsServeURL.Text;
               }
               else if (m_intCurrentTab == 2)
               {
                  //DAP
                  m_oTileServer = null;
                  m_WmsURL = "";
               }
               else if (m_intCurrentTab == 1)
               {
                  m_oServer = null;
                  m_WmsURL = "";

                  string cacheDir = System.IO.Path.Combine(m_worldWind.WorldWindSettings.CachePath, txtName.Text);
                  ImageTileService imageTileService = new ImageTileService(txtDatabaseName.Text, txtServerURL.Text, txtServerURL.Text);

                  GeographicBoundingBox geoBox = new GeographicBoundingBox(
                     Math.Round(Convert.ToDouble(numN.Value), 0),
                     Math.Round(Convert.ToDouble(numS.Value), 0),
                     Math.Round(Convert.ToDouble(numW.Value), 0),
                     Math.Round(Convert.ToDouble(numE.Value), 0));
                  m_oTileServer = new LayerGeneration.QuadLayerBuilder(
                     txtName.Text,
                     Convert.ToInt32(numHeight.Value),
                     chkTileServerUseTerrainMap.Checked,
                     geoBox, numTileSize.Value, Convert.ToInt32(numLevels.Value), Convert.ToInt32(numImagePixelSize.Value),
                     imageTileService,cmbTileServerFileExtension.Text, Convert.ToByte(chkShowOnAdd.Checked ? 255 : 0),
                     m_worldWind.CurrentWorld, m_worldWind.WorldWindSettings.CachePath, m_worldWind.WorldWindSettings.CachePath, m_oParent);
               }

               Close();
            }
             }
             // Change next to finish for those screens that end the wizard
             if (m_intCurrentTab != 0)
             {
            butNext.Text = "&OK";
             }
        }
Beispiel #25
0
        private void LoadTileServerSet(dappleview.tileserversetType entry)
        {
            if (entry.Hastilelayers())
            {
                for (int i = 0; i < entry.tilelayers.tilelayerCount; i++)
                {
                    dappleview.tilelayerType oLayer = entry.tilelayers.GettilelayerAt(i);
                    dappleview.boundingboxType oBoundsData = oLayer.boundingbox;
                    GeographicBoundingBox oBounds = new GeographicBoundingBox(
                        oBoundsData.maxlat.Value,
                        oBoundsData.minlat.Value,
                        oBoundsData.minlon.Value,
                        oBoundsData.maxlon.Value);

                    ImageTileLayerModelNode oNode = new ImageTileLayerModelNode(
                        this,
                        oLayer.name.Value,
                        new Uri(oLayer.url.Value),
                        oLayer.imageextension.Value,
                        oLayer.levelzerotilesize.Value,
                        oLayer.dataset.Value,
                        oLayer.levels.Value,
                        oBounds,
                        oLayer.Hasdistanceabovesurface() ? oLayer.distanceabovesurface.Value : Convert.ToInt32(dappleview.tilelayerType.GetdistanceabovesurfaceDefault(), CultureInfo.InvariantCulture),
                        oLayer.Hastilepixelsize() ? oLayer.tilepixelsize.Value : Convert.ToInt32(dappleview.tilelayerType.GettilepixelsizeDefault(), CultureInfo.InvariantCulture)
                        );

                    this.AddImageTileLayer(entry.name.Value, oNode);
                }
            }
        }
Beispiel #26
0
        internal void SetSearchFilter(String strKeyword, GeographicBoundingBox oBounds)
        {
            lock (m_oLock)
            {
                if (strKeyword != m_strSearchKeyword || oBounds != m_oSearchBounds)
                {
                    if (SelectedServer != null)
                        m_oSelectedNode = SelectedServer;

                    m_strSearchKeyword = strKeyword;
                    m_oSearchBounds = oBounds;
                    m_oRootNode.DAPServers.SearchFilterChanged();
                    if (m_oRootNode.PersonalDapServer != null)
                    {
                        m_oRootNode.PersonalDapServer.SearchFilterChanged();
                    }

                    OnSearchFilterChanged(EventArgs.Empty);
                }
            }
        }
Beispiel #27
0
        private System.Drawing.Point[] getScreenPoints(Shapefile_Point[] sourcePoints, int offset, int length, GeographicBoundingBox dstBB, Size dstImageSize)
        {
            double degreesPerPixelX = (dstBB.East - dstBB.West) / (double)dstImageSize.Width;
            double degreesPerPixelY = (dstBB.North - dstBB.South) / (double)dstImageSize.Height;

            ArrayList screenPointList = new ArrayList();

            for (int i = offset; i < offset + length; i++)
            {
                double screenX = (sourcePoints[i].X - dstBB.West) / degreesPerPixelX;
                double screenY = (dstBB.North - sourcePoints[i].Y) / degreesPerPixelY;

                if (screenPointList.Count > 0)
                {
                    Point v = (Point)screenPointList[screenPointList.Count - 1];
                    if (v.X == (int)screenX && v.Y == (int)screenY)
                    {
                        continue;
                    }
                }

                screenPointList.Add(new Point((int)screenX, (int)screenY));
            }

            if (screenPointList.Count <= 1)
            {
                return new Point[] { new Point(0, 0), new Point(0, 0) }
            }
            ;

            return((Point[])screenPointList.ToArray(typeof(Point)));
        }
Beispiel #28
0
        private void drawPolygon(Shapefile_Polygon polygon, Graphics g, Color c, GeographicBoundingBox dstBB, Size imageSize)
        {
            if (polygon.Parts.Length > 1)
            {
                if (m_ShapeTileArgs.PolygonFill)
                {
                    if (m_ShapeTileArgs.ShapeFillStyle == ShapeFillStyle.Solid)
                    {
                        using (SolidBrush brush = new SolidBrush(c))
                        {
                            g.FillPolygon(brush, getScreenPoints(polygon.Points, 0, polygon.Parts[1], dstBB, imageSize));
                        }
                    }
                    else
                    {
                        using (System.Drawing.Drawing2D.HatchBrush brush = new System.Drawing.Drawing2D.HatchBrush(
                                   getGDIHatchStyle(m_ShapeTileArgs.ShapeFillStyle),
                                   c,
                                   System.Drawing.Color.Black))
                        {
                            g.FillPolygon(brush, getScreenPoints(polygon.Points, 0, polygon.Parts[1], dstBB, imageSize));
                        }
                    }
                }

                if (m_ShapeTileArgs.OutlinePolygons)
                {
                    using (Pen p = new Pen(m_ShapeTileArgs.LineColor, m_ShapeTileArgs.LineWidth))
                    {
                        for (int partsItr = 0; partsItr < polygon.Parts.Length - 1; partsItr++)
                        {
                            g.DrawPolygon(p,
                                          getScreenPoints(polygon.Points, polygon.Parts[partsItr], polygon.Parts[partsItr + 1] - polygon.Parts[partsItr], dstBB, imageSize));
                        }

                        g.DrawPolygon(p,
                                      getScreenPoints(polygon.Points, polygon.Parts[polygon.Parts.Length - 1],
                                                      polygon.Points.Length - polygon.Parts[polygon.Parts.Length - 1], dstBB, imageSize)
                                      );
                    }
                }

                if (m_ShapeTileArgs.PolygonFill)
                {
                    if (m_ShapeTileArgs.ShapeFillStyle == ShapeFillStyle.Solid)
                    {
                        using (SolidBrush brush = new SolidBrush(System.Drawing.Color.Black))
                        {
                            for (int partsItr = 1; partsItr < polygon.Parts.Length - 1; partsItr++)
                            {
                                g.FillPolygon(brush,
                                              getScreenPoints(polygon.Points, polygon.Parts[partsItr], polygon.Parts[partsItr + 1] - polygon.Parts[partsItr], dstBB, imageSize)
                                              );
                            }

                            g.FillPolygon(brush,
                                          getScreenPoints(polygon.Points, polygon.Parts[polygon.Parts.Length - 1],
                                                          polygon.Points.Length - polygon.Parts[polygon.Parts.Length - 1], dstBB, imageSize)
                                          );
                        }
                    }
                    else
                    {
                        using (System.Drawing.Drawing2D.HatchBrush brush = new System.Drawing.Drawing2D.HatchBrush(
                                   getGDIHatchStyle(m_ShapeTileArgs.ShapeFillStyle),
                                   c,
                                   System.Drawing.Color.Black))
                        {
                            for (int partsItr = 1; partsItr < polygon.Parts.Length - 1; partsItr++)
                            {
                                g.FillPolygon(brush,
                                              getScreenPoints(polygon.Points, polygon.Parts[partsItr], polygon.Parts[partsItr + 1] - polygon.Parts[partsItr], dstBB, imageSize)
                                              );
                            }

                            g.FillPolygon(brush,
                                          getScreenPoints(polygon.Points, polygon.Parts[polygon.Parts.Length - 1],
                                                          polygon.Points.Length - polygon.Parts[polygon.Parts.Length - 1], dstBB, imageSize)
                                          );
                        }
                    }
                }
            }
            else
            {
                if (m_ShapeTileArgs.PolygonFill)
                {
                    if (m_ShapeTileArgs.ShapeFillStyle == ShapeFillStyle.Solid)
                    {
                        using (SolidBrush brush = new SolidBrush(c))
                        {
                            g.FillPolygon(brush, getScreenPoints(polygon.Points, 0, polygon.Points.Length, dstBB, imageSize));
                        }
                    }
                    else
                    {
                        using (System.Drawing.Drawing2D.HatchBrush brush = new System.Drawing.Drawing2D.HatchBrush(
                                   getGDIHatchStyle(m_ShapeTileArgs.ShapeFillStyle),
                                   c,
                                   System.Drawing.Color.Black))
                        {
                            g.FillPolygon(brush, getScreenPoints(polygon.Points, 0, polygon.Points.Length, dstBB, imageSize));
                        }
                    }
                }


                if (m_ShapeTileArgs.OutlinePolygons)
                {
                    using (Pen p = new Pen(m_ShapeTileArgs.LineColor, m_ShapeTileArgs.LineWidth))
                    {
                        g.DrawPolygon(p, getScreenPoints(polygon.Points, 0, polygon.Points.Length, dstBB, imageSize));
                    }
                }
            }
        }
Beispiel #29
0
        /// <summary>
        /// Method to update polygon bounding box
        /// </summary>
        protected void CalcBoundingBox()
        {
            double minY = double.MaxValue;
            double maxY = double.MinValue;
            double minX = double.MaxValue;
            double maxX = double.MinValue;
            double minZ = double.MaxValue;
            double maxZ = double.MinValue;

            if (m_outerRing != null && m_outerRing.Points.Length > 0)
            {
                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 += m_world.EquatorialRadius;
            maxZ += m_world.EquatorialRadius;

            BoundingBox = new BoundingBox(
                (float)minY, (float)maxY, (float)minX, (float)maxX, (float)minZ, (float)maxZ);
        }
 public bool Contains(GeographicBoundingBox test)
 {
     return (test.West >= this.West && test.East <= this.East && test.South >= this.South && test.North < this.North);
 }
Beispiel #31
0
        internal override LayerBuilder getBuilder(DappleModel oModel)
        {
            GeographicBoundingBox oLayerBounds = new GeographicBoundingBox();
            bool blTerrainMapped;
            int iHeight, iLevels, iSize;
            double dLvl0Tilesie;

            if (!Double.TryParse(getAttribute("west"), NumberStyles.Any, CultureInfo.InvariantCulture, out oLayerBounds.West)) return null;
            if (!Double.TryParse(getAttribute("south"), NumberStyles.Any, CultureInfo.InvariantCulture, out oLayerBounds.South)) return null;
            if (!Double.TryParse(getAttribute("east"), NumberStyles.Any, CultureInfo.InvariantCulture, out oLayerBounds.East)) return null;
            if (!Double.TryParse(getAttribute("north"), NumberStyles.Any, CultureInfo.InvariantCulture, out oLayerBounds.North)) return null;
            if (!Int32.TryParse(getAttribute("height"), NumberStyles.Any, CultureInfo.InvariantCulture, out iHeight)) return null;
            if (!Int32.TryParse(getAttribute("levels"), NumberStyles.Any, CultureInfo.InvariantCulture, out iLevels)) return null;
            if (!Int32.TryParse(getAttribute("size"), NumberStyles.Any, CultureInfo.InvariantCulture, out iSize)) return null;
            if (!Boolean.TryParse(getAttribute("terrainmapped"), out blTerrainMapped)) return null;
            if (!Double.TryParse(getAttribute("lvl0tilesize"), NumberStyles.Any, CultureInfo.InvariantCulture, out dLvl0Tilesie)) return null;

            return new NltQuadLayerBuilder(
                getAttribute("name"),
                iHeight,
                blTerrainMapped,
                oLayerBounds,
                dLvl0Tilesie,
                iLevels,
                iSize,
                m_oServer.ToBaseUri(),
                getAttribute("datasetname"),
                getAttribute("imgfileext"),
                255,
                MainForm.WorldWindowSingleton,
                null);
        }
        public bool Intersects(GeographicBoundingBox boundingBox)
        {
            // --- Calculate the center and the width of the bounding boxes ---

            double thisDLat = this.North - this.South;
            double thisCLat = (this.North + this.South) / 2.0;
            double thisDLon = this.East - this.West;
            double thisCLon = (this.East + this.West) / 2.0;
            double otherDLat = boundingBox.North - boundingBox.South;
            double otherCLat = (boundingBox.North + boundingBox.South) / 2.0;
            double otherDLon = boundingBox.East - boundingBox.West;
            double otherCLon = (boundingBox.East + boundingBox.West) / 2.0;

            // --- Swap centers so thisCLon is the west one ---

            if (thisCLon > otherCLon)
            {
                double temp = thisCLon;
                thisCLon = otherCLon;
                otherCLon = temp;
            }

            // --- Minimize the distance between the bounding boxes ---

            while (otherCLon - thisCLon > 180.0)
            {
                thisCLon += 360.0;
            }

            // --- Check that the separation between the two boxes' centers is
            // --- less than half the sum of their extents

            return (Math.Abs(thisCLat - otherCLat) < (thisDLat + otherDLat) / 2.0) &&
                (Math.Abs(thisCLon - otherCLon) < (thisDLon + otherDLon) / 2.0);
        }
Beispiel #33
0
        protected virtual void CreateMesh(GeographicBoundingBox geographicBoundingBox, int meshPointCount, ref CustomVertex.PositionColoredTextured[] vertices, ref short[] indices)
        {
            int upperBound = meshPointCount - 1;
            float scaleFactor = (float)1/upperBound;
            double latrange = Math.Abs(geographicBoundingBox.North - geographicBoundingBox.South);
            double lonrange;
            if(geographicBoundingBox.West < geographicBoundingBox.East)
                lonrange = geographicBoundingBox.East - geographicBoundingBox.West;
            else
                lonrange = 360.0f + geographicBoundingBox.East - geographicBoundingBox.West;

            double layerRadius = m_parentProjectedLayer.World.EquatorialRadius;

            int opacityColor = System.Drawing.Color.FromArgb(
                //m_parentProjectedLayer.Opacity,
                0,0,0).ToArgb();
            vertices = new CustomVertex.PositionColoredTextured[meshPointCount * meshPointCount];
            for(int i = 0; i < meshPointCount; i++)
            {
                for(int j = 0; j < meshPointCount; j++)
                {
                    double height = 0;
                    if(m_parentProjectedLayer.World.TerrainAccessor != null)
                        height = m_verticalExaggeration * m_parentProjectedLayer.World.TerrainAccessor.GetElevationAt(
                            (double)geographicBoundingBox.North - scaleFactor * latrange * i,
                            (double)geographicBoundingBox.West + scaleFactor * lonrange * j,
                            (double)upperBound / latrange);

                    Point3d pos = MathEngine.SphericalToCartesian(
                        geographicBoundingBox.North - scaleFactor*latrange*i,
                        geographicBoundingBox.West + scaleFactor*lonrange*j,
                        layerRadius + height);

               vertices[i * meshPointCount + j].X = (float)pos.X;
               vertices[i * meshPointCount + j].Y = (float)pos.Y;
               vertices[i * meshPointCount + j].Z = (float)pos.Z;

                    vertices[i*meshPointCount + j].Tu = j*scaleFactor;
                    vertices[i*meshPointCount + j].Tv = i*scaleFactor;
                    vertices[i*meshPointCount + j].Color = opacityColor;
                }
            }

            indices = new short[2 * upperBound * upperBound * 3];
            for(int i = 0; i < upperBound; i++)
            {
                for(int j = 0; j < upperBound; j++)
                {
                    indices[(2*3*i*upperBound) + 6*j] = (short)(i*meshPointCount + j);
                    indices[(2*3*i*upperBound) + 6*j + 1] = (short)((i+1)*meshPointCount + j);
                    indices[(2*3*i*upperBound) + 6*j + 2] = (short)(i*meshPointCount + j+1);

                    indices[(2*3*i*upperBound) + 6*j + 3] = (short)(i*meshPointCount + j+1);
                    indices[(2*3*i*upperBound) + 6*j + 4] = (short)((i+1)*meshPointCount + j);
                    indices[(2*3*i*upperBound) + 6*j + 5] = (short)((i+1)*meshPointCount + j+1);
                }
            }
        }
        public static GeographicBoundingBox NullBox()
        {
            GeographicBoundingBox result = new GeographicBoundingBox();
            result.North = double.MinValue;
            result.South = double.MaxValue;
            result.East = double.MinValue;
            result.West = double.MaxValue;
            result.MaximumAltitude = double.MinValue;
            result.MinimumAltitude = double.MaxValue;

            return result;
        }
Beispiel #35
0
        private Renderable.ImageLayer CreateImageLayer(double north, double south, double west, double east)
        {
            if (m_parentProjectedLayer.Bounds.Equals(GeographicBoundingBox.NullBox()) || !m_parentProjectedLayer.Bounds.Intersects(new GeographicBoundingBox(north, south, west, east)))
            {
                return null;
            }

            Bitmap b = null;
            Graphics g = null;
            Renderable.ImageLayer result = null;
            GeographicBoundingBox geoBB = new GeographicBoundingBox(north, south, west, east);
            int numberPolygonsInTile = 0;

            if (m_parentProjectedLayer.LineStrings != null)
            {
                for (int i = 0; i < m_parentProjectedLayer.LineStrings.Length; i++)
                {
                    if (!m_parentProjectedLayer.LineStrings[i].Visible)
                        continue;

                    GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.LineStrings[i].GetGeographicBoundingBox();

                    if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB))
                    {
                        continue;
                    }
                    else
                    {
                        if (g == null)
                        {
                            b = new Bitmap(TileSize, TileSize, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            g = Graphics.FromImage(b);
                        }

                        drawLineString(m_parentProjectedLayer.LineStrings[i], g, geoBB, b.Size);
                        numberPolygonsInTile++;
                    }
                }
            }

            if (m_parentProjectedLayer.Polygons != null)
            {
                for (int i = 0; i < m_parentProjectedLayer.Polygons.Length; i++)
                {
                    if (!m_parentProjectedLayer.Polygons[i].Visible)
                        continue;

                    GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.Polygons[i].GetGeographicBoundingBox();

                    if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB))
                    {
                        continue;
                    }
                    else
                    {
                        if (g == null)
                        {
                            b = new Bitmap(TileSize, TileSize, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            g = Graphics.FromImage(b);
                        }

                        drawPolygon(m_parentProjectedLayer.Polygons[i], g, geoBB, b.Size);
                        numberPolygonsInTile++;
                    }
                }
            }

            if (b != null)
            {
                System.Drawing.Imaging.BitmapData srcInfo = b.LockBits(new Rectangle(0, 0,
                    b.Width, b.Height),
                    System.Drawing.Imaging.ImageLockMode.ReadOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                bool isBlank = true;
                unsafe
                {
                    int* srcPointer = (int*)srcInfo.Scan0;
                    for (int i = 0; i < b.Height; i++)
                    {
                        for (int j = 0; j < b.Width; j++)
                        {
                            int color = *srcPointer++;

                            if (((color >> 24) & 0xff) > 0)
                            {
                                isBlank = false;
                                break;
                            }
                        }

                        srcPointer += (srcInfo.Stride >> 2) - b.Width;
                    }
                }

                b.UnlockBits(srcInfo);
                if (isBlank)
                    numberPolygonsInTile = 0;
            }

            if (b != null && numberPolygonsInTile > 0)
            {
                MemoryStream ms = new MemoryStream();
                b.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                ms.Seek(0, SeekOrigin.Begin);

                result = new WorldWind.Renderable.ImageLayer(String.Format("PVT ImageLayer L{0} R{1} C{2}", Level, Row, Col), m_parentProjectedLayer.World, 0, ms, (float)south, (float)north, (float)west, (float)east, 1.0f, m_parentProjectedLayer.World.TerrainAccessor);

                result.Opacity = this.Opacity;
            }

            if (g != null)
            {
                g.Dispose();
                b.Dispose();
            }

            return result;
        }
Beispiel #36
0
        internal override LayerBuilder getBuilder(DappleModel oModel)
        {
            oModel.AddArcIMSServer(m_oServer as ArcIMSServerUri, true, false, false);

            GeographicBoundingBox oLayerBounds = new GeographicBoundingBox();
            double dMinScale, dMaxScale;
            if (!Double.TryParse(getAttribute("minx"), NumberStyles.Any, CultureInfo.InvariantCulture, out oLayerBounds.West)) return null;
            if (!Double.TryParse(getAttribute("miny"), NumberStyles.Any, CultureInfo.InvariantCulture, out oLayerBounds.South)) return null;
            if (!Double.TryParse(getAttribute("maxx"), NumberStyles.Any, CultureInfo.InvariantCulture, out oLayerBounds.East)) return null;
            if (!Double.TryParse(getAttribute("maxy"), NumberStyles.Any, CultureInfo.InvariantCulture, out oLayerBounds.North)) return null;
            if (!Double.TryParse(getAttribute("minscale"), NumberStyles.Any, CultureInfo.InvariantCulture, out dMinScale)) return null;
            if (!Double.TryParse(getAttribute("maxscale"), NumberStyles.Any, CultureInfo.InvariantCulture, out dMaxScale)) return null;

            return new ArcIMSQuadLayerBuilder(
                m_oServer as ArcIMSServerUri,
                getAttribute("servicename"),
                getAttribute("title"),
                getAttribute("layerid"),
                oLayerBounds,
                new ArcIMSFeatureCoordSys(new CultureInfo("en-US")),
                MainForm.WorldWindowSingleton,
                null,
                dMinScale,
                dMaxScale,
                new CultureInfo("en-US"));
        }
Beispiel #37
0
        /// <summary>
        /// Write out settings for the picture dataset
        /// </summary>
        /// <param name="oDatasetElement"></param>
        /// <param name="strDestFolder"></param>
        /// <param name="bDefaultResolution"></param>
        /// <returns></returns>
        internal override ExtractSaveResult Save(System.Xml.XmlElement oDatasetElement, string strDestFolder, DownloadSettings.DownloadCoordinateSystem eCS)
        {
            System.Xml.XmlAttribute oAttr = oDatasetElement.OwnerDocument.CreateAttribute("type");
            oAttr.Value = "geotiff";
            oDatasetElement.Attributes.Append(oAttr);

            oAttr       = oDatasetElement.OwnerDocument.CreateAttribute("title");
            oAttr.Value = m_oNonDapBuilder.Title;
            oDatasetElement.Attributes.Append(oAttr);

            oAttr       = oDatasetElement.OwnerDocument.CreateAttribute("file");
            oAttr.Value = System.IO.Path.Combine(strDestFolder, System.IO.Path.ChangeExtension(Utility.FileSystem.SanitizeFilename(tbFilename.Text), TIF_EXT));
            oDatasetElement.Attributes.Append(oAttr);

            // --- Delete all the files that OM generates, so we don't get invalid projections ---
            try
            {
                if (System.IO.File.Exists(oAttr.Value))
                {
                    System.IO.File.Delete(oAttr.Value);
                }
                if (System.IO.File.Exists(System.IO.Path.ChangeExtension(oAttr.Value, ".ipj")))
                {
                    System.IO.File.Delete(System.IO.Path.ChangeExtension(oAttr.Value, ".ipj"));
                }
                if (System.IO.File.Exists(System.IO.Path.ChangeExtension(oAttr.Value, ".gi")))
                {
                    System.IO.File.Delete(System.IO.Path.ChangeExtension(oAttr.Value, ".gi"));
                }
                if (System.IO.File.Exists(System.IO.Path.ChangeExtension(oAttr.Value, ".tif.xml")))
                {
                    System.IO.File.Delete(System.IO.Path.ChangeExtension(oAttr.Value, ".tif.xml"));
                }
            }
            catch (System.IO.IOException)
            {
                MessageBox.Show("Could not save file " + oAttr.Value + ", please choose a different filename.", "Extraction error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(ExtractSaveResult.Cancel);
            }

            if (m_oNonDapBuilder is GeorefImageLayerBuilder)
            {
                System.IO.File.Copy(((GeorefImageLayerBuilder)m_oNonDapBuilder).FileName, oAttr.Value, true);
            }
            else
            {
                if (!m_oNonDapBuilder.exportToGeoTiff(oAttr.Value))
                {
                    MessageBox.Show(this, "Could not download " + m_oNonDapBuilder.Title + ", data layer's extents do not intersect the viewed area.", "Extraction Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(ExtractSaveResult.Ignore);
                }
            }

            System.Xml.XmlElement          oDisplayElement = oDatasetElement.OwnerDocument.CreateElement("display_options");
            Options.Picture.DisplayOptions eDisplayOption  = (Options.Picture.DisplayOptions)cbDisplayOptions.SelectedIndex;
            oDisplayElement.InnerText = eDisplayOption.ToString();
            oDatasetElement.AppendChild(oDisplayElement);

            WorldWind.GeographicBoundingBox oViewBox = WorldWind.GeographicBoundingBox.FromQuad(MainForm.WorldWindowSingleton.CurrentAreaOfInterest);
            String szViewCRS = Dapple.Extract.Resolution.WGS_84;

            WorldWind.GeographicBoundingBox oMapBox = MainForm.MapAoi;
            String szMapCRS = MainForm.MapAoiCoordinateSystem;

            bool blNewMap;

            if (oMapBox == null)
            {
                blNewMap = true;
            }
            else
            {
                if (MainForm.MontajInterface.ProjectBoundingRectangle(szMapCRS, ref oMapBox.West, ref oMapBox.South, ref oMapBox.East, ref oMapBox.North, szViewCRS))
                {
                    blNewMap = (!oViewBox.Intersects(oMapBox));
                }
                else
                {
                    blNewMap = true;
                }
            }

            oAttr       = oDatasetElement.OwnerDocument.CreateAttribute("new_map");
            oAttr.Value = blNewMap.ToString();
            oDatasetElement.Attributes.Append(oAttr);


            GeographicBoundingBox oGeoTiffBox = oViewBox.Clone() as GeographicBoundingBox;

            if (m_oNonDapBuilder is GeorefImageLayerBuilder)
            {
                oGeoTiffBox = GeorefImageLayerBuilder.GetExtentsFromGeotif(((GeorefImageLayerBuilder)m_oNonDapBuilder).FileName);
            }

            oAttr       = oDatasetElement.OwnerDocument.CreateAttribute("minx");
            oAttr.Value = oGeoTiffBox.West.ToString(CultureInfo.InvariantCulture);
            oDatasetElement.Attributes.Append(oAttr);

            oAttr       = oDatasetElement.OwnerDocument.CreateAttribute("miny");
            oAttr.Value = oGeoTiffBox.South.ToString(CultureInfo.InvariantCulture);
            oDatasetElement.Attributes.Append(oAttr);

            oAttr       = oDatasetElement.OwnerDocument.CreateAttribute("maxx");
            oAttr.Value = oGeoTiffBox.East.ToString(CultureInfo.InvariantCulture);
            oDatasetElement.Attributes.Append(oAttr);

            oAttr       = oDatasetElement.OwnerDocument.CreateAttribute("maxy");
            oAttr.Value = oGeoTiffBox.North.ToString(CultureInfo.InvariantCulture);
            oDatasetElement.Attributes.Append(oAttr);

            oAttr       = oDatasetElement.OwnerDocument.CreateAttribute("coordinate_system");
            oAttr.Value = szViewCRS;
            oDatasetElement.Attributes.Append(oAttr);

            String szDownloadType = String.Empty;
            String szDownloadUrl  = String.Empty;
            String szLayerId      = String.Empty;

            m_oNonDapBuilder.GetOMMetadata(out szDownloadType, out szDownloadUrl, out szLayerId);

            oAttr       = oDatasetElement.OwnerDocument.CreateAttribute("download_type");
            oAttr.Value = szDownloadType;
            oDatasetElement.Attributes.Append(oAttr);

            oAttr       = oDatasetElement.OwnerDocument.CreateAttribute("url");
            oAttr.Value = szDownloadUrl;
            oDatasetElement.Attributes.Append(oAttr);

            oAttr       = oDatasetElement.OwnerDocument.CreateAttribute("id");
            oAttr.Value = szLayerId;
            oDatasetElement.Attributes.Append(oAttr);

            return(ExtractSaveResult.Extract);
        }
		/*public byte Opacity
		{
			get
			{
				return m_parentProjectedLayer.Opacity;
			}
			set
			{
				if(m_NwImageLayer != null)
				{
					m_NwImageLayer.Opacity = value;
				}
				if(m_NeImageLayer != null)
				{
					m_NeImageLayer.Opacity = value;
				}
				if(m_SwImageLayer != null)
				{
					m_SwImageLayer.Opacity = value;
				}
				if(m_SeImageLayer != null)
				{
					m_SeImageLayer.Opacity = value;
				}

				if(m_NorthWestChild != null)
				{
					m_NorthWestChild.Opacity = value;
				}
				if(m_NorthEastChild != null)
				{
					m_NorthEastChild.Opacity = value;
				}
				if(m_SouthWestChild != null)
				{
					m_SouthWestChild.Opacity = value;
				}
				if(m_SouthEastChild != null)
				{
					m_SouthEastChild.Opacity = value;
				}
			}
		}*/

		private Renderable.ImageLayer CreateImageLayer(double north, double south, double west, double east, DrawArgs drawArgs, string imagePath)
		{
			Bitmap b = null;
			Graphics g = null;
			Renderable.ImageLayer imageLayer = null;
			GeographicBoundingBox geoBB = new GeographicBoundingBox(north, south, west, east);
			int numberPolygonsInTile = 0;

			FileInfo imageFile = new FileInfo(imagePath);

			if(!m_parentProjectedLayer.EnableCaching ||
				!imageFile.Exists
				)
			{
				if(m_parentProjectedLayer.LineStrings != null)
				{
					for(int i = 0; i < m_parentProjectedLayer.LineStrings.Length; i++)
					{
						if(!m_parentProjectedLayer.LineStrings[i].Visible)
							continue;
						
						GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.LineStrings[i].GetGeographicBoundingBox();

						if(currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB))
						{
							continue;
						}
						else
						{
							if(b == null)
							{
								b = new Bitmap(
									m_parentProjectedLayer.TileSize.Width,
									m_parentProjectedLayer.TileSize.Height,
									System.Drawing.Imaging.PixelFormat.Format32bppArgb);
							}

							if(g == null)
							{
								g = Graphics.FromImage(b);
							}

							drawLineString(
								m_parentProjectedLayer.LineStrings[i],
								g,
								geoBB,
								b.Size
								);
							
							numberPolygonsInTile++;
						}
					}
				}

				if(m_parentProjectedLayer.Polygons != null)
				{
					for(int i = 0; i < m_parentProjectedLayer.Polygons.Length; i++)
					{
						if(!m_parentProjectedLayer.Polygons[i].Visible)
							continue;

						GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.Polygons[i].GetGeographicBoundingBox();

						if(currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB))
						{
							continue;
						}
						else
						{
							if(b == null)
							{
								b = new Bitmap(
									m_parentProjectedLayer.TileSize.Width,
									m_parentProjectedLayer.TileSize.Height,
									System.Drawing.Imaging.PixelFormat.Format32bppArgb);
							}

							if(g == null)
							{
								g = Graphics.FromImage(b);
							}
							drawPolygon(
								m_parentProjectedLayer.Polygons[i],
								g,
								geoBB,
								b.Size);
	
							numberPolygonsInTile++;
						}
					}
				}
			}

			if(b != null)
			{
				System.Drawing.Imaging.BitmapData srcInfo = b.LockBits(new Rectangle(0, 0, 
					b.Width, b.Height), 
					System.Drawing.Imaging.ImageLockMode.ReadOnly, 
					System.Drawing.Imaging.PixelFormat.Format32bppArgb);

				bool isBlank = true;
				unsafe
				{
					int* srcPointer = (int*)srcInfo.Scan0;
					for(int i = 0; i < b.Height; i++) 
					{
						for(int j = 0; j < b.Width; j++) 
						{
							int color = *srcPointer++;
						
							if(((color >> 24) & 0xff) > 0)
							{
								isBlank = false;
								break;
							}
						}

						srcPointer += (srcInfo.Stride>>2) - b.Width;
					}
				}

				b.UnlockBits(srcInfo);
				if(isBlank)
					numberPolygonsInTile = 0;
			}
          
		//	if(!m_parentProjectedLayer.EnableCaching)
		//	{
				string id = System.DateTime.Now.Ticks.ToString();

				if(b != null && numberPolygonsInTile > 0)
				{
					MemoryStream ms = new MemoryStream();
					b.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

					//must copy original stream into new stream, if not, error occurs, not sure why
					m_ImageStream = new MemoryStream(ms.GetBuffer());
					
					imageLayer = new WorldWind.Renderable.ImageLayer(
						id,
						m_parentProjectedLayer.World,
						0,
						m_ImageStream,
						System.Drawing.Color.Black.ToArgb(),
						(float)south,
						(float)north,
						(float)west,
						(float)east,
						1.0f//(float)m_parentProjectedLayer.Opacity / 255.0f
						,
						m_parentProjectedLayer.World.TerrainAccessor);
					
					ms.Close();
				}

		/*	}
			else if(imageFile.Exists || numberPolygonsInTile > 0)
			{
				string id = System.DateTime.Now.Ticks.ToString();

				if(b != null)
				{
					MemoryStream ms = new MemoryStream();
					b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
					if(!imageFile.Directory.Exists)
						imageFile.Directory.Create();

					//must copy original stream into new stream, if not, error occurs, not sure why
					m_ImageStream = new MemoryStream(ms.GetBuffer());
					ImageHelper.ConvertToDxt3(m_ImageStream, imageFile.FullName);
					
					ms.Close();
				}

				imageLayer = new WorldWind.Renderable.ImageLayer(
					id,
					m_parentProjectedLayer.World,
					0,
					imageFile.FullName,
					//System.Drawing.Color.Black.ToArgb(),
					(float)south,
					(float)north,
					(float)west,
					(float)east,
					1.0f,//(float)m_parentProjectedLayer.Opacity / 255.0f,
					m_parentProjectedLayer.World.TerrainAccessor);
				
				imageLayer.TransparentColor = System.Drawing.Color.Black.ToArgb();
			}
		*/			
			if(b != null)
			{
				b.Dispose();
			}
			if(g != null)
			{
				g.Dispose();
			}

			b = null;
			g = null;

			//might not be necessary
			//GC.Collect();

			return imageLayer;
		}
Beispiel #39
0
		private bool isShapeRecordInBounds(GeographicBoundingBox geoBB, ShapeRecord record)
		{
			if(record.Point != null)
			{
				if(record.Point.X < geoBB.West || record.Point.X > geoBB.East ||
					record.Point.Y > geoBB.North || record.Point.Y < geoBB.South)
				{
					return false;
				}
				else
				{	
					return true;
				}
			}
			else if(record.MultiPoint != null)
			{
				if(record.MultiPoint.BoundingBox.North <= geoBB.South ||
					record.MultiPoint.BoundingBox.South >= geoBB.North ||
					record.MultiPoint.BoundingBox.West >= geoBB.East ||
					record.MultiPoint.BoundingBox.East <= geoBB.West)
				{
					return false;
				}
				else
				{
					return true;
				}
			}
			else if(record.PolyLine != null)
			{
				if(record.PolyLine.BoundingBox.North <= geoBB.South ||
					record.PolyLine.BoundingBox.South >= geoBB.North ||
					record.PolyLine.BoundingBox.West >= geoBB.East ||
					record.PolyLine.BoundingBox.East <= geoBB.West)
				{
					return false;
				}
				else
				{
					return true;
				}	
			}
			else if(record.Polygon != null)
			{
				if(record.Polygon.BoundingBox.North <= geoBB.South ||
					record.Polygon.BoundingBox.South >= geoBB.North ||
					record.Polygon.BoundingBox.West >= geoBB.East ||
					record.Polygon.BoundingBox.East <= geoBB.West)
				{
					return false;
				}
				else
				{
					return true;
				}	
			}

			return false;
		}
Beispiel #40
0
        internal WMSLayerModelNode(DappleModel oModel, WMSLayer oData)
            : base(oModel)
        {
            m_oData = oData;
            m_oBounds = new GeographicBoundingBox((double)m_oData.North, (double)m_oData.South, (double)m_oData.West, (double)m_oData.East);

            m_oViewLegend = new ToolStripMenuItem("View Legend...", IconKeys.ImageList.Images[IconKeys.ViewLegendMenuItem], new EventHandler(c_miViewLegend_Click));

            MarkLoaded();
        }
Beispiel #41
0
		private Renderable.ImageLayer CreateImageLayer(double north, double south, double west, double east, DrawArgs drawArgs)
		{
			Bitmap b = null;
			Graphics g = null;
			Renderable.ImageLayer imageLayer = null;
			GeographicBoundingBox geoBB = new GeographicBoundingBox(north, south, west, east);
	
			int numberPolygonsInTile = 0;
			for(int i = 0; i < m_ShapeTileArgs.ShapeRecords.Count; i++)
			{
				ShapeRecord currentRecord = (ShapeRecord)m_ShapeTileArgs.ShapeRecords[i];
				
				if(currentRecord.Null != null || 
					currentRecord.Point != null || 
					currentRecord.MultiPoint != null ||
					!isShapeRecordInBounds(geoBB, currentRecord))
				{
					continue;
				}
				else
				{
					if(b == null)
					{
						b = new Bitmap(m_ShapeTileArgs.TilePixelSize.Width,
							m_ShapeTileArgs.TilePixelSize.Height,
							System.Drawing.Imaging.PixelFormat.Format32bppArgb);
					}

					if(g == null)
					{
						g = Graphics.FromImage(b);
					}

					System.Drawing.Color color = m_ShapeTileArgs.PolygonColor;

					//Fix Black Tiles
					g.DrawLine(new Pen(color),0,0,1,1);
					
					
					if(m_ShapeTileArgs.UseScalar && m_ShapeTileArgs.ScaleColors)
					{
						double red = 1.0;
						double green = 1.0;
						double blue = 1.0;
							
						try
						{
							//TODO: make this a function and abstract to allow multiple gradient mappings
							double dv;

							double curScalar = double.Parse(currentRecord.Value.ToString());

							if (curScalar < m_ShapeTileArgs.ScaleMin)
								curScalar = m_ShapeTileArgs.ScaleMin;
							if (curScalar > m_ShapeTileArgs.ScaleMax)
								curScalar = m_ShapeTileArgs.ScaleMax;
							
							dv = m_ShapeTileArgs.ScaleMax - m_ShapeTileArgs.ScaleMin;

							if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.25 * dv)) 
							{
								red = 0;
								green = 4 * (curScalar - m_ShapeTileArgs.ScaleMin) / dv;
							} 
							else if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.5 * dv)) 
							{
								red = 0;
								blue = 1 + 4 * (m_ShapeTileArgs.ScaleMin + 0.25 * dv - curScalar) / dv;
							} 
							else if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.75 * dv)) 
							{
								red = 4 * (curScalar - m_ShapeTileArgs.ScaleMin - 0.5 * dv) / dv;
								blue = 0;
							} 
							else 
							{
								green = 1 + 4 * (m_ShapeTileArgs.ScaleMin + 0.75 * dv - curScalar) / dv;
								blue = 0;
							}

							color = System.Drawing.Color.FromArgb((int)(255*red), (int)(255*green), (int)(255*blue));
							
						}
						catch(Exception)
						{
						//	Log.Write((string)currentPoly.ScalarHash[m_ShapeTileArgs.ColorKey]);
						//	Log.Write(String.Format("Min: {0}, Max: {1}", m_ShapeTileArgs.ScaleMin, m_ShapeTileArgs.ScaleMax));
						//	Log.Write(String.Format("{0},{1},{2}", red, green, blue));
						//	Log.Write(ex);
						}
					}
					else
					{
						if(m_ShapeTileArgs.ColorAssignments.Count > 0 && m_ShapeTileArgs.ScaleColors)
						{
							try
							{
								string colorAssignmentKey = (string)currentRecord.Value;
								foreach(string cak in m_ShapeTileArgs.ColorAssignments.Keys)
								{
									if(String.Compare(cak, colorAssignmentKey, true) == 0)
									{
										color = (System.Drawing.Color)m_ShapeTileArgs.ColorAssignments[cak];
										break;
									}
								}
							}
							catch(Exception)
							{
							}
						}
					}
					
					if(currentRecord.Polygon != null)
					{
						drawPolygon(currentRecord.Polygon,
							g,
							color,
							geoBB,
							b.Size);
					}
					
					if(m_ShapeTileArgs.ColorAssignments.Count == 0 ||  
						!m_ShapeTileArgs.ScaleColors)
					{
						color = m_ShapeTileArgs.LineColor;
					}

					if(currentRecord.PolyLine != null)
					{
						drawPolyLine(currentRecord.PolyLine,
							g,
							color,
							geoBB,
							b.Size);
					}
					numberPolygonsInTile++;
				}
				
			}
            
			if(numberPolygonsInTile > 0)
			{
				string id = System.DateTime.Now.Ticks.ToString();

				MemoryStream ms = new MemoryStream();
				b.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
				//b.Save("Shapefiles\\imagecache\\"+north+""+south+""+east+""+west+ ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
				
				//must copy original stream into new stream, if not, error occurs, not sure why
				m_ImageStream = new MemoryStream(ms.GetBuffer());

			//	Texture texture = TextureLoader.FromStream(
			//		drawArgs.device, mss, 0, 0, 1,
			//		Usage.None, World.Settings.TextureFormat, Pool.Managed, Filter.Box, Filter.Box, System.Drawing.Color.Black.ToArgb());

			
				imageLayer = new WorldWind.Renderable.ImageLayer(
					id,
					m_ShapeTileArgs.ParentWorld,
					0,// should be distance above surface
					m_ImageStream,
					System.Drawing.Color.Black.ToArgb(),
					(float)south,
					(float)north,
					(float)west,
					(float)east,
					(float)m_ShapeTileArgs.ParentShapeFileLayer.Opacity / 255.0f,
					m_ShapeTileArgs.ParentWorld.TerrainAccessor);
					
				
				//mss.Close();
				ms.Close();
			}
					
			if(b != null)
			{
				b.Dispose();
			}
			if(g != null)
			{
				g.Dispose();
			}

			b = null;
			g = null;

			//might not be necessary
			//GC.Collect();

			return imageLayer;
		}
Beispiel #42
0
        private void drawLineString(LineString lineString, Graphics g, GeographicBoundingBox dstBB, Size imageSize)
        {
            using(Pen p = new Pen(lineString.Color, lineString.LineWidth))
            {
                g.DrawLines(p, getScreenPoints(lineString.Coordinates, 0, lineString.Coordinates.Length, dstBB, imageSize));

            }
        }
Beispiel #43
0
		private void drawPolyLine(Shapefile_PolyLine polyLine, Graphics g, Color c, GeographicBoundingBox dstBB, Size imageSize)
		{
			using(Pen p = new Pen(c, m_ShapeTileArgs.LineWidth))
			{
				p.Color = c;
				if(polyLine.Parts.Length > 1)
				{
					for(int partsItr = 0; partsItr < polyLine.Parts.Length - 1; partsItr++)
					{
						g.DrawLines(p,
							getScreenPoints(polyLine.Points, polyLine.Parts[partsItr], polyLine.Parts[partsItr + 1] - polyLine.Parts[partsItr], dstBB, imageSize));

					}

					g.DrawLines(p,
						getScreenPoints(polyLine.Points, polyLine.Parts[polyLine.Parts.Length - 1],
						polyLine.Points.Length - polyLine.Parts[polyLine.Parts.Length - 1], dstBB, imageSize));
				}
				else
				{
					g.DrawLines(p, getScreenPoints(polyLine.Points, 0, polyLine.Points.Length, dstBB, imageSize));
				}
			}
		}
Beispiel #44
0
        private System.Drawing.Point[] getScreenPoints(Point3d[] sourcePoints, int offset, int length, GeographicBoundingBox dstBB, Size dstImageSize)
        {
            double degreesPerPixelX = (dstBB.East - dstBB.West) / (double)dstImageSize.Width;
            double degreesPerPixelY = (dstBB.North - dstBB.South) / (double)dstImageSize.Height;

            ArrayList screenPointList = new ArrayList();
            for(int i = offset; i < offset + length; i++)
            {
                double screenX = (sourcePoints[i].X - dstBB.West) / degreesPerPixelX;
                double screenY = (dstBB.North - sourcePoints[i].Y) / degreesPerPixelY;

                if(screenPointList.Count > 0)
                {
                    Point v = (Point)screenPointList[screenPointList.Count - 1];
                    if(v.X == (int)screenX && v.Y == (int)screenY)
                    {
                        continue;
                    }
                }

                screenPointList.Add(new Point((int)screenX, (int)screenY));
            }

            if(screenPointList.Count <= 1)
                return new Point[] { new Point(0,0), new Point(0,0) };

            return (Point[])screenPointList.ToArray(typeof(Point));
        }
Beispiel #45
0
		private void drawPolygon(Shapefile_Polygon polygon, Graphics g, Color c, GeographicBoundingBox dstBB, Size imageSize)
		{
			if(polygon.Parts.Length > 1)
			{
				if(m_ShapeTileArgs.PolygonFill)
				{
					if(m_ShapeTileArgs.ShapeFillStyle == ShapeFillStyle.Solid)
					{
						using(SolidBrush brush = new SolidBrush(c))
						{
							g.FillPolygon(brush, getScreenPoints(polygon.Points, 0, polygon.Parts[1], dstBB, imageSize));
						}
					}
					else
					{
						using(System.Drawing.Drawing2D.HatchBrush brush = new System.Drawing.Drawing2D.HatchBrush(
								  getGDIHatchStyle(m_ShapeTileArgs.ShapeFillStyle),
								  c,
								  System.Drawing.Color.Black))
						{
							g.FillPolygon(brush, getScreenPoints(polygon.Points, 0, polygon.Parts[1], dstBB, imageSize));
						}
					}
				}
				
				if(m_ShapeTileArgs.OutlinePolygons)
				{
					using(Pen p = new Pen(m_ShapeTileArgs.LineColor, m_ShapeTileArgs.LineWidth))
					{
						for(int partsItr = 0; partsItr < polygon.Parts.Length - 1; partsItr++)
						{
							g.DrawPolygon(p, 
								getScreenPoints(polygon.Points, polygon.Parts[partsItr], polygon.Parts[partsItr+1] - polygon.Parts[partsItr], dstBB, imageSize));
						}

						g.DrawPolygon(p, 
							getScreenPoints(polygon.Points, polygon.Parts[polygon.Parts.Length - 1],
							polygon.Points.Length - polygon.Parts[polygon.Parts.Length - 1], dstBB, imageSize)
							);
					}
				}

				if(m_ShapeTileArgs.PolygonFill)
				{
					if(m_ShapeTileArgs.ShapeFillStyle == ShapeFillStyle.Solid)
					{
						using(SolidBrush brush = new SolidBrush(System.Drawing.Color.Black))
						{
							for(int partsItr = 1; partsItr < polygon.Parts.Length - 1; partsItr++)
							{
								g.FillPolygon(brush, 
									getScreenPoints(polygon.Points, polygon.Parts[partsItr], polygon.Parts[partsItr+1] - polygon.Parts[partsItr], dstBB, imageSize)
									);
							}

							g.FillPolygon(brush, 
								getScreenPoints(polygon.Points, polygon.Parts[polygon.Parts.Length - 1],
								polygon.Points.Length - polygon.Parts[polygon.Parts.Length - 1], dstBB, imageSize)
								);
						}
					}
					else
					{
						using(System.Drawing.Drawing2D.HatchBrush brush = new System.Drawing.Drawing2D.HatchBrush(
								  getGDIHatchStyle(m_ShapeTileArgs.ShapeFillStyle),
								  c,
								  System.Drawing.Color.Black))
						{
							for(int partsItr = 1; partsItr < polygon.Parts.Length - 1; partsItr++)
							{
								g.FillPolygon(brush, 
									getScreenPoints(polygon.Points, polygon.Parts[partsItr], polygon.Parts[partsItr+1] - polygon.Parts[partsItr], dstBB, imageSize)
									);
							}

							g.FillPolygon(brush, 
								getScreenPoints(polygon.Points, polygon.Parts[polygon.Parts.Length - 1],
								polygon.Points.Length - polygon.Parts[polygon.Parts.Length - 1], dstBB, imageSize)
								);
						}
					}
				}				
			}
			else
			{
				if(m_ShapeTileArgs.PolygonFill)
				{
					if(m_ShapeTileArgs.ShapeFillStyle == ShapeFillStyle.Solid)
					{
						using(SolidBrush brush = new SolidBrush(c))
						{
							g.FillPolygon(brush, getScreenPoints(polygon.Points, 0, polygon.Points.Length, dstBB, imageSize));
						}
					}
					else
					{
						using(System.Drawing.Drawing2D.HatchBrush brush = new System.Drawing.Drawing2D.HatchBrush(
								  getGDIHatchStyle(m_ShapeTileArgs.ShapeFillStyle),
								  c,
								  System.Drawing.Color.Black))
						{
							g.FillPolygon(brush, getScreenPoints(polygon.Points, 0, polygon.Points.Length, dstBB, imageSize));
						}
					}
				}

				
				if(m_ShapeTileArgs.OutlinePolygons)
				{
					using(Pen p = new Pen(m_ShapeTileArgs.LineColor, m_ShapeTileArgs.LineWidth))
					{
						g.DrawPolygon(p, getScreenPoints(polygon.Points, 0, polygon.Points.Length, dstBB, imageSize));
					}
				}
			}
		}
Beispiel #46
0
		public ShapeFileLayer(
			string id,
			World parentWorld,
			string shapeFilePath,
			double minimumViewingAltitude,
			double maximumViewingAltitude,
			float lztsd,
			GeographicBoundingBox bounds,
			string dataKey,
			bool scaleColorsToData,
			double scalarFilterMin,
			double scalarFilterMax,
			double scaleMin,
			double scaleMax,
			string[] noDataValues,
			string[] activeDataValues,
			bool polygonFill,
			bool outlinePolygons,
			System.Drawing.Color polygonFillColor,
			ShapeFillStyle shapeFillHatchStyle,
			System.Drawing.Color lineColor,
			float lineWidth,
			bool showLabels,
			System.Drawing.Color labelColor,
			string iconFilePath,
			int iconWidth,
			int iconHeight,
			byte iconOpacity) : base(id, parentWorld.Position, parentWorld.Orientation)
		{

			this.RenderPriority = WorldWind.Renderable.RenderPriority.LinePaths;

			m_MinimumViewingAltitude = minimumViewingAltitude;
			m_MaximumViewingAltitude = maximumViewingAltitude;
			m_lztsd = lztsd;

			m_ShapeTileArgs = new ShapeTileArgs(
				parentWorld,
				new System.Drawing.Size(256, 256),
				parentWorld.EquatorialRadius,
				this,
				dataKey,
				scaleColorsToData,
				scaleMin,
				scaleMax,
				noDataValues,
				activeDataValues,
				polygonFill,
				outlinePolygons,
				polygonFillColor,
				shapeFillHatchStyle,
				lineColor,
				labelColor,
				lineWidth,
				showLabels
				);

			m_ScalarFilterMin = scalarFilterMin;
			m_ScalarFilterMax = scalarFilterMax;

			m_ShapeFilePath = shapeFilePath;

			m_IconFilePath = iconFilePath;
			m_IconWidth = iconWidth;
			m_IconHeight = iconHeight;
			m_IconOpacity = iconOpacity;
			/*Produces tile tree for whole earth*/
			/*Need to implement clipping*/			
			m_NumberRootTilesHigh = (int)(180.0f/m_lztsd);
			double tileSize = 180.0f/m_NumberRootTilesHigh;
			m_RootTiles = new ShapeTile[m_NumberRootTilesHigh * (m_NumberRootTilesHigh * 2)];

			System.Console.WriteLine("North:{0} South:{1} East:{2} West:{3}",
				bounds.North,bounds.South,bounds.East,bounds.West);
			int istart = 0;
			int iend = m_NumberRootTilesHigh;
			int jstart = 0;
			int jend = m_NumberRootTilesHigh * 2;

			int createdtiles = 0;
			for(int i = istart; i < iend; i++)
			{
				for(int j = jstart; j < jend; j++)
				{
					double north = (i + 1) * tileSize - 90.0f;
					double south = i  * tileSize - 90.0f;
					double west = j * tileSize - 180.0f;
					double east = (j + 1) * tileSize - 180.0f;
					m_RootTiles[i * m_NumberRootTilesHigh * 2 + j] = new ShapeTile(
							new GeographicBoundingBox(
							north,
							south,
							west,
							east),
							m_ShapeTileArgs);
					createdtiles++;
				}
			}
			Console.WriteLine("Created Tiles "+createdtiles);
		}
        protected virtual void CreateMesh(GeographicBoundingBox geographicBoundingBox, int meshPointCount, ref CustomVertex.PositionColoredTextured[] vertices, ref short[] indices)
        {
            int    upperBound  = meshPointCount - 1;
            float  scaleFactor = (float)1 / upperBound;
            double latrange    = Math.Abs(geographicBoundingBox.North - geographicBoundingBox.South);
            double lonrange;

            if (geographicBoundingBox.West < geographicBoundingBox.East)
            {
                lonrange = geographicBoundingBox.East - geographicBoundingBox.West;
            }
            else
            {
                lonrange = 360.0f + geographicBoundingBox.East - geographicBoundingBox.West;
            }

            double layerRadius = m_parentProjectedLayer.World.EquatorialRadius;

            int opacityColor = System.Drawing.Color.FromArgb(
                //m_parentProjectedLayer.Opacity,
                0, 0, 0).ToArgb();

            vertices = new CustomVertex.PositionColoredTextured[meshPointCount * meshPointCount];
            for (int i = 0; i < meshPointCount; i++)
            {
                for (int j = 0; j < meshPointCount; j++)
                {
                    double height = 0;
                    if (m_parentProjectedLayer.World.TerrainAccessor != null)
                    {
                        height = m_verticalExaggeration * m_parentProjectedLayer.World.TerrainAccessor.GetElevationAt(
                            (double)geographicBoundingBox.North - scaleFactor * latrange * i,
                            (double)geographicBoundingBox.West + scaleFactor * lonrange * j,
                            (double)upperBound / latrange);
                    }

                    Vector3 pos = MathEngine.SphericalToCartesian(
                        geographicBoundingBox.North - scaleFactor * latrange * i,
                        geographicBoundingBox.West + scaleFactor * lonrange * j,
                        layerRadius + height);

                    vertices[i * meshPointCount + j].X = pos.X;
                    vertices[i * meshPointCount + j].Y = pos.Y;
                    vertices[i * meshPointCount + j].Z = pos.Z;

                    vertices[i * meshPointCount + j].Tu    = j * scaleFactor;
                    vertices[i * meshPointCount + j].Tv    = i * scaleFactor;
                    vertices[i * meshPointCount + j].Color = opacityColor;
                }
            }

            indices = new short[2 * upperBound * upperBound * 3];
            for (int i = 0; i < upperBound; i++)
            {
                for (int j = 0; j < upperBound; j++)
                {
                    indices[(2 * 3 * i * upperBound) + 6 * j]     = (short)(i * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 1] = (short)((i + 1) * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 2] = (short)(i * meshPointCount + j + 1);

                    indices[(2 * 3 * i * upperBound) + 6 * j + 3] = (short)(i * meshPointCount + j + 1);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 4] = (short)((i + 1) * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 5] = (short)((i + 1) * meshPointCount + j + 1);
                }
            }
        }