public void Write(GeoRefData geodata) { double[] Xs = null; double[] Ys = null; ShapeLib.ShapeType type = ShapeLib.ShapeType.NullShape; if (geodata.Geometry is IXYPoint) { IXYPoint p = (IXYPoint)geodata.Geometry; type = ShapeLib.ShapeType.Point; Xs = new double[] { p.X }; Ys = new double[] { p.Y }; } else if (geodata.Geometry.GetType().Equals(typeof(XYPolyline))) { XYPolyline p = (XYPolyline)geodata.Geometry; type = ShapeLib.ShapeType.PolyLine; int npoints =p.Points.Count; Xs = new double[npoints]; Ys = new double[npoints]; for (int i = 0; i < npoints; i++) { Xs[i] = p.Points[i].X; Ys[i] = p.Points[i].Y; } } else if (geodata.Geometry.GetType().Equals(typeof(XYLine))) { XYLine p = (XYLine)geodata.Geometry; type = ShapeLib.ShapeType.PolyLine; Xs = new double[]{p.P1.X, p.P2.X}; Ys = new double[] { p.P1.Y, p.P2.Y }; ; } else if (geodata.Geometry.GetType().Equals(typeof(XYPolygon))) { XYPolygon p = (XYPolygon)geodata.Geometry; type = ShapeLib.ShapeType.Polygon; int npoints = p.Points.Count; int extrapoint=0; if (p.Points.First() != p.Points.Last()) //First and last point has to be the same to make polygon extrapoint = 1; Xs = new double[npoints + extrapoint]; Ys = new double[npoints + extrapoint]; p.Points.Reverse(); if (extrapoint == 1) { Xs[npoints] = p.Points[0].X; Ys[npoints] = p.Points[0].Y; } for (int i = 0; i < npoints; i++) { Xs[i] = p.Points[i].X; Ys[i] = p.Points[i].Y; } p.Points.Reverse(); } else if (geodata.Geometry.GetType().Equals(typeof(MultiPartPolygon))) { MultiPartPolygon p = (MultiPartPolygon)geodata.Geometry; type = ShapeLib.ShapeType.Polygon; int npoints = p.Polygons.Sum(pol => pol.Points.Count); int extrapoints = p.Polygons.Count(pp => pp.Points.First() != pp.Points.Last()); Xs = new double[npoints + extrapoints]; Ys = new double[npoints + extrapoints]; int i = 0; foreach (var poly in p.Polygons) { poly.Points.Reverse(); foreach (var point in poly.Points) { Xs[i] = point.X; Ys[i] = point.Y; i++; } if (poly.Points.First() != poly.Points.Last()) { Xs[i] = poly.Points.First().X; Ys[i] = poly.Points.First().Y; i++; } poly.Points.Reverse(); } } if (_shapePointer == IntPtr.Zero) _shapePointer = ShapeLib.SHPCreate(_fileName, type); if (_shapePointer == IntPtr.Zero) throw new Exception("Could not create: " + Path.GetFullPath(_fileName) + "\nMake sure directory exists."); IntPtr obj; if (geodata.Geometry.GetType().Equals(typeof(MultiPartPolygon))) { MultiPartPolygon p = (MultiPartPolygon)geodata.Geometry; int[] partstarts = new int[p.Polygons.Count]; partstarts[0]=0; ShapeLib.PartType[] partype = new ShapeLib.PartType[p.Polygons.Count]; for (int i = 0; i < partype.Count(); i++) partype[i] = ShapeLib.PartType.Ring; for (int i = 1; i < partstarts.Count(); i++) { partstarts[i] = partstarts[i - 1] + p.Polygons[i - 1].Points.Count; if (p.Polygons[i - 1].Points.Last() != p.Polygons[i - 1].Points.First()) partstarts[i]++; } obj = ShapeLib.SHPCreateObject(type, -1, partstarts.Count(), partstarts, partype, Xs.Count(), Xs, Ys, null, null); } else obj = ShapeLib.SHPCreateSimpleObject(type, Xs.Count(), Xs, Ys, null); ShapeLib.SHPWriteObject(_shapePointer, -1, obj); ShapeLib.SHPDestroyObject(obj); _dbf.WriteData(geodata.Data); NoOfEntries++; }
public void Write(GeoRefData geodata) { double[] Xs = null; double[] Ys = null; ShapeLib.ShapeType type = ShapeLib.ShapeType.NullShape; if (geodata.Geometry is IXYPoint) { IXYPoint p = (IXYPoint)geodata.Geometry; type = ShapeLib.ShapeType.Point; Xs = new double[] { p.X }; Ys = new double[] { p.Y }; } else if (geodata.Geometry.GetType().Equals(typeof(XYPolyline))) { XYPolyline p = (XYPolyline)geodata.Geometry; type = ShapeLib.ShapeType.PolyLine; int npoints = p.Points.Count; Xs = new double[npoints]; Ys = new double[npoints]; for (int i = 0; i < npoints; i++) { Xs[i] = p.Points[i].X; Ys[i] = p.Points[i].Y; } } else if (geodata.Geometry.GetType().Equals(typeof(XYLine))) { XYLine p = (XYLine)geodata.Geometry; type = ShapeLib.ShapeType.PolyLine; int npoints = 2; Xs = new double[] { p.P1.X, p.P2.X }; Ys = new double[] { p.P1.Y, p.P2.Y };; } else if (geodata.Geometry.GetType().Equals(typeof(XYPolygon))) { XYPolygon p = (XYPolygon)geodata.Geometry; type = ShapeLib.ShapeType.Polygon; int npoints = p.Points.Count; Xs = new double[npoints]; Ys = new double[npoints]; p.Points.Reverse(); for (int i = 0; i < npoints; i++) { Xs[i] = p.Points[i].X; Ys[i] = p.Points[i].Y; } p.Points.Reverse(); } else if (geodata.Geometry.GetType().Equals(typeof(MultiPartPolygon))) { MultiPartPolygon p = (MultiPartPolygon)geodata.Geometry; type = ShapeLib.ShapeType.Polygon; int npoints = p.Polygons.Sum(pol => pol.Points.Count); foreach (var poly in p.Polygons) { poly.Points.Reverse(); } Xs = new double[npoints]; Ys = new double[npoints]; int i = 0; foreach (var point in p.Polygons.SelectMany(pol => pol.Points)) { Xs[i] = point.X; Ys[i] = point.Y; i++; } foreach (var poly in p.Polygons) { poly.Points.Reverse(); } } if (_shapePointer == IntPtr.Zero) { _shapePointer = ShapeLib.SHPCreate(_fileName, type); } if (_shapePointer == IntPtr.Zero) { throw new Exception("Could not create: " + Path.GetFullPath(_fileName) + "\nMake sure directory exists."); } IntPtr obj; if (geodata.Geometry.GetType().Equals(typeof(MultiPartPolygon))) { MultiPartPolygon p = (MultiPartPolygon)geodata.Geometry; int[] partstarts = new int[p.Polygons.Count]; partstarts[0] = 0; ShapeLib.PartType[] partype = new ShapeLib.PartType[p.Polygons.Count]; for (int i = 0; i < partype.Count(); i++) { partype[i] = ShapeLib.PartType.Ring; } for (int i = 1; i < partstarts.Count(); i++) { partstarts[i] = partstarts[i - 1] + p.Polygons[i - 1].Points.Count; } obj = ShapeLib.SHPCreateObject(type, -1, partstarts.Count(), partstarts, partype, Xs.Count(), Xs, Ys, null, null); } else { obj = ShapeLib.SHPCreateSimpleObject(type, Xs.Count(), Xs, Ys, null); } ShapeLib.SHPWriteObject(_shapePointer, -1, obj); ShapeLib.SHPDestroyObject(obj); _dbf.WriteData(geodata.Data); NoOfEntries++; }
private void method_2(ICoFeature icoFeature_0) { try { int[] numArray; ShapeLib.PartType[] typeArray; int num5; int count = 0; int num2 = 0; int num3 = 0; int index = 0; switch (icoFeature_0.Type) { case CoFeatureType.Point: foreach (ICoPoint point in (icoFeature_0 as ICoPointFeature).Point) { this.double_0 = new double[1]; this.double_1 = new double[1]; this.double_0[0] = point.X; this.double_1[0] = point.Y; this.intptr_2 = ShapeLib.SHPCreateObject(this.shapeType_0, -1, 0, null, null, 1, this.double_0, this.double_1, null, null); num2 = ShapeLib.SHPWriteObject(this.intptr_0, -1, this.intptr_2); ShapeLib.SHPDestroyObject(this.intptr_2); this.method_3(icoFeature_0, num2); } return; case CoFeatureType.Line: case CoFeatureType.Annotation: return; case CoFeatureType.Polygon: { ICoPolygonFeature feature2 = icoFeature_0 as ICoPolygonFeature; if (feature2 != null) { count = feature2.Points.Count; numArray = new int[count]; typeArray = new ShapeLib.PartType[count]; typeArray[0] = ShapeLib.PartType.Ring; numArray[0] = 0; num3 = feature2.Points[0].Count; for (num5 = 1; num5 < count; num5++) { numArray[num5] = num3; typeArray[num5] = ShapeLib.PartType.Ring; num3 += feature2.Points[num5].Count; } this.double_0 = new double[num3]; this.double_1 = new double[num3]; int num6 = 0; foreach (CoPointCollection points in feature2.Points) { int num8; double num7 = this.method_8(points); if (num6 == 0) { if (num7 > 0.0) { foreach (ICoPoint point2 in points) { this.double_0[index] = point2.X; this.double_1[index] = point2.Y; index++; } } else { num8 = points.Count - 1; while (num8 >= 0) { this.double_0[index] = points[num8].X; this.double_1[index] = points[num8].Y; index++; num8--; } } } else if (num7 > 0.0) { for (num8 = points.Count - 1; num8 >= 0; num8--) { this.double_0[index] = points[num8].X; this.double_1[index] = points[num8].Y; index++; } } else { foreach (ICoPoint point2 in points) { this.double_0[index] = point2.X; this.double_1[index] = point2.Y; index++; } } num6++; } this.intptr_2 = ShapeLib.SHPCreateObject(this.shapeType_0, -1, count, numArray, typeArray, num3, this.double_0, this.double_1, null, null); try { num2 = ShapeLib.SHPWriteObject(this.intptr_0, -1, this.intptr_2); ShapeLib.SHPDestroyObject(this.intptr_2); this.method_3(icoFeature_0, num2); } catch { } } return; } case CoFeatureType.Polyline: break; default: return; } ICoPolylineFeature feature = icoFeature_0 as ICoPolylineFeature; count = feature.Points.Count; numArray = new int[count]; typeArray = new ShapeLib.PartType[count]; typeArray[0] = ShapeLib.PartType.Ring; numArray[0] = 0; num3 = feature.Points[0].Count; for (num5 = 1; num5 < count; num5++) { numArray[num5] = num3; typeArray[num5] = ShapeLib.PartType.Ring; num3 += feature.Points[num5].Count; } this.double_0 = new double[num3]; this.double_1 = new double[num3]; foreach (CoPointCollection points in feature.Points) { foreach (ICoPoint point2 in points) { this.double_0[index] = point2.X; this.double_1[index] = point2.Y; index++; } } this.intptr_2 = ShapeLib.SHPCreateObject(this.shapeType_0, -1, count, numArray, typeArray, num3, this.double_0, this.double_1, null, null); num2 = ShapeLib.SHPWriteObject(this.intptr_0, -1, this.intptr_2); ShapeLib.SHPDestroyObject(this.intptr_2); this.method_3(icoFeature_0, num2); } finally { } }
public static extern string SHPPartTypeName(ShapeLib.PartType partType_0);