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?
Solved! Go to Solution.
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?
Solved! Go to 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
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
That's exactly what we have been trying to find. Thank you very much!
Paul
That's exactly what we have been trying to find. Thank you very much!
Paul
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
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
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.
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.
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?
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?
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();
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();
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<<.
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.