Exemplo n.º 1
0
        internal BlueMarbleBuilder()
            : base("Blue Marble", MainForm.WorldWindowSingleton, null)
        {
            ImageLayer oBaseLayer = new WorldWind.Renderable.ImageLayer(
                "Blue Marble ImageLayer",
                MainForm.WorldWindowSingleton.CurrentWorld,
                0,
                String.Format(CultureInfo.InvariantCulture, "{0}\\Data\\Earth\\BmngBathy\\world.topo.bathy.2004{1:D2}.jpg", Path.GetDirectoryName(Application.ExecutablePath), 7),
                -90, 90, -180, 180, 1.0f, null);

            WorldWind.NltImageStore imageStore = new WorldWind.NltImageStore(String.Format(CultureInfo.InvariantCulture, "bmng.topo.bathy.2004{0:D2}", 7), "http://worldwind25.arc.nasa.gov/tile/tile.aspx");
            imageStore.DataDirectory            = null;
            imageStore.LevelZeroTileSizeDegrees = 36.0;
            imageStore.LevelCount     = 5;
            imageStore.ImageExtension = "jpg";
            imageStore.CacheDirectory = MainForm.WorldWindowSingleton.Cache.CacheDirectory + "\\Earth\\BMNG\\";

            WorldWind.ImageStore[] ias = new WorldWind.ImageStore[1];
            ias[0] = imageStore;

            QuadTileSet oTiledBaseLayer = new WorldWind.Renderable.QuadTileSet(
                "Blue Marble QuadTileSet",
                MainForm.WorldWindowSingleton.CurrentWorld,
                0,
                90, -90, -180, 180, true, ias);

            RenderableObjectList oRenderableList = new RenderableObjectList("This name doesn't matter, it gets rewritten");

            oRenderableList.Add(oBaseLayer);
            oRenderableList.Add(oTiledBaseLayer);
            oRenderableList.RenderPriority = RenderPriority.TerrainMappedImages;

            m_hObject = oRenderableList;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a pre-constructed feed to the list and its layer to the root layer
        /// </summary>
        /// <param name="feed">feed to add</param>
        /// <param name="addToRoot">sets whether or not the layer gets added to this root layer</param>
        public void Add(GeoRssFeed feed, bool addToRoot)
        {
            if (addToRoot)
            {
                m_rootLayer.Add(feed.Layer);
            }

            m_feeds.Add(feed);
            m_form.UpdateDataGridView();
        }
 public override void Load()
 {
     // Setup Drag&Drop functionality
     Global.worldWindow.DragEnter += new DragEventHandler(OgrVectorImporter_DragEnter);
     Global.worldWindow.DragDrop  += new DragEventHandler(OgrVectorImporter_DragDrop);
     world = Global.worldWindow.CurrentWorld;
     layer = new RenderableObjectList(Name);
     world.RenderableObjects.Add(layer);
     waitMessage = new WaitMessage();
     layer.Add(waitMessage);
     LoadSaveXmlConfig(true);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 存储一些列的对象
        /// </summary>
        /// <param name="ro">存储的对象</param>
        /// <param name="file">存储位置</param>
        public static void SaveAs(RenderableObject ro, string file)
        {
            XmlDocument worldDoc = new XmlDocument();

            worldDoc.AppendChild((worldDoc.CreateXmlDeclaration("1.0", "utf-8", null)));
            if (ro is RenderableObjectList)
            {
                //worldDoc.AppendChild(saveLayer((RenderableObjectList)ro, worldDoc));
                worldDoc.AppendChild(ro.ToXml(worldDoc));
            }
            else
            {
                RenderableObjectList rol = new RenderableObjectList("Saved");
                rol.Add(ro);
                worldDoc.AppendChild(saveLayer(rol, worldDoc));
            }

            worldDoc.Save(file);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Plugin entry point - All plugins must implement this function
        /// </summary>
        public override void Load()
        {
            // Setup Drag&Drop functionality
            m_Application.WorldWindow.DragEnter += new DragEventHandler(OgrVectorImporter_DragEnter);
            m_Application.WorldWindow.DragDrop  += new DragEventHandler(OgrVectorImporter_DragDrop);


            world = m_Application.WorldWindow.CurrentWorld;
            layer = new RenderableObjectList(Name);
            world.RenderableObjects.Add(layer);
            waitMessage = new WaitMessage();
            layer.Add(waitMessage);

            menuItem        = new MenuItem("Import vectors from OGR data source...");
            menuItem.Click += new EventHandler(menuItem_Click);
            ParentApplication.PluginsMenu.MenuItems.Add(menuItem);

            LoadSaveXmlConfig(true);
        }
        private void ParseGeometry(OGR.Geometry geom, string keyStringValue, double keyNumericValue, string labelValue)
        {
            int geomType = geom.GetGeometryType();

            if (geomType == ogr.wkbUnknown)
            {
                return;
            }

            // points
            else if (geomType == ogr.wkbPoint || geomType == ogr.wkbPoint25D)
            {
                bool dataSubListExists = false;

                foreach (Icons l in styleSubList.ChildObjects)
                {
                    if (l.Name == keyStringValue)
                    {
                        dataSubList       = l;
                        dataSubListExists = true;
                    }
                }

                if (!dataSubListExists)
                {
                    dataSubList = new Icons(keyStringValue);
                    //subSubList.DisableExpansion = true;
                    styleSubList.Add(dataSubList);
                }

                double[] p = { geom.GetX(0), geom.GetY(0) };
                if (needsTransformation)
                {
                    coordTransform.TransformPoint(p);
                }

                WorldWind.Renderable.Icon ic = new WorldWind.Renderable.Icon(labelValue, p[1], p[0], 0);
                //ic.TextureFileName = Path.Combine(this.PluginDirectory, "icon.png");
                ic.TextureFileName = "";
                //ic.Width = 12;
                //ic.Height = 12;

                dataSubList.Add(ic);
                //Console.WriteLine("  Found point, contains " + geom.GetPointCount());
                waitMessage.Text += "\nFound " + geom.GetGeometryName();
            }


            // linestring or multi-line
            else if (geomType == ogr.wkbLineString ||
                     geomType == ogr.wkbLineString25D)
            {
                //Console.WriteLine("  Found " + geom.GetGeometryName() + ", contains " + geom.GetPointCount() + "points, " + geom.GetGeometryCount() + " sub-geometries");
                waitMessage.Text += "\nFound " + geom.GetGeometryName() + ", contains " + geom.GetPointCount() + " points, " + geom.GetGeometryCount() + " sub-geometries";
                bool dataSubListExists = false;

                foreach (Icons l in styleSubList.ChildObjects)
                {
                    if (l.Name == keyStringValue)
                    {
                        dataSubList       = l;
                        dataSubListExists = true;
                    }
                }

                if (!dataSubListExists)
                {
                    dataSubList = new Icons(keyStringValue);
                    //subSubList.DisableExpansion = true;
                    styleSubList.Add(dataSubList);
                }

                int       pointCount = geom.GetPointCount();
                Point3d[] p          = new Point3d[pointCount];

                //TODO: handle 2.5/3D?
                for (int i = 0; i < pointCount; i++)
                {
                    double[] point = { geom.GetX(i), geom.GetY(i) };
                    if (needsTransformation)
                    {
                        coordTransform.TransformPoint(point);
                    }

                    p[i] = new Point3d(point[0], point[1], 0);
                }

                //Color lineColor = Color.FromArgb(infoSelector.LineAlpha, infoSelector.LineColor);
                Color lineColor = InterpolateColor(keyNumericValue, true);

                LineFeature lf = new LineFeature(labelValue,
                                                 world,
                                                 p,
                                                 lineColor);
                lf.LineWidth = infoSelector.NumericMinStyle.LineWidth;
                dataSubList.Add(lf);
            }

            // polygon...
            else if (geomType == ogr.wkbPolygon || geomType == ogr.wkbPolygon25D)
            {
                bool dataSubListExists = false;

                foreach (Icons l in styleSubList.ChildObjects)
                {
                    if (l.Name == keyStringValue)
                    {
                        dataSubList       = l;
                        dataSubListExists = true;
                    }
                }

                if (!dataSubListExists)
                {
                    dataSubList = new Icons(keyStringValue);
                    //subSubList.DisableExpansion = true;
                    styleSubList.Add(dataSubList);
                }

                //Console.WriteLine("  Found " + geom.GetGeometryName() + ", contains " + geom.GetGeometryCount() + " sub-geometries");
                waitMessage.Text += "\nFound " + geom.GetGeometryName() + ", contains " + geom.GetPointCount() + " points, " + geom.GetGeometryCount() + " sub-geometries";

                int numInnerRings = geom.GetGeometryCount() - 1;

                LinearRing[] innerRings;
                if (numInnerRings != 0)
                {
                    innerRings = new LinearRing[numInnerRings];
                }
                else
                {
                    innerRings = null;
                }

                LinearRing outerRing = new LinearRing();

                OGR.Geometry ring;

                //outer ring...
                ring              = geom.GetGeometryRef(0);
                waitMessage.Text += "\nFound " + ring.GetGeometryName() + ", contains " + ring.GetPointCount() + " points, " + ring.GetGeometryCount() + " sub-geometries";

                int       pointCount = ring.GetPointCount();
                Point3d[] p          = new Point3d[pointCount];

                for (int k = 0; k < pointCount; k++)
                {
                    double   x     = ring.GetX(k);
                    double   y     = ring.GetY(k);
                    double[] point = { x, y };
                    if (needsTransformation)
                    {
                        coordTransform.TransformPoint(point);
                    }

                    p[k] = new Point3d(point[0], point[1], 0);
                }

                outerRing.Points = p;

                //inner rings...
                if (innerRings != null)
                {
                    for (int i = 1; i < geom.GetGeometryCount(); i++)
                    {
                        ring              = geom.GetGeometryRef(i);
                        waitMessage.Text += "\nFound " + ring.GetGeometryName() + ", contains " + ring.GetPointCount() + " points, " + ring.GetGeometryCount() + " sub-geometries";
                        for (int j = 0; j < ring.GetPointCount(); j++)
                        {
                            int       innerRingPointCount = ring.GetPointCount();
                            Point3d[] q = new Point3d[innerRingPointCount];

                            for (int k = 0; k < innerRingPointCount; k++)
                            {
                                double   x     = ring.GetX(k);
                                double   y     = ring.GetY(k);
                                double[] point = { x, y };
                                if (needsTransformation)
                                {
                                    coordTransform.TransformPoint(point);
                                }

                                q[k] = new Point3d(point[0], point[1], 0);
                            }

                            LinearRing r = new LinearRing();
                            r.Points = q;

                            innerRings[i - 1] = r;
                        }
                    }
                }

                Color fillColor = InterpolateColor(keyNumericValue, false);
                Color lineColor = InterpolateColor(keyNumericValue, true);

                PolygonFeature pf = new PolygonFeature(
                    labelValue,
                    world,
                    outerRing,
                    innerRings,
                    fillColor);

                pf.Outline      = infoSelector.NumericMinStyle.OutlinePolygons;
                pf.OutlineColor = lineColor;
                dataSubList.Add(pf);
            }

            else if (geomType == ogr.wkbMultiPoint ||
                     geomType == ogr.wkbMultiPoint25D ||
                     geomType == ogr.wkbMultiLineString ||
                     geomType == ogr.wkbMultiLineString25D ||
                     geomType == ogr.wkbMultiPolygon ||
                     geomType == ogr.wkbMultiPolygon25D)
            {
                waitMessage.Text += "\nFound " + geom.GetGeometryName() + ", contains " + geom.GetGeometryCount() + " sub-geometries";
                ParseGeometry(geom, keyStringValue, keyNumericValue, labelValue);
            }
        }
        void LoadFile()
        {
            FileInfo f = new FileInfo(fileName);

            fileSubList = null;

            // Create the LM branch for the file...
            foreach (RenderableObject l in layer.ChildObjects)
            {
                if (l.Name == f.Name)
                {
                    fileSubList = (RenderableObjectList)l;
                    break;
                }
            }

            if (fileSubList == null)
            {
                fileSubList = new RenderableObjectList(f.Name);
            }

            layer.Add(fileSubList);


            ogr.UseExceptions();

            try
            {
                ogr.RegisterAll();
                ds       = ogr.Open(fileName, 0);
                ogrLayer = ds.GetLayerByIndex(0);
                SpatialReference inSrs = ogrLayer.GetSpatialRef();

                ArrayList fieldNames = GetFieldNames(ogrLayer);

                infoSelector = new VectorInfoSelector(ogrLayer);
                if (infoSelector.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                styleSubList      = new RenderableObjectList(infoSelector.TextStyle.Layername);
                styleSubList.IsOn = false;
                fileSubList.Add(styleSubList);

                keyFieldName   = infoSelector.TextStyle.KeyDataFieldName;
                keyDataType    = infoSelector.TextStyle.DataType;
                labelFieldName = infoSelector.TextStyle.LabelFieldName;

                if (keyDataType == DataType.Text && infoSelector.TextStyle.TextFilter)
                {
                    filterString   = infoSelector.TextStyle.TextFilterString;
                    textFilterType = infoSelector.TextStyle.TextFilterType;
                }

                maxPolygonColor    = infoSelector.NumericMaxStyle.PolygonColor;
                maxLineColor       = infoSelector.NumericMaxStyle.LineColor;
                maxLineWidth       = infoSelector.NumericMaxStyle.LineWidth;
                maxOutlinePolygons = infoSelector.NumericMaxStyle.OutlinePolygons;

                minPolygonColor    = infoSelector.NumericMinStyle.PolygonColor;
                minLineColor       = infoSelector.NumericMinStyle.LineColor;
                minLineWidth       = infoSelector.NumericMinStyle.LineWidth;
                minOutlinePolygons = infoSelector.NumericMinStyle.OutlinePolygons;

                noDataLineColor       = infoSelector.NumericNoDataStyle.LineColor;
                noDataLineWidth       = infoSelector.NumericNoDataStyle.LineWidth;
                noDataPolygonColor    = infoSelector.NumericNoDataStyle.PolygonColor;
                noDataOutlinePolygons = infoSelector.NumericNoDataStyle.OutlinePolygons;
                noDataValue           = infoSelector.NumericNoDataStyle.NoDataValue;

                textLineColor       = infoSelector.TextStyle.LineColor;
                textLineWidth       = infoSelector.TextStyle.LineWidth;
                textPolygonColor    = infoSelector.TextStyle.PolygonColor;
                textOutlinePolygons = infoSelector.TextStyle.OutlinePolygons;


                if (infoSelector.Projection.Contains("EPSG"))
                {
                    string trimString = "EPSG:";
                    string epsgString = infoSelector.Projection.Trim(trimString.ToCharArray());
                    int    epsg       = int.Parse(epsgString);
                    inSrs = new SpatialReference("");
                    inSrs.ImportFromEPSG(epsg);
                }
                else if (infoSelector.Projection == "" || infoSelector.Projection == "(unknown)")
                {
                    inSrs = null;
                }
                else
                {
                    inSrs = new SpatialReference("");
                    inSrs.ImportFromProj4(infoSelector.Projection);
                }

                OGR.SpatialReference outSrs = new OGR.SpatialReference(outWkt);
                //outSrs.ImportFromEPSG(4326);

                if (inSrs != null)
                {
                    coordTransform      = new CoordinateTransformation(inSrs, outSrs);
                    needsTransformation = true;
                    Console.WriteLine("Reprojecting...");
                }

                keyFieldIndex   = GetFieldIndexFromString(keyFieldName, fieldNames);
                labelFieldIndex = GetFieldIndexFromString(labelFieldName, fieldNames);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\nNo features imported.");
                return;
            }

            Thread t = new Thread(new System.Threading.ThreadStart(LoadVectors));

            t.IsBackground = true;
            t.Start();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Plugin entry point - All plugins must implement this function
        /// </summary>
        public override void Load()
        {
            FileInfo savedFile = new FileInfo(SavedFilePath);

            if (!savedFile.Exists)
            {
                if (!savedFile.Directory.Exists)
                {
                    savedFile.Directory.Create();
                }

                try
                {
                    // Offline check
                    if (World.Settings.WorkOffline)
                    {
                        throw new Exception("Offline mode active.");
                    }

                    MFW3D.Net.WebDownload download = new MFW3D.Net.WebDownload(DataFileUri);
                    download.DownloadFile(savedFile.FullName);
                    download.Dispose();
                }
                catch { }
            }

            m_wavingFlagsList      = new RenderableObjectList("Waving Flags");
            m_wavingFlagsList.IsOn = false;
            System.Collections.Hashtable countryHash = new System.Collections.Hashtable();

            using (StreamReader reader = savedFile.OpenText())
            {
                string   header  = reader.ReadLine();
                string[] headers = header.Split('\t');

                string line = reader.ReadLine();
                while (line != null)
                {
                    System.Collections.Hashtable fieldHash = new System.Collections.Hashtable();
                    string[] lineParts = line.Split('\t');

                    //Log.Write(string.Format("{0}\t{1}", lineParts[0], lineParts[1]));
                    try
                    {
                        if ((lineParts[3].Length > 0) && (lineParts[4].Length > 0))
                        {
                            double latitude  = double.Parse(lineParts[3], System.Globalization.CultureInfo.InvariantCulture);
                            double longitude = double.Parse(lineParts[4], System.Globalization.CultureInfo.InvariantCulture);

                            if (lineParts[1].Length == 2)
                            {
                                string   flagFileUri   = FlagTextureDirectoryUri + "/" + lineParts[1] + FlagSuffix;
                                FileInfo savedFlagFile = new FileInfo(SavedFlagsDirectory + "\\" + lineParts[1] + ".dds");

                                WavingFlagLayer flag = new WavingFlagLayer(
                                    lineParts[0],
                                    Global.worldWindow.CurrentWorld,
                                    latitude,
                                    longitude,
                                    flagFileUri);

                                flag.SavedImagePath = savedFlagFile.FullName;
                                flag.ScaleX         = 100000;
                                flag.ScaleY         = 100000;
                                flag.ScaleZ         = 100000;
                                flag.Bar3D          = new Bar3D(flag.Name, flag.World, latitude, longitude, 0, flag.ScaleZ, System.Drawing.Color.Red);
                                flag.Bar3D.ScaleX   = 0.3f * flag.ScaleX;
                                flag.Bar3D.ScaleY   = 0.3f * flag.ScaleY;
                                flag.Bar3D.IsOn     = false;
                                flag.RenderPriority = RenderPriority.Custom;

                                flag.OnMouseEnterEvent += new EventHandler(flag_OnMouseEnterEvent);
                                flag.OnMouseLeaveEvent += new EventHandler(flag_OnMouseLeaveEvent);
                                flag.OnMouseUpEvent    += new System.Windows.Forms.MouseEventHandler(flag_OnMouseUpEvent);
                                m_wavingFlagsList.Add(flag);

                                for (int i = 0; i < lineParts.Length; i++)
                                {
                                    try
                                    {
                                        double value;
                                        if (double.TryParse(lineParts[i], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out value))
                                        {
                                            fieldHash.Add(headers[i], value);
                                        }
                                        else
                                        {
                                            fieldHash.Add(headers[i], lineParts[i]);
                                        }
                                    }
                                    catch
                                    {
                                        fieldHash.Add(headers[i], lineParts[i]);
                                    }
                                }
                                countryHash.Add(lineParts[0], fieldHash);
                            }
                            else
                            {
                                //Log.Write(Log.Levels.Debug, "blank: " + lineParts[0]);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Write(Log.Levels.Warning, string.Format("Exception: {0} - {1}", lineParts[0], ex.ToString()));
                    }

                    line = reader.ReadLine();
                }
                Headers = headers;
            }

            CountryHash = countryHash;

            InitializeCiaForm();

            Global.worldWindow.CurrentWorld.RenderableObjects.Add(m_wavingFlagsList);
        }