hi i wants to query on my province shapefile my code is for adding province
ShapeFileFeatureLayer province = new ShapeFileFeatureLayer(MapPath("~/Layer/afghanistanprovince.shp"));
// province.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
province.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle(“Prov_Name”, new GeoFont(“Verdana”, 9),
new GeoSolidBrush(GeoColor.StandardColors.Blue));
province.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.State1;
province.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 2);
province.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
Map1.StaticOverlay.Layers.Add(province);
basically if user query select * from prov_name where prov_name=‘kabul’ how can i achieve this please give me some sample code thanks in advance.
Query on shape file
Hi Raja,
I think this APIs in query tools is what you need, for example:
province.QueryTools.ExecuteQuery("");
But you should to know it’s mainly support some simple query, please test whether your SQL statement can works well.
Regards,
Don
hi Don
My layer file name is afghanistanprovince.shp and i wants to select only kabul province and i did like this
province.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle(“Prov_Name”, new GeoFont(“Verdana”, 9),
new GeoSolidBrush(GeoColor.StandardColors.Blue));
province.Open();
province.QueryTools.ExecuteQuery("select * from afghanistanprovince where Prov_Name=‘kabul’ ");
is it correct ? but it is not working
Hi Raja,
Do you meant you aren’t only want to query from shape file, but also want to only render the queried features?
If that’s what you want, I think you can execute province.QueryTools.ExecuteQuery to get a list of feature, then put all of them to a separated InmemoryFeatureLayer for render.
Regards,
Don
hi can you please provide me sample code for query.
Hi Raja,
Please let me know your detail secnario, so that I can help you on more detail code.
Regards,
Don
hi Don
my detail scenario is the followings
first time when page load all province is display in my map and where i have a multiline textbox which take query from user for example select * from myshapefile where province_name like 'kabul’
and on button click only kabul border is display on map all other province will remove from map that is what i am looking for at very first time please let me know if you wnats anything more and first time code is this:
ShapeFileFeatureLayer province = new ShapeFileFeatureLayer(MapPath("~/Layer/afghanistanprovince.shp"));
// province.Open();
// province.QueryTools.ExecuteQuery("select * from afghanistanprovince where Prov_Name=‘kabul’ ");
//province.QueryTools.GetColumns();
// province.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
province.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle(“Prov_Name”, new GeoFont(“Verdana”, 9),
new GeoSolidBrush(GeoColor.StandardColors.Blue));
province.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(GeoPens.Blue);
province.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 2);
province.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
Map1.StaticOverlay.Layers.Add(“Province”, province);
Hi Raja,
Thanks for let me know your detail scenario.
In fact the ExecuteQuery API is for query data result in DBF file, so it won’t return shape. I build a simple sample as below, which shows how to query feature from original layer then get the queried feature and only show it on map, wish that’s helpful for you.
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"…\SampleData\Data\Countries02.shp");
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
worldLayer.Open();
// Use LINQ to find the queried feature here, its “CNTRY_NAME” equal “Canada”
var queriedFeatures = from t in worldLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns) where t.ColumnValues[“CNTRY_NAME”] == “Canada” select t;
InMemoryFeatureLayer resultLayer = new InMemoryFeatureLayer();
resultLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
resultLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
foreach (Feature f in queriedFeatures)
{
resultLayer.InternalFeatures.Add(f);
}
LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add(“WorldLayer”, resultLayer);
winformsMap1.Overlays.Add(“WorldOverlay”, staticOverlay);
winformsMap1.CurrentExtent = new RectangleShape(-139.2, 92.4, 120.9, -93.2);
winformsMap1.Refresh();
Regards,
Don