예제 #1
0
        //打开
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text == null)
            {
                MessageBox.Show("数据库名不能为空");
                return;
            }
            if (textBox2.Text == null)
            {
                MessageBox.Show("表名不能为空");
                return;
            }
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect      = true;
            dialog.InitialDirectory = "E:\\0cuijing\\geometry-json-translate-属性保存\\shapefile";
            dialog.Filter           = "Shape Files (*.shp;*.dbf)|*.shp;*.dbf";
            dialog.ShowDialog();
            if (dialog.Files == null)
            {
                return;
            }
            //判断拖放的文件是否为.shp和.dbf
            FileInfo shapefile = null;
            FileInfo dbffile   = null;

            foreach (FileInfo fi in dialog.Files)
            {
                if (fi.Extension.ToLower() == ".shp")
                {
                    shapefile = fi;
                }
                if (fi.Extension.ToLower() == ".dbf")
                {
                    dbffile = fi;
                }
            }
            // 读取Shapefile数据
            if (shapefile != null && dbffile != null)
            {
                shapeFileReader.Read(shapefile, dbffile);
            }
            else
            {
                MessageBox.Show("请同时选择.dbf和.shp文件");
                return;
            }
        }
예제 #2
0
    void Start()
    {
        ShapeFile shapeFile = new ShapeFile();

        shapeFile.Read(path);
        Debug.Log(shapeFile.ToString());
        List <Vector3> vertices = new List <Vector3>();

        foreach (ShapeFileRecord record in shapeFile.Records)
        {
            foreach (Vector3 point in record.Points)
            {
                vertices.Add(point);
                Debug.Log(point);
            }
            foreach (Vector3 point in vertices)
            {
                Debug.Log(point);
            }
        }
    }
예제 #3
0
        private void openWarning_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = true;
            if (!(ofd.ShowDialog() ?? false))
            {
                return;
            }
            FileInfo shapeFile = null;
            FileInfo dbfFile   = null;

            foreach (FileInfo fi in ofd.Files)
            {
                if (fi.Extension.ToLower() == ".shp")
                {
                    shapeFile = fi;
                }
                if (fi.Extension.ToLower() == ".dbf")
                {
                    dbfFile = fi;
                }
            }
            //Read the SHP and DBF files into the ShapeFileReader
            ShapeFile shapeFileReader = new ShapeFile();

            if (shapeFile != null && dbfFile != null)
            {
                shapeFileReader.Read(shapeFile, dbfFile);
            }
            else
            {
                HtmlPage.Window.Alert("Please select a SP and a DBF file to proceed.");
                return;
            }

            Color[] color = new Color[4];
            color[0] = Colors.Blue;
            color[1] = Colors.Yellow;
            color[2] = Colors.Orange;
            color[3] = Colors.Red;

            GraphicsLayer graphicsLayer = Map.Layers["Warning Region"] as GraphicsLayer;

            graphicsLayer.Graphics.Clear();


            WarningRegion region1 = new WarningRegion()
            {
                Name  = "Daya Bay",
                Level = 3,
                Chla  = 15.0
            };
            WarningRegion region2 = new WarningRegion()
            {
                Name  = "Mirs Bay",
                Level = 1,
                Chla  = 15.0
            };
            WarningRegion region3 = new WarningRegion()
            {
                Name  = "Shenzhen Bay",
                Level = 2,
                Chla  = 15.0
            };
            WarningRegion region4 = new WarningRegion()
            {
                Name  = "Maozhou",
                Level = 2,
                Chla  = 15.0
            };
            WarningRegion region5 = new WarningRegion()
            {
                Name  = "Shekou",
                Level = 1,
                Chla  = 15.0
            };
            WarningRegion region6 = new WarningRegion()
            {
                Name  = "Lingding",
                Level = 1,
                Chla  = 15.0
            };
            List <WarningRegion> listregion = new List <WarningRegion>();

            listregion.Add(region1);
            listregion.Add(region2);
            listregion.Add(region3);
            listregion.Add(region4);
            listregion.Add(region5);
            listregion.Add(region6);
            int i = 0;

            foreach (ShapeFileRecord record in shapeFileReader.Records)
            {
                Symbol MySm = new SimpleFillSymbol()
                {
                    BorderBrush     = new System.Windows.Media.SolidColorBrush(Colors.DarkGray),
                    BorderThickness = 2,
                    Fill            = new System.Windows.Media.SolidColorBrush(color[listregion[i].Level - 1])
                    {
                        Opacity = 0.7
                    }
                };
                Graphic graphic = record.ToGraphic();
                graphic.Geometry.SpatialReference = new SpatialReference(4326);
                if (graphic != null)
                {
                    graphic.Symbol = MySm;
                    graphicsLayer.Graphics.Add(graphic);
                }
                graphic.Attributes.Add("Name", listregion[i].Name);
                graphic.Attributes.Add("Region", listregion[i]);
                i++;
            }
        }
