ThinkGeo.com    |     Documentation    |     Premium Support

Intersection of two ShapeFeatureLayers

Hello ,
I want intersecting polygon of two layers. One is GutBoundary layer n other is RoadLayer.
But i am not able to get the intersection polygon.I also referred web edition’s given sample.
i want result like Image1 which is attached but i am getting result like Image2 .
Please refer attached image files n shape files in ShapeFile folder.
I am eagerly waiting for your reply ASAP
thank you in advance

Here i am attaching my code sample
protected void btnDetails_Click(object sender, EventArgs e)
{
//RP Layer
ShapeFileFeatureLayer RPLayer = new ShapeFileFeatureLayer(Filepath + “VILLAGES/” + “BAVDHAN_BK” + “/RP_ROAD.shp”);
//RPLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Transparent, GeoColor.StandardColors.DarkRed,2);
//RPLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle(“ID”, “Arial”, 8, DrawingFontStyles.Bold, GeoColor.StandardColors.Violet, 0, 0);
RPLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
//RPLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad2;
ShapeFileFeatureSource.BuildIndexFile(RPLayer.ShapePathFileName);
//Gut Boundary
//ShapeFileFeatureLayer GutBOLayer = new ShapeFileFeatureLayer(Filepath + “VILLAGES/” + drpVillage.SelectedItem.Text.ToUpper() +"/"+drpVillage.SelectedItem.Text.ToUpper() + “.shp”);
ShapeFileFeatureLayer GutBOLayer = new ShapeFileFeatureLayer(Filepath + “VILLAGES/” + “BAVDHAN_BK/GUT_BO_BAVDHAN_BK.shp”);
//GutBOLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Transparent, GeoColor.FromArgb(255, 132, 132, 154), 1);
GutBOLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle(“ID,TEXTSTRING”, “Arial”, 10, DrawingFontStyles.Bold, GeoColor.StandardColors.Transparent, 0, 0);
GutBOLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
ShapeFileFeatureSource.BuildIndexFile(GutBOLayer.ShapePathFileName);
//Gut TEXT
ShapeFileFeatureLayer GutTextLayer = new ShapeFileFeatureLayer(Filepath + “VILLAGES/BAVDHAN_BK/” + “/GUT_TEXT_BAVDHAN_BK.shp”);
//GutTextLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Transparent, GeoColor.StandardColors.Black, 1);
GutTextLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle(“TEXTSTRING”, “Arial”, 8, DrawingFontStyles.Bold, GeoColor.StandardColors.LightCoral, 0, 0);
GutTextLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
ShapeFileFeatureSource.BuildIndexFile(GutTextLayer.ShapePathFileName);

        LayerOverlay staticOverlay = new LayerOverlay();
        staticOverlay.Layers.Add("RPFile",RPLayer);
        staticOverlay.Layers.Add("GOFile", GutBOLayer);
        staticOverlay.Layers.Add("GOTextFile", GutTextLayer);

        Map1.CustomOverlays.Add(staticOverlay);
        RPLayer.Open();
        Map1.CurrentExtent = RPLayer.GetBoundingBox();
        AreaStyle areast = new AreaStyle();
        areast.OutlinePen.Color = GeoColor.StandardColors.Black;
        AreaStyle areastrp = new AreaStyle();
        areastrp.OutlinePen.Color = GeoColor.StandardColors.Brown;
        areastrp.OutlinePen.Width = 2;
        GutBOLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(areast);
        RPLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(areastrp);
    }

protected void Map1_Click(object sender, MapClickedEventArgs e)
{
Collection finalFeature = new Collection();
ValueStyle valueSchema = new ValueStyle();
valueSchema.ColumnName = “TEXTSTRING”;
ValueStyle RoadvalueSchema = new ValueStyle();
RoadvalueSchema.ColumnName = “ID”;
RectangleShape rshp = new RectangleShape();
ShapeFileFeatureLayer RPLayerShape = (ShapeFileFeatureLayer)((LayerOverlay)Map1.CustomOverlays[0]).Layers[“RPFile”];
ShapeFileFeatureLayer GOLayerShape = (ShapeFileFeatureLayer)((LayerOverlay)Map1.CustomOverlays[0]).Layers[“GOFile”];
//InMemoryFeatureLayer inMemoryIntersect = (InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[“InMemoryLayer”];
//InMemoryFeatureLayer inMemoryIntersect1 = (InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[“InMemoryLayer1”];
GOLayerShape.Open();
RPLayerShape.Open();
Collection GOintersectFeature = GOLayerShape.QueryTools.GetFeaturesIntersecting(e.Position, new string[3] { “ID”, “TEXTSTRING”, “AREA” });
Collection intersectFeature = RPLayerShape.QueryTools.GetFeaturesIntersecting(e.Position, new string[3] { “ID”, “STRING”, “AREA1” });
GOLayerShape.Close();
RPLayerShape.Close();
InMemoryFeatureLayer inMemory = new InMemoryFeatureLayer();
inMemory.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Green));
inMemory.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay dynamicOverlay = new LayerOverlay();
dynamicOverlay.Layers.Add(“InMemoryF”, inMemory);
//dynamicOverlay.Layers.Add(inMemory1);
dynamicOverlay.TileType = TileType.SingleTile;
dynamicOverlay.IsBaseOverlay = false;
inMemory.InternalFeatures.Add(GOintersectFeature[0]);
//valueSchema.ValueItems.Add(new ValueItem(intersectFeature[0].ColumnValues[“ID”], new AreaStyle(new GeoSolidBrush(GeoColor.StandardColors.White))));
//RoadvalueSchema.ValueItems.Add(new ValueItem(intersectFeature[0].ColumnValues[“ID”], new AreaStyle(new GeoSolidBrush(GeoColor.StandardColors.LightSkyBlue))));//intersectFeature[0].ColumnValues[“STRING”]
//GOLayerShape.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueSchema);
RPLayerShape.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(RoadvalueSchema);
//dynamicOverlay.Layers.Add(inMemory);
//dynamicOverlay.Layers.Add(inMemory1);
Map1.CustomOverlays.Add(dynamicOverlay);
dynamicOverlay.Redraw();
}


ShapeFiles.zip (208.6 KB)

Hi Mouni_M,

Your data miss the shx file so we cannot make the code run.

But from your Image1 and Image2, you can found one of them is A layer intersect B layer but the other one is B layer intersect A layer.

So I think the solution should be swap the layers, you can try to change the layer of QueryTools.GetFeaturesIntersecting function.

Wish that’s helpful.

Regards,

Ethan

Thank you Ethan for ur reply.
Actually i have modified that road shape file to get desired output.but for too many shape files i can not do the same.
so please help me out
Here i am attaching shx filesShapeFiles.zip (210.4 KB)

Hi Mouni_M,

This is the result of: GOLayerShape.QueryTools.GetFeaturesIntersecting(e.Position

And this is the result of: RPLayerShape.QueryTools.GetFeaturesIntersecting(e.Position

So if you want to implement the result like your image 1, you should want add this line:

Feature result = GOintersectFeature[0].GetIntersection(intersectFeature[0]);

and add it to layer:
inMemory.InternalFeatures.Clear();
inMemory.InternalFeatures.Add(result);

Then you get this result:

Here is the sample:
9272.zip (296.7 KB)

Regards,

Ethan

Thank you Ethan

Regards,
Mouni

Hi Mouni,

I am glad to hear that’s helpful.

Regards,

Ethan