/// <summary>
        /// This method gets the map object out of the mapfactory with given mapalias and 
        /// Adds a point feature into a temp layer, exports it to memory stream and streams it back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            // Extract points from the string
            System.Drawing.Point [] points = this.ExtractPoints(this.DataString);

            MapControlModel model = MapControlModel.GetModelFromSession();
            model.SetMapSize(MapAlias, MapWidth, MapHeight);

            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            if(map == null) return;

            // There will be only one point, convert it to spatial
            MapInfo.Geometry.DPoint point;
            map.DisplayTransform.FromDisplay(points[0], out point);

            IMapLayer lyr = map.Layers[SampleConstants.TempLayerAlias];
            if(lyr == null)
            {
                TableInfoMemTable ti = new TableInfoMemTable(SampleConstants.TempTableAlias);
                // Make the table mappable
                ti.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(map.GetDisplayCoordSys()));
                ti.Columns.Add(ColumnFactory.CreateStyleColumn());

                Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
                map.Layers.Insert(0, new FeatureLayer(table, "templayer", SampleConstants.TempLayerAlias));
            }
            lyr = map.Layers[SampleConstants.TempLayerAlias];
            if(lyr == null) return;
            FeatureLayer fLyr = lyr as FeatureLayer;

            MapInfo.Geometry.Point geoPoint = new MapInfo.Geometry.Point(map.GetDisplayCoordSys(), point);
            // Create a Point style which is a red pin point.
            SimpleVectorPointStyle vs = new SimpleVectorPointStyle();
            vs.Code = 67;
            vs.Color = Color.Red;
            vs.PointSize = Convert.ToInt16(24);
            vs.Attributes = StyleAttributes.PointAttributes.BaseAll;
            vs.SetApplyAll();

            // Create a Feature which contains a Point geometry and insert it into temp table.
            Feature pntFeature = new Feature(geoPoint, vs);
            MapInfo.Data.Key key = fLyr.Table.InsertFeature(pntFeature);

            // Send contents back to client.
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);
            StreamImageToClient(ms);
        }
        /// <summary>
        /// This method gets the map object out of the mapfactory with given mapalias and
        /// Adds a point feature into a temp layer, exports it to memory stream and streams it back to client.
        /// </summary>
        /// <remarks>None</remarks>
        public override void Process()
        {
            // Extract points from the string
            System.Drawing.Point [] points = this.ExtractPoints(this.DataString);

            MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);

            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
            if (map == null)
            {
                return;
            }

            // There will be only one point, convert it to spatial
            MapInfo.Geometry.DPoint point;
            map.DisplayTransform.FromDisplay(points[0], out point);

            IMapLayer lyr = map.Layers[SampleConstants.TempLayerAlias];

            if (lyr == null)
            {
                TableInfoMemTable ti = new TableInfoMemTable(SampleConstants.TempTableAlias);
                // Make the table mappable
                ti.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(map.GetDisplayCoordSys()));
                ti.Columns.Add(ColumnFactory.CreateStyleColumn());

                Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
                map.Layers.Insert(0, new FeatureLayer(table, "templayer", SampleConstants.TempLayerAlias));
            }
            lyr = map.Layers[SampleConstants.TempLayerAlias];
            if (lyr == null)
            {
                return;
            }
            FeatureLayer fLyr = lyr as FeatureLayer;

            MapInfo.Geometry.Point geoPoint = new MapInfo.Geometry.Point(map.GetDisplayCoordSys(), point);
            // Create a Point style which is a red pin point.
            SimpleVectorPointStyle vs = new SimpleVectorPointStyle();

            vs.Code       = 67;
            vs.Color      = Color.Red;
            vs.PointSize  = Convert.ToInt16(24);
            vs.Attributes = StyleAttributes.PointAttributes.BaseAll;
            vs.SetApplyAll();

            // Create a Feature which contains a Point geometry and insert it into temp table.
            Feature pntFeature = new Feature(geoPoint, vs);

            MapInfo.Data.Key key = fLyr.Table.InsertFeature(pntFeature);

            // Send contents back to client.
            MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat);

            StreamImageToClient(ms);
        }
        static void Main(string[] args)
        {
            // register URL with a specific WFS reader
            WfsReaderFactory.RegisterHandler(URL, typeof(WfsReader));

            // Get the WFS capabilities of the WFS server using the HTTP GET method.
            try
            {

                // Get the WFS capabilities of the WFS server using the HTTP GET method.
                WfsCapabilities Capabilities = WfsClient.GetCapabilities(RequestMethod.GET, URL);
            }
            catch
            {
                MessageBox.Show("Please check if " + URL + " is a valid WFS URL");
                return;
            }

            // Do something with the the WfsCapabilities here...

            // Get the schema for the USA feature type
            string[] TypeNames = new string[] { "miwfs:USA" };

            // Do something with the schema here...
            XmlSchema usaSchema = WfsClient.DescribeFeatureType(URL, TypeNames);

            // Get all features from the USA feature type
            MultiFeatureCollection usa = WfsClient.GetFeature(URL, TypeNames, null, null, -1, null);
            IFeatureCollection fc = usa[0];

            // iterate over the Usa MultiFeatureCollection and add each
            // IFeatureCollection to a MemTable, etc...
            TableInfoMemTable memTableInfo = new TableInfoMemTable("myMemTable");
            foreach (Column c in fc.Columns) {
                memTableInfo.Columns.Add(c);
            }
            Table memTable = Session.Current.Catalog.CreateTable(memTableInfo);
            memTable.InsertFeatures(fc);

            // create a layer from the MemTable
            FeatureLayer featureLayer = new FeatureLayer(memTable);

            // create the map and add the layer
            Map map = Session.Current.MapFactory.CreateEmptyMap(new Size(500, 500));
            map.Layers.Add(featureLayer);

            // export the map to a file
            if (args.Length > 0 && args[0] != null && args[0].Trim().Length != 0) {
                using (MapExport me = new MapExport(map)) {
                    me.Format = ExportFormat.Gif;
                    me.Export(args[0]);
                }
            }

            // clean up the map
            Session.Current.MapFactory.Remove(map);
        }
