Example #1
0
        /// <summary>
        /// Gets the geometry by ID.
        /// </summary>
        /// <param name="oid">The oid.</param>
        /// <returns></returns>
        public Geometry GetGeometryByID(uint oid)
        {
            Feature feature = _features[Convert.ToInt32(oid)];

            return
                (GeometryConverter.ToSharpMapGeometry(
                     feature.Geometry as NtsGeometry));
        }
Example #2
0
        /// <summary>
        /// Gets the geometry by ID.
        /// </summary>
        /// <param name="oid">The oid.</param>
        /// <returns></returns>
        public Geometry GetGeometryByID(uint oid)
        {
            Feature feature = features[Convert.ToInt32(oid)];

            return
                (GeometryConverter.ToSharpMapGeometry(
                     feature.Geometry as GisSharpBlog.NetTopologySuite.Geometries.Geometry));
        }
Example #3
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);
 }
Example #4
0
        /// <summary>
        /// Creates a new row in the given <see cref="SharpMap.Data.FeatureDataTable"/> <paramref name="dataTable"/>
        /// using data in <see cref="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 static void CreateNewRow(FeatureDataTable dataTable, Feature feature)
        {
            FeatureDataRow dataRow = dataTable.NewRow();

            dataRow.Geometry =
                GeometryConverter.ToSharpMapGeometry(feature.Geometry as NtsGeometry);
            foreach (string columnName in feature.Attributes.GetNames())
            {
                dataRow[columnName] = feature.Attributes[columnName];
            }
            dataTable.AddRow(dataRow);
        }
Example #5
0
        /// <summary>
        /// Returns features within the specified bounding box.
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public Collection <SharpMap.Geometries.Geometry> GetGeometriesInView(SharpMap.Geometries.BoundingBox bbox)
        {
            // Identifies all the features within the given BoundingBox
            GisSharpBlog.NetTopologySuite.Geometries.Envelope envelope = GeometryConverter.ToNTSEnvelope(bbox);
            Collection <SharpMap.Geometries.Geometry>         geoms    = new Collection <SharpMap.Geometries.Geometry>();

            foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in features)
            {
                if (envelope.Intersects(feature.Geometry.EnvelopeInternal))
                {
                    geoms.Add(GeometryConverter.ToSharpMapGeometry(feature.Geometry as GisSharpBlog.NetTopologySuite.Geometries.Geometry));
                }
            }
            return(geoms);
        }
        /// <summary>
        /// This method returns a FeatureDataTable containing all the rows from the shapefile that intersect the testGeometry.
        /// The ShapeFile.ExecuteIntersectionQuery method only tests bounding boxes so we use the FilterDelegate property to add a true
        /// intersection test using NetTopologySuite
        /// </summary>
        /// <param name="pathToShapefile">The path to the shapefile</param>
        /// <param name="testGeometry">The geometry that we want to test against</param>
        /// <returns></returns>
        public FeatureDataTable GetIntersectingFeaturesUsingFilterDelegate(string pathToShapefile, SMGeometry testGeometry)
        {
            //create a new shapefile provider
            using (ShapeFile shapefile = new ShapeFile(pathToShapefile))
            {
                //create an nts GeometryFactory
                GeometryFactory geometryFactory = new GeometryFactory();

                //convert the testGeometry into the equivalent NTS geometry
                GeoAPI.Geometries.IGeometry testGeometryAsNtsGeom = GeometryConverter.ToNTSGeometry(testGeometry, geometryFactory);

                SMGeometry check = GeometryConverter.ToSharpMapGeometry(testGeometryAsNtsGeom);
                if (!check.Equals(testGeometry))
                {
                    throw new ApplicationException("conversion error");
                }

                //set the shapefile providers' FilterDelegate property to a new anonymous method
                //this delegate method will be called for each potential row
                shapefile.FilterDelegate = delegate(FeatureDataRow featureDataRow)
                {
                    //get the geometry from the featureDataRow
                    SMGeometry rowGeometry = featureDataRow.Geometry;
                    //convert it to the equivalent NTS geometry
                    GeoAPI.Geometries.IGeometry compareGeometryAsNtsGeometry =
                        GeometryConverter.ToNTSGeometry(rowGeometry, geometryFactory);
                    //do the test. Note that the testGeometryAsNtsGeometry is available here because it is
                    //declared in the same scope as the anonymous method.
                    bool intersects =
                        testGeometryAsNtsGeom.Intersects(compareGeometryAsNtsGeometry);
                    //return the result
                    return(intersects);
                };


                //create a new FeatureDataSet
                FeatureDataSet featureDataSet = new FeatureDataSet();
                //open the shapefile
                shapefile.Open();
                //call ExecuteIntersectionQuery. The FilterDelegate will be used to limit the result set
                shapefile.ExecuteIntersectionQuery(testGeometry, featureDataSet);
                //close the shapefile
                shapefile.Close();
                //return the populated FeatureDataTable
                return(featureDataSet.Tables[0]);
            }
        }
Example #7
0
        /// <summary>
        /// Returns features within the specified bounding box.
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public Collection <Geometry> GetGeometriesInView(BoundingBox bbox)
        {
            // Identifies all the features within the given BoundingBox
            Envelope envelope           = GeometryConverter.ToNTSEnvelope(bbox);
            Collection <Geometry> geoms = new Collection <Geometry>();

            foreach (Feature feature in _features)
            {
                if (envelope.Intersects(feature.Geometry.EnvelopeInternal))
                {
                    geoms.Add(
                        GeometryConverter.ToSharpMapGeometry(
                            feature.Geometry as NtsGeometry));
                }
            }
            return(geoms);
        }
Example #8
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);
        }
Example #9
0
        /// <summary>
        /// Gets the feature identified from the given <paramref name="rowId" />.
        /// </summary>
        /// <param name="rowId">The row ID.</param>
        /// <returns></returns>
        public FeatureDataRow GetFeature(uint rowId)
        {
            Feature          feature   = _features[Convert.ToInt32(rowId)];
            FeatureDataTable dataTable = new FeatureDataTable();

            foreach (string columnName in feature.Attributes.GetNames())
            {
                dataTable.Columns.Add(new DataColumn(columnName, feature.Attributes.GetType(columnName)));
            }

            FeatureDataRow dataRow = dataTable.NewRow();

            dataRow.Geometry =
                GeometryConverter.ToSharpMapGeometry(
                    feature.Geometry as NtsGeometry);
            foreach (string columnName in feature.Attributes.GetNames())
            {
                dataRow[columnName] = feature.Attributes[columnName];
            }
            return(dataRow);
        }