示例#1
0
        private void FillInformationLayer()
        {
            StreamResourceInfo      shapeResourceInfo = Application.GetResourceStream(new Uri("/ShapefileManualReading;component/Resources/world.shp", UriKind.RelativeOrAbsolute));
            StreamResourceInfo      dbfResourceInfo   = Application.GetResourceStream(new Uri("/ShapefileManualReading;component/Resources/world.dbf", UriKind.RelativeOrAbsolute));
            List <FrameworkElement> shapes            = ShapeFileReader.Read(shapeResourceInfo.Stream, dbfResourceInfo.Stream);

            foreach (var shape in shapes)
            {
                this.informationLayer.Items.Add(shape);
            }
        }
示例#2
0
        private void SetupMapLayers()
        {
            string dir      = Directory.GetCurrentDirectory();
            string dataPath = "\\..\\..\\..\\data\\geodata\\maps\\";
            string fileName = "europe_nation";


            ShapeFileReader shapeReader = new ShapeFileReader();

            iMapData = shapeReader.Read(dir + dataPath + fileName + ".shp"
                                        , dir + dataPath + fileName + ".dbf"
                                        , dir + dataPath + fileName + ".shx");

            // Border Layer
            borderLayer         = new MapPolygonBorderLayer();
            borderLayer.MapData = iMapData;

            // Polygon Layer
            polygonLayer          = new MapPolygonLayer();
            polygonLayer.MapData  = iMapData;
            polygonLayer.ColorMap = iColorMap;
            polygonLayer.IndexVisibilityHandler = iPcPlot.IndexVisibilityHandler;
            iPcPlot.FilterChanged += new EventHandler(iPcPlot_FilterChanged);

            polygonSelectionLayer              = new MapPolygonLayer();
            polygonSelectionLayer.MapData      = iMapData;
            polygonSelectionLayer.PolygonColor = Color.FromArgb(220, 220, 220);
            polygonSelectionLayer.Alpha        = 120;

            borderSelectionLayer             = new MapPolygonBorderLayer();
            borderSelectionLayer.MapData     = iMapData;
            borderSelectionLayer.BorderColor = Color.Black;
            borderSelectionLayer.Translation = new Vector3(0.6f, 0.6f, 0); // borderSelectionLayer.Translation.X;

            iSelectedInVisibility = new IndexVisibilityHandler(iMapData.RegionList.Count);
            iSelectedVisibility   = new IndexVisibilityHandler(iMapData.RegionList.Count);
            iSelectedInVisibility.Clear();

            iInVisibilityList = iSelectedInVisibility.CreateVisibilityList();
            iVisibilityList   = iSelectedVisibility.CreateVisibilityList();

            for (int i = 0, endI = iMapData.RegionList.Count; i < endI; i++)
            {
                iVisibilityList.SetVisibility(i, 0, false);
            }


            polygonSelectionLayer.IndexVisibilityHandler = iSelectedInVisibility;
            borderSelectionLayer.IndexVisibilityHandler  = iSelectedVisibility;

//            polygonSelectionLayer.SelectedPolygonColor = Color.Transparent;

            // Glyph Layer
            glyphLayer = new CountryGlyphLayer(iPanel);
            glyphLayer.ActiveGlyphPositioner         = new CenterGlyphPositioner();
            glyphLayer.ActiveGlyphPositioner.MapData = iMapData;
            glyphLayer.Input = iDataCube;
            glyphLayer.IndexVisibilityHandler = iPcPlot.IndexVisibilityHandler;

            // Choropleth Map
            choroMap = new ChoroplethMap();
            choroMap.VizComponentMouseDown += new EventHandler <VizComponentMouseEventArgs>(MouseDown);
            choroMap.VizComponentMouseUp   += new EventHandler <VizComponentMouseEventArgs>(MouseUp);

            // Add layers on the proper order
            choroMap.AddLayer(polygonLayer);
            choroMap.AddLayer(borderLayer);
            choroMap.AddLayer(polygonSelectionLayer);
            choroMap.AddLayer(borderSelectionLayer);
            choroMap.AddLayer(glyphLayer);
            Invalidate();

            //iSelectedColorLegend = new InteractiveColorLegend();
            //iSelectedColorLegend.ColorMap = iLegendColorMap;
            //iSelectedColorLegend.BorderColor = Color.Black;
            //iSelectedColorLegend.ShowMinMaxValues = false;
            //iSelectedColorLegend.SetLegendSize(10, 200);
            //iSelectedColorLegend.SetPosition(50F, 10F);
            //iSelectedColorLegend.SetLegendSize(0.02f, 0.2f);
            //iSelectedColorLegend.ShowColorEdgeSliders = false;
            //iSelectedColorLegend.ShowColorEdgeSliderValue = false;
            ////iSelectedColorLegend.ColorEdgeValuesChanged += new EventHandler(ColorLegendChanged);
            //choroMap.AddSubComponent(iSelectedColorLegend);


            iColorLegend          = new InteractiveColorLegend();
            iColorLegend.ColorMap = iColorMap;
            //iColorLegend.BorderColor = Color.Black;
            //iColorLegend.SliderTextColor = Color.Black;
            //iColorLegend.ShowMinMaxValues = true;
            iColorLegend.SetPosition(10, 10);
            iColorLegend.SetLegendSize(15, 200);
            iColorLegend.ShowColorEdgeSliders     = true;
            iColorLegend.ShowColorEdgeSliderValue = false;
            iColorLegend.ColorEdgeValuesChanged  += new EventHandler(ColorLegendChanged);

            //iColorLegend.ShowValueSliders = true;
            //iColorLegend.ShowValueSliderValue = true;
            //iColorLegend.ValueSliderValuesChanged += new EventHandler(ColorLegendChanged);
            //iColorLegend.SetEdgeSliders(InteractiveColorLegend.SliderLinePosition.Center, InteractiveColorLegend.TextPosition.RightOrBottom, true);


            choroMap.AddSubComponent(iColorLegend);
            renderer.Add(choroMap, iPanel);
        }
