//pPointColl is the new polyline. IPointCollection pPointColl = new PolylineClass(); //TODO: IPoint pt = new Point(); pt.PutCoords(10, 0); pt.Z = 1; pt.ID = 1; pPointColl.AddPoint(pt); pt = new Point(); pt.PutCoords(10, 10); pt.Z = 0; pt.ID = 2; pPointColl.AddPoint(pt); pt = new Point(); pt.PutCoords(20, 10); pt.Z = 0; pt.ID = 3; pPointColl.AddPoint(pt); pt = new Point(); pt.PutCoords(20, 0); pt.Z = 0; pt.ID = 4; pPointColl.AddPoint(pt); (pPointColl as IPolyline).SpatialReference = MyCodeLib.DefaultSpatialReference(); (pPointColl as IZAware).ZAware = true; var itopo = (ITopologicalOperator) pPointColl; itopo.Simplify(); IGeometry5 geom5 = (IGeometry5) pPointColl;
Solved! Go to Solution.
Private Sub GeometryTest() Dim pGeometry As ESRI.ArcGIS.Geometry.IGeometry5 Dim pPointColl As ESRI.ArcGIS.Geometry.IPointCollection Dim pt As ESRI.ArcGIS.Geometry.IPoint Dim pTopo As ESRI.ArcGIS.Geometry.ITopologicalOperator Try pPointColl = New ESRI.ArcGIS.Geometry.Polyline pt = New ESRI.ArcGIS.Geometry.Point pt.PutCoords(10, 0) pt.Z = 1 pt.ID = 1 pPointColl.AddPoint(pt) pt = New ESRI.ArcGIS.Geometry.Point() pt.PutCoords(10, 10) pt.Z = 0 pt.ID = 2 pPointColl.AddPoint(pt) pt = New ESRI.ArcGIS.Geometry.Point() pt.PutCoords(20, 10) pt.Z = 0 pt.ID = 3 pPointColl.AddPoint(pt) pt = New ESRI.ArcGIS.Geometry.Point() pt.PutCoords(20, 0) pt.Z = 0 pt.ID = 4 pPointColl.AddPoint(pt) 'TryCast(pPointColl, ESRI.ArcGIS.Geometry.IPolyline).SpatialReference = MyCodeLib.DefaultSpatialReference() 'TryCast(pPointColl, IZAware).ZAware = True pTopo = DirectCast(pPointColl, ESRI.ArcGIS.Geometry.ITopologicalOperator) pTopo.Simplify() pGeometry = DirectCast(pPointColl, ESRI.ArcGIS.Geometry.IGeometry5) Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.ToString) End Try End Sub
var centroid = geom5.CentroidEx;
public IGeographicCoordinateSystem2 DefineWGS84GeoCoordsys() { ISpatialReferenceFactory2 spatRefFact = new SpatialReferenceEnvironmentClass(); // Create WGS84 Geographic Coordinate System - esriSRGeoCS_WGS1984 - 'GCS_WGS_1984'. IGeographicCoordinateSystem2 pGeoCoordSys = (IGeographicCoordinateSystem2)spatRefFact.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); // Set the domain extents for the new dataset // You can use either the Domain or the FalseOriginAndUnits methods // (note that the xy domain must be square). pGeoCoordSys.SetFalseOriginAndUnits(-180, -90, 1000000); pGeoCoordSys.SetMFalseOriginAndUnits(1, 1); pGeoCoordSys.SetZFalseOriginAndUnits(1, 1); return pGeoCoordSys; }
Private Sub GeometryTest() Dim pGeometry As ESRI.ArcGIS.Geometry.IGeometry5 Dim pPointColl As ESRI.ArcGIS.Geometry.IPointCollection Dim pt As ESRI.ArcGIS.Geometry.IPoint Dim pTopo As ESRI.ArcGIS.Geometry.ITopologicalOperator Try pPointColl = New ESRI.ArcGIS.Geometry.Polyline pt = New ESRI.ArcGIS.Geometry.Point pt.PutCoords(10, 0) pt.Z = 1 pt.ID = 1 pPointColl.AddPoint(pt) pt = New ESRI.ArcGIS.Geometry.Point() pt.PutCoords(10, 10) pt.Z = 0 pt.ID = 2 pPointColl.AddPoint(pt) pt = New ESRI.ArcGIS.Geometry.Point() pt.PutCoords(20, 10) pt.Z = 0 pt.ID = 3 pPointColl.AddPoint(pt) pt = New ESRI.ArcGIS.Geometry.Point() pt.PutCoords(20, 0) pt.Z = 0 pt.ID = 4 pPointColl.AddPoint(pt) TryCast(pPointColl, ESRI.ArcGIS.Geometry.IPolyline).SpatialReference = DefineWGS84GeoCoordsys() TryCast(pPointColl, ESRI.ArcGIS.Geometry.IZAware).ZAware = True pTopo = DirectCast(pPointColl, ESRI.ArcGIS.Geometry.ITopologicalOperator) pTopo.Simplify() pGeometry = DirectCast(pPointColl, ESRI.ArcGIS.Geometry.IGeometry5) Dim centroid As ESRI.ArcGIS.Geometry.IPoint centroid = pGeometry.CentroidEx MsgBox(centroid.X & ", " & centroid.Y) Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.ToString) End Try End Sub Public Function DefineWGS84GeoCoordsys() As ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem2 Dim spatRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory2 = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment ' Create WGS84 Geographic Coordinate System - esriSRGeoCS_WGS1984 - 'GCS_WGS_1984'. Dim pGeoCoordSys As ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem2 = DirectCast(spatRefFact.CreateGeographicCoordinateSystem(CInt(ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984)), ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem2) ' Set the domain extents for the new dataset ' You can use either the Domain or the FalseOriginAndUnits methods ' (note that the xy domain must be square). pGeoCoordSys.SetFalseOriginAndUnits(-180, -90, 1000000) pGeoCoordSys.SetMFalseOriginAndUnits(1, 1) pGeoCoordSys.SetZFalseOriginAndUnits(1, 1) Return pGeoCoordSys End Function