AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FDO Spatial Query (polygon) in VB.NET (or C#)

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
4323 Views, 7 Replies

FDO Spatial Query (polygon) in VB.NET (or C#)

Anonymous
Not applicable

I have been looking for examples of how to query an FDO feature from VB or C# and filter the query by a polygon.

 

The test data store is a SHP file, but the future data store could be MySQL, Oracle or SQL Server.

 

I have found how to connect and how to get to the feature but not how to use the feature reader with a polygon.

 

I have generated a WKT string of the polygon from a polyline fed to the function in VB.NET from Lisp.

 

How do I use the WKT string to set a filter for a spatial query from the FDO connection or feature?

0 Likes

FDO Spatial Query (polygon) in VB.NET (or C#)

I have been looking for examples of how to query an FDO feature from VB or C# and filter the query by a polygon.

 

The test data store is a SHP file, but the future data store could be MySQL, Oracle or SQL Server.

 

I have found how to connect and how to get to the feature but not how to use the feature reader with a polygon.

 

I have generated a WKT string of the polygon from a polyline fed to the function in VB.NET from Lisp.

 

How do I use the WKT string to set a filter for a spatial query from the FDO connection or feature?

7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Accepted solution

Hi,

 

The following .NET code snippet should be usefull to you which demonstartes how to form a spatial query -

 

<code_begin>

 

                //spatial relationship inside a basic filter
                MgFeatureQueryOptions query = new MgFeatureQueryOptions();


                query.SetFilter("Geometry INTERSECTS GeomFromText('POLYGON ((135450.170691914 176714.481673732, 136292.021019111 176121.027356537, 135961.299875354 175651.879698467, 135119.449548157 176245.334015662, 135450.170691914 176714.481673732))') ");

                //Get the features
                MgResourceIdentifier resId = new MgResourceIdentifier(fsId);
                MgFeatureReader ftrRdr = fs.SelectFeatures(resId, className, query);
        
                //Display the IDS and lengths of the selected features
                while (ftrRdr.ReadNext())
                {
                    int id = ftrRdr.GetInt32("FeatId");                   
                    ed.WriteMessage("\nID: " + id );
                }
                ftrRdr.Close();

 

 

<code_end>

 

HTH,

 

Thanks,

 

Partha Sarkar

Autodesk

0 Likes

Hi,

 

The following .NET code snippet should be usefull to you which demonstartes how to form a spatial query -

 

<code_begin>

 

                //spatial relationship inside a basic filter
                MgFeatureQueryOptions query = new MgFeatureQueryOptions();


                query.SetFilter("Geometry INTERSECTS GeomFromText('POLYGON ((135450.170691914 176714.481673732, 136292.021019111 176121.027356537, 135961.299875354 175651.879698467, 135119.449548157 176245.334015662, 135450.170691914 176714.481673732))') ");

                //Get the features
                MgResourceIdentifier resId = new MgResourceIdentifier(fsId);
                MgFeatureReader ftrRdr = fs.SelectFeatures(resId, className, query);
        
                //Display the IDS and lengths of the selected features
                while (ftrRdr.ReadNext())
                {
                    int id = ftrRdr.GetInt32("FeatId");                   
                    ed.WriteMessage("\nID: " + id );
                }
                ftrRdr.Close();

 

 

<code_end>

 

HTH,

 

Thanks,

 

Partha Sarkar

Autodesk

Message 3 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

That's exactly what we have been trying to find. Thank you very much!

 

Paul

 

0 Likes

That's exactly what we have been trying to find. Thank you very much!

 

Paul

 

Message 4 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Hi

 

I am making a lisp program in autocad for analizing feature about urban porppos. 

I want to make a spatial query in autocad after  I entered a shp file (or sdf file)

I try many time but no good result.I dont know what is the 'DM Command'

I take this massage

Command: _DMCommand
Enter command: ID_CMD_DM_EDIT_QUERY

 

after this command come a window for creare quert but I dot like this window becuse make a halt in my program.

please help me

 

thanks

Ali

 

 

0 Likes

Hi

 

I am making a lisp program in autocad for analizing feature about urban porppos. 

I want to make a spatial query in autocad after  I entered a shp file (or sdf file)

I try many time but no good result.I dont know what is the 'DM Command'

I take this massage

Command: _DMCommand
Enter command: ID_CMD_DM_EDIT_QUERY

 

after this command come a window for creare quert but I dot like this window becuse make a halt in my program.

please help me

 

thanks

Ali

 

 

Message 5 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

This thread is about using C#.NET or VB.NET to query an FDO source.  You should start a new thread with your question in one of the LISP forums.

 

0 Likes

This thread is about using C#.NET or VB.NET to query an FDO source.  You should start a new thread with your question in one of the LISP forums.

 

Message 6 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

hello how to get the points dynamically? (Geometry INTERSECTS GeomFromText('POLYGON ((135450.170691914 176714.481673732, 136292.021019111 176121.027356537, 135961.299875354 175651.879698467, 135119.449548157 176245.334015662, 135450.170691914 176714.481673732).
is it possible to draw and select points the points of the shape? like rectangle or circle?

0 Likes

hello how to get the points dynamically? (Geometry INTERSECTS GeomFromText('POLYGON ((135450.170691914 176714.481673732, 136292.021019111 176121.027356537, 135961.299875354 175651.879698467, 135119.449548157 176245.334015662, 135450.170691914 176714.481673732).
is it possible to draw and select points the points of the shape? like rectangle or circle?

Message 7 of 8
fieldguy
in reply to: Anonymous

fieldguy
Advisor
Advisor

Will this code work to query a property from an FDO SHP file?  My manual query works as in the attached graphic.

 

I have established a connection to the shp using:

IConnectionManager icm = OSGeo.FDO.ClientServices.FeatureAccessManager.GetConnectionManager();
OSGeo.FDO.Connections.IConnection ic = icm.CreateConnection("OSGeo.SHP");
string fname = "DefaultFileLocation= path to shp file ";
ic.ConnectionString = fname;
ic.Open();
// how to query feature by property value?
ic.Close();

0 Likes

Will this code work to query a property from an FDO SHP file?  My manual query works as in the attached graphic.

 

I have established a connection to the shp using:

IConnectionManager icm = OSGeo.FDO.ClientServices.FeatureAccessManager.GetConnectionManager();
OSGeo.FDO.Connections.IConnection ic = icm.CreateConnection("OSGeo.SHP");
string fname = "DefaultFileLocation= path to shp file ";
ic.ConnectionString = fname;
ic.Open();
// how to query feature by property value?
ic.Close();

Message 8 of 8
fieldguy
in reply to: fieldguy

fieldguy
Advisor
Advisor

I got it.  The post from @Anonymous is missing the details for "fsId" and "resId".  

My goal was to get a centroid of a polygon from a shape file based on a database field value ("PLAN_BLOCK='plan, block, lot'").  There are a few methods available to get there.

I ended up with 2 solutions (attached). The FDO solution does not require the layer to be connected & added to map.

There are several posts for reading (thanks to all!) thanks @Anonymous for >>this<<.

 

0 Likes

I got it.  The post from @Anonymous is missing the details for "fsId" and "resId".  

My goal was to get a centroid of a polygon from a shape file based on a database field value ("PLAN_BLOCK='plan, block, lot'").  There are a few methods available to get there.

I ended up with 2 solutions (attached). The FDO solution does not require the layer to be connected & added to map.

There are several posts for reading (thanks to all!) thanks @Anonymous for >>this<<.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report