示例#1
0
        /// <summary>
        /// Creates a FeatureDataTable from arrays of x, y and z components
        /// </summary>
        /// <param name="xcomponents">an array of doubles representing the x ordinate values</param>
        /// <param name="ycomponents">an array of doubles representing the y ordinate values</param>
        /// <param name="zcomponents">an array of doubles representing the z ordinate values</param>
        /// <returns></returns>
        public static SharpMap.Data.FeatureDataTable CreatePointFeatureDataTableFromArrays(double[] xcomponents, 
                                                                 double[] ycomponents,
                                                                 double[] zcomponents)
        {
            bool threedee = false;
            if (zcomponents != null)
            {
                if (!(zcomponents.Length == ycomponents.Length && zcomponents.Length == xcomponents.Length))
                    throw new System.ApplicationException("Mismatched Array Lengths");

                threedee = true;
            }
            else
            {
                if (ycomponents.Length != xcomponents.Length)
                    throw new System.ApplicationException("Mismatched Array Lengths");
            }

            SharpMap.Data.FeatureDataTable fdt = new SharpMap.Data.FeatureDataTable();
            fdt.Columns.Add("TimeStamp", typeof (System.DateTime)); // add example timestamp attribute
            for (int i = 0; i < xcomponents.Length; i++)
            {
                SharpMap.Data.FeatureDataRow fdr = fdt.NewRow();

                fdr.Geometry = threedee
                                   ? new SharpMap.Geometries.Point3D(xcomponents[i], ycomponents[i], zcomponents[i])
                                   : new SharpMap.Geometries.Point(xcomponents[i], ycomponents[i]);

                fdr["TimeStamp"] = System.DateTime.Now; //set the timestamp property
                fdt.AddRow(fdr);
            }

            return fdt;
        }
示例#2
0
        /// <summary>
        /// Gets the feature at the specified Object ID
        /// </summary>
        /// <param name="oid"></param>
        /// <param name="table"></param>
        /// <returns></returns>
        internal SharpMap.Data.FeatureDataRow GetFeature(uint oid, SharpMap.Data.FeatureDataTable table)
        {
            if (!_isOpen)
            {
                throw (new ApplicationException("An attempt was made to read from a closed DBF file"));
            }
            if (oid >= _NumberOfRecords)
            {
                throw (new ArgumentException("Invalid DataRow requested at index " + oid.ToString()));
            }
            fs.Seek(_HeaderLength + oid * _RecordLength, 0);

            SharpMap.Data.FeatureDataRow dr = table.NewRow();

            if (br.ReadChar() == '*')             //is record marked deleted?
            {
                return(null);
            }

            for (int i = 0; i < DbaseColumns.Length; i++)
            {
                DbaseField dbf = DbaseColumns[i];
                dr[dbf.ColumnName] = ReadDbfValue(dbf);
            }
            return(dr);
        }
        private static SharpMap.Data.FeatureDataTable CreateTable(string columnName, Type type)
        {
            var fdt = new SharpMap.Data.FeatureDataTable();

            fdt.Columns.Add(new System.Data.DataColumn(columnName, type));
            return(fdt);
        }
示例#4
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'.
        /// Please note that the ShapeFile provider currently doesn't fully support geometryintersection
        /// and thus only BoundingBox/BoundingBox querying are performed. The results are NOT
        /// guaranteed to lie withing 'geom'.
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(IGeometry geom, FeatureDataSet ds)
        {
            SharpMap.Data.FeatureDataTable dt = (SharpMap.Data.FeatureDataTable)dbaseFile.NewTable;
            IEnvelope bbox = geom.EnvelopeInternal;
            //Get candidates by intersecting the spatial index tree
            Collection <uint> objectlist = tree.Search(bbox);

            if (objectlist.Count == 0)
            {
                return;
            }

            for (int j = 0; j < objectlist.Count; j++)
            {
                for (uint i = (uint)dt.Rows.Count - 1; i >= 0; i--)
                {
                    FeatureDataRow fdr = GetFeature(objectlist[j], dt);
                    if (fdr.Geometry != null)
                    {
                        if (fdr.Geometry.Intersects(geom))
                        {
                            if (FilterDelegate == null || FilterDelegate(fdr))
                            {
                                dt.AddRow(fdr);
                            }
                        }
                    }
                }
            }
            ds.Tables.Add(dt);
        }
示例#5
0
        private void MapBox1_MapQueried(SharpMap.Data.FeatureDataTable data)
        {
            if (mapBox1.ActiveTool == Tools.QueryPoint || mapBox1.ActiveTool == Tools.Query)
            {
                InfoWindows form = new InfoWindows();
                form.tabControlMain.TabPages.Clear();
                form.Owner = this;
                for (int i = 0; i < data.Rows.Count; i++)
                {
                    TabPage      page = new TabPage();
                    DataGridView grid = new DataGridView();
                    grid.Dock = DockStyle.Fill;
                    page.Controls.Add(grid);

                    DataTable dt = new DataTable();
                    dt.Columns.Add("field", typeof(string));
                    dt.Columns.Add("value", typeof(string));

                    for (int x = 0; x < data.Columns.Count; x++)
                    {
                        var dr = dt.NewRow();
                        dr[0] = data.Columns[x].Caption;
                        dr[1] = data.Rows[i][x];

                        dt.Rows.Add(dr);
                    }
                    grid.DataSource = dt;

                    form.tabControlMain.TabPages.Add(page);
                    form.tabControlMain.TabPages[form.tabControlMain.TabPages.Count - 1].Text = data.TableName;
                }

                form.Show();
            }
        }
