Example #1
0
        private void display_shape_file()
        {
            int totalShapeCount = 0;
            int totalNodeCount = 0;
            GpsViewNET.Ellipse objEllipse = null;
            GpsViewNET.Rectangle objRectangle = null;
            GpsViewNET.Brush objBrush = null;
            //GpsViewNET.Label objLabel = null;

            try
            {
                shapeFile = new GpsShapeNET.ShapeFile();

                // Open the shapefile

                shapeFile.Open(shapefilepath, GpsShapeNET.FileMode.FILE_READ);

                double Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, Mmin, Mmax = 0;

                // Read bounding values specified for whole shapefile and create a blank map
                // scaled with these bounding values.
                shapeFile.GetBoundingBox(out Xmin, out Xmax, out Ymin, out Ymax, out Zmin, out Zmax, out Mmin, out Mmax);

                Xmin_ = Xmin;
                Xmax_ = Xmax;
                Ymin_ = Ymin;
                Ymax_ = Ymax;

                bool bIsDatum = false;
                if (Ymax <= 90 && Ymin >= -90 && Xmax <= 180 && Xmin >= -180)
                {
                    bIsDatum = true;
                }

                create_blank_map(Xmin, Xmax, Ymin, Ymax, bIsDatum);

                // Create a new layer for this shapefile.
                // We like draw all shapes from a certain shapefile on a seperate layer.
                string layerName = String.Format("main", layerID);
                map1.ActiveLayer(layerName);

                layerID++;

                // We create an ellipse object and using it to draw all nodes.
                int width = Convert.ToInt32(map1.Zoom);
                int height = Convert.ToInt32(map1.Zoom);

                // We create a brush object and using it for drawing polygon shapes.
                objBrush = make_brush();

                // Get shape type.
                // All shape types supported by ESRI are defined in enum GpsShapeNET.ShapeFileType.
                GpsShapeNET.ShapeFileType shapeFileType = shapeFile.ShapeFileType;

                // Define a position object to calculate nodes position
                // according to it.
                // NOTE! Shapes may use different coordinate system than mapshape's.
                GpsToolsNET.Position nodePosition = new GpsToolsNET.Position();
                if (bIsDatum)
                {
                    nodePosition.Datum = GpsToolsNET.Datum.WGS_84;
                }
                else
                {
                    nodePosition.Grid = GpsToolsNET.Grid.UTM_NORTH;
                    nodePosition.Zone = "15";
                }

                // Start to read all shapes from shapefile.
                // NOTE: Even Seek() can be used to access a certain shape.
                int shapeId = 0;
                while ((shape = shapeFile.Read()) != null)
                {
                    shape.ShapeID = shapeId++;
                    objEllipse = make_ellipse();
                    // Calculate number of shapes and total number of nodes.
                    int nodeCount = shape.TotalNodeCount;
                    if (nodeCount == 0)
                    {
                        // Nothing to draw. Get next shape.
                        continue;
                    }

                    totalNodeCount += nodeCount;
                    totalShapeCount++;

                    shape.DatumGridTemplate = nodePosition;

                    shape.GetBoundingBox(out Xmin, out Xmax, out Ymin, out Ymax, out Zmin, out Zmax, out Mmin, out Mmax);

                    // Create a mapshape to handle drawing for this shape.
                    mapShape = map1.NewMapShape(shape);
                    //mapShapeLabels = map1.NewMapShape(shape);
                    //mapShape.ID = 666;

                    switch (shapeFileType)
                    {
                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_POINT:
                            mapShape.NodeTemplate = objEllipse;
                            //mapShapeLabels.NodeTemplate = make_label(shape.ShapeID.ToString());
                            //mapShape.NodeTemplate = objRectangle;
                            break;
                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_POINT_Z:
                            mapShape.NodeTemplate = objEllipse;
                            break;
                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_POINT_M:
                            mapShape.NodeTemplate = objEllipse;
                            break;

                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_MULTIPOINT:
                            mapShape.NodeTemplate = objEllipse;
                            mapShape.Border.Width = 0;
                            mapShape.Background.Transparent = true;
                            break;
                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_MULTIPOINT_Z:
                            mapShape.NodeTemplate = objEllipse;
                            mapShape.Border.Width = 0;
                            mapShape.Background.Transparent = true;
                            break;
                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_MULTIPOINT_M:
                            // Set an ellipse as a nodetemplate.
                            // All nodes in the shape will drawn/marked with this object.
                            mapShape.NodeTemplate = objEllipse;
                            mapShape.Border.Width = 0;
                            mapShape.Background.Transparent = true;
                            break;

                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_POLYLINE:
                            mapShape.Border.Width = 1;
                            break;
                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_POLYLINE_Z:
                            mapShape.Border.Width = 1;
                            break;
                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_POLYLINE_M:
                            // Set pen width to 1 to draw lines with. Default value is 0.
                            mapShape.Border.Width = 1;
                            break;

                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_POLYGON:
                            mapShape.Background = objBrush;
                            break;
                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_POLYGON_Z:
                            mapShape.Background = objBrush;
                            break;
                        case GpsShapeNET.ShapeFileType.SHAPE_TYPE_POLYGON_M:
                            mapShape.Background = objBrush;

                            // NOTE! Background object could also be defined by directly
                            // setting it's properties. Following example defines a blue brush object
                            // for drawing polygons.
                            // mapShape.Background.Transparent = false;
                            // mapShape.Background.Blue  = 255;
                            break;
                    }
                }

                bFileLoaded = true;

                //lbTotalNodeNumber.Text = totalNodeCount.ToString();
                //lbNumberOfShapes.Text = totalShapeCount.ToString();
                //shapeFile.Close();

                // View all shapes on the map.
                map1.Update();
            }
            catch (Exception exp)
            {
                shapeFile.Close();
                bFileLoaded = false;
                MessageBox.Show(exp.Message);
                return;
            }
        }
Example #2
0
        private void GeoRedeProject_Load(object sender, EventArgs e)
        {
            //datum
            GpsToolsNET.Position nodeDatumGrid = new GpsToolsNET.Position();
            nodeDatumGrid.Datum = GpsToolsNET.Datum.WGS_84;

            //carrega shapeCasas
            shapeCasas = new GpsShapeNET.Shape();
            shapeCasas.DatumGridTemplate = nodeDatumGrid;
            //mapShapeCasas = map1.NewMapShape(shapeCasas);
            double Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, Mmin, Mmax = 0;
            shapeCasas.GetBoundingBox(out Xmin, out Xmax, out Ymin, out Ymax, out Zmin, out Zmax, out Mmin, out Mmax);

            Xmin_ = Xmin;
            Xmax_ = Xmax;
            Ymin_ = Ymin;
            Ymax_ = Ymax;

            create_blank_map(Xmin, Xmax, Ymin, Ymax, false);

            string layerName = String.Format("main", layerID);
            map1.ActiveLayer(layerName);

            Cursor.Current = Cursors.Default;
            Application.DoEvents();
        }