Example #1
0
        public static FeatureDataRow LocatePolygon2(SharpMap.Geometries.Point punto, SharpMap.Data.FeatureDataTable fdt)
        {
            FeatureDataRow fdr = null;

            if ((fdt as DataTable).Rows.Count == 1)
            {
                fdr = (FeatureDataRow)(fdt as DataTable).Rows[0];
            }
            else
            {
                GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory f = new GeometryFactory(new PrecisionModel());
                foreach (DataRow r in (fdt as DataTable).Rows)
                {
                    if ((r as  FeatureDataRow).Geometry.GetType() == typeof(SharpMap.Geometries.MultiPolygon))
                    {
                        // Doble cast: de Geometria a MultiPolygon, y de DataRow a FeatureDataRow.
                        SharpMap.Geometries.MultiPolygon SharpMultiPol = (SharpMap.Geometries.MultiPolygon)(r as  FeatureDataRow).Geometry;
                        GisSharpBlog.NetTopologySuite.Geometries.Geometry[] NTSGeom = GeometryConverter.ToNTSGeometry(new SharpMap.Geometries.Geometry[1] {
                            SharpMultiPol
                        }, f);
                        GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon NTSMultiPol = (GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon)NTSGeom[0];
                        if (NTSMultiPol.Contains(new GisSharpBlog.NetTopologySuite.Geometries.Point(punto.X, punto.Y)) == true)
                        {
                            fdr = (FeatureDataRow)r;
                            break;
                        }
                    }
                }
            }
            return(fdr);
        }
Example #2
0
        void ShowSelectLayer(SharpMap.Data.FeatureDataTable data)
        {
            Layer layer = null;

            foreach (Layer tmplayer in this.mapBox1.Map.Layers)
            {
                if (tmplayer.LayerName == "selectedLyr")
                {
                    layer = tmplayer;
                }
            }

            if (layer != null)
            {
                this.mapBox1.Map.Layers.Remove(layer);
            }

            SharpMap.Layers.VectorLayer selectedLyr = new SharpMap.Layers.VectorLayer("selectedLyr");
            foreach (FeatureDataRow row in data.Rows)
            {
                selectedLyr.DataSource          = new SharpMap.Data.Providers.GeometryProvider(row as SharpMap.Data.FeatureDataRow);
                selectedLyr.Style.EnableOutline = true;
                selectedLyr.Style.Outline       = new Pen(Color.FromArgb(50, 255, 255), 4);
                selectedLyr.Style.Fill          = new SolidBrush(Color.Transparent);
                mapBox1.Map.Layers.Add(selectedLyr);
                this.mapBox1.Refresh();
            }
        }
        private void AddSineCurveLayers(Map map, LabelLayerMode mode,
                                        LabelStyle.HorizontalAlignmentEnum hzAlign,
                                        LabelStyle.VerticalAlignmentEnum vtAlign)
        {
            string text;

            switch (mode)
            {
            case LabelLayerMode.SineCurveExtended:
                text =
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam";    //", quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
                break;

            default:
                text = "Lorem ipsum olor sit amet, consectetur adipisici elit";
                break;
            }

            var fdt = new SharpMap.Data.FeatureDataTable();

            fdt.BeginInit();
            fdt.Columns.Add(new System.Data.DataColumn("ID", typeof(int)));
            fdt.Columns.Add(new System.Data.DataColumn("LABEL", typeof(string)));
            fdt.PrimaryKey = new[] { fdt.Columns[0] };
            fdt.EndInit();
            fdt.BeginLoadData();
            var fdr = (SharpMap.Data.FeatureDataRow)fdt.LoadDataRow(new object[] { 1, text }, true);

            fdr.Geometry = CreateSineLine(new GeoAPI.Geometries.Coordinate(10, 10));
            fdt.EndLoadData();

            var vLyr = new SharpMap.Layers.VectorLayer("Geometry", new GeometryFeatureProvider(fdt));

            vLyr.Style.Line    = new System.Drawing.Pen(System.Drawing.Color.Black, 4);
            vLyr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            vLyr.SRID          = map.SRID;
            map.Layers.Add(vLyr);

            var lLyr = new SharpMap.Layers.LabelLayer("Label")
            {
                DataSource = vLyr.DataSource, LabelColumn = "LABEL"
            };

            lLyr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            lLyr.Style.ForeColor   = System.Drawing.Color.Cyan;
            lLyr.Style.BackColor   = new SolidBrush(Color.FromArgb(128, Color.LightSlateGray));
            //lLyr.Style.Halo = new Pen(Color.Yellow, 4);
            lLyr.Style.IgnoreLength        = mode == LabelLayerMode.SineCurveExtended;
            lLyr.Style.HorizontalAlignment = hzAlign;
            lLyr.Style.VerticalAlignment   = vtAlign;
            //ll.Style.IsTextOnPath = textOnPath;
            map.Layers.Add(lLyr);
        }
