Wednesday, 30 March 2016

arcgis server - Intersection failing because of vertices of polygons


I've written some code to intersect features of one layer with another's, but one layer has polygons (the squares in the image) and the other has circles (not filled).


The problem is that I'm using IPointCollection interface to get the features' points and I'm only getting the border vertices of the squares


enter image description here


I tried getting the convex hull of one single feature but I failed because to use the intersect method I still have to convert to a IPointCollection


Here's the code I am using


// Get first layer's points
IGeometry multipoint = new MultipointClass();
multipoint.SpatialReference = m_firstLayerFirstfeatureIGeometry.SpatialReference;
IPointCollection multipointPoints = (IPointCollection)multipoint;


// Cycle all features of first layer and add them to the collection
foreach (DataRow m_dr in m_firstLayerfeatureGraphics.Rows)
{
// Takes this feature's geometry
ESRI.ArcGIS.ADF.Web.Geometry.Geometry adfFeature =
m_firstLayerfeatureGraphics.GeometryFromRow(m_dr) as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
// convert to a igeometry object
ESRI.ArcGIS.Geometry.IGeometry m_tempfeatureIGeometry =
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Local.Converter.ToIGeometry(adfFeature, ctx);


IPointCollection mtempfet = (IPointCollection)m_tempfeatureIGeometry;

//Add copies of the polyline vertices to the multipoint.
multipointPoints.AddPointCollection((IPointCollection)mtempfet);
}


ESRI.ArcGIS.Geometry.ITopologicalOperator6 mtopo1 = (ESRI.ArcGIS.Geometry.ITopologicalOperator6)multipointPoints;



// Get second layer's points
IGeometry multipoint2 = new MultipointClass();
multipoint2.SpatialReference = m_masterLayerFirstfeatureIGeometry.SpatialReference;
IPointCollection multipointPoints2 = (IPointCollection)multipoint2;

// Cycle all features of first layer and add them to the collection
foreach (DataRow m_dr in m_masterLayerfeatureGraphics.Rows)
{
// Takes this feature's geometry

ESRI.ArcGIS.ADF.Web.Geometry.Geometry adfFeature =
m_firstLayerfeatureGraphics.GeometryFromRow(m_dr) as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
// convert to a igeometry object
ESRI.ArcGIS.Geometry.IGeometry m_tempfeatureIGeometry =
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Local.Converter.ToIGeometry(adfFeature, ctx);

IPointCollection mtempfet = (IPointCollection)m_tempfeatureIGeometry;

//Add copies of the polyline vertices to the multipoint.
multipointPoints2.AddPointCollection(mtempfet);

}


ESRI.ArcGIS.Geometry.ITopologicalOperator6 mtopo2 = (ESRI.ArcGIS.Geometry.ITopologicalOperator6)multipointPoints2;



// INTERSECTION
ESRI.ArcGIS.Geometry.IGeometry mpointCol = (ESRI.ArcGIS.Geometry.IGeometry)mtopo2.IntersectEx((IGeometry)mtopo1, false, esriGeometryDimension.esriGeometryNoDimension);



// Draw the result
DrawIGeometryOnMap(m_Map, mpointCol);

Answer




Aggregate the points collection to a polygon


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...