コード例 #1
0
ファイル: Croqui.cs プロジェクト: alphaman8/CIP_beta1
        private void salvarShapeTrack()
        {
            try
            {
                //salvar as mudanças no shape file
                GpsShapeNET.ShapeFile shapeFile = new GpsShapeNET.ShapeFile();
                shapeFile.ShapeFileType = GpsShapeNET.ShapeFileType.SHAPE_TYPE_POLYLINE;

                if (System.IO.File.Exists(filename)) {
                    shapeFile.Open(filename, GpsShapeNET.FileMode.FILE_APPEND);
                    lInfo.Text = "Posições: " + countWrited;
                    countWrited++;
                } else {
                    shapeFile.Open(filename, GpsShapeNET.FileMode.FILE_WRITE);
                }

                //mapShapeTrack.Shape.ShapeID = 1234;

                //shapeFile.Write(mapShapeTrack.Shape);
                objShapeTrack.ShapeID = 1;
                shapeFile.Write(objShapeTrack);

                shapeFile.Close();

                //coleta 150 posições por aquivo
                if (countWrited == 400)
                {
                    filename = Library.appDir + "\\shp\\track_" + Poste.ObraLpt + "_" +
                                DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second +
                                DateTime.Now.Day +
                                DateTime.Now.Month +
                                DateTime.Now.Year + ".shp";
                    countWrited = 0;
                    objShapeTrack.ClearShape();
                }
                //MessageBox.Show("Arquivo Salvo. Total de nós: "+objShapeTrack.TotalNodeCount);
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Não foi possível salvar o arquivo shape: "+ex.Message);
            }
        }
コード例 #2
0
ファイル: Croqui.cs プロジェクト: alphaman8/CIP_beta1
        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;
            }
        }
コード例 #3
0
ファイル: Croqui.cs プロジェクト: alphaman8/CIP_beta1
        private void menuItem20_Click(object sender, EventArgs e)
        {
            string shpProjeto = Library.appDir + "\\shp\\projeto_" + Poste.ProjetoId + ".shp";

            try
            {
                //salvar as mudanças no shape file
                GpsShapeNET.ShapeFile shapeFile = new GpsShapeNET.ShapeFile();
                shapeFile.ShapeFileType = GpsShapeNET.ShapeFileType.SHAPE_TYPE_MULTI_MATCH;

                shapeFile.Open(shpProjeto, GpsShapeNET.FileMode.FILE_WRITE);

                //objShapeResidencia.ShapeID = 0;
                //objShapePontoSangria.ShapeID = 1;
                //objShapePontoSig.ShapeID = 1;
                shapeFile.Write(objShapeResidencia);
                shapeFile.Write(objShapePontoSangria);
                //shapeFile.Write(objShapeLabels);

                shapeFile.Close();

                MessageBox.Show("Arquivo criado");
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Não foi possível salvar o arquivo shape: "+ex.Message);
            }
        }