コード例 #1
0
ファイル: ShapeLoader.cs プロジェクト: AlexAbramov/gis
        void Read(ShapePolyline sp)
        {
            for (int p = 0; p < sp.numParts; p++)
            {
                uint max = sp.numPoints;
                if (p < sp.numParts - 1)
                {
                    max = sp.parts[p + 1];
                }

                uint len = sp.numPoints;
                if (p < sp.numParts - 1)
                {
                    len = sp.parts[p + 1] - sp.parts[p];
                }
                else
                {
                    len = sp.numPoints - sp.parts[p];
                }

                Point[] pnt = new Point[len];
                int     j   = 0;
                for (uint i = sp.parts[p]; i < max; i++)
                {
                    pnt[j].X = XTransform(sp.points[i].X);
                    pnt[j].Y = YTransform(sp.points[i].Y);
                    j++;
                }
                GPolyline gobj = new GPolyline(curType, pnt);
            }
        }
コード例 #2
0
ファイル: CachedVectorData.cs プロジェクト: configare/hispeed
        private void ProjectFeature(Feature fet)
        {
            Shape geometry = fet.Geometry;

            double[] xs = new double[1];
            double[] ys = new double[1];
            if (geometry is ShapePolygon)
            {
                ShapePolygon plygon = geometry as ShapePolygon;
                foreach (ShapeRing ring in plygon.Rings)
                {
                    foreach (ShapePoint pt in ring.Points)
                    {
                        xs[0] = pt.X;
                        ys[0] = pt.Y;
                        _coordTransform.Transform(xs, ys);
                        pt.X = xs[0];
                        pt.Y = ys[0];
                    }
                    ring.UpdateCentroid();
                    ring.UpdateEnvelope();
                }
                plygon.UpdateCentroid();
                plygon.UpdateEnvelope();
            }
            else if (geometry is ShapePolyline)
            {
                ShapePolyline plyline = geometry as ShapePolyline;
                foreach (ShapeLineString line in plyline.Parts)
                {
                    foreach (ShapePoint pt in line.Points)
                    {
                        xs[0] = pt.X;
                        ys[0] = pt.Y;
                        _coordTransform.Transform(xs, ys);
                        pt.X = xs[0];
                        pt.Y = ys[0];
                    }
                    line.UpdateCentroid();
                    line.UpdateEnvelope();
                }
                plyline.UpdateCentroid();
                plyline.UpdateEnvelope();
            }
            else if (geometry is ShapePoint)
            {
                ShapePoint pt = geometry as ShapePoint;
                xs[0] = pt.X;
                ys[0] = pt.Y;
                _coordTransform.Transform(xs, ys);
                pt.X = xs[0];
                pt.Y = ys[0];
                pt.UpdateCentroid();
                pt.UpdateEnvelope();
            }
            fet.Geometry.UpdateCentroid();
            fet.Geometry.UpdateEnvelope();
            fet.Projected = true;
        }
コード例 #3
0
        private void TryExportIceLine(Feature[] features, string iceLineShpFileName)
        {
            double geoX, geoY = 0;

            GeoDo.RSS.Core.DrawEngine.ICoordinateTransform tran = _canvas.CoordTransform;
            List <Feature> fets = new List <Feature>();
            int            oid  = 0;

            foreach (Feature fet in features)
            {
                ShapePolyline          line           = fet.Geometry as ShapePolyline;
                List <ShapeLineString> newLineStrings = new List <ShapeLineString>();
                ShapeLineString        newpart        = null;
                ShapePoint             newPt          = null;
                ShapeLineString        part           = null;;
                List <ShapePoint>      newpts         = new List <ShapePoint>();
                for (int m = 0; m < line.Parts.Length; m++)
                {
                    part = line.Parts[m];
                    for (int j = 0; j < part.Points.Length; j++)
                    {
                        ShapePoint sp = part.Points[j];
                        if (line.IsProjected)
                        {
                            tran.Prj2Geo(sp.X, sp.Y, out geoX, out geoY);
                            newPt = new ShapePoint(geoX, geoY);
                        }
                        else
                        {
                            newPt = new ShapePoint(sp.X, sp.Y);
                        }
                        newpts.Add(newPt);
                    }
                    newpart = new ShapeLineString(newpts.ToArray());
                    newLineStrings.Add(newpart);
                }
                ShapePolyline sply       = new ShapePolyline(newLineStrings.ToArray());
                string[]      fieldvalue = new string[] { fet.FieldValues[0] };
                Feature       outFet     = new Feature(oid, sply, new string[] { _fieldName }, fieldvalue, null);
                oid++;
                fets.Add(outFet);
            }
            TryExport2ShapeFile(fets.ToArray(), iceLineShpFileName, enumShapeType.Polyline);
        }