Example #4
0
        private void mapBox1_MapQueried(SharpMap.Data.FeatureDataTable data)
        {
            int count = data.Rows.Count;

            foreach (DataRow dr in data.Rows)
            {
                ShowSelectLayer(data);
                string s = "";
                for (int i = 0; i < data.Columns.Count; i++)
                {
                    s = s + dr[i].ToString() + ",";
                }
                Console.WriteLine(s);
            }
        }
        private static FeatureDataTable <TOid> internalCreateTableWithId(FeatureDataTable tableCopy, DataColumn objectIdColumn, IGeometryFactory factory)
        {
            FeatureDataTable <TOid> tableWithId = new FeatureDataTable <TOid>(tableCopy, objectIdColumn.ColumnName, factory);

            // TODO: shouldn't this be in the base class? Need to check if changing base behavior will break stuff.
            foreach (DataColumn col in tableCopy.Columns)
            {
                if (String.Compare(col.ColumnName, objectIdColumn.ColumnName, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    continue;
                }

                DataColumn colCopy = new DataColumn(col.ColumnName, col.DataType);
                colCopy.AllowDBNull       = col.AllowDBNull;
                colCopy.AutoIncrement     = col.AutoIncrement;
                colCopy.AutoIncrementSeed = col.AutoIncrementSeed;
                colCopy.AutoIncrementStep = col.AutoIncrementStep;
                colCopy.DateTimeMode      = col.DateTimeMode;
                colCopy.DefaultValue      = col.DefaultValue;

                foreach (DictionaryEntry entry in col.ExtendedProperties)
                {
                    colCopy.ExtendedProperties[entry.Key] = entry.Value;
                }

                colCopy.MaxLength = col.MaxLength;
                colCopy.ReadOnly  = col.ReadOnly;
                colCopy.Unique    = col.Unique;
                tableWithId.Columns.Add(colCopy);
            }

            foreach (DataRow row in tableCopy)
            {
                FeatureDataRow <TOid> newRow = tableWithId.NewRow() as FeatureDataRow <TOid>;
                Debug.Assert(newRow != null);
                Int32 itemCount = newRow.ItemArray.Length;
                newRow.ItemArray = new Object[itemCount];
                //Array.Copy(row.ItemArray, newRow.ItemArray, itemCount);
                newRow.ItemArray = row.ItemArray;
                tableWithId.AddRow(newRow);
            }

            return(tableWithId);
        }
Example #6
0
        public DataConverter(Func <TSource, TTarget> conversionDlgt, IFeatureDataRecord source, int oidColumnIndex, IGeometryFactory geometryFactory)
        {
            _conversionDelegate = conversionDlgt;
            _oidColumnIndex     = oidColumnIndex;
            string oidColName = source.GetName(oidColumnIndex);

            FeatureDataTable <TTarget> trgt = new FeatureDataTable <TTarget>("SchemaTable", oidColName,
                                                                             geometryFactory);

            for (int i = 0; i < source.FieldCount; i++)
            {
                if (i != oidColumnIndex)
                {
                    trgt.Columns.Add(new DataColumn(source.GetName(i), source.GetFieldType(i)));
                }
            }


            _target = trgt;
        }
Example #7
0
        public static FeatureDataTable <TOid> CreateTableWithId(FeatureDataTable table, string columnName)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            if (columnName == null)
            {
                throw new ArgumentNullException("columnName");
            }

            //table = table.Copy() as FeatureDataTable;

            if (!table.Columns.Contains(columnName))
            {
                table.Columns.Add(columnName, typeof(TOid));
            }

            return(InternalCreateTableWithId(table, table.Columns[columnName]));
        }
