.NET

Reply
Active Contributor
dr5156
Posts: 33
Registered: ‎12-08-2010
Message 1 of 7 (447 Views)

Query to Filter Data in .NET

447 Views, 6 Replies
10-23-2012 05:43 AM

Hi

 

I am trying to Apply Location query on Query to Filter Data in .NET

 

Anyone please provide the sample code or procedure to program

 

Dayalan

Regards,
Dayalan
Distinguished Contributor
djonio
Posts: 105
Registered: ‎12-29-2005
Message 2 of 7 (427 Views)

Re: Query to Filter Data in .NET

10-23-2012 08:12 AM in reply to: dr5156

For which vertical? Civil/Map3d?

Mentor
khoa.ho
Posts: 216
Registered: ‎09-15-2011
Message 3 of 7 (422 Views)

Re: Query to Filter Data in .NET

10-23-2012 08:52 AM in reply to: dr5156

I am not sure for what you want. You can use Predicate delegate (with Invoke method) for your custom query inside the loop. Or you can use LINQ with where condition.

 

-Khoa

Active Contributor
dr5156
Posts: 33
Registered: ‎12-08-2010
Message 4 of 7 (381 Views)

Re: Query to Filter Data in .NET

10-24-2012 09:07 PM in reply to: khoa.ho

Hi all,

 

I am using AutoCAD Map3d Enterprise 2012.

 

We have "Query to Filter data" out-of-box functionality. In this i want to apply "Location" query filter using .net programming

 

Some one please help me...

 

Regards

Dayalan

Regards,
Dayalan
Distinguished Contributor
djonio
Posts: 105
Registered: ‎12-29-2005
Message 5 of 7 (363 Views)

Re: Query to Filter Data in .NET

10-25-2012 04:37 AM in reply to: dr5156

Here is an example that should get you going. I believe that I have posted something similiar on the Map3d forum a few years back. You may have better luck there.

public void getbasemap()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = HostApplicationServices.WorkingDatabase;
            ProjectModel prjModel = HostMapApplicationServices.Application.ActiveProject;
            string current_projection = prjModel.Projection;
            ProjectOptions prjOptions = prjModel.Options;
            DrawingSet drawingset = prjModel.DrawingSet;
            MapApplication mapApi = HostMapApplicationServices.Application;
            //Yes, we need to use an alias
			Aliases aliases = mapApi.Aliases;
            string The_Keymap_alias = "FinalPathToKeymapDWG";
            //Go get the file name
			string The_Keymap = Get_(ref CWDS, "FinalPathToKeymapDWG");
            //Remove Alias
            try
            {
                aliases.RemoveAlias(The_Keymap_alias);
            }
            catch (MapException)
            {
                doc.Editor.WriteMessage("\nFailed to remove alias ... probably OK.");
            }
            //Add Alias
            try
            {
                aliases.AddAlias(The_Keymap_alias, The_Keymap);
            }
            catch (MapException)
            {
                doc.Editor.WriteMessage("\nFailed to add alias. NOT good.");
            }
            drawingset.AttachDrawing(The_Keymap_alias);
			
			//Get the current query and set the mode draw/preview...
            QueryModel qryModel = prjModel.CurQuery;
            qryModel.Mode = Autodesk.Gis.Map.Constants.QueryType.QueryDraw;
            qryModel.Clear();
            // The root query object
            QueryBranch qb_root = QueryBranch.Create();

            // By location condition
			// No need for window locationtype here I want the entire drawing
            LocationCondition locationcondition = new LocationCondition();
            locationcondition.LocationType = Autodesk.Gis.Map.Constants.LocationType.LocationCrossing;
            locationcondition.Boundary = AllBoundary.Create();
            // Make a branch
            QueryBranch qblocation = QueryBranch.Create();
            qblocation.AppendOperand(locationcondition);
            // append it to the root
            qb_root.AppendOperand(qblocation);

            // By Properties condition
            PropertyCondition propertycondition = new PropertyCondition();
            propertycondition.JoinOperator = Autodesk.Gis.Map.Constants.JoinOperator.OperatorAnd;
            propertycondition.PropertyType = Autodesk.Gis.Map.Constants.PropertyType.Layer;
            propertycondition.ConditionOperator = Autodesk.Gis.Map.Constants.ConditionOperator.ConditionEqual;
			//Go get the list of layers
            string The_KeymapLayers = Get_(ref CWDS, "KeymapLayers");
            propertycondition.Value = The_KeymapLayers;

            // Make a branch
            QueryBranch qbproperties = QueryBranch.Create();
            qbproperties.AppendOperand(propertycondition);
            // append it to the root
            qb_root.AppendOperand(qbproperties);
            // Construct it
            qryModel.Define(qb_root);
            // Execute it
            ObjectIdCollection queried_keymap_objs_collection = qryModel.Execute(drawingset);

            // some local cleanup
            qb_root.Clear();
            qblocation.Clear();
            qbproperties.Clear();
            qryModel.Clear();
            locationcondition.Dispose();
            //
            // Now we wish to see everything so that we can construct the Viewports for the small
            // viewport the contains the "whole" drawing.
            //
            AcadApplication pApp;
            pApp = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
            pApp.ZoomExtents();
            //
            // These globals are used for/by the Viewports
            //
            KEYMAP_EXTENTS_MAX = db.Extmax;
            KEYMAP_EXTENTS_MIN = db.Extmin;
            KEYMAP_EXTENTS_center = new Point2d((KEYMAP_EXTENTS_MAX.X + KEYMAP_EXTENTS_MIN.X) / 2, (KEYMAP_EXTENTS_MAX.Y + KEYMAP_EXTENTS_MIN.Y) / 2);

            drawingset.DetachDrawing(The_Keymap_alias);
        }

 r,