コード例 #4
0
        private unsafe Feature GetFeature(ContourLine cntLine, ICanvas canvas, int OID)
        {
            int ptCount = cntLine.Count;

            ShapePoint[] pts = new ShapePoint[ptCount];
            fixed(PointF *ptr0 = cntLine.Points)
            {
                PointF *ptr = ptr0;

                for (int i = 0; i < ptCount; i++, ptr++)
                {
                    double geoX, geoY;
                    canvas.CoordTransform.Prj2Geo(ptr->X, ptr->Y, out geoX, out geoY);
                    pts[i] = new ShapePoint(geoX, geoY);
                }
            }

            ShapeLineString ring = new ShapeLineString(pts);
            ShapePolyline   ply  = new ShapePolyline(new ShapeLineString[] { ring });
            Feature         fet  = new Feature(OID, ply, new string[] { "Contour" }, new string[] { cntLine.ContourValue.ToString() }, null);

            return(fet);
        }
コード例 #5
0
ファイル: CommandContour.cs プロジェクト: configare/hispeed
        private unsafe Feature GetFeature(ContourLine cntLine, double resX, double resY,
                                          double minX, double maxY, int OID)
        {
            int ptCount = cntLine.Count;

            ShapePoint[] pts = new ShapePoint[ptCount];
            fixed(PointF *ptr0 = cntLine.Points)
            {
                PointF *ptr = ptr0;

                for (int i = 0; i < ptCount; i++, ptr++)
                {
                    ptr->X = (float)(ptr->X * resX + minX);
                    ptr->Y = (float)(maxY - ptr->Y * resY);
                    pts[i] = new ShapePoint(ptr->X, ptr->Y);
                }
            }

            ShapeLineString ring = new ShapeLineString(pts);
            ShapePolyline   ply  = new ShapePolyline(new ShapeLineString[] { ring });
            Feature         fet  = new Feature(OID, ply, new string[] { "Contour" }, new string[] { cntLine.ContourValue.ToString() }, null);

            return(fet);
        }
コード例 #6
0
        private Feature[] ConstructPoint(float[] lats, float[] lons)
        {
            List <Feature> features = new List <Feature>();
            ShapePoint     pt;

            string[] fieldValues = null;
            string[] fieldNames  = null;
            //除去经度、纬度属性
            //int fieldCount = _fields.Length;
            int pointCount        = lats.Length;
            List <ShapePoint> sps = new List <ShapePoint>();

            for (int oid = 0; oid < pointCount; oid++)
            {
                pt = new ShapePoint(lons[oid], lats[oid]);
                sps.Add(pt);
            }
            ShapeLineString[] parts = new ShapeLineString[] { new ShapeLineString(sps.ToArray()) };
            ShapePolyline     spl   = new ShapePolyline(parts);
            Feature           f     = new Feature(0, spl, fieldNames, fieldValues, null);

            features.Add(f);
            return(features.ToArray());
        }