Example #8
0
    public SharpMap.Layers.VectorLayer CreateGeometryLayer()
    {
        SharpMap.Data.FeatureDataTable fdt = new SharpMap.Data.FeatureDataTable();
        fdt.Columns.Add(new DataColumn("Name", typeof(String)));

        SharpMap.Data.FeatureDataRow fdr;

        fdr = fdt.NewRow();

        fdr["Name"]  = "Mayence";
        fdr.Geometry = (Geometry) new Point(8.1, 50.0);

        fdt.AddRow(fdr);


        SharpMap.Layers.VectorLayer vLayer = new SharpMap.Layers.VectorLayer("GeometryProvider");
        vLayer.DataSource = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt);
        vLayer.SRID       = 4326;

        return(vLayer);
    }
Example #9
0
            private static SharpMap.Data.FeatureDataTable VehicleDataTable()
            {
                var dt = new SharpMap.Data.FeatureDataTable {
                    TableName = "VilniusTransportData"
                };

                System.Data.DataColumnCollection dcc = dt.Columns;
                dcc.AddRange(new[]
                {
                    new System.Data.DataColumn("Id", typeof(int)),
                    //new System.Data.DataColumn("Lat", typeof(double)),
                    //new System.Data.DataColumn("Lng", typeof(double)),
                    new System.Data.DataColumn("Line", typeof(string)),
                    new System.Data.DataColumn("LastStop", typeof(string)),
                    new System.Data.DataColumn("TrackType", typeof(string)),
                    new System.Data.DataColumn("AreaName", typeof(string)),
                    new System.Data.DataColumn("StreetName", typeof(string)),
                    new System.Data.DataColumn("Time", typeof(string)),
                    new System.Data.DataColumn("Bearing", typeof(double))
                });
                return(dt);
            }
        protected override Int32 Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
        {
            if (dataTables.Length == 0)
            {
                return(0);
            }

            Int32 tableIndex = 0;

            IFeatureDataReader featureReader = dataReader as IFeatureDataReader;

            if (featureReader == null)
            {
                throw new ArgumentException("Parameter 'dataReader' " +
                                            "must be a IFeatureDataReader instance.");
            }

            do
            {
                FeatureDataTable table = dataTables[tableIndex] as FeatureDataTable;

                if (table == null)
                {
                    throw new ArgumentException("Components of 'dataTables' must be " +
                                                "FeatureDataTable instances.");
                }

                if (table.Columns.Count == 0)
                {
                    FillSchema(table, SchemaType.Mapped, featureReader);
                }

                table.Merge((IEnumerable <IFeatureDataRecord>)featureReader, null, _factory, SchemaMergeAction.AddWithKey | SchemaMergeAction.CaseInsensitive);

                tableIndex++;
            } while (dataReader.NextResult());

            return(dataTables[0].Rows.Count);
        }
Example #11
0
        /// <summary>
        /// Creates a new <see cref="FeatureDataView"/> on the given
        /// <see cref="FeatureDataTable"/> having the specified geometry filter,
        /// sort order and row state filter.
        /// </summary>
        /// <param name="table">Table to create view on.</param>
        /// <param name="definition">
        /// Spatial expression used in building view to filter feature table rows.
        /// </param>
        /// <param name="sort">Sort expression to order view by.</param>
        /// <param name="rowState">Filter on the state of the rows to view.</param>
        public FeatureDataView(FeatureDataTable table,
                               FeatureQueryExpression definition,
                               String sort,
                               DataViewRowState rowState)
            : base(
                table,
                "",
                String.IsNullOrEmpty(sort)
                            ? table.PrimaryKey.Length == 1
                                    ? table.PrimaryKey[0].ColumnName
                                    : ""
                            : sort,
                rowState)
        {
            _viewDefinition = definition;

            // This call rebuilds the index which was just built with
            // the call into the base constructor, which may be a performance
            // hit. A more robust solution would be to just recreate the
            // behavior of the base constructor here, so we can create the
            // underlying index once.
            setFilterPredicate();
        }
Example #12
0
 public FeatureDataTableProxy(IGeometryFactory factory, FeatureDataTable table)
 {
     GeometryFactory = factory;
     _table          = table;
 }
Example #13
0
 private static SharpMap.Data.FeatureDataTable VehicleDataTable()
 {
     var dt = new SharpMap.Data.FeatureDataTable { TableName = "VilniusTransportData" };
     System.Data.DataColumnCollection dcc = dt.Columns;
     dcc.AddRange(new[]
                       {
                           new System.Data.DataColumn("Id", typeof(int)), 
                           //new System.Data.DataColumn("Lat", typeof(double)), 
                           //new System.Data.DataColumn("Lng", typeof(double)), 
                           new System.Data.DataColumn("Line", typeof(string)), 
                           new System.Data.DataColumn("LastStop", typeof(string)), 
                           new System.Data.DataColumn("TrackType", typeof(string)), 
                           new System.Data.DataColumn("AreaName", typeof(string)), 
                           new System.Data.DataColumn("StreetName", typeof(string)), 
                           new System.Data.DataColumn("Time", typeof(string)), 
                           new System.Data.DataColumn("Bearing", typeof(double)) 
                       });
     return dt;
 }
