private void CreateParcelFromSegmentCollection(ISegmentCollection Segments, string PlanName) { int iCnt = Segments.SegmentCount; ISegment[] pSegmentArr = new ISegment[iCnt]; for (int j = 0; j < iCnt; j++) { pSegmentArr[j] = Segments.get_Segment(j); } ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension"); IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd; try { ICadastralPacketManager pCadPacketMan = (ICadastralPacketManager)pCadEd; bool bStartedWithPacketOpen = pCadPacketMan.PacketOpen; if (!bStartedWithPacketOpen) { m_editor.StartOperation(); } //1. Start map edit session ICadastralMapEdit pCadMapEdit = (ICadastralMapEdit)pCadEd; pCadMapEdit.StartMapEdit(esriMapEditType.esriMEEmpty, "NewParcel", false); //2. Get job packet ICadastralPacket pCadaPacket = pCadPacketMan.JobPacket; //3. Create Plan (new) string sPlanName = PlanName; //first check to ensure plan is not already in the database. IGSPlan pGSPlan = FindFabricPlanByName(sPlanName, pCadEd); if (pGSPlan == null) { //if plan is null, it was not found and can be created pGSPlan = new GSPlanClass(); // 3.a set values pGSPlan.Accuracy = 4; pGSPlan.Name = sPlanName; } //3.b Add the plan to the job packet ICadastralPlan pCadaPlan = (ICadastralPlan)pCadaPacket; pCadaPlan.AddPlan(pGSPlan); //4. Create Parcel ICadastralParcel pCadaParcel = (ICadastralParcel)pCadaPacket; IGSParcel pNewGSParcel = new GSParcelClass(); //Make sure that any extended attributes on the parcel have their default values set IGSAttributes pGSAttributes = (IGSAttributes)pNewGSParcel; if (pGSAttributes != null) { ICadastralObjectSetup pCadaObjSetup = (ICadastralObjectSetup)pParcEditorMan; pCadaObjSetup.AddExtendedAttributes(pGSAttributes); pCadaObjSetup.SetDefaultValues(pGSAttributes); } //4a. Add the parcel to the packet. (do this before addlines) // - This will enable us to Acquire the parcel ID, // - Having the parcel attached to the packet allows InsertLine to function. pCadaParcel.AddParcel(pNewGSParcel); pNewGSParcel.Lot = "NewParcel"; pNewGSParcel.Type = 7; //4b. Set Plan (created above) IGSPlan thePlan = pCadaPlan.GetPlan(sPlanName); pNewGSParcel.Plan = thePlan; //4c. Insert GSLines (from new) into GSParcel //4d. To bypass join, you can create GSPoints and assign those point IDs to the GSLines. ICadastralPoints pCadaPoints = (ICadastralPoints)pCadaPacket; IMetricUnitConverter pMetricUnitConv = (IMetricUnitConverter)pCadEd; //Set up the initial start point, POB IPoint pPt1 = Segments.get_Segment(0).FromPoint; IZAware pZAw = (IZAware)pPt1; pZAw.ZAware = true; pPt1.Z = 0; //defaulting to 0 //Convert the point into metric units, and get a new (in-mem) point id IGSPoint pGSPointFrom = pMetricUnitConv.SetGSPoint(pPt1); pCadaPoints.AddPoint(pGSPointFrom); int iID1 = pGSPointFrom.Id; int iID1_Orig = iID1; int index = 0; IGSLine pGSLine = null; //++++++++++++ Add Courses ++++++++++++++ int iID2 = -1; bool bIsLoop = (Math.Abs(pPt1.X - Segments.get_Segment(iCnt - 1).ToPoint.X)) < 0.01 && (Math.Abs(pPt1.Y - Segments.get_Segment(iCnt - 1).ToPoint.Y)) < 0.01; IAngularConverter pAngConv = new AngularConverterClass(); for (int j = 0; j < iCnt; j++) { pSegmentArr[j] = Segments.get_Segment(j); double dDir = 0; //radians north azimuth ILine pLineOrChord = new LineClass(); pLineOrChord.PutCoords(pSegmentArr[j].FromPoint, pSegmentArr[j].ToPoint); if (pAngConv.SetAngle(pLineOrChord.Angle, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians)) { dDir = pAngConv.GetAngle(esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians); } double dDist = pLineOrChord.Length; double dRadius = 0; int iAccuracy = -1; int iUserLineType = -1; int iCategory = -1; if (pSegmentArr[j] is ICircularArc) { ICircularArc pCircArc = pSegmentArr[j] as ICircularArc; dRadius = pCircArc.Radius; if (pCircArc.IsCounterClockwise) { dRadius = dRadius * -1; } } bool bComputeToPoint = (bIsLoop && (j < iCnt - 1)) || !bIsLoop; //From, Direction (NAz Radians), Distance (map's projection units), Radius pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1, iID1, dDir, dDist, dRadius, iAccuracy, iUserLineType, iCategory, bComputeToPoint, out iID2); if (j < iCnt - 1 || !bIsLoop) { iID1 = iID2; } else if ((j == iCnt - 1) && bIsLoop) { pGSLine.ToPoint = iID1_Orig; //closing the traverse back to the POB } iID2 = -1; //Add the line to the new parcel if (pGSLine != null) { pNewGSParcel.InsertLine(++index, pGSLine); } } //Add radial lines for circular curves pNewGSParcel.AddRadialLines(); // 4.e then set join=true on the parcel. pNewGSParcel.Joined = true; //let the packet know that a change has been made pCadPacketMan.SetPacketModified(true); //save the new parcel try { pCadMapEdit.StopMapEdit(true); } catch { if (!bStartedWithPacketOpen) { m_editor.AbortOperation(); } return; } if (!bStartedWithPacketOpen) { m_editor.StopOperation("New Parcel"); } pCadPacketMan.PartialRefresh(); } catch (Exception ex) { m_editor.AbortOperation(); MessageBox.Show(ex.Message); } }
private IGSLine CreateGSLine(IMetricUnitConverter MetricConversion, ICadastralPoints CadastralPoints, ref IPoint FromPointInToPointOut, int FromPointID, double Direction, double Distance, double Radius, int Accuracy, int UserLineType, int Category, bool ComputeToPoint, out int ToPointID) { //In this function, Radius == 0 means a straight line //If the radius is >0 or <0 then the line is a circular curve with Distance as the chord length //for curves Bearing means chord bearing //negative radius means a curve to the left, positive radius curve to the right //for no Accuracy, no Type, or no Category pass in -1 //Bearing is in north azimuth radians IGSLine pLine = new GSLineClass(); pLine.Bearing = Direction; //direction is in radians north azimuth double dConvertedDistance = 0; MetricConversion.ConvertDistance(esriCadastralUnitConversionType.esriCUCToMetric, Distance, ref dConvertedDistance); pLine.Distance = dConvertedDistance; //needs to be in meters; if (Math.Abs(Radius) > 0) { MetricConversion.ConvertDistance(esriCadastralUnitConversionType.esriCUCToMetric, Radius, ref dConvertedDistance); pLine.Radius = dConvertedDistance; //needs to be in meters; } pLine.FromPoint = FromPointID; pLine.ToPoint = -1; if (Accuracy > -1) { pLine.Accuracy = Accuracy; } if (UserLineType > -1) { pLine.LineType = UserLineType; } if (Category > -1) { pLine.Category = (esriCadastralLineCategory)Category; } //Make sure that any extended attributes on the line have their default values set IGSAttributes pGSAttributes = (IGSAttributes)pLine; if (pGSAttributes != null) { ICadastralObjectSetup pCadaObjSetup = (ICadastralObjectSetup)MetricConversion; //QI pCadaObjSetup.AddExtendedAttributes(pGSAttributes); pCadaObjSetup.SetDefaultValues(pGSAttributes); } //Compute the new end point for the line. //FromPointInToPointOut is in units of the map projection. ICurve pCurv = MetricConversion.GetSurveyedLine(pLine, CadastralPoints, false, FromPointInToPointOut); //pCurv is also in the units of the map projection. Convert the end point to metric units. FromPointInToPointOut = pCurv.ToPoint;//pass the new To point back out FromPointInToPointOut.Z = 0; IGSPoint pGSPointTo = MetricConversion.SetGSPoint(FromPointInToPointOut); if (ComputeToPoint) { CadastralPoints.AddPoint(pGSPointTo); pLine.ToPoint = pGSPointTo.Id; ToPointID = pLine.ToPoint; } else { ToPointID = -1; } if (pCurv is ICircularArc) { ICircularArc pCircArc = (ICircularArc)pCurv; IPoint pCtrPt = pCircArc.CenterPoint; IZAware pZAw = (IZAware)pCtrPt; pZAw.ZAware = true; pCtrPt.Z = 0; IGSPoint pGSCtrPt = MetricConversion.SetGSPoint(pCtrPt); CadastralPoints.AddPoint(pGSCtrPt); pLine.CenterPoint = pGSCtrPt.Id; } return(pLine); }
protected override void OnClick() { // **SAMPLE CODE NOTE** // the following code show the mechanics of creating a new parcel using the ICadastralMapEdit interface // there is no user interface to enter parcel record data, and the parcel line records are hard -coded // for the purposes of this sample code. The center of the map extent is used as the point of beginning // for the parcel. ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension"); IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd; IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor"); if (pEd.EditState == esriEditState.esriStateNotEditing) { MessageBox.Show("Please start editing and try again."); return; } try { ICadastralPacketManager pCadPacketMan = (ICadastralPacketManager)pCadEd; bool bStartedWithPacketOpen = pCadPacketMan.PacketOpen; if (!bStartedWithPacketOpen) { pEd.StartOperation(); } //1. Start map edit session ICadastralMapEdit pCadMapEdit = (ICadastralMapEdit)pCadEd; pCadMapEdit.StartMapEdit(esriMapEditType.esriMEEmpty, "NewParcel", false); //2. Get job packet ICadastralPacket pCadaPacket = pCadPacketMan.JobPacket; //3. Create Plan (new) string sPlanName = "My New Plan"; //first check to ensure plan is not already in the database. IGSPlan pGSPlan = FindFabricPlanByName(sPlanName, pCadEd); if (pGSPlan == null) { //if plan is null, it was not found and can be created pGSPlan = new GSPlanClass(); // 3.a set values pGSPlan.Accuracy = 4; pGSPlan.Name = sPlanName; } //3.b Add the plan to the job packet ICadastralPlan pCadaPlan = (ICadastralPlan)pCadaPacket; pCadaPlan.AddPlan(pGSPlan); //4. Create Parcel ICadastralParcel pCadaParcel = (ICadastralParcel)pCadaPacket; IGSParcel pNewGSParcel = new GSParcelClass(); //Make sure that any extended attributes on the parcel have their default values set IGSAttributes pGSAttributes = (IGSAttributes)pNewGSParcel; if (pGSAttributes != null) { ICadastralObjectSetup pCadaObjSetup = (ICadastralObjectSetup)pParcEditorMan; pCadaObjSetup.AddExtendedAttributes(pGSAttributes); pCadaObjSetup.SetDefaultValues(pGSAttributes); } //4a. Add the parcel to the packet. (do this before addlines) // - This will enable us to Acquire the parcel ID, // - Having the parcel attached to the packet allows InsertLine to function. pCadaParcel.AddParcel(pNewGSParcel); pNewGSParcel.Lot = "NewParcel"; pNewGSParcel.Type = 7; //4b. Set Plan (created above) IGSPlan thePlan = pCadaPlan.GetPlan(sPlanName); pNewGSParcel.Plan = thePlan; //4c. Insert GSLines (from new) into GSParcel //4d. To bypass join, you can create GSPoints and assign those point IDs to the GSLines. ICadastralPoints pCadaPoints = (ICadastralPoints)pCadaPacket; IMetricUnitConverter pMetricUnitConv = (IMetricUnitConverter)pCadEd; //Set up the initial start point, POB //This sample code starts from the middle of the map, and defines 4 lines of a parcel //The first course is a straight line, the other 3 courses are circular arcs IArea pArea = (IArea)ArcMap.Document.ActiveView.Extent; IPoint pPt1 = pArea.Centroid; IZAware pZAw = (IZAware)pPt1; pZAw.ZAware = true; pPt1.Z = 0; //defaulting to 0 //Convert the point into metric units, and get a new (in-mem) point id IGSPoint pGSPointFrom = pMetricUnitConv.SetGSPoint(pPt1); pCadaPoints.AddPoint(pGSPointFrom); int iID1 = pGSPointFrom.Id; int index = 0; //++++++++++++ Course 1 ++++++++++++++ int iID2 = -1; //From, Direction (NAz Radians), Distance (map's projection units), Radius IGSLine pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1, iID1, 0, 100, 0, -1, -1, -1, true, out iID2); //Add the line to the new parcel if (pGSLine != null) { pNewGSParcel.InsertLine(++index, pGSLine); } //++++++++++++ Course 2 ++++++++++++++ int iID3 = -1; pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1, iID2, (Math.PI / 2), 100, -80, -1, -1, -1, true, out iID3); if (pGSLine != null) { pNewGSParcel.InsertLine(++index, pGSLine); } //++++++++++++ Course 3 ++++++++++++++ int iID4 = -1; pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1, iID3, Math.PI, 100, 80, -1, -1, -1, true, out iID4); if (pGSLine != null) { pNewGSParcel.InsertLine(++index, pGSLine); } //++++++++++++ Course 4 ++++++++++++++ //close back to point of beginning int i = -1; pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1, iID4, (3 * Math.PI / 2), 100, 200, -1, -1, -1, false, out i); pGSLine.ToPoint = iID1; //closing the traverse back to the POB if (pGSLine != null) { pNewGSParcel.InsertLine(++index, pGSLine); } //Add radial lines for circular curves pNewGSParcel.AddRadialLines(); // 4.e then set join=true on the parcel. pNewGSParcel.Joined = true; //let the packet know that a change has been made pCadPacketMan.SetPacketModified(true); //save the new parcel try { pCadMapEdit.StopMapEdit(true); } catch { if (!bStartedWithPacketOpen) { pEd.AbortOperation(); } return; } if (!bStartedWithPacketOpen) { pEd.StopOperation("New Parcel"); } pCadPacketMan.PartialRefresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }