7 votos

Cómo agregar una nueva Parcela en el interior de la estructura de la Parcela a partir de los actuales entidades de parcela (ArcObjects)

Quiero crear una nueva parcela en una capa de estructura de parcela. Tengo las coordenadas x, y para las parcelas a ser creado. He buscado mucho y se encontró realmente nada de lo que realmente se "CREA" una parcela.

Esto es lo que he probado hasta ahora:

IPointCollection pts = feat.ShapeCopy as IPointCollection; //an existig polygon from another featureclass used for copying x,y,z..
ICadastralPoints cadPoints = new CadastralPacketClass();
for (int i = 0; i < pts.PointCount; i++)
{
    IPoint p = pts.get_Point(i);
    IGSPoint gsPt = new GSPointClass();
    gsPt.X = p.X;
    gsPt.Y = p.Y;
    gsPt.Z = p.Z;
    gsPt.Type = -1; //just tried when nothing worked..made no difference..
    cadPoints.AddPoint(gsPt);
}

IEnumCELines ceLines = new EnumCELinesClass();

ICadastralLines cadLines = new CadastralPacketClass();
ISegmentCollection segments = feat.ShapeCopy as ISegmentCollection; //an existig polygon from another featureclass used for getting segments
for (int i = 0; i < segments.SegmentCount; i++)
{
    ISegment seg = segments.get_Segment(i);

    IGSLine gsLine = new GSLineClass();
    double bearingDeg = utils.GetBearing(seg.FromPoint, seg.ToPoint);
    gsLine.Bearing = (Math.PI * bearingDeg) / 180;
    gsLine.Distance = seg.Length;

    ceLines.Add(gsLine);
}

IEnumGSLines gsLines = ceLines as IEnumGSLines;

IParcelLineFunctions parcelLineFunctions = new ParcelFunctionsClass();
IConstructParcelFunctions constrParcelFunctions = new ParcelFunctionsClass();
ICadastralPacket m_EditPacket = cadExtension.GetEditPacket();

IEnumGSParcels outputParcels = null;
int peRrorLinePointfrom = -1;
int peRrorLinePointTo = -1;

IGSPlan gsPlan = gsParcel.Plan; //gsParcel is an existing parcel..

constrParcelFunctions.ConstructParcelsFromLines(gsPlan, cadPoints, gsLines, m_EditPacket, 1, ref outputParcels, ref peRrorLinePointfrom, ref peRrorLinePointTo);

IGSParcel resultParcel = outputParcels.Next(); //resultParcel is null now..was expecting this to have some value..

Espero que alguien me guiara en la dirección correcta.

2voto

Farid Cher Puntos 5306

Asegúrese de que hay una capa de estructura de parcela presentes en el mapa y ha iniciado la edición. agregue el siguiente assemlbies a su proyecto, si no lo han hecho ya.

  • ESRI.ArcGIS.CadastralUI
  • ESRI.ArcGIS.GeoSurvey
  • ESRI.ArcGIS.GeoDatabaseExtensions

El uso de esta Clase y sus métodos para crear una estructura de parcela de un paquete característica. Este método se ha probado, sin embargo si tu encontrado algún error, que me haga saber.

//@FaridCher at GIS.StackExchange
//can be copied and/or distributed without the express permission

using ESRI.ArcGIS.CadastralUI;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.GeoDatabaseExtensions;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.GeoSurvey;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace MyParcelFabric
{
    class CreateParcelFabric_FromPolygonSelection
    {
        protected override void OnClick()
        {
            var enums = ArcMap.Document.ActiveView.FocusMap.FeatureSelection as IEnumFeature;
            IFeature feat = enums.Next();
            if (feat == null)
            {
                return;
            }
            CreateParcelFabric(feat);
        }

        private void CreateParcelFabric(IFeature polygonFeature)
        {
            try
            {
                UID pUID = new UIDClass();
                pUID.Value = "{114D685F-99B7-4B63-B09F-6D1A41A4DDC1}";
                ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)ArcMap.Application.FindExtensionByCLSID(pUID);
                ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByCLSID(pUID);
                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;
                }

                ICadastralPacketManager pCadPacketMan = (ICadastralPacketManager)pCadEd;
                bool bStartedWithPacketOpen = pCadPacketMan.PacketOpen;
                if (!bStartedWithPacketOpen)
                    pEd.StartOperation();

                //Start map edit session
                ICadastralMapEdit pCadMapEdit = (ICadastralMapEdit)pCadEd;
                pCadMapEdit.StartMapEdit(esriMapEditType.esriMEEmpty, "NewParcel", false);

                //Get job packet
                ICadastralPacket pCadaPacket = pCadPacketMan.JobPacket;

                //Create Plan (new)
                string sPlanName = "My New Plan";
                IGSPlan pGSPlan = null;
                pGSPlan = new GSPlanClass();
                //set values
                pGSPlan.Accuracy = 4;
                pGSPlan.Name = sPlanName;

                //Add the plan to the job packet
                ICadastralPlan pCadaPlan = (ICadastralPlan)pCadaPacket;
                pCadaPlan.AddPlan(pGSPlan);

                //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);
                }

                //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;
                //Set Plan (created above)
                IGSPlan thePlan = pCadaPlan.GetPlan(sPlanName);
                pNewGSParcel.Plan = thePlan;


                ICadastralPoints pCadaPoints = (ICadastralPoints)pCadaPacket;
                IMetricUnitConverter pMetricUnitConv = (IMetricUnitConverter)pCadEd;

                ISegmentCollection segments = polygonFeature.ShapeCopy as ISegmentCollection;

                //first segment point of polygon as the start of ParFab
                var 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 iID_First_Last = pGSPointFrom.Id;
                int iID1 = iID_First_Last;
                int iID2 = -1;

                int index = 0;
                for (int i = 0; i < segments.SegmentCount; i++)
                {
                    ISegment seg = segments.get_Segment(i);

                    double bearingRad = getBearing(seg.FromPoint, seg.ToPoint);

                    bool computeToPoint = true;
                    if (i == segments.SegmentCount - 1)
                        computeToPoint = false;

                    IGSLine pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1,
                      iID1, bearingRad, seg.Length, 0, -1, -1, -1, computeToPoint, out iID2);

                    iID1 = iID2;
                    iID2 = -1;

                    if (i == segments.SegmentCount - 1)
                        pGSLine.ToPoint = iID_First_Last;

                    pNewGSParcel.InsertLine(++index, pGSLine);
                }

                //Add radial lines for circular curves
                pNewGSParcel.AddRadialLines();

                //then set join=true on the parcel.
                pNewGSParcel.Joined = true;

                //let the packet know that a change has been made
                pCadPacketMan.SetPacketModified(true);
                try
                {
                    pCadMapEdit.StopMapEdit(true);
                }
                catch
                {
                    if (!bStartedWithPacketOpen)
                        pEd.AbortOperation();
                    return;
                }
                if (!bStartedWithPacketOpen)
                    pEd.StopOperation("New Parcel Fabric");

                pCadPacketMan.PartialRefresh();
            }
            catch (Exception ex)
            {
                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 = (ESRI.ArcGIS.GeoDatabaseExtensions.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;
        }

        private double getBearing(IPoint fromPoint, IPoint toPoint)
        {
            ILine line = new LineClass();
            line.PutCoords(fromPoint, toPoint);
            double angle = line.Angle;
            return Math.PI / 2 - angle;
        }
    }
}

i-Ciencias.com

I-Ciencias es una comunidad de estudiantes y amantes de la ciencia en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X