public ShapefileDataReader(IStreamProviderRegistry streamProviderRegistry, IGeometryFactory geometryFactory)
        {
            if (streamProviderRegistry==null)
                throw new ArgumentNullException("streamProviderRegistry");
            if (geometryFactory == null)
                throw new ArgumentNullException("geometryFactory");
            _open = true;

            _dbfReader = new DbaseFileReader(streamProviderRegistry);
            _shpReader = new ShapefileReader(streamProviderRegistry, geometryFactory);

            _dbfHeader = _dbfReader.GetHeader();
            _recordCount = _dbfHeader.NumRecords;

            // copy dbase fields to our own array. Insert into the first position, the shape column
            _dbaseFields = new DbaseFieldDescriptor[_dbfHeader.Fields.Length + 1];
            _dbaseFields[0] = DbaseFieldDescriptor.ShapeField();
            for (int i = 0; i < _dbfHeader.Fields.Length; i++)
                _dbaseFields[i + 1] = _dbfHeader.Fields[i];

            _shpHeader = _shpReader.Header;
            _dbfEnumerator = _dbfReader.GetEnumerator();
            _shpEnumerator = _shpReader.GetEnumerator();
            _moreRecords = true;
        }
        public ShapefileDataReader(string path, IGeometryFactory geometryFactory = null, GeometryTransform transform = null)
            : base(path, geometryFactory, transform)
        {
            _dbf = DbfFile.Open(Path.ChangeExtension(path, ".dbf"));

            _currentRecord = new DbfRecord(_dbf.Header);
        }
Exemple #3
0
 /// <summary>
 /// Constructs a <c>Point</c> with the given coordinate.
 /// </summary>
 /// <param name="coordinates">
 /// Contains the single coordinate on which to base this <c>Point</c>,
 /// or <c>null</c> to create the empty point.
 /// </param>
 /// <param name="factory"></param>
 public Point(ICoordinateSequence coordinates, IGeometryFactory factory) : base(factory)
 {               
     if (coordinates == null) 
         coordinates = factory.CoordinateSequenceFactory.Create(new Coordinate[] { });
     NetTopologySuite.Utilities.Assert.IsTrue(coordinates.Count <= 1);
     this._coordinates = coordinates;
 }        
        private void Execute(IGeometryFactory factory)
        {
            const string wkt1 = @"POLYGON ((34.8998882099012 30.3837960942026, 34.9010566737651 30.3644568453302, 34.952062587058 30.3841960548712, 34.9237694926759 30.3379967024143, 34.8688043479468 30.2722872698552, 34.8675239767921 30.2729668362851, 34.8644624659558 30.2746560404891, 34.8614352803289 30.2763912924804, 34.8584433396252 30.2781720660657, 34.8554875530179 30.2799978212197, 34.8525688188649 30.2818680042466, 34.8496880244379 30.2837820479458, 34.8468460456542 30.2857393717817, 34.8440437468117 30.2877393820578, 34.8412819803279 30.2897814720941, 34.8385615864812 30.291865022409, 34.8358833931563 30.2939894009049, 34.8332482155932 30.2961539630577, 34.8306568561393 30.2983580521099, 34.8281101040059 30.3006009992674, 34.8256087350277 30.3028821239005, 34.8231535114263 30.3052007337477, 34.8207451815784 30.3075561251236, 34.8183844797864 30.3099475831299, 34.8160721260548 30.3123743818706, 34.813808825869 30.3148357846692, 34.8115952699799 30.3173310442906, 34.8094321341915 30.3198594031656, 34.8073200791532 30.3224200936183, 34.8052597501567 30.3250123380972, 34.8038593775008 30.3268416420348, 34.8413134524996 30.34133631112, 34.8380456129141 30.3420679436136, 34.8345469119455 30.3429079098264, 34.8310655827664 30.3438006160548, 34.827824169131 30.3446853380141, 34.827602680711 30.3447457917824, 34.8241592556176 30.3457431505854, 34.8207363515157 30.3467923902175, 34.8173350063135 30.3478931927008, 34.8139562514873 30.34904522442, 34.8106011117732 30.3502481362226, 34.80727060486 30.3515015635225, 34.8039657410851 30.3528051264095, 34.8006875231308 30.3541584297621, 34.7974369457248 30.355561063366, 34.8114061852091 30.3793421607384, 34.8098261518056 30.3806388748041, 34.8072325551456 30.3828429255909, 34.8046836035397 30.3850858339783, 34.8021800734927 30.387366919357, 34.7997227278858 30.3896854894863, 34.797312315744 30.3920408407015, 34.7949495720071 30.3944322581256, 34.7926352173053 30.3968590158832, 34.7903699577383 30.3993203773193, 34.7881544846595 30.4018155952199, 34.8175519633847 30.421036532238, 34.8473374156124 30.4405111377535, 34.8473374156124 30.4405111377536, 34.8945946797018 30.4714093282142, 34.89504284421 30.4639917561117, 34.9249010902965 30.4502666241023, 34.9120339400511 30.4239712613602, 34.8990624811609 30.3974627330299, 34.8990624811609 30.3974627330298, 34.8998882099012 30.3837960942026), (34.8998882099012 30.3837960942026, 34.8896581575596 30.3782440174851, 34.8896581575596 30.3782440174851, 34.8998882099012 30.3837960942026))";
            const string wkt2 = @"POLYGON ((34.89504284421 30.4639917561117, 34.8974881525283 30.4235194508906, 34.8362388038152 30.4216169690234, 34.8683403196915 30.4762662772922, 34.89504284421 30.4639917561117))";

            WKTReader reader = new WKTReader(factory);

            IGeometry g1 = reader.Read(wkt1);
            Assert.IsFalse(g1.IsValid);
            IGeometry v1 = g1.Buffer(0);
            Assert.IsTrue(v1.IsValid);

            IGeometry g2 = reader.Read(wkt2);
            //Assert.IsFalse(g2.IsValid);
            IGeometry v2 = g2.Buffer(0);
            Assert.IsTrue(v2.IsValid);

            IGeometry union1 = g1.Union(g2);
            Assert.IsNotNull(union1);
            Assert.IsTrue(union1.IsValid);

            IGeometry union2 = v1.Union(v2);
            Assert.IsNotNull(union2);
            Assert.IsTrue(union2.IsValid);
        }
        /// <summary>
        /// Initializes a new instance of the Shapefile class with the given parameters.
        /// </summary>
        /// <param name="filename">The filename of the shape file to read (with .shp).</param>
        /// <param name="geometryFactory">The GeometryFactory to use when creating Geometry objects.</param>
        public ShapefileReader(string filename, IGeometryFactory geometryFactory)
        {
            Guard.IsNotNull(filename, "filename");
            Guard.IsNotNull(geometryFactory, "geometryFactory");

            _filename = filename;
            _geometryFactory = geometryFactory;

            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                // read header information. note, we open the file, read the header information and then
                // close the file. This means the file is not opened again until GetEnumerator() is requested.
                // For each call to GetEnumerator() a new BinaryReader is created.
                using (
                    var stream = new IsolatedStorageFileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read,
                                                               isf))
                {
                    using (var shpBinaryReader = new BigEndianBinaryReader(stream))
                    {
                        _mainHeader = new ShapefileHeader(shpBinaryReader);
                        shpBinaryReader.Close();
                    }
                }
            }
        }
        public DataConverter(IGeometryFactory factory)
        {
            if (factory == null)
                throw new ArgumentNullException("factory");

            _factory = factory;
        }
 public ShapefileBlockReader(string path, ShapefileIndexReader index, IGeometryFactory geometryFactory = null, GeometryTransform transform = null, int blockSize = 25)
     : base(path, geometryFactory, transform)
 {
     _block = new int[blockSize, 2];
     _blockPos = blockSize;
     _index = index;
 }
