public int IndexOfNearest(DSGeometry[] contextGeometries) { if (contextGeometries == null) throw new System.ArgumentNullException("contextGeometries"); IGeometryEntity[] hostentities = contextGeometries.ConvertAll(DSGeometryExtension.ToEntity<DSGeometry, IGeometryEntity>); if(hostentities == null) throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "contextGeometries", "IndexOfNearest"), "contextGeometries"); return GetIndexOfNearestGeometry(hostentities, PointEntity); }
/// <summary> /// /// </summary> /// <returns></returns> public DSGeometry SelectNearest(DSGeometry[] contextGeometries) { if (contextGeometries == null) throw new System.ArgumentNullException("contextGeometries"); IGeometryEntity[] hostentities = contextGeometries.ConvertAll(DSGeometryExtension.ToEntity<DSGeometry, IGeometryEntity>); if(hostentities == null) throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "contextGeometries", "SelectNearest"), "contextGeometries"); int nearestIndex = GetIndexOfNearestGeometry(hostentities, PointEntity); IGeometryEntity nearestGeom = hostentities[nearestIndex]; return DSGeometry.ToGeometry(nearestGeom, false); //returning one of the existing geometry, so persist is no-op. }
/// <summary> /// Creates a block with the given name, reference coordinate system and from the /// specified geometries /// </summary> /// <param name="blockName">the block name</param> /// <param name="referenceCoordinateSystem">the reference coordinate system</param> /// <param name="contents">the geometries contained in the block</param> /// <returns></returns> public static DSBlock FromGeometry(string blockName, DSCoordinateSystem referenceCoordinateSystem, DSGeometry[] contents) { string kMethodName = "DSBlock.FromGeometry"; if (null == referenceCoordinateSystem) throw new ArgumentNullException("contextCoordinateSystem"); if (string.IsNullOrEmpty(blockName)) throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName"); IGeometryEntity[] hosts = contents.ConvertAll(DSGeometryExtension.ToEntity<DSGeometry, IGeometryEntity>); if (null == hosts || hosts.Length == 0) throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, "geometries", kMethodName), "geometries"); IBlockHelper helper = HostFactory.Factory.GetBlockHelper(); if (null == helper) throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); if (helper.DefineBlock(referenceCoordinateSystem.CSEntity, blockName, hosts)) { return new DSBlock(blockName); } return null; }