示例#3
0
        public GLib Load()
        {
            foreach (string filePath in fileNames)
            {
                using (ShapeFileReader sr = new ShapeFileReader(filePath))
                {
                    UpdateBounds(sr.bound);
                }
            }
            if (!boundsUpdated)
            {
                return(null);
            }

            SetTransform();
            CreateLib();

            foreach (string filePath in fileNames)
            {
                using (ShapeFileReader sr = new ShapeFileReader(filePath))
                {
                    //					object[] attrs;
                    if (!CreateType(sr.GetUnitType()))
                    {
                        continue;
                    }
                    curType.Name = Path.GetFileNameWithoutExtension(filePath);
                    while (sr.Read())
                    {
                        switch (sr.GetUnitType())
                        {
                        case ShapeUnit.Arc:
                            //								Read((ShapeArc)sr.Get());
                            break;

                        case ShapeUnit.Point:
                            Read((ShapePoint)sr.Get());
                            break;

                        case ShapeUnit.Polygon:
                            Read((ShapePolygon)sr.Get());
                            break;

//							case ShapeUnit.PointGroup:
                        //								Read((ShapePointGroup)sr.Get());
//								break;
                        case ShapeUnit.PolyLine:
                            Read((ShapePolyline)sr.Get());
                            break;
                        }
                    }
                }
            }
            lib.SMin = 10;
            if (lib.Bounds.IsNull)
            {
                lib.SetBounds(new Rect(0, 0, 1000000, 1000000));
            }
            lib.SMax = Geomethod.GeoLib.GeoLibUtils.RoundScale(lib.Bounds.MaxSize / 10);
            lib.Scales.InitScales();
            return(lib);
        }
示例#4
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());
        }
示例#5
0
        public TestShape()
        {
            /*			string	drv = "Driver={Microsoft dBase Driver (*.dbf)};DBQ=";
             *
             *          //		«десь конструктор с connection
             *
             * //			string	filename1 = @"f:\dima\shape\bk_st.shp";
             *          string	filename1 = @"f:\dima\shape\detroit\hist.shp";
             * //			string	filename1 = @"f:\dima\shape\detroit\roads.shp";
             *
             *          OdbcConnection	con   =  new OdbcConnection( drv + Path.GetDirectoryName( filename1 ) );
             *          con.Open();
             *
             *          using( ShapeFileReader	sr = new ShapeFileReader( filename1, con ) )
             *          {
             *              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, "»мена полей и типов" );
             *
             *              int	cnt = 0;
             *              while( sr.Read() )
             *              {
             *                  if( sr.shapeType == ShapeUnit.Point )
             *                  {
             *                      object[]	attrs;
             *                      ShapePoint	sp = (ShapePoint)sr.Get( out attrs );
             *                      if( cnt < 2 )
             *                      {
             *                          Console.WriteLine( sp.point.X.ToString() + " " + sp.point.Y.ToString(), " оординаты" );
             *                          string	at = null;
             *                          for( int i = 0; i < attrs.Length; i++ )
             *                              at += attrs[i].ToString() + "\n";
             *                          Console.WriteLine( at, "јтрибуты" );
             *                      }
             *                  }
             *                  cnt++;
             *              }
             *              string	Bound = sr.shapeType.ToString()  + "\n " +
             *                  sr.bound.maxx.ToString() + "\n " +
             *                  sr.bound.maxy.ToString() + "\n " +
             *                  sr.bound.minx.ToString() + "\n " +
             *                  sr.bound.miny.ToString() + "\n " +
             *                  cnt.ToString();
             *              Console.WriteLine( Bound, "“ип, границы и количество объектов" );
             *
             *          }
             *          con.Close();
             */
            //			«десь конструктор без connection

            string filename2 = @"f:\dima\shape\bk_tb.shp";

            using (ShapeFileReader sr = new ShapeFileReader(filename2))
            {
                while (sr.Read())
                {
                    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++;
                            }
                        }
                    }
                }
            }

            //		«десь конструктор с connection и таблицей

            /*			try
             *                      {
             * //				string	filename3 = @"f:\dima\shape\bk_st.shp";
             * //				string	filename3 = @"f:\dima\shape\detroit\roads.shp";
             *      string	filename3 = @"f:\dima\shape\detroit\hist.shp";
             *      string	drvJet	= @"Provider=Microsoft.Jet.OLEDB.4.0;";
             *      string	ext		= @";Extended Properties=dBASE IV;User ID=Admin;Password="******"Data Source=" + Path.GetDirectoryName( filename3 ) + ext;
             *      OleDbConnection	con3 = new OleDbConnection(  str2 );
             *      con3.Open();
             *
             *      DataTable	dt = new DataTable();
             *
             *      ShapeFileReader	sr1 = new ShapeFileReader( filename3, con3, dt );
             *      sr1.Dispose();
             *      con3.Close();
             *
             *      for( int i = 0; i < dt.Rows.Count; i++ )
             *      {
             *              string	str = null;
             *              for( int j = 0;  j < dt.Columns.Count; j++ )
             *                      str += dt.Columns[j].ColumnName + "\t = " + dt.Rows[i][j].ToString() + "\n";
             *              Console.WriteLine( str, dt.TableName + "[" + i + "]" );
             *
             *              if( i > 2 )
             *                      break;
             *      }
             *
             * }
             * catch( Exception e )
             * {
             *      Console.WriteLine( e.ToString() );
             * }
             */
        }