Exemple #8
0
 /// <summary>
 /// Writes to the given stream the equilivent shape file record given a Geometry object.
 /// </summary>
 /// <param name="geometry">The geometry object to write.</param>
 /// <param name="file">The stream to write to.</param>
 /// <param name="geometryFactory">The geometry factory to use.</param>
 public override void Write(IGeometry geometry, System.IO.BinaryWriter file, IGeometryFactory geometryFactory)
 {
     file.Write(int.Parse(Enum.Format(typeof(ShapeGeometryTypes), this.ShapeType, "d")));
     ICoordinate external = geometry.Coordinates[0];
     file.Write(external.X);
     file.Write(external.Y);
 }
Exemple #9
0
 /// <summary>
 /// Constructs a <c>Point</c> with the given coordinate.
 /// </summary>
 /// <param name="coordinates">
 /// Contains the single coordinate on which to base this <c>Point</c>,
 /// or <c>null</c> to create the empty point.
 /// </param>
 /// <param name="factory"></param>
 public Point(ICoordinateSequence coordinates, IGeometryFactory factory) : base(factory)
 {               
     if (coordinates == null) 
         coordinates = factory.CoordinateSequenceFactory.Create(new ICoordinate[] { });
     Debug.Assert(coordinates.Count <= 1);
     this.coordinates = (ICoordinateSequence) coordinates;
 }        
        /// <summary>
        /// Initializes a new instance of the ShapefileDataReader class.
        /// </summary>
        /// <param name="filename">The shapefile to read (minus the .shp extension)</param>
        ///<param name="geometryFactory">The GeometryFactory to use.</param>
        public ShapefileDataReader(string filename, IGeometryFactory geometryFactory)
        {
            if (String.IsNullOrEmpty(filename))
                throw new ArgumentNullException("filename");
            if (geometryFactory == null)
                throw new ArgumentNullException("geometryFactory");
            _open = true;

            string dbfFile = Path.ChangeExtension(filename, "dbf");
            _dbfReader = new DbaseFileReader(dbfFile);
            string shpFile = Path.ChangeExtension(filename, "shp");
            _shpReader = new ShapefileReader(shpFile, geometryFactory);

            _dbfHeader = _dbfReader.GetHeader();
            _recordCount = _dbfHeader.NumRecords;

            // copy dbase fields to our own array. Insert into the first position, the shape column
            _dbaseFields = new DbaseFieldDescriptor[_dbfHeader.Fields.Length + 1];
            _dbaseFields[0] = DbaseFieldDescriptor.ShapeField();
            for (int i = 0; i < _dbfHeader.Fields.Length; i++)
                _dbaseFields[i + 1] = _dbfHeader.Fields[i];

            _shpHeader = _shpReader.Header;
            _dbfEnumerator = _dbfReader.GetEnumerator();
            _shpEnumerator = _shpReader.GetEnumerator();
            _moreRecords = true;
        }
