예제 #1
0
		/// <summary>
		/// Converts a GeometryCollection to &lt;GeometryCollection Tagged
		/// Text&gt; format, then Appends it to the writer.
		/// </summary>
		/// <param name="geometryCollection">The GeometryCollection to process</param>
		/// <param name="writer">The output stream writer to Append to.</param>
		protected void AppendGeometryCollectionTaggedText(GeometryCollection geometryCollection, TextWriter writer)
		{
			writer.Write("<g>");
			AppendGeometryCollectionText(geometryCollection,  writer);
			writer.Write("</g>");
		}
예제 #2
0
		/// <summary>
		/// Converts a GeometryCollection to &lt;GeometryCollection Text &gt; format, then Appends it to the writer.
		/// </summary>
		/// <param name="geometryCollection">The GeometryCollection to process.</param>
		/// <param name="writer">The output stream writer to Append to.</param>
		protected void AppendGeometryCollectionText(GeometryCollection geometryCollection, TextWriter writer)
		{	
			if (geometryCollection.IsEmpty()) 
			{
			}
			else 
			{
				for (int i = 0; i < geometryCollection.GetNumGeometries(); i++) 
				{
					AppendGeometryTaggedText(geometryCollection.GetGeometryN(i),  writer);
				}
			}			
		}
예제 #3
0
		/// <summary>
		/// Converts a GeometryCollection to &lt;GeometryCollection Tagged
		/// Text&gt; format, then Appends it to the writer.
		/// </summary>
		/// <param name="geometryCollection">The GeometryCollection to process</param>
		/// <param name="level"></param>
		/// <param name="writer">The output stream writer to Append to.</param>
		protected void AppendGeometryCollectionTaggedText(GeometryCollection geometryCollection, int level,
														  StringWriter writer)
		{
			
			writer.Write("GEOMETRYCOLLECTION ");
			AppendGeometryCollectionText(geometryCollection, level, writer);
			
		}
예제 #4
0
		/// <summary>
		/// Converts a GeometryCollection to &lt;GeometryCollection Text &gt; format, then Appends it to the writer.
		/// </summary>
		/// <param name="geometryCollection">The GeometryCollection to process.</param>
		/// <param name="level"></param>
		/// <param name="writer">The output stream writer to Append to.</param>
		protected void AppendGeometryCollectionText(GeometryCollection geometryCollection, int level,
													StringWriter writer)
		{
			
			if ( geometryCollection.IsEmpty() ) 
			{
				writer.Write("EMPTY");
			}
			else 
			{
				int level2 = level;
				writer.Write("(");
				for (int i = 0; i < geometryCollection.GetNumGeometries(); i++) 
				{
					if (i > 0) 
					{
						writer.Write(", ");
						level2 = level + 1;
					}
					//AppendGeometryTaggedText(geometryCollection.GetGeometryN(i), level2, writer);
					AppendGeometryTaggedText(geometryCollection.GetGeometryN(i), level2, writer);
				}
				writer.Write(")");
			}
			
		}
예제 #5
0
		/// <summary>
		/// Writes a geometrycollection.
		/// </summary>
		/// <param name="gc">The geometrycollection to be written.</param>
		private void WriteGeometryCollection(GeometryCollection gc, byte format)
		{
			//Get the number of geometries in this geometrycollection.
			int numGeometries = gc.GetNumGeometries();

			//Write the number of geometries.
			_bWriter.Write(numGeometries);

			//Loop on the number of geometries.
			for(int i = 0; i < numGeometries; i++)
			{
				//Write the type of each geometry.
				WriteType(gc[i]);

				//Write each geometry.
				WriteGeometry(gc[i], format);
			}
		}
		private bool HasRepeatedPoint(GeometryCollection gc)
		{	
			for (int i = 0; i < gc.GetNumGeometries(); i++) 
			{

				Geometry g = (Geometry)gc.GetGeometryN(i);
				if (HasRepeatedPoint(g)) return true;
			}
			return false;
		}
예제 #7
0
		private void AddCollection(GeometryCollection gc)
		{
			
			for (int i = 0; i < gc.GetNumGeometries(); i++) 
			{
				Geometry g = (Geometry)gc.GetGeometryN(i);
				Add(g);
			}
			
		}
