Ejemplo n.º 1
0
        /// <summary>
        /// Builds from the given provider.
        /// </summary>
        /// <param name="provider">
        /// The base <see cref="SharpMap.Data.Providers.IProvider"/>
        /// from witch initialize the <see cref="NtsProvider"/> instance.
        /// </param>
        private void BuildFromProvider(SharpMap.Data.Providers.IProvider provider)
        {
            // Features list initialization
            features = new List <GisSharpBlog.NetTopologySuite.Features.Feature>(provider.GetFeatureCount());

            try
            {
                // Load all features from the given provider
                provider.Open();
                Collection <uint> ids = provider.GetObjectIDsInView(provider.GetExtents());
                foreach (uint id in ids)
                {
                    SharpMap.Data.FeatureDataRow dataRow = provider.GetFeature(id);
                    GisSharpBlog.NetTopologySuite.Geometries.Geometry      geometry   = GeometryConverter.ToNTSGeometry(dataRow.Geometry, geometryFactory);
                    GisSharpBlog.NetTopologySuite.Features.AttributesTable attributes = new GisSharpBlog.NetTopologySuite.Features.AttributesTable();
                    foreach (DataColumn column in dataRow.Table.Columns)
                    {
                        if (dataRow[column] == null || dataRow[column].GetType() == typeof(System.DBNull))
                        {
                            throw new ApplicationException("Null values not supported");
                        }
                        attributes.AddAttribute(column.ColumnName, dataRow[column]);
                    }
                    features.Add(new GisSharpBlog.NetTopologySuite.Features.Feature(geometry, attributes));
                }
            }
            finally
            {
                if (provider.IsOpen)
                {
                    provider.Close();
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Converts any <see cref="SharpMap.Geometries.Geometry"/> array to the correspondant 
 /// <see cref=GisSharpBlog.NetTopologySuite.Geometries.Geometry"/> array.
 /// </summary>
 /// <param name="geometries"></param>
 /// <param name="factory"></param>
 /// <returns></returns>
 public static GisSharpBlog.NetTopologySuite.Geometries.Geometry[] ToNTSGeometry(SharpMap.Geometries.Geometry[] geometries,
     GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory)
 {            
     GisSharpBlog.NetTopologySuite.Geometries.Geometry[] converted = new GisSharpBlog.NetTopologySuite.Geometries.Geometry[geometries.Length];
     int index = 0;
     foreach (SharpMap.Geometries.Geometry geometry in geometries)
         converted[index++] = GeometryConverter.ToNTSGeometry(geometry, factory);
     if((geometries.Length != converted.Length))
         throw new ApplicationException("Conversion error");
     return converted;
 }
Ejemplo n.º 3
0
        internal static GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection ToNTSGeometryCollection(SharpMap.Geometries.GeometryCollection geometryCollection,
                                                                                                            GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory)
        {
            GisSharpBlog.NetTopologySuite.Geometries.Geometry[] geometries = new GisSharpBlog.NetTopologySuite.Geometries.Geometry[geometryCollection.Collection.Count];
            int index = 0;

            foreach (SharpMap.Geometries.Geometry geometry in geometryCollection.Collection)
            {
                geometries[index++] = ToNTSGeometry(geometry, factory);
            }
            return(factory.CreateGeometryCollection(geometries) as GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Converts any <see cref="SharpMap.Geometries.Geometry"/> array to the correspondant
        /// <see cref=GisSharpBlog.NetTopologySuite.Geometries.Geometry"/> array.
        /// </summary>
        /// <param name="geometries"></param>
        /// <param name="factory"></param>
        /// <returns></returns>
        public static GisSharpBlog.NetTopologySuite.Geometries.Geometry[] ToNTSGeometry(SharpMap.Geometries.Geometry[] geometries,
                                                                                        GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory)
        {
            GisSharpBlog.NetTopologySuite.Geometries.Geometry[] converted = new GisSharpBlog.NetTopologySuite.Geometries.Geometry[geometries.Length];
            int index = 0;

            foreach (SharpMap.Geometries.Geometry geometry in geometries)
            {
                converted[index++] = GeometryConverter.ToNTSGeometry(geometry, factory);
            }
            if ((geometries.Length != converted.Length))
            {
                throw new ApplicationException("Conversion error");
            }
            return(converted);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Converts any <see cref="SharpMap.Geometries.Geometry"/> to the correspondant
        /// <see cref=GisSharpBlog.NetTopologySuite.Geometries.Geometry"/>.
        /// </summary>
        /// <param name="geometry"></param>
        /// <returns></returns>
        public static SharpMap.Geometries.Geometry ToSharpMapGeometry(GisSharpBlog.NetTopologySuite.Geometries.Geometry geometry)
        {
            if (geometry == null)
            {
                throw new NullReferenceException("geometry");
            }

            if (geometry.GetType() == typeof(GisSharpBlog.NetTopologySuite.Geometries.Point))
            {
                return(ToSharpMapPoint(geometry as GisSharpBlog.NetTopologySuite.Geometries.Point));
            }

            else if (geometry.GetType() == typeof(GisSharpBlog.NetTopologySuite.Geometries.LineString))
            {
                return(ToSharpMapLineString(geometry as GisSharpBlog.NetTopologySuite.Geometries.LineString));
            }

            else if (geometry.GetType() == typeof(GisSharpBlog.NetTopologySuite.Geometries.Polygon))
            {
                return(ToSharpMapPolygon(geometry as GisSharpBlog.NetTopologySuite.Geometries.Polygon));
            }

            else if (geometry.GetType() == typeof(GisSharpBlog.NetTopologySuite.Geometries.MultiPoint))
            {
                return(ToSharpMapMultiPoint(geometry as GisSharpBlog.NetTopologySuite.Geometries.MultiPoint));
            }

            else if (geometry.GetType() == typeof(GisSharpBlog.NetTopologySuite.Geometries.MultiLineString))
            {
                return(ToSharpMapMultiLineString(geometry as GisSharpBlog.NetTopologySuite.Geometries.MultiLineString));
            }

            else if (geometry.GetType() == typeof(GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon))
            {
                return(ToSharpMapMultiPolygon(geometry as GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon));
            }

            else if (geometry.GetType() == typeof(GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection))
            {
                return(ToSharpMapGeometryCollection(geometry as GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection));
            }

            else
            {
                throw new NotSupportedException("Type " + geometry.GetType().FullName + " not supported");
            }
        }
Ejemplo n.º 7
0
 internal static GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection ToNTSGeometryCollection(SharpMap.Geometries.GeometryCollection geometryCollection,
     GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory)
 {
     GisSharpBlog.NetTopologySuite.Geometries.Geometry[] geometries = new GisSharpBlog.NetTopologySuite.Geometries.Geometry[geometryCollection.Collection.Count];
     int index = 0;
     foreach (SharpMap.Geometries.Geometry geometry in geometryCollection.Collection)
         geometries[index++] = ToNTSGeometry(geometry, factory);
     return factory.CreateGeometryCollection(geometries);
 }