Пример #1
0
 public bool Validate()
 {
     if (FeatureSet != null)
     {
         var dt = FeatureSet.DataTable;
         if (dt.Rows.Count == ActiveCellCount)
         {
             if (!dt.Columns.Contains(ParaValueField))
             {
                 dt.Columns.Add(new DataColumn(ParaValueField, Type.GetType("System.Double")));
                 for (int i = 0; i < dt.Rows.Count; i++)
                 {
                     dt.Rows[i][ParaValueField] = 0;
                 }
                 FeatureSet.Save();
             }
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Пример #2
0
 public void EditShapefile(string shapefilename)
 {
     using (var fs = new FeatureSet(Path.Combine(FranceProjectPath, "Shapefiles", shapefilename)))
     {
         // Go to edit mode:
         fs.StartEditingShapes();
         Assert.IsTrue(fs.EditingShapes, "Could not set in edit mode");
         // Save shapefile:
         fs.Save();
         // Close feature set:
         fs.Close();
     }
 }
        /// <summary>
        /// Overloaded method for rendering point data on map
        /// </summary>
        /// <param name="MyRemainingFacets"></param>
        private void PutReturnOnMap(IEnumerable <FacetedSearch3.CUAHSIFacetedSearch.SiteData> MyRemainingFacets)
        {
            ClearPointLayersFromMap();
            FeatureSet fs = new FeatureSet(FeatureType.Point);

            fs.Projection = KnownCoordinateSystems.Geographic.World.WGS1984;

            foreach (FacetedSearch3.CUAHSIFacetedSearch.SiteData o in MyRemainingFacets)
            {
                DotSpatial.Topology.Point p = new DotSpatial.Topology.Point();
                p.X = o.longitude;
                p.Y = o.latitude;
                fs.AddFeature(p);
            }

            fs.Filename = FacetedShapeFileName;
            fs.Save();

            App.Map.AddLayer(FacetedShapeFileName);
            // map1.Layers.Add(MyLocations);
        }
Пример #4
0
        private void btn_Ok_Click(object sender, EventArgs e)
        {
            string outputDir = tbx_Dir.Text.Trim();

            if (!Directory.Exists(outputDir))
            {
                if (string.IsNullOrWhiteSpace(outputDir))
                {
                    MessageBox.Show("请选择Shapefile文件保存文件夹");
                    return;
                }
                Directory.CreateDirectory(outputDir);
            }


            List <FeatureClass> pOutputFeatureClasses = GetCheckedFeatureClass();

            foreach (FeatureClass feaClass in pOutputFeatureClasses)
            {
                DataTable pDT = feaClass.GetDataTable();
                if (pDT == null)
                {
                    //表格不存在
                    MessageBox.Show(feaClass.Name + "表格不存在。");
                    continue;
                }
                if (pDT.Rows.Count == 0)
                {
                    //MessageCenterMgr.MessageCenter.AddInfoMsg(feaClass.Name + "表格中要素个数为0。");
                    MessageBox.Show(feaClass.Name + "表格中要素个数为0。");
                    continue;
                }

                List <IFeatureSet> feaSets = new List <IFeatureSet>();



                IFeatureSet feaSet = null;
                switch (feaClass.GeometryType)
                {
                case EsriGeometryType.Point:
                    feaSet = new FeatureSet(FeatureType.Point);
                    break;

                case EsriGeometryType.MultiPoint:
                    feaSet = new FeatureSet(FeatureType.MultiPoint);
                    break;

                case EsriGeometryType.Line:
                    feaSet = new FeatureSet(FeatureType.Line);
                    break;

                case EsriGeometryType.Polygon:
                    feaSet = new FeatureSet(FeatureType.Polygon);
                    break;
                }
                if (feaSet == null)
                {
                    MessageBox.Show(feaClass + "表格中几何类型不被支持,请联系开发者处理。");
                    continue;
                }

                Table2ShapeFile(feaSet, pDT, feaClass.GeomShapeFieldName);
                //设置坐标系并保存
                feaSet.Projection = ProjectionInfo.FromEsriString(feaClass.ProjectionString);
                feaSet.Filename   = Path.Combine(tbx_Dir.Text, feaClass.Name + ".shp");
                feaSet.Save();

                MessageBox.Show(feaClass.Name + "表格向Shapefile转换成功。");
            }

            MessageBox.Show("转换完毕");

            pGeoMDBReader.CloseMDB();
            this.Close();
        }
Пример #5
0
        static void Main(string[] args)
        {
            try
            {
                // Connect to the reader.
                // Pass in a reader hostname or IP address as a
                // command line argument when running the example
                if (args.Length != 1)
                {
                    Console.WriteLine("Error: No hostname specified.  Pass in the reader hostname as a command line argument when running the Sdk Example.");
                    return;
                }
                string hostname = args[0];
                reader.Connect(hostname);

                string executingPath = Path.GetFullPath(Path.Combine(Assembly.GetExecutingAssembly().Location, ".."));

                // Query the reader features and print the results.
                Console.WriteLine("Reader Features");
                Console.WriteLine("---------------");
                FeatureSet features = reader.QueryFeatureSet();
                Console.WriteLine("Model name : {0}", features.ModelName);
                Console.WriteLine("Model number : {0}", features.ModelNumber);
                Console.WriteLine("Reader model : {0}", features.ReaderModel.ToString());
                Console.WriteLine("Firmware version : {0}", features.FirmwareVersion);
                Console.WriteLine("Antenna count : {0}\n", features.AntennaCount);

                // Write the reader features to file.
                string featuresFile = Path.Combine(executingPath, "features.xml");
                features.Save(featuresFile);

                // Query the current reader status.
                Console.WriteLine("Reader Status");
                Console.WriteLine("---------------");
                Status status = reader.QueryStatus();
                Console.WriteLine("Is connected : {0}", status.IsConnected);
                Console.WriteLine("Is singulating : {0}", status.IsSingulating);
                Console.WriteLine("Temperature : {0}° C\n", status.TemperatureInCelsius);

                // Configure the reader with the default settings.
                reader.ApplyDefaultSettings();

                // Display the current reader settings.
                DisplayCurrentSettings();

                // Save the settings to file in XML format.
                Console.WriteLine("Saving settings to file.");
                Settings settings     = reader.QuerySettings();
                string   settingsFile = Path.Combine(executingPath, "settings.xml");
                settings.Save(settingsFile);

                // Wait here, so we can edit the
                // settings.xml file in a text editor.
                Console.WriteLine("Edit settings.xml and press enter.");
                Console.ReadLine();

                // Load the modified settings from file.
                Console.WriteLine("Loading settings from file.");
                settings = Settings.Load(settingsFile);

                // Apply the settings we just loaded from file.
                Console.WriteLine("Applying settings from file.\n");
                reader.ApplySettings(settings);

                // Display the settings again to show the changes.
                DisplayCurrentSettings();

                // Wait for the user to press enter.
                Console.WriteLine("Press enter to exit.");
                Console.ReadLine();

                // Disconnect from the reader.
                reader.Disconnect();
            }
            catch (OctaneSdkException e)
            {
                // Handle Octane SDK errors.
                Console.WriteLine("Octane SDK exception: {0}", e.Message);
            }
            catch (Exception e)
            {
                // Handle other .NET errors.
                Console.WriteLine("Exception : {0}", e.Message);
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            try
            {
                // Connect to the reader.
                // Change the ReaderHostname constant in SolutionConstants.cs
                // to the IP address or hostname of your reader.
                reader.Connect(SolutionConstants.ReaderHostname);

                // Query the reader features and print the results.
                Console.WriteLine("Reader Features");
                Console.WriteLine("---------------");
                FeatureSet features = reader.QueryFeatureSet();
                Console.WriteLine("Model name : {0}", features.ModelName);
                Console.WriteLine("Model number : {0}", features.ModelNumber);
                Console.WriteLine("Reader model : {0}", features.ReaderModel.ToString());
                Console.WriteLine("Firmware version : {0}", features.FirmwareVersion);
                Console.WriteLine("Antenna count : {0}\n", features.AntennaCount);

                // Write the reader features to file.
                features.Save("features.xml");

                // Query the current reader status.
                Console.WriteLine("Reader Status");
                Console.WriteLine("---------------");
                Status status = reader.QueryStatus();
                Console.WriteLine("Is connected : {0}", status.IsConnected);
                Console.WriteLine("Is singulating : {0}", status.IsSingulating);
                Console.WriteLine("Temperature : {0}° C\n", status.TemperatureInCelsius);

                // Configure the reader with the default settings.
                reader.ApplyDefaultSettings();

                // Display the current reader settings.
                DisplayCurrentSettings();

                // Save the settings to file in XML format.
                Console.WriteLine("Saving settings to file.");
                Settings settings = reader.QuerySettings();
                settings.Save("settings.xml");

                // Wait here, so we can edit the
                // settings.xml file in a text editor.
                Console.WriteLine("Edit settings.xml and press enter.");
                Console.ReadLine();

                // Load the modified settings from file.
                Console.WriteLine("Loading settings from file.");
                settings = Settings.Load("settings.xml");

                // Apply the settings we just loaded from file.
                Console.WriteLine("Applying settings from file.\n");
                reader.ApplySettings(settings);

                // Display the settings again to show the changes.
                DisplayCurrentSettings();

                // Wait for the user to press enter.
                Console.WriteLine("Press enter to exit.");
                Console.ReadLine();

                // Disconnect from the reader.
                reader.Disconnect();
            }
            catch (OctaneSdkException e)
            {
                // Handle Octane SDK errors.
                Console.WriteLine("Octane SDK exception: {0}", e.Message);
            }
            catch (Exception e)
            {
                // Handle other .NET errors.
                Console.WriteLine("Exception : {0}", e.Message);
            }
        }
Пример #7
0
        public static void CreateNew()
        {
            void CreatePoint()
            {
                IFeatureSet fs     = new FeatureSet(FeatureType.Point);
                var         point1 = new GeoPoint(133, 30);
                var         point2 = new GeoPoint(133, 32);
                var         point3 = new GeoPoint(134, 30);

                var feature1 = new Feature(new Geometry(point1));
                var feature2 = new Feature(new Geometry(point2));
                var feature3 = new Feature(new Geometry(point3));

                fs.Features.Add(feature1);
                fs.Features.Add(feature2);
                fs.Features.Add(feature3);
                fs.Crs = Crs.Wgs84Gcs;

                var dataTable = new DataTable();

                dataTable.Columns.Add("名称", typeof(string));
                dataTable.Columns.Add("id", typeof(int));
                var row1 = dataTable.NewRow();
                var row2 = dataTable.NewRow();
                var row3 = dataTable.NewRow();

                row1[0] = "点1";
                row1[1] = 1;

                row2[0] = "点2";
                row2[1] = 2;

                row3[0] = "点3";
                row3[1] = 3;

                dataTable.Rows.Add(row1);
                dataTable.Rows.Add(row2);
                dataTable.Rows.Add(row3);

                fs.AttrTable = dataTable;

                fs.Save("../createNew/point.shp");
            }

            void CreateMultiPoint()
            {
                IFeatureSet fs = new FeatureSet(FeatureType.MultiPoint);

                var point1 = new GeoPoint(133, 30);
                var point2 = new GeoPoint(133, 32);
                var point3 = new GeoPoint(134, 30);

                var point4 = new GeoPoint(134, 34);
                var point5 = new GeoPoint(135, 35);

                var multiPoint1 = new MultiPoint(new List <GeoPoint>()
                {
                    point1, point2, point3
                });

                var multiPoint2 = new MultiPoint();

                multiPoint2.Points.Add(point4);
                multiPoint2.Points.Add(point5);


                var feature1 = new Feature(new Geometry(multiPoint1));
                var feature2 = new Feature(new Geometry(multiPoint2));

                fs.Features.Add(feature1);
                fs.Features.Add(feature2);
                fs.Crs = Crs.Wgs84Gcs;

                var dataTable = new DataTable();

                dataTable.Columns.Add("名称", typeof(string));
                dataTable.Columns.Add("id", typeof(int));
                var row1 = dataTable.NewRow();
                var row2 = dataTable.NewRow();

                row1[0] = "多点1";
                row1[1] = 1;

                row2[0] = "多点2";
                row2[1] = 2;

                dataTable.Rows.Add(row1);
                dataTable.Rows.Add(row2);

                fs.AttrTable = dataTable;

                fs.Save("../createNew/multipoint.shp");
            }

            void CreatePolyLine()
            {
                IFeatureSet fs = new FeatureSet(FeatureType.PolyLine);

                var point1 = new GeoPoint(133, 30);
                var point2 = new GeoPoint(133, 32);
                var point3 = new GeoPoint(134, 30);

                var point4 = new GeoPoint(134, 34);
                var point5 = new GeoPoint(135, 35);

                //line ring
                var polyLine1 = new PolyLine(new List <GeoPoint>()
                {
                    point1, point2, point3, point1
                });
                var isLineRing = polyLine1.IsLineRing;

                var polyLine2 = new PolyLine(new List <GeoPoint>()
                {
                    point4, point5
                });

                var feature1 = new Feature(new Geometry(polyLine1));
                var feature2 = new Feature(new Geometry(polyLine2));

                fs.Features.Add(feature1);
                fs.Features.Add(feature2);
                fs.Crs = Crs.Wgs84Gcs;

                var dataTable = new DataTable();

                dataTable.Columns.Add("名称", typeof(string));
                dataTable.Columns.Add("id", typeof(int));
                var row1 = dataTable.NewRow();
                var row2 = dataTable.NewRow();

                row1[0] = "线1";
                row1[1] = 1;

                row2[0] = "线2";
                row2[1] = 2;

                dataTable.Rows.Add(row1);
                dataTable.Rows.Add(row2);

                fs.AttrTable = dataTable;

                fs.Save("../createNew/polyline.shp");
            }

            void CreateMultiPolyLine()
            {
                IFeatureSet fs = new FeatureSet(FeatureType.PolyLine);

                var point1 = new GeoPoint(132, 30);
                var point2 = new GeoPoint(136, 30);
                var point3 = new GeoPoint(134, 28);
                var point4 = new GeoPoint(134, 32);

                var polyLine1 = new PolyLine(new List <GeoPoint>()
                {
                    point1, point2
                });

                var polyLine2 = new PolyLine(new List <GeoPoint>()
                {
                    point3, point4
                });

                var multiPolyLine1 = new MultiPolyLine(new List <PolyLine>()
                {
                    polyLine1, polyLine2
                });

                var feature1 = new Feature(new Geometry(multiPolyLine1));

                fs.Features.Add(feature1);
                fs.Crs = Crs.Wgs84Gcs;

                var dataTable = new DataTable();

                dataTable.Columns.Add("名称", typeof(string));
                dataTable.Columns.Add("id", typeof(int));
                var row1 = dataTable.NewRow();

                row1[0] = "十字多线";
                row1[1] = 1;

                dataTable.Rows.Add(row1);

                fs.AttrTable = dataTable;

                fs.Save("../createNew/multiPolyLine.shp");
            }

            void CreatePolygon()
            {
                IFeatureSet fs = new FeatureSet(FeatureType.Polygon);

                var point1 = new GeoPoint(132, 30);
                var point2 = new GeoPoint(136, 30);
                var point3 = new GeoPoint(132, 35);

                var edge = new PolyLine(new List <GeoPoint>()
                {
                    point1, point2, point3, point1
                });

                var polygon = new Polygon(edge);

                //edge,Clockwise
                var point4 = new GeoPoint(140, 30);
                var point5 = new GeoPoint(140, 35);
                var point6 = new GeoPoint(150, 35);
                var point7 = new GeoPoint(150, 30);
                var edge2  = new PolyLine(new List <GeoPoint>()
                {
                    point4, point5, point6, point7, point4
                });

                //points sketch
                //              .(point9)
                //
                //  .(point8)          .(point10)
                //
                var point8  = new GeoPoint(142, 31);
                var point9  = new GeoPoint(145, 33);
                var point10 = new GeoPoint(148, 31);

                //hole, need Counterclockwise,
                //if Counterclockwise, sequence should be:
                //point8, point10, point9
                //It will be handled inside the library.
                //It will be a line ring inside the library too
                var hole = new PolyLine(new List <GeoPoint>()
                {
                    point8, point9, point10
                });
                var polygon2 = new Polygon(edge2, hole);


                var feature1 = new Feature(new Geometry(polygon));
                var feature2 = new Feature(new Geometry(polygon2));

                fs.Features.Set(new List <IFeature>()
                {
                    feature1,
                    feature2
                });
                fs.Crs = Crs.Wgs84Gcs;


                var dataTable = new DataTable();

                dataTable.Columns.Add("名称", typeof(string));
                dataTable.Columns.Add("id", typeof(int));
                var row1 = dataTable.NewRow();
                var row2 = dataTable.NewRow();

                row1[0] = "简单面";
                row1[1] = 1;

                row2[0] = "带洞面";
                row2[1] = 2;

                dataTable.Rows.Add(row1);
                dataTable.Rows.Add(row2);

                fs.AttrTable = dataTable;

                fs.Save("../createNew/polygon.shp");
            }

            CreatePoint();
            CreateMultiPoint();
            CreatePolyLine();
            CreateMultiPolyLine();
            CreatePolygon();
        }
Пример #8
0
        public void RaiseCallbackEvent(String eventArgument)
//        public virtual void RaiseCallbackEvent(String eventArgument)  //to override in subclass
        {
//            returnCommand = "REFRESH";  //unsightly refresh when change legend selection
            returnCommand = "NOTHING";

//            string Nm = SessionName;  //not used

            GDIMap m = (GDIMap)System.Web.HttpContext.Current.Session[(string)ViewState[ClientID]];

            if (m == null)
            {
                return;
            }

            string[] arg = eventArgument.Split('|');

            string cmd = arg[0].ToUpper();

            switch (cmd)
            {
            case "ZOOMALL":
            {
                ZoomAll(ref m);
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "SELECT":
            {
                if (m.Layers.SelectedLayer != null)
                {
                    System.Drawing.Point pt1 = new System.Drawing.Point(Convert.ToInt32(arg[1]), Convert.ToInt32(arg[2]));
                    System.Drawing.Point pt2 = new System.Drawing.Point(Convert.ToInt32(arg[3]), Convert.ToInt32(arg[4]));

                    Coordinate pm1 = m.PixelToProj(pt1);
                    Coordinate pm2 = m.PixelToProj(pt2);

                    Extent ex = new Extent(Math.Min(pm1.X, pm2.X), Math.Min(pm1.Y, pm2.Y),
                                           Math.Max(pm1.X, pm2.X), Math.Max(pm1.Y, pm2.Y));

                    IEnvelope MapEnv = m.Extent.ToEnvelope();

                    m.Layers.SelectedLayer.ClearSelection(out MapEnv);


                    m.Layers.SelectedLayer.ClearSelection();

                    IEnvelope affectedarea = null;

//                                m.Layers.SelectedLayer.Select(m.ViewExtents.ToEnvelope(), ex.ToEnvelope(), Symbology.SelectionMode.IntersectsExtent, out affectedarea);
                    m.Layers.SelectedLayer.Select(ex.ToEnvelope(), ex.ToEnvelope(), Symbology.SelectionMode.Intersects, out affectedarea);

                    returnCommand = "STRUCTURE";
                }
                else
                {
                    returnValue   = "<table><tr><td>Select a layer first.<p></td></tr><table>";
                    returnCommand = "POPUP";
//                                returnValue = "Select a layer first.";
//                                returnCommand = "ALERT";
                }
            }
            break;

            case "INFO":
            {
                System.Drawing.Point pt = new System.Drawing.Point(Convert.ToInt32(arg[2]), Convert.ToInt32(arg[3]));
                Coordinate           pm = m.PixelToProj(pt);

                Extent ex = new Extent(pm.X, pm.Y, pm.X, pm.Y);

                if (m.Layers.SelectedLayer != null)
                {
                    FeatureSet fs = m.Layers.SelectedLayer.DataSet as FeatureSet;

//                                List<IFeature> flist = fs.Select(ex);  //returns empty list when IndexMode == false
                    List <int> flist = fs.SelectIndices(ex);

                    int n = flist.Count;

//                                returnValue = "<table border='1'>";  //looks goofy
                    returnValue = "<table>";

                    if (n > 0)
                    {
                        for (int i = 0; i < fs.DataTable.Columns.Count; i++)
                        {
                            returnValue += "<tr><td>" + fs.DataTable.Columns[i].ColumnName +
//                                                       "</td><td>" + flist[0].DataRow[i].ToString() + "</td></tr>";
                                           "</td><td>" + fs.GetFeature(flist[0]).DataRow[i].ToString() + "</td></tr>";
                        }

                        returnValue  += "</table>";
                        returnCommand = "POPUP";
                    }
                }
                else
                {
                    returnValue   = "<table><tr><td>Select a layer first.<p></td></tr><table>";
                    returnCommand = "POPUP";
//                                returnValue = "Select a layer first.";
//                                returnCommand = "ALERT";
                }
            }
            break;


            case "RESIZE":
            {
                Size NewSz    = new Size(Convert.ToInt32(arg[2]), Convert.ToInt32(arg[3]));
                Size ActualSz = ControlSize;

                if (ActualSz.Width == 0 || ActualSz.Height == 0)
                {
                    ControlSize = NewSz;

                    ZoomAll(ref m);

                    returnCommand = "STRUCTURE";
                }
                else
                {
                    if (NewSz != ActualSz)
                    {
                        ControlSize = NewSz;

                        returnCommand = "STRUCTURE";
                    }
                    else
                    {
                        returnCommand = "NOTHING";
                    }
                }
            }
            break;

            case "ZOOMRECT":
            {
                System.Drawing.Point pt1 = new System.Drawing.Point(Convert.ToInt32(arg[1]), Convert.ToInt32(arg[2]));
                System.Drawing.Point pt2 = new System.Drawing.Point(Convert.ToInt32(arg[3]), Convert.ToInt32(arg[4]));

                Coordinate pm1 = m.PixelToProj(pt1);
                Coordinate pm2 = m.PixelToProj(pt2);

                Extent x = new Extent(Math.Min(pm1.X, pm2.X),
                                      Math.Min(pm1.Y, pm2.Y),
                                      Math.Max(pm1.X, pm2.X),
                                      Math.Max(pm1.Y, pm2.Y));

                m.ViewExtents = x;
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "ZOOMIN":
            {
                int x = Convert.ToInt32(arg[1]);
                int y = Convert.ToInt32(arg[2]);

                System.Drawing.Point pntZoomAndCenter = new System.Drawing.Point((x - m.Size.Width / 2), (y - m.Size.Height / 2));
                m.MapFrame.Pan(pntZoomAndCenter);
                m.ZoomIn();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "ZOOMOUT":
            {
                int x = Convert.ToInt32(arg[1]);
                int y = Convert.ToInt32(arg[2]);

                System.Drawing.Point pnt = new System.Drawing.Point((x - m.Size.Width / 2), (y - m.Size.Height / 2));

                m.MapFrame.Pan(pnt);
                m.ZoomOut();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "PAN":
            {
                int x = Convert.ToInt32(arg[1]);
                int y = Convert.ToInt32(arg[2]);

// not used:                System.Drawing.Point pnt = new System.Drawing.Point((x - m.Size.Width / 2), (y - m.Size.Height / 2));

                m.MapFrame.Pan(new System.Drawing.Point(x, y));
                returnCommand = "REFRESH";
            }
            break;

            case "WHEELIN":
            {
                m.ZoomIn();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "WHEELOUT":
            {
                m.ZoomOut();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "DATAGRID":          //moved to here from RaisePostBackEvent
            {
                if (m.Layers.SelectedLayer != null)
                {
                    //string script=null;

                    IMapFeatureLayer MFL = (IMapFeatureLayer)m.Layers.SelectedLayer;

                    int n = MFL.Selection.Count;

                    FeatureSet fs;
                    DataTable  rs;
                    if (n > 0)
                    {
                        fs = MFL.Selection.ToFeatureSet();
                        rs = fs.DataTable;
                    }
                    else
                    {
                        fs = MFL.DataSet as FeatureSet;
                        rs = fs.DataTable;
                    }

                    if (DataOnGrid != null)              //Let event handler display grid?
                    {
                        DataGridEventArgs e = new DataGridEventArgs();
                        e.Recordsource = rs;
                        DataOnGrid(this, e);
                    }
                    else              //Display default HTML grid
                    {
                        returnValue = "<table border='1'><tr>";

                        for (int h = 0; h < rs.Columns.Count; h++)
                        {
                            returnValue += "<th>" + rs.Columns[h].ColumnName + "</th>";
                        }
                        returnValue += "</tr>";

                        string rowHtml;
                        for (int r = 0; r < rs.Rows.Count; r++)
                        {              //note: _much_ faster if build each row separately
                            rowHtml = "<tr>";
                            for (int c = 0; c < rs.Columns.Count; c++)
                            {
                                rowHtml += "<td>" + fs.GetFeature(r).DataRow[c].ToString() + "</td>";
                            }
                            rowHtml     += "</tr>";
                            returnValue += rowHtml;
                        }
                        returnValue  += "</table>";
                        returnCommand = "POPUP";
                    }
                }
                else
                {
                    returnValue   = "<table><tr><td>Select a layer first.<p></td></tr><table>";
                    returnCommand = "POPUP";
                }
            }
            break;

            case "ADDFEATURE":          //moved to here from RaisePostBackEvent
            {
                int num = Convert.ToInt32(arg[1]);

                System.Drawing.Point pt = new System.Drawing.Point();
                Coordinate[]         pm = new Coordinate[num];

                for (int i = 0; i < num; i++)
                {
                    pt.X = Convert.ToInt32(arg[(i + 1) * 2]);
                    pt.Y = Convert.ToInt32(arg[(i + 1) * 2 + 1]);

                    pm[i] = m.PixelToProj(pt);
                }

                if (m.Layers.SelectedLayer != null)
                {
                    FeatureSet  fs = m.Layers.SelectedLayer.DataSet as FeatureSet;
                    Feature     f;
                    FeatureType ft = FeatureType.Unspecified;

                    IMapFeatureLayer MFL = (IMapFeatureLayer)m.Layers.SelectedLayer;

                    if (MFL.GetType() == typeof(MapPointLayer))
                    {
                        ft = FeatureType.Point;
                    }
                    if (MFL.GetType() == typeof(MapLineLayer))
                    {
                        ft = FeatureType.Line;
                    }
                    if (MFL.GetType() == typeof(MapPolygonLayer))
                    {
                        ft = FeatureType.Polygon;
                    }

                    if (ft != FeatureType.Unspecified)
                    {
                        f = new Feature(ft, pm);

                        try
                        {
                            if (AddFeature != null)
                            {
                                AddFeature(this, fs, f);
                            }
                            else
                            {
                                try
                                {
                                    fs.AddFeature(f);
                                    fs.Save();
                                }
                                catch
                                {
                                    fs.Features.Remove(f);
                                    throw;              //re-throw exception
                                }
                                fs.InitializeVertices();
                            }
                            //Apparently have to force recreating labels when add feature.
                            if (MFL.LabelLayer != null)
                            {
                                // Recreating label layer works.
//                                            MapLabelLayer NewLabels = new MapLabelLayer();
//                                            NewLabels.Symbology = MFL.LabelLayer.Symbology;
//                                            NewLabels.Symbolizer = MFL.LabelLayer.Symbolizer;
//                                            MFL.LabelLayer = NewLabels;
                                // Recreating just labels also works.
                                MFL.LabelLayer.CreateLabels();
                            }
                            returnCommand = "FORCEREFRESH";
                        }
                        catch (Exception e)
                        {
                            returnValue   = "Unable to save feature.<p>" + e.Message;
                            returnCommand = "POPUPANDREFRESH";              //erase new shape too
                        }

//                                    fs.IndexMode = true;
                        //Adding a feature sets FeatureSet.IndexMode to false,
                        // causing fs.Select above in INFO case to return a list
                        // with Count == 0. One workaround is to set IndexMode
                        // back to true. This does cause all existing labels
                        // to disapper with refresh, but recreating label layer
                        // above fixed that. (Also tried InitializeVertices,
                        // InvalidateEnvelope, InvalidateVertices, UpdateExtents, etc.)
                        // Oops, setting IndexMode back to true corrupts shapes...
                    }
                }
            }
            break;
            }

            //ControlMap = m;
            System.Web.HttpContext.Current.Session[(string)ViewState[ClientID]] = m;

            if (returnCommand == "STRUCTURE")
            {
                returnValue = redraw(ref m);

                if (OnRedraw != null)
                {
                    OnRedraw(this);
                }
            }

            if (returnCommand == "REFRESH" | returnCommand == "REFRESHANDHIDEBUFFER")
            {
                returnValue = refresh(ref m);

                if (OnRedraw != null)
                {
                    OnRedraw(this);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// given a data table, create an in-memory point feature set.
        /// The feature set must have the 'Latitude' and 'Longitude' numeric
        /// columns
        /// </summary>
        /// <param name="themeTable">The table of distinct series</param>
        /// <param name="projection">The projection of the theme feature set</param>
        /// <returns>A point FeatureSet in the WGS-84 coordinate system
        /// All columns of the data table will be converted to atrribute fields</returns>
        private IFeatureSet TableToFeatureSet(DataTable themeTable, ProjectionInfo projection = null)
        {
            //index of the Latitude column
            int latColIndex = -1;

            //index of the Longitude column
            int lonColIndex = -1;

            //get the latitude and longitude column indices
            for (int col = 0; col < themeTable.Columns.Count; col++)
            {
                string colName = themeTable.Columns[col].ColumnName.ToLower();

                if (colName == "latitude")
                {
                    latColIndex = col;
                }

                if (colName == "longitude")
                {
                    lonColIndex = col;
                }
            }

            //check if the latitude column exists
            if (latColIndex == -1)
            {
                throw new ArgumentException("The table doesn't have a column 'Latitude'");
            }
            //check if the longitude column exists
            if (lonColIndex == -1)
            {
                throw new ArgumentException("The table doesn't have a column 'Longitude'");
            }

            //generate attribute table schema
            var fs             = new FeatureSet(FeatureType.Point);
            var attributeTable = fs.DataTable;

            foreach (DataColumn column in themeTable.Columns)
            {
                attributeTable.Columns.Add(column.DataType == typeof(DateTime)
                                               ? new Field(column.ColumnName, 'C', 16, 0)
                                               : new DataColumn(column.ColumnName, column.DataType));
            }

            //generate features
            foreach (DataRow row in themeTable.Rows)
            {
                double lat        = Convert.ToDouble(row[latColIndex]);
                double lon        = Convert.ToDouble(row[lonColIndex]);
                var    coord      = new Coordinate(lon, lat);
                var    newFeature = new Feature(FeatureType.Point, new[] { coord });
                fs.Features.Add(newFeature);

                var featureRow = newFeature.DataRow;
                for (int c = 0; c < attributeTable.Columns.Count; c++)
                {
                    featureRow[c] = themeTable.Columns[c].DataType == typeof(DateTime)
                                        ? ConvertTime((DateTime)row[c])
                                        : row[c];
                }
            }

            //to save the feature set to a file with unique name
            string uniqueID = DateTime.Now.ToString("yyyyMMdd_hhmmss");
            var    rnd      = new Random();

            uniqueID += rnd.Next(100).ToString("000");
            var filename = Path.Combine(Settings.Instance.CurrentProjectDirectory, "theme_" + uniqueID + ".shp");

            fs.Filename   = filename;
            fs.Projection = _wgs84Projection;
            fs.Save();
            fs.Dispose();

            var fs2 = FeatureSet.OpenFile(filename);

            //to reproject the feature set
            if (projection != null)
            {
                fs2.Reproject(projection);
            }

            return(fs2);
        }
        /// <summary>
        /// Creates shapefile from search results, shows shapefile on map display
        /// </summary>
        /// <param name="SeriesCatalogResults"></param>
        private void PutReturnOnMap(IEnumerable <FacetedSearch3.CUAHSIFacetedSearch.SeriesCatalogRecord> SeriesCatalogResults)
        {
            FeatureSet fs = new FeatureSet(FeatureType.Point);

            try
            {
                ClearPointLayersFromMap();

                // string shapeFileName = String.Format(@"{0}\{1}.shp", Settings.Instance.TempDirectory, "FacetedSearchResult");

                fs.DataTable.Columns.Add(new DataColumn("ServiceCode", typeof(string)));
                fs.DataTable.Columns.Add(new DataColumn("ServiceURL", typeof(string)));
                fs.DataTable.Columns.Add(new DataColumn("SiteCode", typeof(string)));
                fs.DataTable.Columns.Add(new DataColumn("SiteName", typeof(string))); //to improve display of labels and pop-up. shows a copy of SiteCode
                fs.DataTable.Columns.Add(new DataColumn("VarCode", typeof(string)));
                fs.DataTable.Columns.Add(new DataColumn("VarName", typeof(string)));  //to improve display of labels and pop-up. shows a copy of VarCode
                fs.DataTable.Columns.Add(new DataColumn("StartDate", typeof(DateTime)));
                fs.DataTable.Columns.Add(new DataColumn("EndDate", typeof(DateTime)));
                fs.DataTable.Columns.Add(new DataColumn("ValueCount", typeof(int)));

                foreach (FacetedSearch3.CUAHSIFacetedSearch.SeriesCatalogRecord o in SeriesCatalogResults)
                {
                    DotSpatial.Topology.Point p = new DotSpatial.Topology.Point(o.Longitude, o.Latitude);
                    IFeature f = fs.AddFeature(p);
                    f.DataRow.BeginEdit();
                    f.DataRow["ServiceCode"] = o.ServCode;
                    f.DataRow["ServiceURL"]  = o.ServURL;
                    f.DataRow["SiteCode"]    = o.SiteCode;
                    f.DataRow["SiteName"]    = o.SiteName;
                    f.DataRow["VarCode"]     = o.VarCode;
                    f.DataRow["VarName"]     = o.VariableName;
                    f.DataRow["StartDate"]   = o.StartDate;
                    f.DataRow["EndDate"]     = o.EndDate;
                    f.DataRow["ValueCount"]  = o.ValueCount;
                    f.DataRow.EndEdit();
                }

                //set the projection
                fs.Projection =
                    new ProjectionInfo();
                fs.ProjectionString = "+proj=longlat +ellps=WGS84 +no_defs";

                // the faceted search shapefile is saved to the current project directory
                // preferably this should be in the current project's directory
                // if the current project directory doesn't exist then use a temp folder
                string facetedSearchShapefileFullPath;
                if (App.SerializationManager.CurrentProjectDirectory == null)
                {
                    string hdTempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "HydroDesktop");
                    facetedSearchShapefileFullPath = System.IO.Path.Combine(hdTempPath, FacetedShapeFileName);
                }
                else
                {
                    facetedSearchShapefileFullPath = System.IO.Path.Combine(App.SerializationManager.CurrentProjectDirectory, FacetedShapeFileName);
                }
                fs.Filename = facetedSearchShapefileFullPath;
                fs.Save();

                // implement threshold for adding to map directly or via shapefile on disk?
                if (SeriesCatalogResults.Count <FacetedSearch3.CUAHSIFacetedSearch.SeriesCatalogRecord>() > 25000)
                {
                }
                else
                {
                }

                // need to use the full path (relative path didn't work when deploying
                // the plugin as a package)
                App.Map.AddLayer(facetedSearchShapefileFullPath);
            }
            finally
            {
                fs.Dispose();
            }

            //add featureSet to the map
            // IMapLayer newLayer = MapArgs.Map.Layers.Add(shapeFileName);

            //add labels
            // MapArgs.Map.AddLabels((IFeatureLayer)newLayer,
            // String.Format("[{0}]", "FacetedSearchResults"), String.Empty,
            //     new LabelSymbolizer());
        }