Пример #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;
            }
        }
Пример #2
0
        private void Croqui_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'lptDataSet.ponto_sangria' table. You can move, or remove it, as needed.
            this.ponto_sangriaTableAdapter.Fill(this.lptDataSet.ponto_sangria, Poste.ProjetoId);

            // TODO: This line of code loads data into the 'lptDataSet.faixa_servidao' table. You can move, or remove it, as needed.
            this.faixa_servidaoTableAdapter.Fill(this.lptDataSet.faixa_servidao, Poste.ProjetoId);
            // TODO: This line of code loads data into the 'lptDataSet.ponto_significativo' table. You can move, or remove it, as needed.
            this.ponto_significativoTableAdapter.Fill(this.lptDataSet.ponto_significativo, Poste.ProjetoId);
            // TODO: This line of code loads data into the 'lptDataSet.cliente' table. You can move, or remove it, as needed.
            this.clienteTableAdapter.Fill(this.lptDataSet.cliente, Poste.ProjetoId);
            // TODO: This line of code loads data into the 'eletrocadDataSet.poste' table. You can move, or remove it, as needed.
            //this.posteTableAdapter.Fill(this.eletrocadDataSet.poste);

            // TODO: This line of code loads data into the 'cadredeDataSet.ILUM' table. You can move, or remove it, as needed.
            //this.iLUMTableAdapter.Fill(this.cadredeDataSet.ILUM);

            //if (openFileDialog1.ShowDialog() == DialogResult.OK)
            //{
            Cursor.Current = Cursors.WaitCursor;
            Application.DoEvents();
            //shapefilepath = openFileDialog1.FileName;

            //display_shape_file();

            //datum
            nodeDatumGrid.Datum = GpsToolsNET.Datum.WGS_84;

            // Create a new shape object.
            objShapeTransformadores = new GpsShapeNET.Shape();
            objShapePoste = new GpsShapeNET.Shape();
            objShapeResidencia = new GpsShapeNET.Shape();
            objShapeTrack = new GpsShapeNET.Shape();
            objShapePontoSig = new GpsShapeNET.Shape();
            objShapePontoSangria = new GpsShapeNET.Shape();
            objShapeFaixaServ = new GpsShapeNET.Shape();
            objShapeLabels = new GpsShapeNET.Shape();

            objShapeTransformadores.DatumGridTemplate = nodeDatumGrid;
            objShapePoste.DatumGridTemplate = nodeDatumGrid;
            objShapeResidencia.DatumGridTemplate = nodeDatumGrid;
            objShapeTrack.DatumGridTemplate = nodeDatumGrid;
            objShapePontoSig.DatumGridTemplate = nodeDatumGrid;
            objShapePontoSangria.DatumGridTemplate = nodeDatumGrid;
            objShapeFaixaServ.DatumGridTemplate = nodeDatumGrid;
            objShapeLabels.DatumGridTemplate = nodeDatumGrid;

            mapShapeTransformadores = map1.NewMapShape(objShapeTransformadores);
            mapShapePoste = map1.NewMapShape(objShapePoste);
            mapShapeResidencia = map1.NewMapShape(objShapeResidencia);
            mapShapeTrack = map1.NewMapShape(objShapeTrack);
            mapShapePontoSig = map1.NewMapShape(objShapePontoSig);
            mapShapeFaixaServ = map1.NewMapShape(objShapeFaixaServ);
            mapShapePontoSangria = map1.NewMapShape(objShapePontoSangria);
            mapShapeLabels = map1.NewMapShape(objShapeLabels);

            //labels
            objLabel = map1.NewLabel();
            objLabel.Width = 100;
            objLabel.Height = 10;
            GpsViewNET.TextFont font = new GpsViewNET.TextFont();
            font.Size = 12;
            objLabel.TextFont = font;
            objLabel.Pen.Width = 2;
            objLabel.Pen.Blue = 255;
            mapShapeLabels.NodeTemplate = objLabel;

            objTrackPontoSangria = map1.NewIcon("faixa_serv");
            mapShapePontoSangria.NodeTemplate = objTrackPontoSangria;

            //track faixa serv
            objTrackFaixaServ = map1.NewIcon("faixa_serv");
            mapShapeFaixaServ.NodeTemplate = objTrackFaixaServ;

            //track ponto significativo
            objTrackPontoSig = map1.NewEllipse();
            objTrackPontoSig.Height = 1;
            objTrackPontoSig.Width = 1;
            mapShapePontoSig.NodeTemplate = objTrackPontoSig;

                //track residencia
            objTrackResidencia = map1.NewEllipse();
            objTrackResidencia.Height = 1;
            objTrackResidencia.Width = 1;
            mapShapeResidencia.NodeTemplate = objTrackResidencia;

                //track poste
                objTrackPoste = map1.NewIcon("light");
                mapShapePoste.NodeTemplate = objTrackPoste;

                //track
                objTrack = map1.NewRectangle();
                objTrack.Brush.Blue = 200;
                objTrack.Brush.Transparent = true;
                objTrack.Width = 1;
                objTrack.Height = 1;
                mapShapeTrack.NodeTemplate = objTrack;

                //track transformadores
                objTrackTransformadores = map1.NewRectangle();
                objTrackTransformadores.Brush.Blue = 255;
                objTrackTransformadores.Width = 6;
                objTrackTransformadores.Height = 6;
                objTrackTransformadores.Pen.Width = 1;
                objTrackTransformadores.Pen.Blue = 255;
                mapShapeTransformadores.NodeTemplate = objTrackTransformadores;
                //mapShapeTransformadores.Background.Transparent = true;
                //mapShapeTransformadores.Border.Width = 0;  // Unset border object.

                //objLabel = map1.NewLabel();
                //mapShapeLabel.NodeTemplate = objLabel;
                //ConectarTrimble();
            //}

                map1.Update();

            // Use ellipse to mark clicked position
            //objEllipseMark = map1.NewEllipse();
                objEllipseMark = make_ellipseMark();

            //preencher lista de transformadores
            //DataTable transf = iLUMTableAdapter.GetDataUTransf();
            //cbTransf.Items.Clear();
            //foreach (DataRow row in transf.Rows)
            //{
            //    object trans = row["UTRANSF"];
            //    cbTransf.Items.Add(trans);
            //}

            //se houver residencia plota elas no mapa
            if (this.lptDataSet.cliente.Rows.Count > 0)
            {
                refreshResidenciaShape();
            }

            //se houver pontos plota eles no mapa
            if (this.eletrocadDataSet.poste.Rows.Count > 0)
            {
                refreshPostesShape();
            }

            if (this.lptDataSet.ponto_significativo.Rows.Count > 0)
            {
                refreshPontoSigShape();
            }

            if (this.lptDataSet.faixa_servidao.Rows.Count > 0)
            {
                refreshFaixaServidaoShape();
            }

            if (this.lptDataSet.ponto_sangria.Rows.Count > 0)
            {
                refreshPontoSangria();
            }

            //if ((MessageBox.Show("Conectar GPS Trimble", "", MessageBoxButtons.OKCancel,
            //    MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)) {
                //ConectarTrimbleSimulacao();
                this.ConectarTrimble();
                txtGPSStatus.Text = gpsTrimbleStatus;
                base.coletarSSFLpt("obra-" + Poste.ObraLpt + " " + DateTime.Now.Day +
                    DateTime.Now.Month +
                    DateTime.Now.Year +
                    DateTime.Now.Hour +
                    DateTime.Now.Minute);
            //}

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