示例#6
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'.
        /// Please note that the ShapeFile provider currently doesn't fully support geometryintersection
        /// and thus only BoundingBox/BoundingBox querying are performed. The results are NOT
        /// guaranteed to lie withing 'geom'.
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(SharpMap.Geometries.Geometry geom, FeatureDataSet ds)
        {
            SharpMap.Data.FeatureDataTable  dt   = (SharpMap.Data.FeatureDataTable)dbaseFile.NewTable;
            SharpMap.Geometries.BoundingBox bbox = geom.GetBoundingBox();
            //Get candidates by intersecting the spatial index tree
            List <uint> objectlist = tree.Search(bbox);

            if (objectlist.Count == 0)
            {
                return;
            }

            for (int j = 0; j < objectlist.Count; j++)
            {
                for (uint i = (uint)dt.Rows.Count - 1; i >= 0; i--)
                {
                    FeatureDataRow fdr = GetFeature(objectlist[j], dt);
                    if (fdr.Geometry != null)
                    {
                        if (fdr.Geometry.GetBoundingBox().Intersects(bbox))
                        {
                            //replace above line with this:  if(fdr.Geometry.Intersects(bbox))  when relation model is complete
                            if (FilterDelegate == null || FilterDelegate(fdr))
                            {
                                dt.AddRow(fdr);
                            }
                        }
                    }
                }
            }
            ds.Tables.Add(dt);
        }
示例#7
0
        private static SharpMap.Data.FeatureDataTable GetRealFeatureDataTable()
        {
            var res = new SharpMap.Data.FeatureDataTable();
            res.Columns.Add("Oid", typeof(uint));
            res.Columns.Add("Data", typeof(int));

            return res;
        }
示例#8
0
 private void CreateBaseTable()
 {
     baseTable = new SharpMap.Data.FeatureDataTable();
     foreach (DbaseField dbf in DbaseColumns)
     {
         baseTable.Columns.Add(dbf.ColumnName, dbf.DataType);
     }
 }
示例#9
0
        private static SharpMap.Data.FeatureDataTable GetRealFeatureDataTable()
        {
            var res = new SharpMap.Data.FeatureDataTable();

            res.Columns.Add("Oid", typeof(uint));
            res.Columns.Add("Data", typeof(int));

            return(res);
        }
示例#10
0
 /// <summary>
 /// Creates a <see cref="SharpMap.Data.FeatureDataTable"/> using a stub feature (feature[0]).
 /// </summary>
 /// <returns><see cref="SharpMap.Data.FeatureDataTable"/></returns>
 private SharpMap.Data.FeatureDataTable CreateFeatureDataTable()
 {
     SharpMap.Data.FeatureDataTable dataTable = new SharpMap.Data.FeatureDataTable();
     foreach (string columnName in features[0].Attributes.GetNames())
     {
         dataTable.Columns.Add(new DataColumn(columnName, features[0].Attributes.GetType(columnName)));
     }
     return(dataTable);
 }
示例#11
0
 /// <summary>
 /// Creates a new row in the given <see cref="SharpMap.Data.FeatureDataTable"/> <paramref name="dataTable"/>
 /// using data in <see cref="GisSharpBlog.NetTopologySuite.Features.Feature"/> <paramref name="feature"/>.
 /// </summary>
 /// <param name="dataTable">The <see cref="SharpMap.Data.FeatureDataTable"/> to fill.</param>
 /// <param name="feature">Data to insert in the <see cref="SharpMap.Data.FeatureDataTable"/>.</param>
 private void CreateNewRow(SharpMap.Data.FeatureDataTable dataTable, GisSharpBlog.NetTopologySuite.Features.Feature feature)
 {
     SharpMap.Data.FeatureDataRow dataRow = dataTable.NewRow();
     dataRow.Geometry = GeometryConverter.ToSharpMapGeometry(feature.Geometry as GisSharpBlog.NetTopologySuite.Geometries.Geometry);
     foreach (string columnName in feature.Attributes.GetNames())
     {
         dataRow[columnName] = feature.Attributes[columnName];
     }
     dataTable.AddRow(dataRow);
 }
示例#12
0
        private static void FillRealDataTable(SharpMap.Data.FeatureDataTable table)
        {
            table.BeginLoadData();
            var factory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(4326);

            uint id = 0;

            foreach (var datas in PointData())
            {
                var row = (SharpMap.Data.FeatureDataRow)table.LoadDataRow(new object[] { id++, datas[0] }, System.Data.LoadOption.OverwriteChanges);
                row.Geometry = factory.CreatePoint(new GeoAPI.Geometries.Coordinate(datas[2], datas[1]));
            }
            table.EndLoadData();
        }