Beispiel #4
0
        private bool InitWorkingLayer()
        {
            MapInfo.Mapping.Map map = null;

            // Get the map
            if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 ||
                (map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null)
            {
                return(false);
            }

            // Make sure the Find layer's MemTable exists
            MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(_workingLayerName);
            if (table == null)
            {
                TableInfoMemTable ti = new TableInfoMemTable(_workingLayerName);
                ti.Temporary = true;
                // Add the Geometry column
                Column col = new MapInfo.Data.GeometryColumn(map.GetDisplayCoordSys());
                col.Alias    = "obj";
                col.DataType = MIDbType.FeatureGeometry;
                ti.Columns.Add(col);
                // Add the Style column
                col          = new MapInfo.Data.Column();
                col.Alias    = "MI_Style";
                col.DataType = MIDbType.Style;
                ti.Columns.Add(col);
                table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
            }
            if (table == null)
            {
                return(false);
            }

            // Make sure the Find layer exists
            MapInfo.Mapping.FeatureLayer layer = (MapInfo.Mapping.FeatureLayer)map.Layers[_workingLayerName];
            if (layer == null)
            {
                layer = new MapInfo.Mapping.FeatureLayer(table, _workingLayerName, _workingLayerName);
                map.Layers.Insert(0, layer);
            }
            if (layer == null)
            {
                return(false);
            }

            // Delete the find object.  There should only be one object in this table.
            (layer.Table as ITableFeatureCollection).Clear();

            return(true);
        }
Beispiel #5
0
        private void loadEagleLayer()
        {
            //初始化鹰眼图层 用户画框

            TableInfoMemTable ti = new TableInfoMemTable("EagleEyeTemp");

            ti.Temporary = true;
            Column column;

            column          = new GeometryColumn(mapControl2.Map.GetDisplayCoordSys());
            column.Alias    = "MI_Geometry ";
            column.DataType = MIDbType.FeatureGeometry;
            ti.Columns.Add(column);

            column          = new Column();
            column.Alias    = "MI_Style ";
            column.DataType = MIDbType.Style;
            ti.Columns.Add(column);
            Table table;

            try
            {
                table = Session.Current.Catalog.CreateTable(ti);
            }
            catch (Exception ex)
            {
                table = Session.Current.Catalog.GetTable("EagleEyeTemp");
            }
            if (mapControl2.Map.Layers["MyEagleEye"] != null)
            {
                mapControl2.Map.Layers.Remove(eagleEye);
            }
            eagleEye = new FeatureLayer(table, "EagleEye ", "MyEagleEye");
            mapControl2.Map.Layers.Insert(0, eagleEye);
            mapControl1.Refresh();
        }
