public void ReadByGeoFilter_ReadShapeDataAfterReaderObjectDisposed_ShouldThrowException()
        {
            Envelope boundsWithWholeTriangle = new Envelope(-1.17459, -1.00231, -1.09803, -0.80861);

            // Arrange.
            m_TempFiles = new TempFileWriter[]
            {
                new TempFileWriter(".shp", ShpFiles.Read("UnifiedChecksMaterial")),
                new TempFileWriter(".dbf", DbfFiles.Read("UnifiedChecksMaterial")),
            };

            m_shapeDataReader = new ShapeDataReader(m_TempFiles[0].Path);

            // Act.
            IEnumerable <IShapefileFeature> results = m_shapeDataReader.ReadByMBRFilter(boundsWithWholeTriangle);

            // Assert.
            Assert.IsNotNull(results);
            IShapefileFeature result = results.Single();

            // Dispose of the reader object.
            m_shapeDataReader.Dispose();

            // Try reading dbf data.
            Assert.Catch <InvalidOperationException>(() =>
            {
                IGeometry table = result.Geometry;
            });
        }
        public void ReadByGeoFilter_ReadShapeDataAfterReaderObjectDisposed_ShouldThrowException()
        {
            Envelope boundsWithWholeTriangle = new Envelope(-1.17459, -1.00231, -1.09803, -0.80861);

            // Arrange.
            m_TempFiles = new TempFileCloudUploader[]
            {
                new TempFileCloudUploader("test.shp", ShpFiles.Read("UnifiedChecksMaterial")),
                new TempFileCloudUploader("test.dbf", DbfFiles.Read("UnifiedChecksMaterial")),
            };

            m_shapeDataReader = new ShapeDataReader(new ShapefileStreamProviderRegistry(GetProvider(m_TempFiles[0].Path), GetProvider(m_TempFiles[1].Path)));

            // Act.
            IEnumerable <IShapefileFeature> results = m_shapeDataReader.ReadByMBRFilter(boundsWithWholeTriangle);

            // Assert.
            Assert.IsNotNull(results);
            IShapefileFeature result = results.Single();

            // Dispose of the reader object.
            m_shapeDataReader.Dispose();

            // Try reading dbf data.
            IGeometry table = result.Geometry;
        }
        /// <summary>
        /// 思路1,对经纬度进行平面程度的三角网化,同时进行sub,一直到当前视图的精度
        /// 然后将经纬度坐标转换成世界坐标,以实现贴椭球体的mesh划分,z这样的实现在地球背面端任然有多边形显示,可以考虑裁剪掉(globeCull或者faceCull的)或者在shader中处理,
        /// </summary>
        public static List <Mesh <Vector3> > FeatureToMesh(IShapefileFeature _feature, Ellipsoid _shape)
        {
            if (_feature == null)
            {
                return(null);
            }
            List <Mesh <Vector3> > meshes = new List <Mesh <Vector3> >();

            if (_feature.Geometry is GeoAPI.Geometries.IMultiPolygon)
            {
                foreach (var item in ((GeoAPI.Geometries.IMultiPolygon)_feature.Geometry).Geometries)
                {
                    var mesh = PolygonToMesh(item as GeoAPI.Geometries.IPolygon, _shape);
                    if (mesh != null)
                    {
                        meshes.Add(mesh);
                    }
                }
                //判断Hole的顺序是否和外边框相同
                //var geo = _feature.Geometry as NetTopologySuite.Geometries.po
                //throw new Exception("Not Support Multipolygon");
            }
            if (_feature.Geometry is GeoAPI.Geometries.IPolygon)
            {
                var mesh = PolygonToMesh(_feature.Geometry as GeoAPI.Geometries.IPolygon, _shape);
                if (mesh != null)
                {
                    meshes.Add(mesh);
                }
            }
            return(meshes);
        }
        public static Mesh <Vector3> FeatureToLineStripAdjacency(IShapefileFeature _feature, Ellipsoid _shape)
        {
            if (_feature == null)
            {
                return(null);
            }
            List <Vector2> points  = new List <Vector2>();
            List <ushort>  indices = new List <ushort>();

            if (_feature.Geometry is GeoAPI.Geometries.IMultiPolygon)
            {
                foreach (var item in ((GeoAPI.Geometries.IMultiPolygon)_feature.Geometry).Geometries)
                {
                    PolygonToLineStripAdjacency(item as GeoAPI.Geometries.IPolygon, _shape, points, indices);
                }
            }
            if (_feature.Geometry is GeoAPI.Geometries.IPolygon)
            {
                PolygonToLineStripAdjacency(_feature.Geometry as GeoAPI.Geometries.IPolygon, _shape, points, indices);
            }
            var mesh = new Mesh <Vector3>();

            mesh.PrimitiveTopology = PrimitiveTopology.LineStripAdjacency;
            mesh.Positions         = points.ConvertAll(i => _shape.ToVector3(new Geodetic2D(i.X, i.Y))).ToArray();
            mesh.Indices           = indices.ToArray();
            return(mesh);
        }
        /// <summary>
        /// 将一个Feature转换成
        /// </summary>
        /// <param name="_feature"></param>
        /// <param name="_shape"></param>
        /// <returns></returns>
        public static Mesh <Vector3> FeatureToPoints(IShapefileFeature _feature, Ellipsoid _shape)
        {
            if (_feature == null)
            {
                return(null);
            }
            List <Vector3> points  = new List <Vector3>();
            List <ushort>  indices = new List <ushort>();

            if (_feature.Geometry is GeoAPI.Geometries.IMultiPolygon)
            {
                foreach (var item in ((GeoAPI.Geometries.IMultiPolygon)_feature.Geometry).Geometries)
                {
                    PolygonToPoints(item as GeoAPI.Geometries.IPolygon, _shape, points, indices);
                }
            }
            if (_feature.Geometry is GeoAPI.Geometries.IPolygon)
            {
                PolygonToPoints(_feature.Geometry as GeoAPI.Geometries.IPolygon, _shape, points, indices);
                //查找其Hole
                var geo = _feature.Geometry as GeoAPI.Geometries.IPolygon;
            }
            var mesh = new Mesh <Vector3>();

            mesh.PrimitiveTopology = PrimitiveTopology.LineStrip;
            mesh.Positions         = points.ToArray();
            mesh.Indices           = indices.ToArray();
            return(mesh);
        }
        public void ReadByGeoFilter_ReadWithRectangleMBRPartiallyInBounds_ShouldReturnRectangle()
        {
            Envelope boundsWithWholeTriangle = new Envelope(-1.17459, -1.00231, -1.09803, -0.80861);

            // Arrange.
            m_TempFiles = new TempFileWriter[]
            {
                new TempFileWriter(".shp", ShpFiles.Read("UnifiedChecksMaterial")),
                new TempFileWriter(".dbf", DbfFiles.Read("UnifiedChecksMaterial")),
            };

            Polygon expectedTriangle = new Polygon(new LinearRing(new Coordinate[]
            {
                new Coordinate(-0.815656565656566, -0.439393939393939),
                new Coordinate(-0.353535353535354, -0.795454545454545),
                new Coordinate(-0.888888888888889, -0.929292929292929),
                new Coordinate(-1.151515151515152, -0.419191919191919),
                new Coordinate(-0.815656565656566, -0.439393939393939),
            }));

            string expectedShapeMetadata = "Rectangle";

            m_shapeDataReader = new ShapeDataReader(m_TempFiles[0].Path);

            // Act.
            IEnumerable <IShapefileFeature> results = m_shapeDataReader.ReadByMBRFilter(boundsWithWholeTriangle);

            // Assert.
            Assert.IsNotNull(results);

            IShapefileFeature result = results.Single();

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <ShapefileFeature>(result);
            Assert.AreEqual(((ShapefileFeature)result).FeatureId, 0);
            Assert.IsNotNull(result.Attributes);

            HelperMethods.AssertPolygonsEqual(result.Geometry as IPolygon, expectedTriangle);

            object shapeNameData = result.Attributes["ShapeName"];

            Assert.IsInstanceOf <string>(shapeNameData);

            Assert.AreEqual((string)shapeNameData, expectedShapeMetadata);
        }
        public void ReadByGeoFilter_ReadWithRectanglePartiallyInBoundsAndFlagSetToTrue_ShouldReturnRectangle()
        {
            Envelope boundsWithWholeTriangle = new Envelope(-0.93340, -0.38902, -0.73281, -0.29179);

            // Arrange.
            m_TempFiles = new TempFileCloudUploader[]
            {
                new TempFileCloudUploader("test.shp", ShpFiles.Read("UnifiedChecksMaterial")),
                new TempFileCloudUploader("test.dbf", DbfFiles.Read("UnifiedChecksMaterial")),
            };

            Polygon expectedTriangle = new Polygon(new LinearRing(new Coordinate[]
            {
                new Coordinate(-0.815656565656566, -0.439393939393939),
                new Coordinate(-0.353535353535354, -0.795454545454545),
                new Coordinate(-0.888888888888889, -0.929292929292929),
                new Coordinate(-1.151515151515152, -0.419191919191919),
                new Coordinate(-0.815656565656566, -0.439393939393939),
            }));

            string expectedShapeMetadata = "Rectangle";

            m_shapeDataReader = new ShapeDataReader(new ShapefileStreamProviderRegistry(GetProvider(m_TempFiles[0].Path), GetProvider(m_TempFiles[1].Path)));

            // Act.
            IEnumerable <IShapefileFeature> results = m_shapeDataReader.ReadByMBRFilter(boundsWithWholeTriangle, true);

            // Assert.
            Assert.IsNotNull(results);

            IShapefileFeature result = results.Single();

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <ShapefileFeature>(result);
            Assert.AreEqual(((ShapefileFeature)result).FeatureId, 0);
            Assert.IsNotNull(result.Attributes);

            HelperMethods.AssertPolygonsEqual(result.Geometry as IPolygon, expectedTriangle);

            object shapeNameData = result.Attributes["ShapeName"];

            Assert.IsInstanceOf <string>(shapeNameData);

            Assert.AreEqual((string)shapeNameData, expectedShapeMetadata);
        }
        public void ReadByGeoFilter_ReadWithWholeTriangleInBounds_ShouldReturnTriangle()
        {
            Envelope boundsWithWholeTriangle = new Envelope(-0.62331, 0.63774, -0.02304, 0.76942);

            // Arrange.
            m_TempFiles = new TempFileWriter[]
            {
                new TempFileWriter(".shp", ShpFiles.Read("UnifiedChecksMaterial")),
                new TempFileWriter(".dbf", DbfFiles.Read("UnifiedChecksMaterial")),
            };

            Polygon expectedTriangle = new Polygon(new LinearRing(new Coordinate[]
            {
                new Coordinate(0.068181818181818, 0.578282828282829),
                new Coordinate(0.421717171717172, 0.070707070707071),
                new Coordinate(-0.457070707070707, 0.080808080808081),
                new Coordinate(0.068181818181818, 0.578282828282829),
            }));

            string expectedShapeMetadata = "Triangle";

            m_shapeDataReader = new ShapeDataReader(m_TempFiles[0].Path);

            // Act.
            IEnumerable <IShapefileFeature> results = m_shapeDataReader.ReadByMBRFilter(boundsWithWholeTriangle);

            // Assert.
            Assert.IsNotNull(results);

            IShapefileFeature result = results.Single();

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <ShapefileFeature>(result);
            Assert.AreEqual(((ShapefileFeature)result).FeatureId, 1);
            Assert.IsNotNull(result.Attributes);

            HelperMethods.AssertPolygonsEqual(result.Geometry as IPolygon, expectedTriangle);

            object shapeNameData = result.Attributes["ShapeName"];

            Assert.IsInstanceOf <string>(shapeNameData);

            Assert.AreEqual((string)shapeNameData, expectedShapeMetadata);
        }
Beispiel #9
0
 /// <summary>
 /// 使用_fea构造FeatureRFender对象
 /// </summary>
 /// <param name="_fea"></param>
 public BaseFeatureRender(IShapefileFeature _fea)
 {
     _feature = _fea;
 }
Beispiel #10
0
 /// <summary>
 /// 使用_fea构造FeatureRFender对象
 /// </summary>
 /// <param name="_fea"></param>
 public BaseFeatureRender(IShapefileFeature _fea, Scene.Scene _scene)
 {
     _feature    = _fea;
     _shape      = _scene.Ellipsoid;
     VectorStyle = new VectorStyle();
 }