public ShapeFile(string fileName) { if (String.IsNullOrEmpty(fileName)) throw new ArgumentNullException(); m_MapName = fileName; IEditSpatialIndex index = new SpatialIndex(); ShapefileDataReader sfdr = Shapefile.CreateDataReader(fileName, new GeometryFactory()); ShapefileHeader hdr = sfdr.ShapeHeader; Envelope ex = hdr.Bounds; m_Extent = new Window(ex.MinX, ex.MinY, ex.MaxX, ex.MaxY); foreach (object o in sfdr) { // You get back an instance of GisSharpBlog.NetTopologySuite.IO.RowStructure, but // that's internal, so cast to the interface it implements (we'll attach this to // the geometry we wrap). //ICustomTypeDescriptor row = (ICustomTypeDescriptor)o; AdhocPropertyList row = CreatePropertyList(sfdr); NTS.Geometry geom = sfdr.Geometry; geom.UserData = row; List<NTS.Geometry> geoms = GetBasicGeometries(geom); foreach (NTS.Geometry g in geoms) { g.UserData = row; if (g is NTS.Point) index.Add(new PointWrapper((NTS.Point)g)); else index.Add(new GeometryWrapper(g)); } } // Don't permit any further additions m_Index = index; }
/// <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; }