Beispiel #6
0
        private void showPointOnSearchTableMap(double x, double y)
        {
            MapInfo.Mapping.Map          map         = Session.Current.MapFactory.CreateEmptyMap(System.IntPtr.Zero, new Size(10, 10));
            MapInfo.Mapping.FeatureLayer searchLayer = new MapInfo.Mapping.FeatureLayer(_searchTable);
            map.Layers.Add(searchLayer);

            MapForm1 mapForm    = new MapForm1(map);
            Form     parentForm = this;

            // create a temp table and add a featurelayer for it (use map alias as table alias)
            // make the table hidden (maybe)
            MapInfo.Geometry.CoordSys coordSys = map.GetDisplayCoordSys();
            TableInfoMemTable         ti       = new TableInfoMemTable("temp");

            ti.Temporary = true;

            // add object column
            Column col;

            col          = new GeometryColumn(coordSys); // specify coordsys for object column
            col.Alias    = "obj";
            col.DataType = MIDbType.FeatureGeometry;
            ti.Columns.Add(col);

            // add style column
            col          = new Column();
            col.Alias    = "MI_Style";
            col.DataType = MIDbType.Style;
            ti.Columns.Add(col);

            Table pointTable = Session.Current.Catalog.CreateTable(ti);

            // I am using a Point example here. You can create a rectangle instead
            MapInfo.Geometry.FeatureGeometry      g  = new MapInfo.Geometry.Point(coordSys, x, y);
            MapInfo.Styles.SimpleVectorPointStyle vs = new MapInfo.Styles.SimpleVectorPointStyle(37, System.Drawing.Color.Red, 14);
            MapInfo.Styles.CompositeStyle         cs = new MapInfo.Styles.CompositeStyle(vs);

            MICommand cmd = _miConnection.CreateCommand();

            cmd.Parameters.Add("geometry", MIDbType.FeatureGeometry);
            cmd.Parameters.Add("style", MIDbType.Style);
            cmd.CommandText = "Insert Into temp (obj,MI_Style) values (geometry,style)";
            cmd.Prepare();
            cmd.Parameters[0].Value = g;
            cmd.Parameters[1].Value = cs;
            int nchanged = cmd.ExecuteNonQuery();

            cmd.Dispose();

            map.Layers.Add(new MapInfo.Mapping.FeatureLayer(pointTable));
            // another way: Map.Load(new MapTableLoader(table));

            // make the map encompass the entire search layer
            map.SetView(searchLayer);

            // size the map form
            mapForm.Size = new Size(500, 500);

            //Show the form like a dialog (modal)
            mapForm.ShowDialog(parentForm);

            pointTable.Close();
        }
        private void showPointOnSearchTableMap(double x, double y)
        {
            MapInfo.Mapping.Map map = Session.Current.MapFactory.CreateEmptyMap(System.IntPtr.Zero, new Size(10, 10));
            MapInfo.Mapping.FeatureLayer searchLayer = new MapInfo.Mapping.FeatureLayer(_searchTable);
            map.Layers.Add(searchLayer);

            MapForm1 mapForm = new MapForm1(map);
            Form parentForm = this;

            // create a temp table and add a featurelayer for it (use map alias as table alias)
            // make the table hidden (maybe)
            MapInfo.Geometry.CoordSys coordSys = map.GetDisplayCoordSys();
            TableInfoMemTable ti = new TableInfoMemTable("temp");
            ti.Temporary = true;

            // add object column
            Column col;
            col = new GeometryColumn(coordSys); // specify coordsys for object column
            col.Alias = "obj";
            col.DataType = MIDbType.FeatureGeometry;
            ti.Columns.Add(col);

            // add style column
            col = new Column();
            col.Alias = "MI_Style";
            col.DataType = MIDbType.Style;
            ti.Columns.Add(col);

            Table pointTable = Session.Current.Catalog.CreateTable(ti);

            // I am using a Point example here. You can create a rectangle instead
            MapInfo.Geometry.FeatureGeometry g = new MapInfo.Geometry.Point(coordSys, x, y);
            MapInfo.Styles.SimpleVectorPointStyle vs = new MapInfo.Styles.SimpleVectorPointStyle(37, System.Drawing.Color.Red, 14);
            MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(vs);

            MICommand cmd = _miConnection.CreateCommand();
            cmd.Parameters.Add("geometry", MIDbType.FeatureGeometry);
            cmd.Parameters.Add("style", MIDbType.Style);
            cmd.CommandText = "Insert Into temp (obj,MI_Style) values (geometry,style)";
            cmd.Prepare();
            cmd.Parameters[0].Value = g;
            cmd.Parameters[1].Value = cs;
            int nchanged = cmd.ExecuteNonQuery();
            cmd.Dispose();

            map.Layers.Add(new MapInfo.Mapping.FeatureLayer(pointTable));
            // another way: Map.Load(new MapTableLoader(table));

            // make the map encompass the entire search layer
            map.SetView(searchLayer);

            // size the map form
            mapForm.Size = new Size(500, 500);

            //Show the form like a dialog (modal)
            mapForm.ShowDialog(parentForm);

            pointTable.Close();
        }
        private bool InitWorkingLayer()
        {
            MapInfo.Mapping.Map map = null;

            // Get the map
            if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 ||
                (map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null)
            {
                return false;
            }

            // Make sure the Find layer's MemTable exists
            MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(_workingLayerName);
            if (table == null)
            {
                TableInfoMemTable ti = new TableInfoMemTable(_workingLayerName);
                ti.Temporary = true;
                // Add the Geometry column
                Column col = new MapInfo.Data.GeometryColumn(map.GetDisplayCoordSys());
                col.Alias = "obj";
                col.DataType = MIDbType.FeatureGeometry;
                ti.Columns.Add(col);
                // Add the Style column
                col = new MapInfo.Data.Column();
                col.Alias = "MI_Style";
                col.DataType = MIDbType.Style;
                ti.Columns.Add(col);
                table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
            }
            if (table == null) return false;

            // Make sure the Find layer exists
            MapInfo.Mapping.FeatureLayer layer = (MapInfo.Mapping.FeatureLayer)map.Layers[_workingLayerName];
            if (layer == null)
            {
                layer = new MapInfo.Mapping.FeatureLayer(table, _workingLayerName, _workingLayerName);
                map.Layers.Insert(0, layer);
            }
            if (layer == null) return false;

            // Delete the find object.  There should only be one object in this table.
            (layer.Table as ITableFeatureCollection).Clear();

            return true;
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            // register URL with a specific WFS reader
            WfsReaderFactory.RegisterHandler(URL, typeof(WfsReader));

            // Get the WFS capabilities of the WFS server using the HTTP GET method.
            try
            {
                // Get the WFS capabilities of the WFS server using the HTTP GET method.
                WfsCapabilities Capabilities = WfsClient.GetCapabilities(RequestMethod.GET, URL);
            }
            catch
            {
                MessageBox.Show("Please check if " + URL + " is a valid WFS URL");
                return;
            }


            // Do something with the the WfsCapabilities here...

            // Get the schema for the USA feature type
            string[] TypeNames = new string[] { "miwfs:USA" };

            // Do something with the schema here...
            XmlSchema usaSchema = WfsClient.DescribeFeatureType(URL, TypeNames);

            // Get all features from the USA feature type
            MultiFeatureCollection usa = WfsClient.GetFeature(URL, TypeNames, null, null, -1, null);
            IFeatureCollection     fc  = usa[0];

            // iterate over the Usa MultiFeatureCollection and add each
            // IFeatureCollection to a MemTable, etc...
            TableInfoMemTable memTableInfo = new TableInfoMemTable("myMemTable");

            foreach (Column c in fc.Columns)
            {
                memTableInfo.Columns.Add(c);
            }
            Table memTable = Session.Current.Catalog.CreateTable(memTableInfo);

            memTable.InsertFeatures(fc);

            // create a layer from the MemTable
            FeatureLayer featureLayer = new FeatureLayer(memTable);

            // create the map and add the layer
            Map map = Session.Current.MapFactory.CreateEmptyMap(new Size(500, 500));

            map.Layers.Add(featureLayer);

            // export the map to a file
            if (args.Length > 0 && args[0] != null && args[0].Trim().Length != 0)
            {
                using (MapExport me = new MapExport(map)) {
                    me.Format = ExportFormat.Gif;
                    me.Export(args[0]);
                }
            }

            // clean up the map
            Session.Current.MapFactory.Remove(map);
        }