예제 #4
0
        private void openShp_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = true;
            if (!(ofd.ShowDialog() ?? false))
            {
                return;
            }
            FileInfo shapeFile = null;
            FileInfo dbfFile   = null;

            foreach (FileInfo fi in ofd.Files)
            {
                if (fi.Extension.ToLower() == ".shp")
                {
                    shapeFile = fi;
                }
                if (fi.Extension.ToLower() == ".dbf")
                {
                    dbfFile = fi;
                }
            }
            //Read the SHP and DBF files into the ShapeFileReader
            ShapeFile shapeFileReader = new ShapeFile();

            if (shapeFile != null && dbfFile != null)
            {
                shapeFileReader.Read(shapeFile, dbfFile);
            }
            else
            {
                HtmlPage.Window.Alert("Please select a SP and a DBF file to proceed.");
                return;
            }
            GraphicsLayer graphicsLayer = Map.Layers["Shenzhen Boundary"] as GraphicsLayer;

            graphicsLayer.Graphics.Clear();
            Symbol MySm = new SimpleFillSymbol()
            {
                BorderBrush = new System.Windows.Media.SolidColorBrush(Colors.White)
                {
                },
                BorderThickness = 1,
                Fill            = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent)
                {
                    Opacity = 0
                }
            };

            foreach (ShapeFileRecord record in shapeFileReader.Records)
            {
                Graphic graphic = record.ToGraphic();
                if (graphic != null)
                {
                    graphic.Symbol = MySm;
                    graphic.Geometry.SpatialReference = new SpatialReference(4326);
                    graphicsLayer.Graphics.Add(graphic);
                }
            }
            graphicsLayer.Refresh();
        }