示例#13
0
        /// <summary>
        /// Creates a FeatureDataTable from arrays of x, y and z components
        /// </summary>
        /// <param name="xcomponents">an array of doubles representing the x ordinate values</param>
        /// <param name="ycomponents">an array of doubles representing the y ordinate values</param>
        /// <param name="zcomponents">an array of doubles representing the z ordinate values</param>
        /// <returns></returns>
        public static SharpMap.Data.FeatureDataTable CreatePointFeatureDataTableFromArrays(double[] xcomponents,
                                                                                           double[] ycomponents,
                                                                                           double[] zcomponents, double[] data = null)
        {
            var factory  = new NetTopologySuite.Geometries.GeometryFactory();
            var threedee = false;

            if (zcomponents != null)
            {
                if (!(zcomponents.Length == ycomponents.Length && zcomponents.Length == xcomponents.Length))
                {
                    throw new System.ApplicationException("Mismatched Array Lengths");
                }

                threedee = true;
            }
            else
            {
                if (ycomponents.Length != xcomponents.Length)
                {
                    throw new System.ApplicationException("Mismatched Array Lengths");
                }
            }

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

            fdt.Columns.Add("TimeStamp", typeof(System.DateTime));  // add example timestamp attribute
            if (data != null)
            {
                fdt.Columns.Add("Data", typeof(System.Double)); // add example timestamp attribute
            }
            for (var i = 0; i < xcomponents.Length; i++)
            {
                SharpMap.Data.FeatureDataRow fdr = fdt.NewRow();

                fdr.Geometry = factory.CreatePoint(threedee
                                   ? new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i], zcomponents[i])
                                   : new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i]));

                fdr["TimeStamp"] = System.DateTime.Now; //set the timestamp property
                if (data != null)
                {
                    fdr["Data"] = data[i];
                }

                fdt.AddRow(fdr);
            }

            return(fdt);
        }
示例#14
0
        private void mapBox1_MapQueried(SharpMap.Data.FeatureDataTable data)
        {
            int count = data.Rows.Count;

            foreach (DataRow dr in data.Rows)
            {
                string s = "";
                for (int i = 0; i < data.Columns.Count; i++)
                {
                    s = s + dr[i].ToString() + ",";
                }
                Console.WriteLine(s);
            }
        }
示例#15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds"></param>
        public void ExecuteIntersectionQuery(SharpMap.Geometries.Geometry geom, FeatureDataSet ds)
        {
            GisSharpBlog.NetTopologySuite.Geometries.Geometry geometry = GeometryConverter.ToNTSGeometry(geom, geometryFactory);
            SharpMap.Data.FeatureDataTable dataTable = CreateFeatureDataTable();

            foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in features)
            {
                if (feature.Geometry.Intersects(geometry))
                {
                    CreateNewRow(dataTable, feature);
                }
            }

            ds.Tables.Add(dataTable);
        }
示例#16
0
        /// <summary>
        /// Create shp with file .prj
        /// </summary>
        /// <param name="table"></param>
        /// <param name="shpType"></param>
        /// <param name="projection"></param>
        /// <param name="path"></param>
        public DxfToShp(SharpMap.Data.FeatureDataTable table, string shpType, string projection, string path)
        {
            CreateShp(table, shpType, path);

            using (System.IO.StreamWriter sw = System.IO.File.AppendText(path + ".prj"))
            {
                if (!string.IsNullOrEmpty(projection))
                {
                    sw.WriteLine("{0}", projection);
                }

                sw.Flush();
                sw.Close();
            }
        }
示例#17
0
        /// <summary>
        /// Gets the feature identified from the given <paramref name="rowID" />.
        /// </summary>
        /// <param name="rowID">The row ID.</param>
        /// <returns></returns>
        public SharpMap.Data.FeatureDataRow GetFeature(uint rowID)
        {
            GisSharpBlog.NetTopologySuite.Features.Feature feature = features[Convert.ToInt32(rowID)];
            SharpMap.Data.FeatureDataTable dataTable = new SharpMap.Data.FeatureDataTable();
            foreach (string columnName in feature.Attributes.GetNames())
            {
                dataTable.Columns.Add(new DataColumn(columnName, feature.Attributes.GetType(columnName)));
            }

            SharpMap.Data.FeatureDataRow dataRow = dataTable.NewRow();
            dataRow.Geometry = GeometryConverter.ToSharpMapGeometry(feature.Geometry as GisSharpBlog.NetTopologySuite.Geometries.Geometry);
            foreach (string columnName in feature.Attributes.GetNames())
            {
                dataRow[columnName] = feature.Attributes[columnName];
            }
            return(dataRow);
        }
示例#18
0
 void eConsulta(SharpMap.Data.FeatureDataTable resultado)
 {
     try
     {
         if ((resultado as DataTable).Rows.Count > 0)
         {
             SharpMap.Data.FeatureDataRow fdr = TopoUtils.LocatePolygon2(this.ultimaPosicion, resultado);
             Estancia est = AdminMapas.RefrescaCapaInfoEst(this.Mapa, fdr[1].ToString());
             this.actualizarPropiedades(est);
             this.tabControl1.SelectedTab = tpInfo;
             this.miVMapa.Refresh();
         }
     }
     catch (Exception error)
     {
         System.Windows.Forms.MessageBox.Show(error.Message, "Error");
     }
 }
