You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects General forum

CREATE A POLYGON USING ADF   Gopi Parthasarathy Nov 26, 2007
Re: CREATE A POLYGON USING ADF   Heming Zhu Nov 26, 2007
Re: CREATE A POLYGON USING ADF   Gopi Parthasarathy Nov 26, 2007
Re: CREATE A POLYGON USING ADF   Noureddine El-zaatari Nov 26, 2007
Re: CREATE A POLYGON USING ADF   Heming Zhu Nov 27, 2007
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject CREATE A POLYGON USING ADF 
Author Gopi Parthasarathy 
Date Nov 26, 2007 
Message I am trying to create a Plogon using the Server 9.2 and VS 2005.
I have to draw a polygon and save it in to a SDE Database.The CODE I work with(below) saves the data into the SDE.but I am not able to display it on the MAP.Can some one let me know what I am doing wrong?


Look at the CREATEFEATURE() and then beyond that for any CLUES......

Thanks in advance
PGNATH
 
 
ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl; //create a web map control
        mapctrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control; 

        PolygonEventArgs peag = (PolygonEventArgs)args;
        System.Drawing.Point[] screen_points = peag.Vectors; //get the screen points
        
        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mf = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)mapctrl.GetFunctionality(0);
        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal ags_mr = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)ags_mf.Resource;
        ESRI.ArcGIS.Server.IServerContext sc = ags_mr.ServerContextInfo.ServerContext;
        ////
        //create a map resource.
        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal gisresource = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)mapctrl.MapResourceManagerInstance.GetResource(0);
        IServerContext mapContext = gisresource.ServerContextInfo.ServerContext; //associate a server context
        IMapServerObjects mso = (IMapServerObjects)gisresource.MapServer;
        IMap map = mso.get_Map(gisresource.DataFrame);
        IFeatureLayer mlayer = null;
        IEnumLayer el = map.get_Layers(null, true);
        ILayer l = null;

        ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDescription;
        mapDescription = ags_mf.MapDescription;
        //define the draw color for the polygon
        RgbColor rgb = new RgbColor();
        rgb.Red = 0;
        rgb.Green = 0;
        rgb.Blue = 255;
        rgb.AlphaValue = 255;
        //get the points from the screen
        PointN[] pnts1 = new PointN[screen_points.Length];
        for (int i = 0; i < screen_points.Length; i++)
        {
            PointN pnt = new PointN();
            ESRI.ArcGIS.ADF.Web.Geometry.Point mappnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points[i], mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
            pnt.X = mappnt.X;
            pnt.Y = mappnt.Y;
            pnts1[i] = pnt;
        }

        ESRI.ArcGIS.ADF.ArcGISServer.Ring[] rings1 = new ESRI.ArcGIS.ADF.ArcGISServer.Ring[1];
        ESRI.ArcGIS.ADF.ArcGISServer.Ring ring1 = new ESRI.ArcGIS.ADF.ArcGISServer.Ring();
        ring1.PointArray = pnts1; //assign the points to the ring.

        ESRI.ArcGIS.ADF.ArcGISServer.PolygonN polygon = new ESRI.ArcGIS.ADF.ArcGISServer.PolygonN();
        rings1[0] = ring1;
        polygon.RingArray = rings1;
        polygon.Extent = new EnvelopeN();
        polygon.HasID = false;
        polygon.HasM = false;
        polygon.HasZ = false;
        polygon.SpatialReference = mapDescription.SpatialReference;
        

        SimpleFillSymbol sfs = new SimpleFillSymbol();
        sfs.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleFillStyle.esriSFSDiagonalCross;
        //sfs.Color = 0;
        //sfs.Outline = 

        ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement pe = new ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement();
        pe.Symbol = sfs;
        pe.Polygon = polygon;
        while ((l = el.Next()) != null)
        {
            if (l.Name == "SDE.SDE.RD_City_3") //check for the layer being added
                mlayer = (IFeatureLayer)l;
            if (mlayer != null)
            {
                IFeatureClass fc = mlayer.FeatureClass;
                IDataset ds = (IDataset)fc;
                IWorkspace ws = ds.Workspace;
                mapContext.SetObject("theWorkspace", ws); //get the workspace
                IWorkspaceEdit wse = mapContext.GetObject("theWorkspace") as IWorkspaceEdit;
                if (!wse.IsBeingEdited())
                    wse.StartEditing(true);
                wse.StartEditOperation();
                IFeature f = fc.CreateFeature(); //CREATE A NEW FEATURE AND ADD THE POLYGON TO THE FEATURECLASS
                IFeatureSimplify fs = (IFeatureSimplify)f;
                fs.SimplifyGeometry((IGeometry)(ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPolygon(polygon)));
                f.Shape = (IGeometry) ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPolygon(polygon);
                f.set_Value(3, "GOPI44");
                f.set_Value(1, 99);
                f.set_Value(4, 2);
                f.set_Value(5, 06103);
                f.Store();
                wse.StopEditing(true);
            }
        }
              mapctrl.Refresh();
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: CREATE A POLYGON USING ADF 
Author Heming Zhu 
Date Nov 26, 2007 
Message You have to refresh the map after you create a polygon. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: CREATE A POLYGON USING ADF 
Author Gopi Parthasarathy 
Date Nov 26, 2007 
Message mapctrl.refresh is already there...what is the other refresh you are talking about?

