for area style iam getting shape file information.like cntry2.shp file when i click on any area iam getting that particular area informaton.when i use city.shp which is of point style for that iam not getting any information abt that city point.how to get point type information from shapefile.
How to get point type shape file information
Hello rajanikanth,
Thanks for your post, I think the way to get shape file column information are the same, style didn’t effect how you get the column value, it’s only effect how the shape looks like.
Can you show me your code how you read the column value? Are you running the HowDoISamples to get it? Maybe you just miss some column name so that you didn’t get the right value.
Regards,
Gary
but for point shape file iam not getting shape file information.every point is havoing some shape file information.but no point is showing information.but area type shape files are giving information
Hello rajanikanth,
Could you please show me some of your code? I can check what’s the root cause, also I can modfy it if there is something in the code.
Regards,
Gary
Hello rajanikanth,
Could you please show me some of your code? I can check what’s the root cause, also I can modfy it if there is something in the code.
Regards,
Gary
Hello rajanikanth,
Could you please show me some of your code? I can check what’s the root cause, also I can modfy it if there is something in the code.
Regards,
Gary
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
Map1.CurrentExtent = new RectangleShape(-125, 72, 50, -46);
Map1.MapUnit = GeographyUnit.DecimalDegree;
WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay();
ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath("~/SampleData/USA/cities_a.shp"));
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
worldLayer.RequireIndex = false;
LayerOverlay staticOverlay = new LayerOverlay("StaticOverlay");
staticOverlay.IsBaseOverlay = false;
staticOverlay.Layers.Add("WorldLayer", worldLayer);
Map1.CustomOverlays.Add(staticOverlay);
worldLayer.Open();
Map1.CurrentExtent = worldLayer.GetBoundingBox();
worldLayer.Close();
}
}
protected void Map1_Click(object sender, MapClickedEventArgs e)
{
LayerOverlay staticOverlay = (LayerOverlay)Map1.CustomOverlays["StaticOverlay"];
FeatureLayer worldLayer = (FeatureLayer)staticOverlay.Layers["WorldLayer"];
worldLayer.Open();
Collection<Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(e.Position, new string[2] { "AREANAME", "PLACEFIP" });
worldLayer.Close();
if (selectedFeatures.Count > 0)
{
FeaturesGridView.DataSource = GetDataTableFromFeatureSourceColumns(selectedFeatures);
FeaturesGridView.DataBind();
}
}
private static DataTable GetDataTableFromFeatureSourceColumns(Collection<Feature> features)
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("AREANAME");
dataTable.Columns.Add("PLACEFIP");
foreach (Feature feature in features)
{
AddRow(feature, dataTable);
}
return dataTable;
}
private static void AddRow(Feature feature, DataTable dataTable)
{
DataRow dataRow = dataTable.NewRow();
dataRow[0] = feature.ColumnValues["AREANAME"];
dataRow[1] = feature.ColumnValues["PLACEFIP"];
dataTable.Rows.Add(dataRow);
}
this is my code.iam getting all my points in my map.but when i click on any point it does not return any value.selected features count is showing as 0.how to display layer infor mation for this points
helo gray,
iam waiting for your reply.
Hello rajanikanth,
I noticed that you use worldLayer.QueryTools.GetFeaturesContaining() to get selected features on event of Map1_Click, I suspect it’s not a good way in here. On point shape style, the function of GetFeaturesContaning will check if the one point(point in shape file) contain another point(clicked point), it’s hard to “select” the expected point. You can use GetFeaturesWithin or GetFeaturesNearestTo to solve the problem like below codes:
double adjust = 1;
RectangleShape rectPosition = new RectangleShape(e.Position.X - adjust, e.Position.Y + adjust, e.Position.X + adjust, e.Position.Y - adjust);
Collection<Feature> selectedFeatures = selectedLayer.QueryTools.GetFeaturesWithin(rectPosition, columnNames);
Or
Collection<Feature> selectedFeatures = selectedLayer.QueryTools.GetFeaturesNearestTo(e.Position, GeographyUnit.DecimalDegree, 1, columnNames);
Thanks
Gary
helo gray,
you are sending how to show point type shape file information.but i have one more question.first iam adding point type shape file(ex:layer1) .after that i add layer2 which is of area type transperently.after that i add 2 more layers layer3(roads type) and layer4(point type) transperently.
now i want to see all the shape file information according to those points,area,roads.how to do this stuff.can you send me one example which shows different layers information on the map according to those lat and long values.based on layer name and type i need to show the information on the map.
Hello rajanikanth,
You can get different layer using different way. First the shape style of layer certainly could be known, so as layer1(point style) you can use GetFeaturesWithin or GetFeaturesNearestTo, as layer2(line style) you can use GetFeaturesIntersecting
(Create a rectangle based on clicked point) or GetFeaturesTouching, as layer3(polygon style) you can use GetFeaturesInclude, and so on.
The QueryTools provides all kind of function to find a shape through specific shape, you can use them free.
Regards,
Gary
can you show me some sort of example i am not getting clearly.in my page load event i am adding 5 layers(layer1(point).layer2(area),layer3(point),layer4(road),layer5(area)).so in map click event i need to show all the shape file point ot layer or road information.when i click on point it has to show point info if click on area it has to show area info when i click on road it has to show road info.this is my requirement.can u give me some sort of code for this one.
and in map1_click event how can i know whether iam click on point shape file or area shape file or road shpe file.according to clicked shape file and pointor area or road i need to display information on map.
Hi Raj,
The only way to know which layer you are clicking on is to set the sequence of each layer, e.g. Layers[0] is point,
Layers[1] is Line, Layers[2] is Area, in Map1_Click event, you can loop through all the layers and use
Layer.QueryTools to query features, the layer which returns result is what you want.
Regards,
Edgar
how i know the clicked layer on the map.iam confused how i know the clicked layer.please provide some
sort of source code so that i will get idea about that one.that to i load layers dynamically.according
map_click i need to know the layer and i need to display the shape file information.
please provide some sort of code how to know the clicked layer out of 5 layers and how to display the layer information
helo edgar,
iam writing like this in map1_click
foreach (LayerOverlay overlay in Map1.CustomOverlays)
{
foreach (ShapeFileFeatureLayer item in overlay.Layers)
{
item.Open();
ShapeFileType shapeFileType = item.GetShapeFileType();
if (shapeFileType == ShapeFileType.Polygon)//polygon
{
Collection features1 = item.QueryTools.GetFeaturesTouching(e.Position, ReturningColumnsType.AllColumns);
}
if (shapeFileType == ShapeFileType.Point || shapeFileType == ShapeFileType.Multipoint)//points
{
Collection features2 = item.QueryTools.GetFeaturesNearestTo(e.Position, GeographyUnit.Meter, 1, ReturningColumnsType.AllColumns);
}
if (shapeFileType == ShapeFileType.Polyline)//lines
{
Collection features = item.QueryTools.GetFeaturesIntersecting(e.Position, ReturningColumnsType.AllColumns);
}
}
}
while looping the layers some times it returns count>0 for two types.for ex if i select point type if area
is under then it shows area count also>1 and point count also >1 .so here also some confusing is
there what information i need to display on map.if user click on point at that time point and layer count both are >0 so what i need
to display on map.so when i click on point means it has to point file info only.if i click on area means it has to show area info only.
i think you understand my requirement.please check it once.
Raj,
As I said in my previous post, you have to set a sequence of each type of layer, because the point has no volume,
You can only query it by GetFeaturesWithinDistanceOf cause it also returns features by GetFeaturesNearestTo,
the same as line features, it’s very hard to get the features by Intersecting too, so the sequence could be point
on the line on the area, then your code could be modified to
Regards,
Edgar
Thank You Edgar,
After getting those features how i need to display in a popup.
if(features.count>0)
{
here iam not getting how to display the values.
message.AppendFormat("Area", features[0].ColumnValues["Area"]. Trim());
but here iam getting feture values dynamically so how to display these feature values on a popup
ex:Area:usa
population:12000
like this
}
Raj,
You can get feature information in popup as the below codes:
if(features.Count>0)
{
System.Text.StringBuilder information = new System.Text.StringBuilder();
information.Clear();
foreach (Feature item in features)
{
foreach (string key in item.ColumnValues.Keys)
{
information.AppendLine(key + ":" + item.ColumnValues[key]);
}
}
}
if (found)
{
CloudPopup popup = new CloudPopup("popup", e.Position, information.ToString(), 200, 200);
popup.AutoSize = false;
popup.AutoPan = true;
popup.HasCloseButton = true;
Map1.Popups.Add(popup);
}
Regards,
Edgar
if (shapeFileType == ShapeFileType.Point || shapeFileType == ShapeFileType.Multipoint)//points
{
Collection features2 = item.QueryTools.GetFeaturesWithinDistanceOf(e.Position, GeographyUnit.Meter, DistanceUnit.Meter, 50, ReturningColumnsType.AllColumns);
if (features2.Count > 0)
{
//do something
found = true;
break;
}
}
when i use GetFeaturesWithinDistanceOf() this method some times i am getting more than one feature.
and some times i am getting 3 to 5 features.
so i am not getting exact field value. i want to display exact field value.
how to get only single feature what i click on map point.
then i need to display that clicked point values.