示例#19
0
public static void ReprojectFeatureDataTable(SharpMap.Data.FeatureDataTable fdt,
    GeoAPI.CoordinateSystems.ICoordinateSystem target)
{
    var source = SharpMap.CoordinateSystems.CoordinateSystemExtensions.GetCoordinateSystem(fdt[0].Geometry);

    var ctFactory = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
    var ct = ctFactory.CreateFromCoordinateSystems(source, target);
            
    var geomFactory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory((int)target.AuthorityCode);

    for (var i = 0; i < fdt.Rows.Count; i++)
    {
        var fdr = fdt[i];
        fdr.Geometry =
            GeoAPI.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(fdr.Geometry,
                ct.MathTransform, geomFactory);
    }
}
示例#20
0
        private void OnMapQueried(SharpMap.Data.FeatureDataTable features)
        {
            OnClear(this, EventArgs.Empty);

            if (MapControl == null)
            {
                return;
            }

            _geometryProvider     = new SharpMap.Data.Providers.GeometryFeatureProvider(features);
            _layer                = new SharpMap.Layers.VectorLayer("QueriedFeatures", _geometryProvider);
            _layer.IsQueryEnabled = false;

            var map = MapControl.Map;

            map.Layers.Add(_layer);

            MapControl.Refresh();
        }
示例#21
0
        private void CreateShp(SharpMap.Data.FeatureDataTable table, string shpType, string path)
        {
            List <GeoAPI.Geometries.IGeometry> geometries = new List <GeoAPI.Geometries.IGeometry>();

            foreach (SharpMap.Data.FeatureDataRow feature in table)
            {
                if (feature.Geometry.GeometryType.ToUpper() == shpType)
                {
                    geometries.Add(feature.Geometry);
                }
            }

            //Shp
            GisSharpBlog.NetTopologySuite.IO.ShapefileWriter shapeWriter = new GisSharpBlog.NetTopologySuite.IO.ShapefileWriter();
            shapeWriter.Write(path, new GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection(geometries.ToArray()));
            //Dbf
            GisSharpBlog.NetTopologySuite.IO.DbaseFileWriter dataWriter =
                new GisSharpBlog.NetTopologySuite.IO.DbaseFileWriter(path + ".dbf");
            try
            {
                //write column header
                GisSharpBlog.NetTopologySuite.IO.DbaseFileHeader clHeader = GetColumnHeader(table);
                dataWriter.Write(clHeader);
                //write data
                foreach (SharpMap.Data.FeatureDataRow feature in table)
                {
                    if (feature.Geometry.GeometryType.ToUpper() == shpType)
                    {
                        GeoAPI.Extensions.Feature.IFeatureAttributeCollection attribs = feature.Attributes;
                        System.Collections.ArrayList values = new System.Collections.ArrayList();
                        for (int i = 0; i < clHeader.NumFields; i++)
                        {
                            values.Add(attribs[clHeader.Fields[i].Name]);
                        }
                        dataWriter.Write(values);
                    }
                }
            }
            finally
            {
                dataWriter.Close();
            }
        }
        public void GetItemByID()
        {
            var fdt = new SharpMap.Data.FeatureDataTable();
            fdt.Columns.Add(new DataColumn("ID", typeof(uint)));

            var gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();

            for (var i = 0; i < 5; i++)
            {
                var row = fdt.NewRow();
                row[0] = (uint)i;
                row.Geometry = gf.CreatePoint(new GeoAPI.Geometries.Coordinate(i, i));
                fdt.AddRow(row);
            }
            var layer = new SharpMap.Layers.VectorLayer("TMP", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt));

            var res = layer.DataSource.GetFeature(0);
            NUnit.Framework.Assert.IsNotNull(res);
        }
示例#23
0
        /// <summary>
        /// Creates a FeatureDataTable from arrays of x, y and z components
        /// </summary>
        /// <param name="xcomponents">an array of doubles representing the x ordinate values</param>
        /// <param name="ycomponents">an array of doubles representing the y ordinate values</param>
        /// <param name="zcomponents">an array of doubles representing the z ordinate values</param>
        /// <returns></returns>
        public static SharpMap.Data.FeatureDataTable CreatePointFeatureDataTableFromArrays(double[] xcomponents, 
                                                                 double[] ycomponents,
                                                                 double[] zcomponents, double[] data = null)
        {
            var factory = new NetTopologySuite.Geometries.GeometryFactory();
            var threedee = false;
            if (zcomponents != null)
            {
                if (!(zcomponents.Length == ycomponents.Length && zcomponents.Length == xcomponents.Length))
                    throw new System.ApplicationException("Mismatched Array Lengths");

                threedee = true;
            }
            else
            {
                if (ycomponents.Length != xcomponents.Length)
                    throw new System.ApplicationException("Mismatched Array Lengths");
            }

            var fdt = new SharpMap.Data.FeatureDataTable();
            fdt.Columns.Add("TimeStamp", typeof (System.DateTime)); // add example timestamp attribute
            if (data != null)
                fdt.Columns.Add("Data", typeof(System.Double)); // add example timestamp attribute

            
            for (var i = 0; i < xcomponents.Length; i++)
            {
                SharpMap.Data.FeatureDataRow fdr = fdt.NewRow();

                fdr.Geometry = factory.CreatePoint(threedee
                                   ? new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i], zcomponents[i])
                                   : new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i]));

                fdr["TimeStamp"] = System.DateTime.Now; //set the timestamp property
                if (data != null)
                    fdr["Data"] = data[i];

                fdt.AddRow(fdr);
            }

            return fdt;
        }