예제 #8
0
		/// <summary>
		/// Writes a shapefile to disk.
		/// </summary>
		/// <remarks>
		/// <para>Assumes the type given for the first geometry is the same for all subsequent geometries.
		/// For example, is, if the first Geometry is a Multi-polygon/ Polygon, the subsequent geometies are
		/// Muli-polygon/ polygon and not lines or points.</para>
		/// <para>The dbase file for the corresponding shapefile contains one column called row. It contains 
		/// the row number.</para>
		/// </remarks>
		/// <param name="filename">The filename to write to (minus the .shp extension).</param>
		/// <param name="geometryCollection">The GeometryCollection to write.</param>
		/// <param name="geometryFactory">The geometry factory to use.</param>
		public static void Write(string filename, GeometryCollection geometryCollection, GeometryFactory geometryFactory)
		{
			System.IO.FileStream shpStream = new System.IO.FileStream(filename+".shp", System.IO.FileMode.Create);
			System.IO.FileStream shxStream = new System.IO.FileStream(filename+".shx", System.IO.FileMode.Create);
			BigEndianBinaryWriter shpBinaryWriter = new BigEndianBinaryWriter(shpStream);
			BigEndianBinaryWriter shxBinaryWriter = new BigEndianBinaryWriter(shxStream);
			
			// assumes
			ShapeHandler handler = Shapefile.GetShapeHandler(Shapefile.GetShapeType(geometryCollection[0]));

			Geometry body;
			int numShapes = geometryCollection.GetNumGeometries();
			// calc the length of the shp file, so it can put in the header.
			int shpLength =50;
			for (int i = 0; i < numShapes; i++) 
			{
				body = geometryCollection[i];
				shpLength += 4; // length of header in WORDS
				shpLength += handler.GetLength(body); // length of shape in WORDS
			}

			int shxLength = 50+ (4*numShapes);


			// write the .shp header
			ShapefileHeader shpHeader = new ShapefileHeader();
			shpHeader.FileLength = shpLength;

			// get envelopse in external coordinates
			Envelope env = geometryCollection.GetEnvelopeInternal();
			Envelope bounds = ShapeHandler.GetEnvelopeExternal(geometryFactory.PrecisionModel,  env);
			shpHeader.Bounds = bounds;


			// assumes Geometry type of the first item will the same for all other items
			// in the collection.
			shpHeader.ShapeType = Shapefile.GetShapeType( geometryCollection[0] );
			shpHeader.Write(shpBinaryWriter);

			// write the .shx header
			ShapefileHeader shxHeader = new ShapefileHeader();
			shxHeader.FileLength = shxLength;
			shxHeader.Bounds = shpHeader.Bounds;
			
			// assumes Geometry type of the first item will the same for all other items
			// in the collection.
			shxHeader.ShapeType = Shapefile.GetShapeType( geometryCollection[0] );
			shxHeader.Write(shxBinaryWriter);



			// write the individual records.
			int _pos = 50; // header length in WORDS
			for (int i = 0; i < numShapes; i++) 
			{
				body = geometryCollection[i];
				int recordLength = handler.GetLength(body);
				Debug.Assert( Shapefile.GetShapeType(body)!=shpHeader.ShapeType, String.Format("Item {0} in the GeometryCollection is not the same Shapetype as Item 0.",i));
				shpBinaryWriter.WriteIntBE(i+1);
				shpBinaryWriter.WriteIntBE(recordLength);
				
				
				shxBinaryWriter.WriteIntBE(_pos);
				shxBinaryWriter.WriteIntBE(recordLength);
				
				_pos += 4; // length of header in WORDS
				handler.Write(body, shpBinaryWriter,  geometryFactory);
				_pos += recordLength; // length of shape in WORDS
			}

			shxBinaryWriter.Flush();
			shxBinaryWriter.Close();
			shpBinaryWriter.Flush();
			shpBinaryWriter.Close();

			Debug.Assert(_pos!=shpLength,"File length in header and actual file length do not match.");
			//stream.Close();
			//Trace.WriteLineIf(Shapefile.TraceSwitch.Enabled,"File length pos:"+_pos*2+" bytes");
			//Trace.WriteLineIf(Shapefile.TraceSwitch.Enabled,"File length pos "+_pos+ " words");

			WriteDummyDbf(filename+".dbf", numShapes);	
		}
예제 #9
0
		private void CheckValid(GeometryCollection gc)
		{
			for (int i = 0; i < gc.GetNumGeometries(); i++) 
			{
				Geometry g = gc.GetGeometryN(i);
				CheckValid(g);
				if (_validErr != null) return;
			}
		}