Exemple #11
0
		/// <summary>
		/// Writes a Geometry to the given binary wirter.
		/// </summary>
		/// <param name="geometry">The geometry to write.</param>
		/// <param name="file">The file stream to write to.</param>
		/// <param name="geometryFactory">The geometry factory to use.</param>
		public override void Write(IGeometry geometry, System.IO.BinaryWriter file, IGeometryFactory geometryFactory)
		{
            if(!(geometry is IMultiPoint))
                throw new ArgumentException("Geometry Type error: MultiPoint expected, but the type retrieved is " + geometry.GetType().Name);

            // Slow and maybe not useful...
			// if (!geometry.IsValid)
			// 	Trace.WriteLine("Invalid multipoint being written.");

            IMultiPoint mpoint = geometry as IMultiPoint;
            
            file.Write(int.Parse(Enum.Format(typeof(ShapeGeometryTypes), this.ShapeType, "d")));

            IEnvelope box = geometry.EnvelopeInternal;
			IEnvelope bounds = ShapeHandler.GetEnvelopeExternal(geometryFactory.PrecisionModel, box);
			file.Write(bounds.MinX);
			file.Write(bounds.MinY);
			file.Write(bounds.MaxX);
			file.Write(bounds.MaxY);

            int numPoints = mpoint.NumPoints;
			file.Write(numPoints);						

			// write the points 
			for (int i = 0; i < numPoints; i++)
			{
                IPoint point = (IPoint) mpoint.Geometries[i];
                file.Write(point.X);
                file.Write(point.Y);	
			}            
		}
        /// <summary>
        /// Initializes a new instance of the ShapefileDataReader class.
        /// </summary>
        /// <param name="filename">The shapefile to read (minus the .shp extension)</param>
        ///<param name="geometryFactory">The GeometryFactory to use.</param>
        public ShapefileDataReader(string filename, IGeometryFactory geometryFactory)
        {
            if (filename == null)
                throw new ArgumentNullException("filename");
            if (geometryFactory == null)
                throw new ArgumentNullException("geometryFactory");
            _geometryFactory = geometryFactory;
            _open = true;

            if (filename.ToLower().EndsWith(".shp"))
                filename = filename.ToLower().Replace(".shp",String.Empty);

             _dbfReader = new DbaseFileReader(filename + ".dbf");
             _shpReader = new ShapefileReader(filename + ".shp", geometryFactory);

            _dbfHeader =  _dbfReader.GetHeader();
            _recordCount = _dbfHeader.NumRecords;

            // copy dbase fields to our own array. Insert into the first position, the shape column
            _dbaseFields = new DbaseFieldDescriptor[_dbfHeader.Fields.Length + 1];
            _dbaseFields[0] = DbaseFieldDescriptor.ShapeField();
            for(int i=0; i < _dbfHeader.Fields.Length; i++)
                _dbaseFields[i+1] = _dbfHeader.Fields[i];

            _shpHeader = _shpReader.Header;
            _dbfEnumerator = _dbfReader.GetEnumerator();
            _shpEnumerator = _shpReader.GetEnumerator();
            _moreRecords = true;
        }
        private static void PerformTest(IGeometryFactory factory)
        {
            if (factory == null)
                throw new ArgumentNullException("factory");

            WKTReader reader = new WKTReader(factory);
            IGeometry g1 = reader.Read(t1);
            Assert.IsNotNull(g1);
            Assert.IsTrue(g1.IsValid);
            Assert.IsInstanceOf(typeof(IPolygon), g1);
            Assert.IsInstanceOf(typeof(Polygon), g1);

            IGeometry g2 = reader.Read(t2);
            Assert.IsNotNull(g2);
            Assert.IsTrue(g2.IsValid);
            Assert.IsInstanceOf(typeof(IMultiPolygon), g2);
            Assert.IsInstanceOf(typeof(MultiPolygon), g2);

            Stopwatch watch = new Stopwatch();
            watch.Start();
            IGeometry r = g1.Intersection(g2);
            watch.Stop();
            Assert.IsNotNull(r);
            Assert.IsInstanceOf(typeof(IMultiPolygon), r);
            Assert.IsInstanceOf(typeof(MultiPolygon), r);
            Assert.IsTrue(r.IsValid);
            Console.WriteLine("GeometryFactory.Default => Elapsed: {0}", watch.Elapsed);
        }
        protected internal SpatialDbFeatureDataReader(IGeometryFactory geomFactory, IDataReader internalReader,
                                                      string geometryColumn, string oidColumn)
        {
            _geomFactory = geomFactory;
            _internalReader = internalReader;
            _geometryColumn = geometryColumn;
            _oidColumn = oidColumn;


            for (int i = 0; i < internalReader.FieldCount; i++)
            // note: GetOrdinal crashes if the column does not exist so loop through fields
            {
                string name = internalReader.GetName(i);
                if (String.Compare(name, geometryColumn, StringComparison.CurrentCultureIgnoreCase) == 0)
                    _geomColumnIndex = i;

                if (String.Compare(name, oidColumn, StringComparison.CurrentCultureIgnoreCase) == 0)
                    _oidColumnIndex = i;

                if (_geomColumnIndex > -1 && _oidColumnIndex > -1)
                    break;
            }
            if (_oidColumnIndex > -1)
                _oidType = _internalReader.GetFieldType(_oidColumnIndex);
        }
        /// <summary>
        /// Reads a stream and converts the shapefile record to an equilivent geometry object.
        /// </summary>
        /// <param name="file">The stream to read.</param>
        /// <param name="totalRecordLength">Total length of the record we are about to read</param>
        /// <param name="factory">The geometry factory to use when making the object.</param>
        /// <returns>The Geometry object that represents the shape file record.</returns>
        public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory factory)
        {
            int totalRead = 0;
            ShapeGeometryType type = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead);
            //type = (ShapeGeometryType) EnumUtility.Parse(typeof (ShapeGeometryType), shapeTypeNum.ToString());
            if (type == ShapeGeometryType.NullShape)
                return factory.CreatePoint((Coordinate)null);

            if (type != ShapeType)
                throw new ShapefileException(string.Format("Encountered a '{0}' instead of a  '{1}'", type, ShapeType));

            CoordinateBuffer buffer = new CoordinateBuffer(1, NoDataBorderValue, true);
            IPrecisionModel precisionModel = factory.PrecisionModel;

            double x = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
            double y = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));

            double? z = null, m = null;
            
            // Trond Benum: Let's read optional Z and M values                                
            if (HasZValue() && totalRead < totalRecordLength)
                z = ReadDouble(file, totalRecordLength, ref totalRead);

            if ((HasMValue() || HasZValue()) &&
                (totalRead < totalRecordLength))
                m = ReadDouble(file, totalRecordLength, ref totalRead);

            buffer.AddCoordinate(x, y, z, m);
            return factory.CreatePoint(buffer.ToSequence(factory.CoordinateSequenceFactory));
        }
        private static bool TestWktWkb(int number, IGeometryFactory factory, string wkt, string wkb)
        {
            WKTReader r = new WKTReader(factory);
            IGeometry wktGeom = r.Read(wkt);
            WKBReader s = new WKBReader(factory);
            IGeometry wkbGeom = s.Read(WKBReader.HexToBytes(wkb));

            try
            {
                Assert.AreEqual(wkb, WKBWriter.ToHex(wktGeom.AsBinary()), "wkb's don't match");
                Assert.IsTrue(DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9, number + ": DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9");
                if (!wktGeom.EqualsExact(wkbGeom))
                {
                    Assert.AreEqual(wkt, wktGeom.AsText(), number + ": wkt.Equals(wktGeom.AsText())");
                    var wktGeom2 = s.Read(wktGeom.AsBinary());
                    Assert.AreEqual(wkt, wktGeom2.AsText(), number + ": wkt.Equals(wktGeom2.AsText())");
                    var diff = wkbGeom.Difference(wktGeom);
                    Assert.IsTrue(false, number + ": wktGeom.EqualsExact(wkbGeom)\n" + diff.AsText());
                }
                return false;
            }
            catch (AssertionException ex)
            {
                Console.WriteLine(ex.Message);
                return true;
            }
        }
        /// <summary>
        /// Reads a stream and converts the shapefile record to an equilivant geometry object.
        /// </summary>
        /// <param name="file">The stream to read.</param>
        /// <param name="geometryFactory">The geometry factory to use when making the object.</param>
        /// <returns>The Geometry object that represents the shape file record.</returns>
        public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory)
        {
            int shapeTypeNum = file.ReadInt32();

            type = (ShapeGeometryType) Enum.Parse(typeof(ShapeGeometryType), shapeTypeNum.ToString());
            if (type == ShapeGeometryType.NullShape)
                return geometryFactory.CreateMultiPoint(new IPoint[] { });
            
            if (!(type == ShapeGeometryType.MultiPoint  || type == ShapeGeometryType.MultiPointM ||
                  type == ShapeGeometryType.MultiPointZ || type == ShapeGeometryType.MultiPointZM))	
                throw new ShapefileException("Attempting to load a non-multipoint as multipoint.");

            // Read and for now ignore bounds.
            int bblength = GetBoundingBoxLength();
            bbox = new double[bblength];
            for (; bbindex < 4; bbindex++)
            {
                double d = file.ReadDouble();
                bbox[bbindex] = d;
            }

            // Read points
            int numPoints = file.ReadInt32();
            IPoint[] points = new IPoint[numPoints];
            for (int i = 0; i < numPoints; i++)
            {
                double x = file.ReadDouble();
                double y = file.ReadDouble();
                IPoint point = geometryFactory.CreatePoint(new Coordinate(x, y));                
                points[i] = point;
            }
            geom = geometryFactory.CreateMultiPoint(points);
            GrabZMValues(file);
            return geom;
        }        
 ///<summary>
 /// Converts a <see cref="GraphicsPath"/> to a Geometry, flattening it first.
 ///</summary>
 /// <param name="shp">The <see cref="GraphicsPath"/></param>
 /// <param name="flatness">The flatness parameter to use</param>
 /// <param name="geomFact">The GeometryFactory to use</param>
 /// <returns>A Geometry representing the shape</returns>
 public static IGeometry Read(GraphicsPath shp, double flatness, IGeometryFactory geomFact)
 {
     var path = (GraphicsPath)shp.Clone();
     path.Flatten(InvertY, (float)flatness);
     var pathIt = new GraphicsPathIterator(path);
     return Read(pathIt, geomFact);
 }
        public static IExtents2D ParseExtents(IGeometryFactory geomFactory, string extents)
        {
            string[] strVals = extents.Split(new[] {','});
            if (strVals.Length != 4)
                return null;
            double minx = 0;
            double miny = 0;
            double maxx = 0;
            double maxy = 0;
            if (!double.TryParse(strVals[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out minx))
                return null;
            if (!double.TryParse(strVals[2], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out maxx))
                return null;
            if (maxx < minx)
                return null;

            if (!double.TryParse(strVals[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out miny))
                return null;
            if (!double.TryParse(strVals[3], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out maxy))
                return null;
            if (maxy < miny)
                return null;

            return geomFactory.CreateExtents2D(minx, miny, maxx, maxy);
        }
        /// <summary>
        /// Converts any <see cref="GisSharpBlog.NetTopologySuite.Geometries.Geometry"/> to the correspondant 
        /// <see cref="SharpMap.Geometries.Geometry"/>.
        /// </summary>
        public static NTSGeometry ToNTSGeometry(Geometries.Geometry geometry, IGeometryFactory factory)
        {
            if (geometry == null)
                throw new NullReferenceException("geometry");

            if (TypeOf(geometry, typeof(Geometries.Point)))
                return ToNTSPoint(geometry as Geometries.Point, factory);

            if (TypeOf(geometry, typeof (Geometries.LineString)))
                return ToNTSLineString(geometry as Geometries.LineString, factory);

            if (TypeOf(geometry, typeof (Geometries.Polygon)))
                return ToNTSPolygon(geometry as Geometries.Polygon, factory);

            if (TypeOf(geometry, typeof (Geometries.MultiPoint)))
                return ToNTSMultiPoint(geometry as Geometries.MultiPoint, factory);

            if (TypeOf(geometry, typeof (Geometries.MultiLineString)))
                return ToNTSMultiLineString(geometry as Geometries.MultiLineString, factory);

            if (TypeOf(geometry, typeof (Geometries.MultiPolygon)))
                return ToNTSMultiPolygon(geometry as Geometries.MultiPolygon, factory);

            if (TypeOf(geometry, typeof (Geometries.GeometryCollection)))
                return ToNTSGeometryCollection(geometry as Geometries.GeometryCollection, factory);

            var message = String.Format("Type {0} not supported", geometry.GetType().FullName);
            throw new NotSupportedException(message);
        }
        /// <summary>
        /// Adds each line to the graph structure.
        /// </summary>
        /// <param name="lines"></param>
        /// <returns>
        /// <c>true</c> if all <paramref name="lines">lines</paramref> 
        /// are added, <c>false</c> otherwise.
        /// </returns>
        /// <exception cref="TopologyException">
        /// If geometries don't have the same <see cref="IGeometryFactory">factory</see>.
        /// </exception>
        public bool Add(params ILineString[] lines)
        {
            var result = true;
            foreach (var line in lines)
            {
                var newfactory = line.Factory;
                if (factory == null)
                    factory = newfactory;
                else if (!newfactory.PrecisionModel.Equals(factory.PrecisionModel))
                    throw new TopologyException("all geometries must have the same precision model");

                var lineFound = strings.Contains(line);
                result &= !lineFound;
                if (!lineFound)
                    strings.Add(line);
                else continue; // Skip vertex check because line is already present

                var coordinates = line.Coordinates;
                var start = 0;
                var end = coordinates.GetUpperBound(0);  
                AddCoordinateToGraph(coordinates[start]); // StartPoint
                AddCoordinateToGraph(coordinates[end]);   // EndPoint
            }
            return result;
        }
        /// <summary>
        /// Reads a stream and converts the shapefile record to an equilivent geometry object.
        /// </summary>
        /// <param name="file">The stream to read.</param>
        /// <param name="geometryFactory">The geometry factory to use when making the object.</param>
        /// <returns>The Geometry object that represents the shape file record.</returns>
        public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory)
        {
            int shapeTypeNum = file.ReadInt32();
            type = (ShapeGeometryType) Enum.Parse(typeof (ShapeGeometryType), shapeTypeNum.ToString());
            if (type == ShapeGeometryType.NullShape)
            {
                ICoordinate emptyCoordinate = null;
                return geometryFactory.CreatePoint(emptyCoordinate);
            }

            if (!(type == ShapeGeometryType.Point  || type == ShapeGeometryType.PointM ||
                  type == ShapeGeometryType.PointZ || type == ShapeGeometryType.PointZM))
                throw new ShapefileException("Attempting to load a point as point.");		    

            double x = file.ReadDouble();
            double y = file.ReadDouble();		    
            ICoordinate external = new Coordinate(x,y);			
            geometryFactory.PrecisionModel.MakePrecise(external);
            IPoint point = geometryFactory.CreatePoint(external);
            if (HasZValue() || HasMValue())
            {
                IDictionary<ShapeGeometryType, double> data = new Dictionary<ShapeGeometryType, double>(2);
                if (HasZValue())
                    GetZValue(file, data);
                if (HasMValue())
                    GetMValue(file, data);
                // point.UserData = data;
            }
            return point;
        }
        public GraphBuilder2() : this (false) { } // TODO: maybe the default value must be true...

        /// <summary>
        /// Adds each line to the graph structure.
        /// </summary>
        /// <param name="lines"></param>
        /// <returns>
        /// <c>true</c> if all <paramref name="lines">lines</paramref> 
        /// are added, <c>false</c> otherwise.
        /// </returns>
        /// <exception cref="TopologyException">
        /// If geometries don't have the same <see cref="IGeometryFactory">factory</see>.
        /// </exception>
        public bool Add(params ILineString[] lines)
        {
            bool result = true;
            foreach (ILineString line in lines)
            {
                IGeometryFactory newfactory = line.Factory;
                if (factory == null)
                    factory = newfactory;
                else if (!newfactory.PrecisionModel.Equals(factory.PrecisionModel))
                    throw new TopologyException("all geometries must have the same precision model");

                bool lineFound = strings.Contains(line);
                result &= !lineFound;
                if (!lineFound)
                    strings.Add(line);
                else continue; // Skip vertex check because line is already present

                foreach (ICoordinate coord in line.Coordinates)
                {
                    if (!graph.ContainsVertex(coord))
                         graph.AddVertex(coord);
                    
                }
            }
            return result;
        }        
 internal static GeometryLayer CreateFeatureFeatureLayer(IGeometryFactory geoFactory,
                                                         Boolean includeGeometryCollections)
 {
     GeometryLayer layer = new GeometryLayer("TestFeatures",
                                             CreateFeatureDatasource(geoFactory, includeGeometryCollections));
     return layer;
 }
        public static IGeometry ToSource(this Layer self, IGeometry geometry, IGeometryFactory sourceFactory)
        {
            if (geometry.SRID == sourceFactory.SRID)
                return geometry;

#if !DotSpatialProjections
            if (self.ReverseCoordinateTransformation != null)
            {
                return GeometryTransform.TransformGeometry(geometry,
                    self.ReverseCoordinateTransformation.MathTransform, sourceFactory);
            }
#endif
            if (self.CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                var mt = self.CoordinateTransformation.MathTransform;
                mt.Invert();
                var res = GeometryTransform.TransformGeometry(geometry, mt, sourceFactory);
                mt.Invert();
                return res;
#else
                return GeometryTransform.TransformGeometry(geometry, 
                    self.CoordinateTransformation.Target, 
                    self.CoordinateTransformation.Source, SourceFactory);
#endif
            }

            return geometry;
        }
        public void FixtureSetup()
        {
            Environment.CurrentDirectory = Path.Combine(
               AppDomain.CurrentDomain.BaseDirectory,
               @"../../../NetTopologySuite.Samples.Shapefiles");

            factory = GeometryFactory.Fixed;       
        }
 /// <summary>
 /// Initializes a new instance of the FeatureDataSet class with the given name.
 /// </summary>
 public FeatureDataSet(String name, IGeometryFactory geoFactory)
 {
     _geoFactory = geoFactory;
     initClass(name);
     CollectionChangeEventHandler schemaChangedHandler = schemaChanged;
     //this.Tables.CollectionChanged += schemaChangedHandler;
     Relations.CollectionChanged += schemaChangedHandler;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphBuilder2"/> class.
        /// </summary>
        /// <param name="bidirectional">
        /// Specify if the graph must be build using both edges directions.
        /// </param>
        public PathFinder(bool bidirectional)
        {
            this.bidirectional = bidirectional;

            factory = null;
            strings = new List<ILineString>();
            graph   = new AdjacencyGraph<Coordinate, IEdge<Coordinate>>(true);
        }
 public UnionInteracting(IGeometry g0, IGeometry g1)
 {
     _g0 = g0;
     _g1 = g1;
     _geomFactory = g0.Factory;
     _interacts0 = new bool[g0.NumGeometries];
     _interacts1 = new bool[g1.NumGeometries];
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="geometries">
 /// The <c>Geometry</c>s for this <c>GeometryCollection</c>,
 /// or <c>null</c> or an empty array to create the empty
 /// point. Elements may be empty <c>Geometry</c>s,
 /// but not <c>null</c>s.
 /// </param>
 /// <param name="factory"></param>
 public GeometryCollection(IGeometry[] geometries, IGeometryFactory factory) : base(factory)
 {            
     if (geometries == null)             
         geometries = new IGeometry[] { };            
     if (HasNullElements(geometries))             
         throw new ArgumentException("geometries must not contain null elements");            
     this.geometries = geometries;
 }
Exemple #31
0
 public EnvelopeTest()
 {
     precisionModel  = new PrecisionModel(1);
     geometryFactory = new GeometryFactory(precisionModel, 0);
     reader          = new WKTReader(geometryFactory);
 }
Exemple #32
0
 /// <summary>
 /// Create a new convex hull construction for the input <see cref="Coordinate" /> array.
 /// </summary>
 /// <param name="pts"></param>
 /// <param name="geomFactory"></param>
 public ConvexHull(ICoordinate[] pts, IGeometryFactory geomFactory)
 {
     inputPts         = pts;
     this.geomFactory = geomFactory;
 }
Exemple #33
0
        /// <summary>
        /// Creates a shape from a record.
        /// </summary>
        /// <param name="recordNumber">The record number.</param>
        /// <param name="recordContents">The contents of the record.</param>
        /// <param name="factory">The factory used for geometry production.</param>
        /// <param name="metadata">The metadata.</param>
        /// <returns>The shape created from the record data.</returns>
        /// <exception cref="System.ArgumentNullException">recordContents;The record contents are not specified.</exception>
        /// <exception cref="System.ArgumentException">
        /// Record contents length is less than 4 bytes.;recordContents
        /// or
        /// Record content is invalid.;recordContents
        /// </exception>
        public static Shape FromRecord(Int32 recordNumber, Byte[] recordContents, IGeometryFactory factory, IDictionary <String, Object> metadata)
        {
            if (recordContents == null)
            {
                throw new ArgumentNullException("recordContents", "The record contents are not specified.");
            }

            if (recordContents.Length < 4)
            {
                throw new ArgumentException("Record contents length is less than 4 bytes.", "recordContents");
            }

            ShapeType shapeType = (ShapeType)EndianBitConverter.ToInt32(recordContents, 0);

            if (shapeType == ShapeType.Null)
            {
                throw new ArgumentException("Record content is invalid.", "recordContents");
            }

            try
            {
                Int32           coordinateCount, partCount;
                Int32[]         parts       = null;
                ShapePartType[] partTypes   = null;
                Coordinate[]    coordinates = null;
                switch (shapeType)
                {
                case ShapeType.Point:
                case ShapeType.PointM:
                    return(new Shape(recordNumber, shapeType, EndianBitConverter.ToCoordinate(recordContents, 4, 2), factory, metadata));

                case ShapeType.PointZ:
                    return(new Shape(recordNumber, shapeType, EndianBitConverter.ToCoordinate(recordContents, 4, 3), factory, metadata));

                case ShapeType.MultiPoint:
                case ShapeType.MultiPointM:
                    coordinateCount = EndianBitConverter.ToInt32(recordContents, 36);
                    coordinates     = new Coordinate[coordinateCount];
                    for (Int32 i = 0; i < coordinateCount; i++)
                    {
                        coordinates[i] = EndianBitConverter.ToCoordinate(recordContents, 40 + i * 16, 2);
                    }
                    return(new Shape(recordNumber, shapeType, coordinates, factory, metadata));

                case ShapeType.MultiPointZ:
                    coordinateCount = EndianBitConverter.ToInt32(recordContents, 36);
                    coordinates     = new Coordinate[coordinateCount];
                    for (Int32 i = 0; i < coordinateCount; i++)
                    {
                        coordinates[i] = new Coordinate(EndianBitConverter.ToDouble(recordContents, 40 + i * 16), EndianBitConverter.ToDouble(recordContents, 48 + i * 16), EndianBitConverter.ToDouble(recordContents, 48 + coordinateCount * 24 + i * 8));
                    }
                    return(new Shape(recordNumber, shapeType, coordinates, factory, metadata));

                case ShapeType.PolyLine:
                case ShapeType.PolyLineM:
                case ShapeType.Polygon:
                case ShapeType.PolygonM:
                    partCount       = EndianBitConverter.ToInt32(recordContents, 36);
                    coordinateCount = EndianBitConverter.ToInt32(recordContents, 40);
                    parts           = new Int32[partCount];
                    for (Int32 i = 0; i < partCount; i++)
                    {
                        parts[i] = EndianBitConverter.ToInt32(recordContents, 44 + 4 * i);
                    }
                    coordinates = new Coordinate[coordinateCount];
                    for (Int32 i = 0; i < coordinateCount; i++)
                    {
                        coordinates[i] = EndianBitConverter.ToCoordinate(recordContents, 44 + partCount * 4 + i * 16, 2);
                    }
                    return(new Shape(recordNumber, shapeType, coordinates, parts, factory, metadata));

                case ShapeType.PolyLineZ:
                case ShapeType.PolygonZ:
                    partCount       = EndianBitConverter.ToInt32(recordContents, 36);
                    coordinateCount = EndianBitConverter.ToInt32(recordContents, 40);
                    parts           = new Int32[partCount];
                    for (Int32 i = 0; i < partCount; i++)
                    {
                        parts[i] = EndianBitConverter.ToInt32(recordContents, 44 + 4 * i);
                    }
                    coordinates = new Coordinate[coordinateCount];
                    for (Int32 i = 0; i < coordinateCount; i++)
                    {
                        coordinates[i] = new Coordinate(EndianBitConverter.ToDouble(recordContents, 44 + partCount * 4 + i * 16), EndianBitConverter.ToDouble(recordContents, 52 + partCount * 4 + i * 16), EndianBitConverter.ToDouble(recordContents, 60 + partCount * 4 + coordinateCount * 24 + i * 8));
                    }
                    return(new Shape(recordNumber, shapeType, coordinates, parts, factory, metadata));

                case ShapeType.MultiPatch:
                    partCount       = EndianBitConverter.ToInt32(recordContents, 36);
                    coordinateCount = EndianBitConverter.ToInt32(recordContents, 40);
                    parts           = new Int32[partCount];
                    for (Int32 i = 0; i < partCount; i++)
                    {
                        parts[i] = EndianBitConverter.ToInt32(recordContents, 44 + 4 * i);
                    }
                    partTypes = new ShapePartType[partCount];
                    for (Int32 i = 0; i < partCount; i++)
                    {
                        partTypes[i] = (ShapePartType)EndianBitConverter.ToInt32(recordContents, 44 + 4 * partCount + 4 * i);
                    }
                    coordinates = new Coordinate[coordinateCount];
                    for (Int32 i = 0; i < coordinateCount; i++)
                    {
                        coordinates[i] = new Coordinate(EndianBitConverter.ToDouble(recordContents, 44 + partCount * 8 + i * 16), EndianBitConverter.ToDouble(recordContents, 52 + partCount * 8 + i * 16), EndianBitConverter.ToDouble(recordContents, 60 + partCount * 8 + coordinateCount * 24 + i * 8));
                    }
                    return(new Shape(recordNumber, shapeType, coordinates, parts, partTypes, factory, metadata));

                default:
                    throw new ArgumentException();
                }
            }
            catch
            {
                throw new ArgumentException("Record content is invalid.", "recordContents");
            }
        }
Exemple #34
0
 /// <summary>
 /// Releases all managed resources
 /// </summary>
 protected override void ReleaseManagedResources()
 {
     Factory = null;
     base.ReleaseManagedResources();
 }
Exemple #35
0
 /// <summary>
 /// Initialize reader with the given <c>GeometryFactory</c>.
 /// </summary>
 /// <param name="factory"></param>
 public WKBReader(IGeometryFactory factory)
 {
     this.factory = factory;
 }
Exemple #36
0
 public ShapefileWriter(IGeometryFactory geometryFactory, string filename, ShapeGeometryType geomType)
     : this(geometryFactory, new ShapefileStreamProviderRegistry(filename, false, false, false), geomType)
 {
 }
Exemple #37
0
 /// <summary>
 /// Initialize reader with the given <see cref="IGeometryFactory"/>.
 /// </summary>
 public GMLReader(IGeometryFactory factory)
 {
     _factory = factory;
 }
 /// <summary>
 /// Gets the faces of the computed triangulation as a <see cref="IGeometryCollection"/>
 /// of <see cref="Polygon"/>.
 /// </summary>
 /// <param name="geomFact">the geometry factory to use to create the output</param>
 /// <returns>the faces of the triangulation</returns>
 public IGeometryCollection GetTriangles(IGeometryFactory geomFact)
 {
     Create();
     return(_subdiv.GetTriangles(geomFact));
 }
Exemple #39
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="factory"></param>
 public EdgeRing(IGeometryFactory factory)
 {
     _factory = factory;
 }
 /// <summary>
 /// Gets the edges of the computed triangulation as a <see cref="IMultiLineString"/>.
 /// </summary>
 /// <param name="geomFact">The geometry factory to use to create the output</param>
 /// <returns>the edges of the triangulation</returns>
 public IMultiLineString GetEdges(IGeometryFactory geomFact)
 {
     Create();
     return(_subdiv.GetEdges(geomFact));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="start"></param>
 /// <param name="geometryFactory"></param>
 public MinimalEdgeRing(DirectedEdge start, IGeometryFactory geometryFactory)
     : base(start, geometryFactory)
 {
 }
 public void Setup()
 {
     _factory = new GeometryFactory();
 }
Exemple #43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MultiPoint" /> class.
 /// </summary>
 /// <param name="factory">The factory of the multi point.</param>
 /// <param name="metadata">The metadata.</param>
 /// <exception cref="System.ArgumentNullException">The factory is null.</exception>
 /// <exception cref="System.ArgumentException">The specified factory is invalid.</exception>
 public MultiPoint(IGeometryFactory factory, IDictionary <String, Object> metadata)
     : base(factory, metadata)
 {
 }
Exemple #44
0
 /// <summary>
 /// Writes to the given stream the equilivent shape file record given a Geometry object.
 /// </summary>
 /// <param name="geometry">The geometry object to write.</param>
 /// <param name="writer">The writer to use.</param>
 /// <param name="factory">The geometry factory to use.</param>
 public abstract void Write(IGeometry geometry, BinaryWriter writer, IGeometryFactory factory);
Exemple #45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShapefileWriter" /> class
 /// with the given <see cref="GeometryFactory" />.
 /// </summary>
 /// <param name="geometryFactory"></param>
 public ShapefileWriter(IGeometryFactory geometryFactory)
 {
     Factory = geometryFactory;
 }
Exemple #46
0
 /// <summary>
 /// Creates an instance of this class. The <see cref="ConnectionID"/> is set to <see cref="String.Empty"/>,
 /// the spatial reference id to <paramref name="srid"/> and an appropriate factory is chosen.
 /// </summary>
 /// <param name="srid">The spatial reference id</param>
 protected BaseProvider(int srid)
 {
     ConnectionID = string.Empty;
     SRID         = srid;
     Factory      = GeometryServiceProvider.Instance.CreateGeometryFactory(SRID);
 }
Exemple #47
0
 /// <summary>
 /// Reads a stream and converts the shapefile record to an equilivent geometry object.
 /// </summary>
 /// <param name="file">The stream to read.</param>
 /// <param name="totalRecordLength">Total number of total bytes in the record to read.</param>
 /// <param name="factory">The geometry factory to use when making the object.</param>
 /// <returns>The Geometry object that represents the shape file record.</returns>
 public abstract IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory factory);
Exemple #48
0
        /// <summary>
        /// Reads a stream and converts the shapefile record to an equilivent geometry object.
        /// </summary>
        /// <param name="file">The stream to read.</param>
        /// <param name="totalRecordLength">Total length of the record we are about to read</param>
        /// <param name="factory">The geometry factory to use when making the object.</param>
        /// <returns>The Geometry object that represents the shape file record.</returns>
        public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory factory)
        {
            int totalRead = 0;
            var type      = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead);

            if (type == ShapeGeometryType.NullShape)
            {
                return(factory.CreateMultiLineString(null));
            }

            if (type != ShapeType)
            {
                throw new ShapefileException(string.Format("Encountered a '{0}' instead of a  '{1}'", type, ShapeType));
            }

            // Read and for now ignore bounds.
            int bblength = GetBoundingBoxLength();

            boundingBox = new double[bblength];
            for (; boundingBoxIndex < 4; boundingBoxIndex++)
            {
                double d = ReadDouble(file, totalRecordLength, ref totalRead);
                boundingBox[boundingBoxIndex] = d;
            }

            int numParts  = ReadInt32(file, totalRecordLength, ref totalRead);
            int numPoints = ReadInt32(file, totalRecordLength, ref totalRead);

            int[] partOffsets = new int[numParts];
            for (int i = 0; i < numParts; i++)
            {
                partOffsets[i] = ReadInt32(file, totalRecordLength, ref totalRead);
            }

            var lines  = new List <ILineString>(numParts);
            var buffer = new CoordinateBuffer(numPoints, NoDataBorderValue, true);
            var pm     = factory.PrecisionModel;

            for (var part = 0; part < numParts; part++)
            {
                var start  = partOffsets[part];
                var finish = part == numParts - 1
                                 ? numPoints
                                 : partOffsets[part + 1];
                var length = finish - start;

                for (var i = 0; i < length; i++)
                {
                    var x = pm.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
                    var y = pm.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
                    buffer.AddCoordinate(x, y);
                }
                buffer.AddMarker();
            }

            // Trond Benum: We have now read all the parts, let's read optional Z and M values
            // and populate Z in the coordinate before we start manipulating the segments
            // We have to track corresponding optional M values and set them up in the
            // Geometries via ICoordinateSequence further down.
            GetZMValues(file, totalRecordLength, ref totalRead, buffer);

            var sequences = new List <ICoordinateSequence>(buffer.ToSequences(factory.CoordinateSequenceFactory));

            for (var s = 0; s < sequences.Count; s++)
            {
                var points = sequences[s];

                //Skip garbage input data with 0 points
                if (points.Count < 1)
                {
                    continue;
                }

                var createLineString = true;
                if (points.Count == 1)
                {
                    switch (GeometryInstantiationErrorHandling)
                    {
                    case GeometryInstantiationErrorHandlingOption.ThrowException:
                        break;

                    case GeometryInstantiationErrorHandlingOption.Empty:
                        sequences[s] = factory.CoordinateSequenceFactory.Create(0, points.Ordinates);
                        break;

                    case GeometryInstantiationErrorHandlingOption.TryFix:
                        sequences[s] = AddCoordinateToSequence(points, factory.CoordinateSequenceFactory,
                                                               points.GetOrdinate(0, Ordinate.X), points.GetOrdinate(0, Ordinate.Y),
                                                               points.GetOrdinate(0, Ordinate.Z), points.GetOrdinate(0, Ordinate.M));
                        break;

                    case GeometryInstantiationErrorHandlingOption.Null:
                        createLineString = false;
                        break;
                    }
                }

                if (createLineString)
                {
                    // Grabs m values if we have them
                    var line = factory.CreateLineString(points);
                    lines.Add(line);
                }
            }

            geom = (lines.Count != 1)
                ? (IGeometry)factory.CreateMultiLineString(lines.ToArray())
                : lines[0];
            return(geom);
        }
Exemple #49
0
 public GeometryCombiner(ICollection <IGeometry> geoms)
 {
     geomFactory = ExtractFactory(geoms);
     inputGeoms  = geoms;
 }
Exemple #50
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            this.axRenderControl1.Camera.NearClipPlane = 0.1f;
            this.axRenderControl1.Camera.AutoClipPlane = false;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            // 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                dataset = ds.OpenFeatureDataset(setnames[0]);
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            //bool hasfly = false;
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, null, rootId);

                    //if (!hasfly)
                    //{
                    //    IFieldInfoCollection fieldinfos = fc.GetFields();
                    //    IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                    //    IGeometryDef geometryDef = fieldinfo.GeometryDef;
                    //    IEnvelope env = geometryDef.Envelope;
                    //    if (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                    //        env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)
                    //        continue;
                    //    IEulerAngle angle = new EulerAngle();
                    //    angle.Set(0, -20, 0);
                    //    this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    //}
                    //hasfly = true;
                }
            }

            geoFactory               = new GeometryFactory();
            positionPoint            = geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
            positionPoint.SpatialCRS = dataset.SpatialReference;

            // 加载仪表盘
            string modelNameBiaoPan = (strMediaPath + @"\osg\Dashboard\yibiaopan.osg");

            fdepoint_biaopan           = (IModelPoint)geoFactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ);
            fdepoint_biaopan.ModelName = modelNameBiaoPan;
            fdepoint_biaopan.SetCoords(biaoPanX, biaoPanY, biaoPanZ, 0, 0);
            fdepoint_biaopan.SpatialCRS = dataset.SpatialReference;
            render_biaopan = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(fdepoint_biaopan, null, rootId);
            // 加载指针
            string modelNameZhiZhen = (strMediaPath + @"\osg\Dashboard\zhizhen.osg");

            fdepoint_ZhiZhen           = (IModelPoint)geoFactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ);
            fdepoint_ZhiZhen.ModelName = modelNameZhiZhen;
            fdepoint_ZhiZhen.SetCoords(biaoPanX, biaoPanY, biaoPanZ + 0.01, 0, 0);
            fdepoint_ZhiZhen.SpatialCRS = dataset.SpatialReference;
            render_ZhiZhen = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(fdepoint_ZhiZhen, null, rootId);
            // 加载文字标签
            IVector3 positionLabel = new Vector3();

            positionLabel.Set(biaoPanX, biaoPanY, biaoPanZ + 0.1);
            positionPoint.Position = positionLabel;
            label          = this.axRenderControl1.ObjectManager.CreateLabel(rootId);
            label.Text     = "当前的压力值是:" + zhiZhenValue.ToString();
            label.Position = positionPoint;
            ITextSymbol   textSymbol    = new TextSymbol();
            TextAttribute textAttribute = new TextAttribute();

            textAttribute.TextColor      = System.Drawing.Color.Black;
            textAttribute.TextSize       = 30;
            textAttribute.Font           = "宋体";
            textSymbol.TextAttribute     = textAttribute;
            textSymbol.MaxVisualDistance = 3;
            label.TextSymbol             = textSymbol;
            // 飞入表盘
            IEulerAngle angle_camera = new EulerAngle();

            angle_camera.Set(0, -45, 0);
            this.axRenderControl1.Camera.LookAt2(positionPoint, 2, angle_camera);

            // 注册鼠标单击事件
            this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect);


            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "DynamicBoard.html";
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="op"></param>
 /// <param name="geometryFactory"></param>
 /// <param name="ptLocator"></param>
 public LineBuilder(OverlayOp op, IGeometryFactory geometryFactory, PointLocator ptLocator)
 {
     this.op = op;
     this.geometryFactory = geometryFactory;
     this.ptLocator       = ptLocator;
 }