also I get a typecast error in the simplifygeometry and the shape methods.How to convert the polygon to Igeometry ?

Thanks
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: CREATE A POLYGON USING ADF 
Author Noureddine El-zaatari 
Date Nov 26, 2007 
Message looks like everything works fine with no errors, i have faced this problem before, the shape of the new feature you are creating is assigned to null to some reason, here is a working code of getting a polygon, try it out and let me know 
 
ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl;
        mapctrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;

        PolygonEventArgs peag = (PolygonEventArgs)args;
        System.Drawing.Point[] screen_points = peag.Vectors;

        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mf = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)mapctrl.GetFunctionality(0);
        //ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal ags_mr = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)ags_mf.Resource;
        //ESRI.ArcGIS.Server.IServerContext sc = ags_mr.ServerContextInfo.ServerContext;
        ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDescription;
        mapDescription = ags_mf.MapDescription;

        
        PointN[] pnts1 = new PointN[screen_points.Length];

        for (int i = 0; i < screen_points.Length; i++)
        {
            PointN pnt = new PointN();
            ESRI.ArcGIS.ADF.Web.Geometry.Point mappnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points[i], mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
            pnt.X = mappnt.X;
            pnt.Y = mappnt.Y;
            pnts1[i] = pnt;
        }

        Ring[] rings1 = new Ring[1];
        Ring ring1 = new Ring();
        ring1.PointArray = pnts1;
        PolygonN polygon = new PolygonN();
        rings1[0] = ring1;
        polygon.RingArray = rings1;
        polygon.Extent = new EnvelopeN();
        polygon.HasID = false;
        polygon.HasM = false;
        polygon.HasZ = false;
        polygon.SpatialReference = mapDescription.SpatialReference;
 
  Regards,

Noureddine El-Zaatari
(ESRI Kuwait) - Openware

http://www.arcgisserverblog.com/2008/12/arcgis-server-applications.html ->ShowCase

http://www.facebook.com/group.php?gid=2334494455 <- Facebook ArcGIS Group 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: CREATE A POLYGON USING ADF 
Author Heming Zhu 
Date Nov 27, 2007 
Message Add the following code just before your mapctrl.Refresh(); statement. If your can see the polygon, then you are fine. Otherwise you might have to look into you code to varify your polygon.

ICenterAndScale centerScale = sc.CreateObject("esriCarto.CenterAndScale") as ICenterAndScale;
centerScale.Center = polygon.FromPoint;
centerScale.MapScale =15000; //you could try different scale
mapDescription.MapArea = centerScale as IMapArea;