示例#24
0
        private GisSharpBlog.NetTopologySuite.IO.DbaseFileHeader GetColumnHeader(SharpMap.Data.FeatureDataTable table)
        {
            GisSharpBlog.NetTopologySuite.IO.DbaseFileHeader header = new GisSharpBlog.NetTopologySuite.IO.DbaseFileHeader();
            header.NumRecords = table.Rows.Count;

            foreach (System.Data.DataColumn col in table.Columns)
            {
                //Hanya kolom selain hasil generate SharpMap yang dijadikan column header
                if (col.ColumnName != "DSHELL_ADDED_OBJECTID")
                {
                    Type type = col.DataType;
                    if (type == typeof(double) || type == typeof(float))
                    {
                        header.AddColumn(col.ColumnName, 'N', _DoubleLength, _DoubleDecimals);
                    }
                    else if (type == typeof(short) || type == typeof(ushort) ||
                             type == typeof(int) || type == typeof(uint) ||
                             type == typeof(long) || type == typeof(ulong))
                    {
                        header.AddColumn(col.ColumnName, 'N', _IntLength, _IntDecimals);
                    }
                    else if (type == typeof(string))
                    {
                        header.AddColumn(col.ColumnName, 'C', _StringLength, _StringDecimals);
                    }
                    else if (type == typeof(bool))
                    {
                        header.AddColumn(col.ColumnName, 'L', _BoolLength, _BoolDecimals);
                    }
                    else if (type == typeof(DateTime))
                    {
                        header.AddColumn(col.ColumnName, 'D', _DateLength, _DateDecimals);
                    }
                    else
                    {
                        throw new ArgumentException("Type " + type.Name + " not supported");
                    }
                }
            }

            return(header);
        }
        public void TestFindGeoNearPoint()
        {
            var fdt = new SharpMap.Data.FeatureDataTable();
            fdt.Columns.Add(new DataColumn("ID", typeof(uint)));

            var gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();

            for (var i = 0; i < 5; i++)
            {
                var row = fdt.NewRow();
                row[0] = (uint)i;
                row.Geometry = gf.CreatePoint(new GeoAPI.Geometries.Coordinate(i, i));
                fdt.AddRow(row);
            }
            var layer = new SharpMap.Layers.VectorLayer("TMP", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt));

            var res = FindGeoNearPoint(gf.CreatePoint(new GeoAPI.Geometries.Coordinate(0.1, 0.1)), layer, 0.2d);
            NUnit.Framework.Assert.IsNotNull(res);
            NUnit.Framework.Assert.AreEqual(0, (uint)res[0]);
        }
示例#26
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;
    }
        public void GetItemByID()
        {
            var fdt = new SharpMap.Data.FeatureDataTable();

            fdt.Columns.Add(new DataColumn("ID", typeof(uint)));

            var gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();

            for (var i = 0; i < 5; i++)
            {
                var row = fdt.NewRow();
                row[0]       = (uint)i;
                row.Geometry = gf.CreatePoint(new GeoAPI.Geometries.Coordinate(i, i));
                fdt.AddRow(row);
            }
            var layer = new SharpMap.Layers.VectorLayer("TMP", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt));

            var res = layer.DataSource.GetFeature(0);

            NUnit.Framework.Assert.IsNotNull(res);
        }
示例#28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="box"></param>
        /// <param name="ds"></param>
        public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox box, FeatureDataSet ds)
        {
            // Identifies all the features within the given BoundingBox
            GisSharpBlog.NetTopologySuite.Geometries.Envelope     envelope = GeometryConverter.ToNTSEnvelope(box);
            List <GisSharpBlog.NetTopologySuite.Features.Feature> results  = new List <GisSharpBlog.NetTopologySuite.Features.Feature>(features.Count);

            foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in features)
            {
                if (envelope.Intersects(feature.Geometry.EnvelopeInternal))
                {
                    results.Add(feature);
                }
            }

            // Fill DataSet
            SharpMap.Data.FeatureDataTable dataTable = CreateFeatureDataTable();
            foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in results)
            {
                CreateNewRow(dataTable, feature);
            }
            ds.Tables.Add(dataTable);
        }