Exemple #52
0
 protected BaseSamples(IGeometryFactory factory, WKTReader reader)
 {
     Factory = factory;
     Reader  = reader;
 }
Exemple #53
0
 protected GeometryWriter(IGeometryFactory factory)
     : base(factory)
 {
 }
Exemple #54
0
 protected BaseSamples(IGeometryFactory factory) : this(factory, new WKTReader(factory))
 {
 }
Exemple #55
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Shape" /> class.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <exception cref="System.ArgumentNullException">The geometry is null.</exception>
        /// <exception cref="System.ArgumentException">Geometry type is not supported by stream.</exception>
        public Shape(IGeometry geometry)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry", "The geometry is null.");
            }

            _factory = geometry.Factory;

            if (geometry.Metadata != null)
            {
                _metadata = new Dictionary <String, Object>(geometry.Metadata);
            }

            if (geometry is IPoint)
            {
                _type        = geometry.SpatialDimension == 3 ? ShapeType.PointZ : ShapeType.Point;
                _coordinates = new Coordinate[] { (geometry as IPoint).Coordinate };
            }
            else if (geometry is ILine)
            {
                _type        = geometry.SpatialDimension == 3 ? ShapeType.PolyLineZ : ShapeType.PolyLine;
                _coordinates = new Coordinate[] { (geometry as ILine).StartCoordinate, (geometry as ILine).EndCoordinate };
                _parts       = new Int32[] { 0 };
            }
            else if (geometry is ILineString)
            {
                _type        = geometry.SpatialDimension == 3 ? ShapeType.PolyLineZ : ShapeType.PolyLine;
                _coordinates = (geometry as ILineString).Coordinates.ToArray();
                _parts       = new Int32[] { 0 };
            }
            else if (geometry is IPolygon)
            {
                IPolygon sourcePolygon = geometry as IPolygon;

                _type = geometry.SpatialDimension == 3 ? ShapeType.PolygonZ : ShapeType.Polygon;

                List <Coordinate> coordinates = new List <Coordinate>();
                List <Int32>      parts       = new List <Int32>()
                {
                };

                parts.Add(coordinates.Count);
                coordinates.AddRange(sourcePolygon.Shell.Coordinates);

                foreach (ILinearRing linearRing in sourcePolygon.Holes)
                {
                    parts.Add(coordinates.Count);
                    coordinates.AddRange(linearRing.Coordinates);
                }

                _coordinates = coordinates.ToArray();
                _parts       = parts.ToArray();
            }
            else if (geometry is IMultiPoint)
            {
                _type        = geometry.CoordinateDimension == 3 ? ShapeType.MultiPointZ : ShapeType.MultiPoint;
                _coordinates = (geometry as IMultiPoint).Select(point => point.Centroid).ToArray();
            }
            else if (geometry is IMultiPolygon)
            {
                IMultiPolygon sourceMultiPolygon = geometry as IMultiPolygon;

                _type = geometry.SpatialDimension == 3 ? ShapeType.PolygonZ : ShapeType.Polygon;

                List <Coordinate> coordinates = new List <Coordinate>();
                List <Int32>      parts       = new List <Int32>()
                {
                };

                foreach (IPolygon polygon in sourceMultiPolygon)
                {
                    parts.Add(coordinates.Count);
                    coordinates.AddRange(polygon.Shell.Coordinates);

                    foreach (ILinearRing linearRing in polygon.Holes)
                    {
                        parts.Add(coordinates.Count);
                        coordinates.AddRange(linearRing.Coordinates);
                    }
                }

                _coordinates = coordinates.ToArray();
                _parts       = parts.ToArray();

                /*
                 * _type = ShapeType.MultiPatch;
                 *
                 * IMultiPolygon multiPolygon = geometry as IMultiPolygon;
                 * _parts = new Int32[multiPolygon.Sum(polygon => polygon.HoleCount + 1)];
                 * _partTypes = new ShapePartType[multiPolygon.Sum(polygon => polygon.HoleCount + 1)];
                 *
                 * Int32 partIndex = 0;
                 * Int32 coordinateIndex = 0;
                 * List<Coordinate> coordinateList = new List<Coordinate>(multiPolygon.Sum(polygon => polygon.Shell.Count + polygon.Holes.Sum(hole => hole.Count)));
                 *
                 * foreach (IPolygon polygon in multiPolygon)
                 * {
                 *  _parts[partIndex] = coordinateIndex;
                 *  _partTypes[partIndex] = ShapePartType.OuterRing;
                 *  coordinateList.AddRange(polygon.Shell.Coordinates);
                 *
                 *  partIndex++;
                 *  coordinateIndex += polygon.Shell.Count;
                 *
                 *  foreach (ILinearRing hole in polygon.Holes)
                 *  {
                 *      _parts[partIndex] = coordinateIndex;
                 *      _partTypes[partIndex] = ShapePartType.InnerRing;
                 *      coordinateList.AddRange(hole.Coordinates);
                 *
                 *      partIndex++;
                 *      coordinateIndex += hole.Count;
                 *  }
                 * }
                 *
                 * _coordinates = coordinateList.ToArray();
                 */
            }

            else
            {
                throw new ArgumentException(String.Format("Geometry type {0} is not supported by stream.", geometry.Name), "geometry");
            }

            _envelope = Envelope.FromCoordinates(Coordinates);
        }
