Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CadastralFile"/> class.
        /// </summary>
        /// <param name="name">The name of the xml file</param>
        /// <param name="data">The data that was deserialized</param>
        internal CadastralFile(string name, GeoSurveyPacketData data)
        {
            m_Name = Path.GetFileName(name);
            m_Data = data;
            m_Extent = new Window(m_Data.points);
            m_Points = new Dictionary<int, IPoint>(m_Data.points.Length);

            IEditSpatialIndex index = new SpatialIndex();

            foreach (Point p in m_Data.points)
            {
                index.Add(p);
                m_Points.Add(p.pointNo, p);
            }

            foreach (Plan plan in m_Data.plans)
            {
                foreach (Parcel parcel in plan.parcels)
                {
                    // Relate the parcel to it's plan
                    parcel.Plan = plan;

                    foreach (Line line in parcel.lines)
                    {
                        Debug.Assert(line.From == null && line.To == null);

                        // Relate the line to the parcel that it is part of
                        line.Parcel = parcel;

                        line.From = m_Points[line.fromPoint];
                        line.To = m_Points[line.toPoint];

                        if (line.centerPointSpecified)
                            line.Center = m_Points[line.centerPoint];

                        index.Add(line);
                    }

                    /*
                    foreach (LinePoint lp in parcel.linePoints)
                    {
                        // Relate to the parcel it's referenced by

                        // Relate the associated point
                    }
                     */
                }
            }

            m_Index = index;
        }
Example #2
0
        private void LoadForm_Shown(object sender, EventArgs e)
        {
            try
            {
                // Load the cadastral schema
                XmlSchema schema = GetSchema();

                ShowMessage("Checking data");
                string data = File.ReadAllText(m_FileName);

                using (StringReader sr = new StringReader(data))
                {
                    XmlReaderSettings xrs = new XmlReaderSettings();
                    xrs.ConformanceLevel = ConformanceLevel.Document;
                    xrs.ValidationType = ValidationType.Schema;
                    xrs.Schemas.Add(schema);
                    xrs.ValidationEventHandler += new ValidationEventHandler(ValidationEventHandler);

                    XmlReader reader = XmlReader.Create(sr, xrs);
                    while (reader.Read())
                    {
                        if (m_Errors.Count > 100)
                            throw new ApplicationException("Too many problems. Ignoring the rest of the file.");
                    }

                }

                if (m_Errors.Count == 1)
                    ShowMessage("1 problem detected");
                else
                    ShowMessage(m_Errors.Count + " problems detected");

                // Load the data into objects so long as there were no errors
                if (m_Errors.Count == 0)
                {
                    ShowMessage("Deserializing...");
                    m_Data = CadastralFile.ReadXmlString(data);
                    //using (StringReader sr = new StringReader(data))
                    //{
                    //    using (XmlReader xr = XmlReader.Create(sr))
                    //    {
                    //        XmlSerializer xs = new XmlSerializer(typeof(GeoSurveyPacketData));
                    //        GeoSurveyPacketData packet = (GeoSurveyPacketData)xs.Deserialize(xr);
                    //    }
                    //}
                    ShowMessage("Done");
                }
            }

            catch (Exception ex)
            {
                ShowMessage(ex.Message);
            }
        }