示例#29
0
        private static SharpMap.Data.FeatureDataTable TransformedFeatureDataTable(
            System.Drawing.Drawing2D.Matrix matrix, SharpMap.Data.FeatureDataTable fdt)
        {
            SharpMap.Data.FeatureDataTable fdtClone = new SharpMap.Data.FeatureDataTable(fdt);
            fdtClone.Clear();
            foreach (SharpMap.Data.FeatureDataRow row in fdt)
            {
                SharpMap.Data.FeatureDataRow newRow = fdtClone.NewRow();
                for (System.Int32 i = 0; i < fdtClone.Columns.Count; i++)
                    newRow[i] = row[i];

                GeoAPI.Geometries.IPoint smpt = (GeoAPI.Geometries.IPoint)row.Geometry;
                System.Drawing.PointF[] pts = new System.Drawing.PointF[] 
                    { new System.Drawing.PointF((float)smpt.X, (float)smpt.Y) };
                matrix.TransformPoints(pts);
                newRow.Geometry = new NetTopologySuite.Geometries.Point(pts[0].X, pts[0].Y);

                fdtClone.AddRow(newRow);
            }

            return fdtClone;
        }
示例#30
0
        public void TestEnsureVisible()
        {
            //Create a map
            SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(720, 360));

            //Create some random sample data
            SharpMap.Data.FeatureDataTable fdt =
                cd.CreatePointFeatureDataTableFromArrays(cd.GetRandomOrdinates(80, -180, 180),
                                                         cd.GetRandomOrdinates(80, -90, 90), null);

            //Create layer and datasource
            SharpMap.Layers.VectorLayer vl = new SharpMap.Layers.VectorLayer("Points", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt));

            //Create default style
            SharpMap.Styles.VectorStyle defaultStyle = new SharpMap.Styles.VectorStyle();
            defaultStyle.Symbol      = new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\flag.png");
            defaultStyle.SymbolScale = 0.5f;

            //Create theming class and apply to layer
            SymbolRotationTheming srt = new SymbolRotationTheming("Rotation", defaultStyle);

            vl.Theme = new SharpMap.Rendering.Thematics.CustomTheme(srt.GetRotatedSymol);


            map.Layers.Add(vl);
            map.ZoomToExtents();
            map.Zoom   = 60; //2*30
            map.Center = new SharpMap.Geometries.Point(0, 0);

            System.Console.WriteLine(map.Center);
            EnsureVisible(map, new SharpMap.Geometries.Point(-30, 0));
            System.Console.WriteLine(map.Center);
            System.Console.WriteLine();
            EnsureVisible(map, new SharpMap.Geometries.Point(15, 20));
            System.Console.WriteLine(map.Center);
            System.Console.WriteLine();
            EnsureVisible(map, new SharpMap.Geometries.Point(15, -20));
            System.Console.WriteLine(map.Center);
        }
示例#31
0
        /// <summary>
        /// Creates a FeatureDataTable from arrays of x, y and z components
        /// </summary>
        /// <param name="xcomponents">an array of doubles representing the x ordinate values</param>
        /// <param name="ycomponents">an array of doubles representing the y ordinate values</param>
        /// <param name="zcomponents">an array of doubles representing the z ordinate values</param>
        /// <returns></returns>
        public static SharpMap.Data.FeatureDataTable CreatePointFeatureDataTableFromArrays(double[] xcomponents,
                                                                                           double[] ycomponents,
                                                                                           double[] zcomponents)
        {
            bool threedee = false;

            if (zcomponents != null)
            {
                if (!(zcomponents.Length == ycomponents.Length && zcomponents.Length == xcomponents.Length))
                {
                    throw new System.ApplicationException("Mismatched Array Lengths");
                }

                threedee = true;
            }
            else
            {
                if (ycomponents.Length != xcomponents.Length)
                {
                    throw new System.ApplicationException("Mismatched Array Lengths");
                }
            }

            SharpMap.Data.FeatureDataTable fdt = new SharpMap.Data.FeatureDataTable();
            fdt.Columns.Add("TimeStamp", typeof(System.DateTime));  // add example timestamp attribute
            for (int i = 0; i < xcomponents.Length; i++)
            {
                SharpMap.Data.FeatureDataRow fdr = fdt.NewRow();

                fdr.Geometry = threedee
                                   ? new SharpMap.Geometries.Point3D(xcomponents[i], ycomponents[i], zcomponents[i])
                                   : new SharpMap.Geometries.Point(xcomponents[i], ycomponents[i]);

                fdr["TimeStamp"] = System.DateTime.Now; //set the timestamp property
                fdt.AddRow(fdr);
            }

            return(fdt);
        }
示例#32
0
        internal static SharpMap.Data.FeatureDataTable <uint> GetFeatureTableForFields(DbaseField[] _dbaseColumns)
        {
            SharpMap.Data.FeatureDataTable <uint> table = new SharpMap.Data.FeatureDataTable <uint>(DbaseSchema.OidColumnName);
            foreach (DbaseField dbf in _dbaseColumns)
            {
                DataColumn col = table.Columns.Add(dbf.ColumnName, dbf.DataType);
                if (dbf.DataType == typeof(string))
                {
                    col.MaxLength = dbf.Length;
                }
                else
                {
                    col.ExtendedProperties[DbaseSchema.LengthExtendedProperty] = dbf.Length;
                }
                if (dbf.Decimals > 0)
                {
                    col.ExtendedProperties[DbaseSchema.NumericPrecisionExtendedProperty] = dbf.Decimals;
                }
            }

            return(table);
        }