예제 #5
0
    void Start()
    {
        //UnityEngine.Random.InitState(0);

        elevations = new List <float>();

        //float[] seed = new float[octaves];

        //for (int i = 0; i < octaves; i++)
        //{
        //    seed[i] = Random.Range(0.0f, 100.0f);
        //}

        Polygon polygon = new Polygon();

        ShapeFile shapeFile = new ShapeFile();

        shapeFile.Read(path);

        List <double> MinMax  = shapeFile.FileHeader.GetMinMax();
        double        xMin    = MinMax[0];
        double        xMax    = MinMax[1];
        double        yMin    = MinMax[2];
        double        yMax    = MinMax[3];
        int           intxMin = (int)Math.Floor(xMin);
        int           intxMax = (int)Math.Ceiling(xMax);
        int           intyMin = (int)Math.Floor(yMin);
        int           intyMax = (int)Math.Ceiling(yMax);

        Debug.Log(xMin);
        Debug.Log(intxMin);
        Debug.Log(yMin);
        Debug.Log(intyMin);

        xsize = 0;
        ysize = 0;


        Debug.Log(shapeFile.ToString());

        //PoissonDiscSampler sampler = new PoissonDiscSampler(xsize, ysize, minPointRadius);

        //// Add uniformly-spaced points
        //foreach (Vector2 sample in sampler.Samples()) {
        //    polygon.Add(new Vertex((double)sample.x, (double)sample.y));
        //}

        //Add some randomly sampled points

        //for (int i = 0; i < randomPoints; i++)
        //{
        //    polygon.Add(new Vertex(Random.Range(0.0f, xsize), Random.Range(0.0f, ysize)));
        //    xpoint = Random.Range(0.0f, xsize);
        //    ypoint = Random.Range(0.0f, ysize);
        //    Debug.Log(xpoint);
        //    Debug.Log(ypoint);

        //}
        foreach (ShapeFileRecord record in shapeFile.Records)
        {
            foreach (Vector3 point in record.Points)
            {
                polygon.Add(new Vertex((double)point.x, (double)point.y));
                xpoint = point.x;
                ypoint = point.y;
                xsize += 1;
                ysize += 1;
                elevations.Add(point.z);
            }
        }

        TriangleNet.Meshing.ConstraintOptions options = new TriangleNet.Meshing.ConstraintOptions()
        {
            ConformingDelaunay = true
        };
        mesh = (TriangleNet.Mesh)polygon.Triangulate(options); //

        //bin = new TriangleBin(mesh, xsize, ysize, minPointRadius);

        // Sample perlin noise to get elevations
        //foreach (Vertex vert in mesh.Vertices)
        //{
        //    float elevation = 0.0f;
        //    float amplitude = Mathf.Pow(persistence, octaves);
        //    float frequency = 1.0f;
        //    float maxVal = 0.0f;

        //    for (int o = 0; o < octaves; o++)
        //    {
        //        float sample = (Mathf.PerlinNoise(seed[o] + (float)vert.x * sampleSize / (float)xsize * frequency,
        //                                          seed[o] + (float)vert.y * sampleSize / (float)ysize * frequency) - 0.5f) * amplitude;
        //        elevation += sample;
        //        maxVal += amplitude;
        //        amplitude /= persistence;
        //        frequency *= frequencyBase;
        //    }

        //    elevation = elevation / maxVal;
        //    Debug.Log(elevation);
        //    Debug.Log(elevation * elevationScale);
        //    elevations.Add(elevation * elevationScale);
        //}

        //foreach (ShapeFileRecord record in shapeFile.Records)
        //{
        //    foreach (Vector3 point in record.Points)
        //    {
        //        foreach (Vertex vert in mesh.Vertices)
        //        {
        //            elevations.Add(point.z);
        //            zpoint = point.z;
        //            Debug.Log(zpoint);
        //        }
        //    }
        // }


        MakeMesh();

        //ScatterDetailMeshes();
    }
 private bool OpenShapeFile()
 {
     System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
     ofd.Title            = App.Current.FindResource("tbSelectSHPFile").ToString();
     ofd.RestoreDirectory = true;
     ofd.Multiselect      = false;
     ofd.Filter           = "shape file (*.shp)|*.shp";
     if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         string shpFileName = ofd.FileName;
         string dbfFilename = Path.ChangeExtension(shpFileName, ".dbf");
         if (!ofd.CheckFileExists || !File.Exists(dbfFilename))
         {
             MessageBox.Show(App.Current.FindResource("msgSHPError").ToString(), App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             try
             {
                 FileInfo  fiSHP     = new FileInfo(shpFileName);
                 FileInfo  fiDBF     = new FileInfo(dbfFilename);
                 ShapeFile shapeFile = new ShapeFile();
                 shapeFile.Read(fiSHP, fiDBF);
                 if (shapeFile.FileHeader.ShapeType != 5)
                 {
                     throw new Exception(App.Current.FindResource("msgSHPTypeError").ToString());
                 }
                 _graphicsLayer.ClearGraphics();
                 Envelope env = new Envelope();
                 foreach (ShapeFileRecord record in shapeFile.Records)
                 {
                     Graphic graphic = record.ToGraphic();
                     //if the coordinates is wgs 84,try to convert to 3857
                     if (Math.Abs(record.Points[0].X) < 300 || Math.Abs(record.Points[0].Y) < 300)
                     {
                         graphic.Geometry = _webMercator.FromGeographic(graphic.Geometry);
                     }
                     if (graphic != null)
                     {
                         graphic.Symbol = new SimpleFillSymbol()
                         {
                             BorderBrush = new SolidColorBrush(Colors.Red),
                             Fill        = new SolidColorBrush(Color.FromArgb(100, 255, 0, 0))
                         }
                     }
                     ;
                     _graphicsLayer.Graphics.Add(graphic);
                     env = env.Union(graphic.Geometry.Extent);
                 }
                 DownloadExtent   = _webMercator.ToGeographic(env).Extent;
                 _downloadPolygon = AppUtility.ConvertEsriPolygonToPBSPolygon(AppUtility.UnionEsriPolygon(_graphicsLayer.Graphics));
                 return(true);
             }
             catch (Exception e)
             {
                 MessageBox.Show(e.Message, App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     return(false);
 }
 public override void LoadData(string path)
 {
     shapefile = new ShapeFile(path.Replace(".txt", ".shp"));
     shapefile.Read();
 }
 public ShapeFileRenderer(string path)
 {
     shapefile = new ShapeFile(path);
     shapefile.Read();
 }
예제 #9
0
        private int internalQueryFeatures(IFeatureReceiver fr, BoundingRectangle bounds, bool checkBounds)
        {
            if (_cacheAccessor != null && !string.IsNullOrEmpty(fr.Alias))
            {
                _cacheAccessor.Key = fr.Alias;
                if (_cacheAccessor.ExistsInCache)
                {
                    return(FillFromCache(_cacheAccessor, fr, bounds, _processAttributes));
                }
                else
                {
                    // If the object is not found in the cache, you must remove all objects from a file, to put them in the cache
                    checkBounds = false;
                }
            }

            ShapeFile shapeFile = new ShapeFile();

            shapeFile.AttributesEncoding = _attributesEncoding;
            shapeFile.Read(_fileName, checkBounds ? bounds : null);

            if (ProcessAttributes)
            {
                fr.FeatureAttributeNames.Clear();
                foreach (string s in shapeFile.AttributeNames)
                {
                    fr.FeatureAttributeNames.Add(s);
                }
            }

            int    result       = 0;
            string layerHashStr = fr.GetHashCode().ToString();

            List <Feature> points      = new List <Feature>();
            List <Feature> multiPoints = new List <Feature>();
            List <Feature> polylines   = new List <Feature>();
            List <Feature> polygons    = new List <Feature>();

            foreach (ShapeFileRecord record in shapeFile.Records)
            {
                if (!checkBounds ||
                    (record.MaxX >= bounds.MinX && record.MaxY >= bounds.MinY &&
                     record.MinX <= bounds.MaxX && record.MinY <= bounds.MaxY))
                {
                    Feature   newFeature = null;
                    IGeometry geometry   = geometryFromShapeRecord(record);
                    if (geometry != null)
                    {
                        newFeature         = new Feature(geometry);
                        newFeature.UniqKey = layerHashStr + record.RecordNumber.ToString();
                        if (ProcessAttributes && record.Attributes != null)
                        {
                            newFeature.Attributes = record.Attributes.ItemArray;
                        }

                        if (processFeature(newFeature, fr, points, multiPoints, polylines, polygons))
                        {
                            result++;
                        }
                    }
                }
            }

            // If the objects are not extracted from the cache may be added to the cache.
            // This should be done only if the retrieval of all objects (checkBounds == false)
            if (_cacheAccessor != null && !string.IsNullOrEmpty(fr.Alias) &&
                checkBounds == false)
            {
                addFeaturesToCache(fr, points, multiPoints, polylines, polygons);
            }

            return(result);
        }