コード例 #7
0
        public TestShape(string filename)
        {
            int cnt  = 0;
            int pcnt = 0;

            try
            {
//              string	drv = "Driver={Microsoft dBase Driver (*.dbf)};DBQ=";
//              OdbcConnection con = new OdbcConnection(drv + Path.GetDirectoryName( filename ));
//              con.Open();

                using (ShapeFileReader sr = new ShapeFileReader(filename))
                {
                    while (sr.Read())
                    {
                        cnt++;
                        if (sr.shapeType == ShapeUnit.Polygon)
                        {
                            ShapePolygon sp = (ShapePolygon)sr.Get( );

                            for (int p = 0; p < sp.numParts; p++)
                            {
                                uint max = sp.numPoints;
                                if (p < sp.numParts - 1)
                                {
                                    max = sp.parts[p + 1];
                                }

                                uint len = sp.numPoints;
                                if (p < sp.numParts - 1)
                                {
                                    len = sp.parts[p + 1] - sp.parts[p];
                                }
                                else
                                {
                                    len = sp.numPoints - sp.parts[p];
                                }

                                Point[] pnt = new Point[len];
                                int     j   = 0;
                                for (uint i = sp.parts[p]; i < max; i++)
                                {
                                    pnt[j].X = (int)sp.points[i].X;
                                    pnt[j].Y = (int)sp.points[i].Y;
                                    j++;
                                }
                                pcnt += (int)len;
                            }
                        }
                        if (sr.shapeType == ShapeUnit.PolyLine)
                        {
                            ShapePolyline sp = (ShapePolyline)sr.Get();

                            for (int p = 0; p < sp.numParts; p++)
                            {
                                uint max = sp.numPoints;
                                if (p < sp.numParts - 1)
                                {
                                    max = sp.parts[p + 1];
                                }

                                uint len = sp.numPoints;
                                if (p < sp.numParts - 1)
                                {
                                    len = sp.parts[p + 1] - sp.parts[p];
                                }
                                else
                                {
                                    len = sp.numPoints - sp.parts[p];
                                }

                                Point[] pnt = new Point[len];
                                int     j   = 0;
                                for (uint i = sp.parts[p]; i < max; i++)
                                {
                                    pnt[j].X = (int)sp.points[i].X;
                                    pnt[j].Y = (int)sp.points[i].Y;
                                    j++;
                                }
                                pcnt += (int)len;
                            }
                        }

/*                        string str = null;
 *                      object[] an = sr.GetAttrNames();
 *                      object[] tp = sr.GetAttrTypes();
 *                      for (int i = 0; i < an.Length; i++)
 *                          str += an[i] + " " + tp[i] + "\n";
 *                      Console.WriteLine(str, "»мена полей и типов");
 */
                    }
                }
//                con.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            Console.WriteLine("Read " + cnt.ToString() + " objects, " + pcnt.ToString() + " points",
                              this.GetType().ToString());
        }
コード例 #8
0
ファイル: CachedVectorData.cs プロジェクト: configare/hispeed
        private void ProjectFeature(Feature fet)
        {
            Shape geometry = fet.Geometry;

            double[] xs = new double[1];
            double[] ys = new double[1];
            if (geometry is ShapePolygon)
            {
                ShapePolygon plygon = geometry as ShapePolygon;
                foreach (ShapeRing ring in plygon.Rings)
                {
                    foreach (ShapePoint pt in ring.Points)
                    {
                        xs[0] = pt.X;
                        ys[0] = pt.Y;
                        _coordTransform.Transform(xs, ys);
                        pt.X = xs[0];
                        pt.Y = ys[0];
                    }
                    ring.UpdateCentroid();
                    ring.UpdateEnvelope();
                }
                plygon.UpdateCentroid();
                plygon.UpdateEnvelope();
            }
            else if (geometry is ShapePolyline)
            {
                ShapePolyline plyline = geometry as ShapePolyline;
                foreach (ShapeLineString line in plyline.Parts)
                {
                    foreach (ShapePoint pt in line.Points)
                    {
                        xs[0] = pt.X;
                        ys[0] = pt.Y;
                        _coordTransform.Transform(xs, ys);
                        pt.X = xs[0];
                        pt.Y = ys[0];
                    }
                    line.UpdateCentroid();
                    line.UpdateEnvelope();
                }
                plyline.UpdateCentroid();
                plyline.UpdateEnvelope();
            }
            else if (geometry is ShapePoint)
            {
                ShapePoint pt = geometry as ShapePoint;
                xs[0] = pt.X;
                ys[0] = pt.Y;
                _coordTransform.Transform(xs, ys);
                pt.X = xs[0];
                pt.Y = ys[0];
                pt.UpdateCentroid();
                pt.UpdateEnvelope();
            }
            fet.Geometry.UpdateCentroid();
            fet.Geometry.UpdateEnvelope();
            //
            if (fet.Annotations != null && fet.Annotations.Length > 0)
            {
                foreach (LabelLocation loc in fet.Annotations)
                {
                    xs[0] = loc.Location.X;
                    ys[0] = loc.Location.Y;
                    _coordTransform.Transform(xs, ys);
                    loc.Location = new ShapePoint(xs[0], ys[0]);
                }
            }
            //
            fet.Projected = true;
        }