示例#33
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);
            }
        public void TestFindGeoNearPoint()
        {
            var fdt = new SharpMap.Data.FeatureDataTable();

            fdt.Columns.Add(new DataColumn("ID", typeof(uint)));

            var gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();

            for (var i = 0; i < 5; i++)
            {
                var row = fdt.NewRow();
                row[0]       = (uint)i;
                row.Geometry = gf.CreatePoint(new GeoAPI.Geometries.Coordinate(i, i));
                fdt.AddRow(row);
            }
            var layer = new SharpMap.Layers.VectorLayer("TMP", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt));

            var res = FindGeoNearPoint(gf.CreatePoint(new GeoAPI.Geometries.Coordinate(0.1, 0.1)), layer, 0.2d);

            NUnit.Framework.Assert.IsNotNull(res);
            NUnit.Framework.Assert.AreEqual(0, (uint)res[0]);
        }
示例#35
0
        public LayerInfo(SharpMap.Data.FeatureDataTable tabela)
        {
            InitializeComponent();
            this._tabela = tabela;

            //MessageBox.Show("Success!");
            //DataGridViewColumnCollection kolone = new DataGridViewColumnCollection(this._layersDataGrid);
            foreach (DataColumn kol in _tabela.Columns)
            {
                DataGridViewTextBoxColumn kolona = new DataGridViewTextBoxColumn();
                kolona.DataPropertyName = kol.ColumnName;
                kolona.HeaderText = kol.ColumnName;
                kolona.Name = kol.ColumnName;
                kolona.Width = 200;
                this._layersDataGrid.Columns.Add(kolona);
            }
            //this._layersDataGrid.Rows.Add(_tabela.Rows);
            foreach (SharpMap.Data.FeatureDataRow red in _tabela.Rows)
            {
                this._layersDataGrid.Rows.Add(red.ItemArray);
            }
            //this._layersDataGrid.DataSource = tabela.Rows;
        }
示例#36
0
        /// <summary>
        /// Returns all objects whose boundingbox intersects bbox.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Please note that this method doesn't guarantee that the geometries returned actually intersect 'bbox', but only
        /// that their boundingbox intersects 'bbox'.
        /// </para>
        /// </remarks>
        /// <param name="bbox"></param>
        /// <param name="ds"></param>
        /// <returns></returns>
        public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox bbox, SharpMap.Data.FeatureDataSet ds)
        {
            //Use the spatial index to get a list of features whose boundingbox intersects bbox
            List <uint> objectlist = GetObjectIDsInView(bbox);

            SharpMap.Data.FeatureDataTable dt = dbaseFile.NewTable;

            for (int i = 0; i < objectlist.Count; i++)
            {
                SharpMap.Data.FeatureDataRow fdr = dbaseFile.GetFeature(objectlist[i], dt);
                fdr.Geometry = ReadGeometry(objectlist[i]);
                if (fdr.Geometry != null)
                {
                    if (fdr.Geometry.GetBoundingBox().Intersects(bbox))
                    {
                        if (FilterDelegate == null || FilterDelegate(fdr))
                        {
                            dt.AddRow(fdr);
                        }
                    }
                }
            }
            ds.Tables.Add(dt);
        }
示例#37
0
文件: Theming.cs 项目: cugkgq/Project
        public void TestSymbolSelectionTheming()
        {
            //Create a map
            SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(720, 360));

            //Create some random sample data
            SharpMap.Data.FeatureDataTable fdt =
                cd.CreatePointFeatureDataTableFromArrays(cd.GetRandomOrdinates(80, -180, 180),
                                                         cd.GetRandomOrdinates(80, -90, 90), null);

            //Add rotation column and fill with random rotation values
            fdt.Columns.Add("Symbol", typeof(System.Byte[]));
            foreach (SharpMap.Data.FeatureDataRow row in fdt.Rows)
            {
                row["Symbol"] = RandomSymbol((int)System.Math.Floor(cd.RandomNumberGenerator.NextDouble() * 360d));
            }


            //Create layer and datasource
            SharpMap.Layers.VectorLayer vl = new SharpMap.Layers.VectorLayer("Points", new SharpMap.Data.Providers.FeatureProvider(fdt));

            //Create default style
            SharpMap.Styles.VectorStyle defaultStyle = new SharpMap.Styles.VectorStyle();
            defaultStyle.Symbol      = new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\flag.png");
            defaultStyle.SymbolScale = 0.5f;

            //Create theming class and apply to layer
            SymbolFromFeatureDataRowTheming srt = new SymbolFromFeatureDataRowTheming("Symbol", defaultStyle);

            vl.Theme = new SharpMap.Rendering.Thematics.CustomTheme(srt.GetRotatedSymol);

            map.Layers.Add(vl);
            map.ZoomToExtents();
            System.Drawing.Image mapImage = map.GetMap();
            mapImage.Save("SymbolFromFDR.bmp");
        }