Example #14
0
 private void mapImage_MapQueried(SharpMap.Data.FeatureDataTable data)
 {
     dataGridView1.DataSource = data as System.Data.DataTable;
 }
Example #15
0
 /// <summary>
 /// Creates a new <see cref="FeatureDataView"/> on the given
 /// <see cref="FeatureDataTable"/>.
 /// </summary>
 /// <param name="table">Table to create view on.</param>
 public FeatureDataView(FeatureDataTable table)
     : this(table, (FeatureQueryExpression)null, "", DataViewRowState.CurrentRows)
 {
 }
 public Int32 Fill(ICollection <FeatureDataTable> dataTables, IFeatureDataReader dataReader)
 {
     FeatureDataTable[] tables = new FeatureDataTable[dataTables.Count];
     dataTables.CopyTo(tables, 0);
     return(Fill(tables, dataReader, 0, 0));
 }
Example #17
0
 public FeatureDataTableReader(FeatureDataTable table)
 {
     _table = table;
 }
Example #18
0
        public static FeatureDataRow LocatePolygon(SharpMap.Geometries.Point punto, SharpMap.Data.FeatureDataTable fdt)
        {
            FeatureDataRow fdr = null;

            if ((fdt as DataTable).Rows.Count == 1)
            {
                fdr = (FeatureDataRow)(fdt as DataTable).Rows[0];
            }
            else
            {
                GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory f = new GeometryFactory(new PrecisionModel());
                foreach (DataRow r in (fdt as DataTable).Rows)
                {
                    if ((r as  FeatureDataRow).Geometry.GetType() == typeof(SharpMap.Geometries.MultiPolygon))
                    {
                        // Doble cast: de Geometria a MultiPolygon, y de DataRow a FeatureDataRow.
                        SharpMap.Geometries.MultiPolygon SharpMultiPol = (SharpMap.Geometries.MultiPolygon)(r as  FeatureDataRow).Geometry;

                        foreach (SharpMap.Geometries.Polygon SharpPol in SharpMultiPol.Polygons)
                        {
                            //Contorno
                            int countVExt = SharpPol.ExteriorRing.Vertices.Count;
                            int i         = 0;
                            GisSharpBlog.NetTopologySuite.Geometries.Coordinate[] ListaCoordsExt = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate[countVExt];
                            foreach (SharpMap.Geometries.Point p in SharpPol.ExteriorRing.Vertices)
                            {
                                ListaCoordsExt[i++] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(p.X, p.Y);
                            }

                            //Huecos
                            int countPolInt = SharpPol.InteriorRings.Count;
                            int j           = 0;
                            GisSharpBlog.NetTopologySuite.Geometries.LinearRing[] ListaPolInt = new GisSharpBlog.NetTopologySuite.Geometries.LinearRing[countPolInt];
                            foreach (SharpMap.Geometries.LinearRing ring in SharpPol.InteriorRings)
                            {
                                int countVInt = ring.Vertices.Count;
                                int k         = 0;
                                GisSharpBlog.NetTopologySuite.Geometries.Coordinate[] ListaCoordsInt = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate[countVInt];
                                foreach (SharpMap.Geometries.Point p in ring.Vertices)
                                {
                                    ListaCoordsInt[k++] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(p.X, p.Y);
                                }
                                ListaPolInt[j++] = f.CreateLinearRing(ListaCoordsInt);
                            }

                            GisSharpBlog.NetTopologySuite.Geometries.Polygon NTSPol = f.CreatePolygon(f.CreateLinearRing(ListaCoordsExt), ListaPolInt);

                            if (NTSPol.Contains(new GisSharpBlog.NetTopologySuite.Geometries.Point(punto.X, punto.Y)) == true)
                            {
                                fdr = (FeatureDataRow)r;
                                break;
                            }
                        }
                        if (fdr != null)
                        {
                            break;
                        }
                    }
                }
            }
            return(fdr);
        }
 public Int32 Fill(FeatureDataTable table, IFeatureDataReader dataReader)
 {
     return(Fill(new FeatureDataTable[] { table }, dataReader));
 }