dennis

Active Contributor
dr5156
Posts: 33
Registered: ‎12-08-2010
Message 6 of 7 (357 Views)

Re: Query to Filter Data in .NET

10-25-2012 05:26 AM in reply to: dr5156

Thanks for reply.  I am able to create my own Query to filte data using Location on map option in C#.net. But The below last refresh option is not working.

 

I could see the applied query in Create query form. but it is not refreshed on map.

 

Any one please help me.

 

stringgeometryName = parcelsLayer1.GetFeatureGeometryName();

 

MgByteReadergeometryData = featureReader.GetGeometry(geometryName);

 

MgAgfReaderWriter agfReaderWriter = newMgAgfReaderWriter();

 

MgGeometrygeometry = agfReaderWriter.Read(geometryData);

 

MgPolygon mgPoly = geometry asMgPolygon;

 

MgWktReaderWriter wktReaderWriter = newMgWktReaderWriter();

 

stringwkt = wktReaderWriter.Write(mgPoly);

wkt = wkt.Replace(

"POLYGON", "POLYGON XYZ ");

wkt = wkt.Replace(

",", " 0,");

wkt = wkt.Replace(

"))", " 0))");

 

string filter = "GEOM INSIDE GeomFromText('" + wkt + "')";

 

AcMapLayer layer1 = mgLayColl.GetItem("EL_CONDUCTOR") asAcMapLayer;

 

MgResourceIdentifierlayerDefId = layer1.GetLayerDefinition();

 

MgResourceService rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService) asMgResourceService;

 

MgByteReaderlayerReader = rs.GetResourceContent(layerDefId);

 

XmlDocument objXML = newXmlDocument();

 

XmlSerializer objSerializer = newXmlSerializer(typeof(LayerDefinition));

 

LayerDefinition objLayerDef = objSerializer.Deserialize(newStringReader(layerReader.ToString())) asLayerDefinition;

 

VectorLayerDefinitionType objVectorLayerDef = objLayerDef.Item asVectorLayerDefinitionType;

objVectorLayerDef.Filter = filter;

StringWriter objWriter = newStringWriter();

 

XmlSerializer objXs = newXmlSerializer(typeof(LayerDefinition));

objXs.Serialize(objWriter, objLayerDef);

byte[] unicodeBytes = Encoding.Unicode.GetBytes(objWriter.ToString());

 

byte[] utf8Bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, unicodeBytes);

 

MgByteSource objSource = newMgByteSource(utf8Bytes, utf8Bytes.Length);

rs.SetResource(layer1.LayerDefinition, objSource.GetReader(),

null);

layer1.NeedsRefresh();

layer1.ForceRefresh();

Regards,
Dayalan
Distinguished Contributor
djonio
Posts: 105
Registered: ‎12-29-2005
Message 7 of 7 (321 Views)

Re: Query to Filter Data in .NET

10-26-2012 04:13 AM in reply to: dr5156

Please, be a good citizen and use the correct forum. The Map3d Developer and the OSGeo Mapguide forums. I am very sure these folks would appreciate it. I know I will.

r,

dennis

Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.