示例#38
0
 /// <summary>
 /// Gets the feature identified from the given <paramref name="rowID" />.
 /// </summary>
 /// <param name="rowID">The row ID.</param>
 /// <returns></returns>
 public SharpMap.Data.FeatureDataRow GetFeature(uint rowID)
 {
     GisSharpBlog.NetTopologySuite.Features.Feature feature = features[Convert.ToInt32(rowID)];            
     SharpMap.Data.FeatureDataTable dataTable = new SharpMap.Data.FeatureDataTable();            
     foreach (string columnName in feature.Attributes.GetNames())
         dataTable.Columns.Add(new DataColumn(columnName, feature.Attributes.GetType(columnName)));            
     
     SharpMap.Data.FeatureDataRow dataRow = dataTable.NewRow();
     dataRow.Geometry = GeometryConverter.ToSharpMapGeometry(feature.Geometry);
     foreach (string columnName in feature.Attributes.GetNames())
         dataRow[columnName] = feature.Attributes[columnName];
     return dataRow;
 }
示例#39
0
 /// <summary>
 /// Creates a <see cref="SharpMap.Data.FeatureDataTable"/> using a stub feature (feature[0]).
 /// </summary>
 /// <returns><see cref="SharpMap.Data.FeatureDataTable"/></returns>
 private SharpMap.Data.FeatureDataTable CreateFeatureDataTable()
 {            
     SharpMap.Data.FeatureDataTable dataTable = new SharpMap.Data.FeatureDataTable();
     foreach (string columnName in features[0].Attributes.GetNames())
         dataTable.Columns.Add(new DataColumn(columnName, features[0].Attributes.GetType(columnName)));
     return dataTable;
 }
示例#40
0
            private static SharpMap.Data.FeatureDataTable TransformedFeatureDataTable(
            System.Drawing.Drawing2D.Matrix matrix, SharpMap.Data.FeatureDataTable fdt)
            {
                SharpMap.Data.FeatureDataTable fdtClone = new SharpMap.Data.FeatureDataTable(fdt);
                fdtClone.Clear();
                foreach (SharpMap.Data.FeatureDataRow row in fdt)
                {
                SharpMap.Data.FeatureDataRow newRow = fdtClone.NewRow();
                for (System.Int32 i = 0; i < fdtClone.Columns.Count; i++)
                    newRow[i] = row[i];

                SharpMap.Geometries.Point smpt = (SharpMap.Geometries.Point)row.Geometry;
                System.Drawing.PointF[] pts = new System.Drawing.PointF[]
                    { new System.Drawing.PointF((float)smpt.X, (float)smpt.Y) };
                matrix.TransformPoints(pts);
                newRow.Geometry = new SharpMap.Geometries.Point(pts[0].X, pts[0].Y);

                fdtClone.AddRow(newRow);
                }

                return fdtClone;
            }
示例#41
0
        private void LoadParcels(List<PointD> pt, Color color, string labelname)
        {
            SharpMap.Map map = new SharpMap.Map();
            List<GeoAPI.Geometries.Coordinate> vertices = new List<GeoAPI.Geometries.Coordinate>();

            foreach (PointD i in pt)
            {
                GeoAPI.Geometries.Coordinate p = new GeoAPI.Geometries.Coordinate();
                p.X = i.X;
                p.Y = i.Y;
                vertices.Add(p);
            }
            GeoAPI.Geometries.Coordinate l = new GeoAPI.Geometries.Coordinate();
            l.X = pt[0].X;
            l.Y = pt[0].Y;
            vertices.Add(l);

            //Collection<GeoAPI.Geometries.IGeometry> geom = new Collection<GeoAPI.Geometries.IGeometry>();

            GeometryFactory gf = new NetTopologySuite.Geometries.GeometryFactory();
            GeoAPI.Geometries.ILinearRing shell = gf.CreateLinearRing(vertices.ToArray());

            GeoAPI.Geometries.IPolygon polygon = gf.CreatePolygon(shell, null);

            SharpMap.Data.Providers.GeometryProvider geomProvider= new SharpMap.Data.Providers.GeometryProvider(polygon);

            SharpMap.Layers.VectorLayer layerParcels = new SharpMap.Layers.VectorLayer("Parcels");

            SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();

            style.Fill = new SolidBrush(Color.FromArgb(200,color));
            style.Outline = new Pen(new SolidBrush(color));

            layerParcels.Style = style;
            layerParcels.Style.EnableOutline = true;

            layerParcels.DataSource = geomProvider;
            layerParcels.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;

            var fdt = new SharpMap.Data.FeatureDataTable();
            fdt.Columns.Add(new System.Data.DataColumn("id", typeof(uint)));
            fdt.Columns.Add(new System.Data.DataColumn("label", typeof(string)));
            var fdr = (SharpMap.Data.FeatureDataRow)fdt.NewRow();
            fdr.ItemArray = new object[] { 1, labelname };
            fdr.Geometry =  polygon;
            fdt.AddRow(fdr);

            var dataprovider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt);

            var ll = new SharpMap.Layers.LabelLayer("llayer");
            ll.DataSource = dataprovider;
            ll.LabelColumn = "label";
            ll.Style.Font = new Font("Eurostile Extended", 16,FontStyle.Bold);

            mapBox1.Map.Layers.Add(layerParcels);
            mapBox1.Map.Layers.Add(ll);

            mapBox1.Map.ZoomToExtents();
            mapBox1.Refresh();
        }
示例#42
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;
 }