Exemple #56
0
 /// <summary>
 /// Create a new polygonization graph.
 /// </summary>
 /// <param name="factory"></param>
 public PolygonizeGraph(IGeometryFactory factory)
 {
     _factory = factory;
 }
Exemple #57
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Shape" /> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="type">The type.</param>
        /// <param name="coordinates">The coordinates.</param>
        /// <param name="parts">The parts.</param>
        /// <param name="partTypes">The types of the parts.</param>
        /// <param name="factory">The factory used for geometry production.</param>
        /// <param name="metadata">The metadata.</param>
        /// <exception cref="System.ArgumentNullException">
        /// There are no coordinates specified.
        /// or
        /// There are no parts specified.
        /// or
        /// There are no part types specified.
        /// or
        /// The factory is null.
        /// </exception>
        public Shape(Int32 id, ShapeType type, Coordinate[] coordinates, Int32[] parts, ShapePartType[] partTypes, IGeometryFactory factory, IDictionary <String, Object> metadata)
        {
            if (coordinates == null)
            {
                throw new ArgumentNullException("coordinates", "There are no coordinates specified.");
            }
            if (parts == null)
            {
                throw new ArgumentNullException("parts", "There are no parts specified.");
            }
            if (partTypes == null)
            {
                throw new ArgumentNullException("partTypes", "There are no part types specified.");
            }
            if (factory == null)
            {
                throw new ArgumentNullException("factory", "The factory is null.");
            }

            _id          = id;
            _type        = type;
            _parts       = parts;
            _partTypes   = partTypes;
            _coordinates = coordinates;
            _envelope    = Envelope.FromCoordinates(Coordinates);
            _factory     = factory;
            _metadata    = metadata;
        }
Exemple #58
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MultiPoint" /> class.
 /// </summary>
 /// <param name="source">The source of points.</param>
 /// <param name="factory">The factory of the multi point.</param>
 /// <param name="metadata">The metadata.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The factory is null.
 /// or
 /// The source is null.
 /// </exception>
 /// <exception cref="System.ArgumentException">The specified factory is invalid.</exception>
 public MultiPoint(IEnumerable <IPoint> source, IGeometryFactory factory, IDictionary <String, Object> metadata)
     : base(source, factory, metadata)
 {
 }
Exemple #59
0
 /// <summary>
 /// Creates a LineString with the same coordinates as this segment
 /// </summary>
 /// <param name="geomFactory">the geometery factory to use</param>
 /// <returns>A LineString with the same geometry as this segment</returns>
 public ILineString ToGeometry(IGeometryFactory geomFactory)
 {
     return(geomFactory.CreateLineString(new[] { _p0, _p1 }));
 }
Exemple #60
0
 /// <summary>
 /// Initialize reader with the given <c>GeometryFactory</c>.
 /// </summary>
 /// <param name="factory"></param>
 public PostGisReader(IGeometryFactory factory)
 {
     this.factory = factory;
 }