Beispiel #1
0
        private MultiLineString CreateMLS1()
        {
            Coordinates coords = new Coordinates();
            Coordinate coord = new Coordinate();
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            LineString lineString = gf.CreateLineString(coords);
            LineString[] ls = new LineString[10];
            int c = 0;
            for(int i = 10; i > 0; i--)
            {
                for(int j = i; j < i+10; j++)
                {
                    coord = new Coordinate();
                    coord.X = (double)j;
                    coord.Y = (double)j+5;
                    coords.Add(coord);
                }
                lineString = gf.CreateLineString(coords);
                ls[c] = lineString;
                c++;
            }
            MultiLineString multiLS = gf.CreateMultiLineString(ls);

            return multiLS;
        }
Beispiel #2
0
        private MultiLineString nonSimpleMLS()
        {
            Coordinates coords = new Coordinates();
            Coordinate coord = new Coordinate();
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            LineString lineString = gf.CreateLineString(coords);
            LineString[] ls = new LineString[1];

            coord = new Coordinate(2, 2);
            coords.Add(coord);
            coord = new Coordinate(3, 3);
            coords.Add(coord);
            coord = new Coordinate(4, 4);
            coords.Add(coord);
            coord = new Coordinate(5, 5);
            coords.Add(coord);
            coord = new Coordinate(6, 6);
            coords.Add(coord);
            coord = new Coordinate(7, 7);
            coords.Add(coord);
            coord = new Coordinate(8, 8);
            coords.Add(coord);
            coord = new Coordinate(9, 7);
            coords.Add(coord);
            coord = new Coordinate(10, 6);
            coords.Add(coord);
            coord = new Coordinate(10, 5);
            coords.Add(coord);
            coord = new Coordinate(9, 4);
            coords.Add(coord);
            coord = new Coordinate(8, 3);
            coords.Add(coord);
            coord = new Coordinate(7, 4);
            coords.Add(coord);
            coord = new Coordinate(7, 5);
            coords.Add(coord);
            coord = new Coordinate(6, 6);
            coords.Add(coord);
            coord = new Coordinate(5, 7);
            coords.Add(coord);
            coord = new Coordinate(4, 8);
            coords.Add(coord);
            coord = new Coordinate(3, 9);
            coords.Add(coord);
            ls[0] = gf.CreateLineString(coords);

            MultiLineString multiLS = gf.CreateMultiLineString(ls);

            return multiLS;
        }
Beispiel #3
0
        public void test_NumPoints()
        {
            //create a geomerty collection
            MultiLineString multiLS = CreateMLS();

            Assertion.AssertEquals("NumPoints-1: ", 100, multiLS.GetNumPoints());

            //now try it with a null geometry collection
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            multiLS = gf.CreateMultiLineString(null);

            Assertion.AssertEquals("NumPoints-2: ", 0, multiLS.GetNumPoints());

            //now try it with a different geometry collection
            multiLS = closedMLS();

            Assertion.AssertEquals("NumPoints-3: ", 30, multiLS.GetNumPoints());

            //now try it with a mixed geometry collection
            multiLS = nonSimpleMLS();

            Assertion.AssertEquals("NumPoints-4: ", 18, multiLS.GetNumPoints());
        }
Beispiel #4
0
        private MultiLineString closedMLS()
        {
            Coordinates coords = new Coordinates();
            Coordinate coord = new Coordinate();
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            LineString lineString = gf.CreateLineString(coords);
            LineString[] ls = new LineString[2];

            coord = new Coordinate(10, 13);
            coords.Add(coord);
            coord = new Coordinate(11, 13);
            coords.Add(coord);
            coord = new Coordinate(12, 13);
            coords.Add(coord);
            coord = new Coordinate(13, 14);
            coords.Add(coord);
            coord = new Coordinate(14, 15);
            coords.Add(coord);
            coord = new Coordinate(15, 16);
            coords.Add(coord);
            coord = new Coordinate(15, 17);
            coords.Add(coord);
            coord = new Coordinate(15, 18);
            coords.Add(coord);
            coord = new Coordinate(14, 19);
            coords.Add(coord);
            coord = new Coordinate(13, 20);
            coords.Add(coord);
            coord = new Coordinate(12, 21);
            coords.Add(coord);
            coord = new Coordinate(11, 21);
            coords.Add(coord);
            coord = new Coordinate(10, 21);
            coords.Add(coord);
            coord = new Coordinate(9, 20);
            coords.Add(coord);
            coord = new Coordinate(8, 19);
            coords.Add(coord);
            coord = new Coordinate(7, 18);
            coords.Add(coord);
            coord = new Coordinate(7, 17);
            coords.Add(coord);
            coord = new Coordinate(7, 16);
            coords.Add(coord);
            coord = new Coordinate(8, 15);
            coords.Add(coord);
            coord = new Coordinate(9, 14);
            coords.Add(coord);
            coord = new Coordinate(10, 13);
            coords.Add(coord);
            ls[0] = gf.CreateLineString(coords);

            coords = new Coordinates();
            coord = new Coordinate(5, 1);
            coords.Add(coord);
            coord = new Coordinate(6, 2);
            coords.Add(coord);
            coord = new Coordinate(7, 3);
            coords.Add(coord);
            coord = new Coordinate(6, 4);
            coords.Add(coord);
            coord = new Coordinate(5, 5);
            coords.Add(coord);
            coord = new Coordinate(4, 4);
            coords.Add(coord);
            coord = new Coordinate(3, 3);
            coords.Add(coord);
            coord = new Coordinate(4, 2);
            coords.Add(coord);
            coord = new Coordinate(5, 1);
            coords.Add(coord);
            ls[1] = gf.CreateLineString(coords);

            MultiLineString multiLS = gf.CreateMultiLineString(ls);

            return multiLS;
        }
Beispiel #5
0
        public void test_IsEmpty()
        {
            //create a geomerty collection
            MultiLineString multiLS = CreateMLS();

            Assertion.AssertEquals("IsEmpty-1: ", false, multiLS.IsEmpty());

            //now try it with a null geometry collection
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            multiLS = gf.CreateMultiLineString(null);

            Assertion.AssertEquals("IsEmpty-2: ", true, multiLS.IsEmpty());

            //now try it with a different geometry collection
            multiLS = CreateMLS1();

            Assertion.AssertEquals("IsEmpty-3: ", false, multiLS.IsEmpty());

            //now try it again
            multiLS = closedMLS();

            Assertion.AssertEquals("IsEmpty-4: ", false, multiLS.IsEmpty());
        }
Beispiel #6
0
        public void test_IsSimple()
        {
            //create a geomerty collection
            MultiLineString multiLS = CreateMLS();

            Assertion.AssertEquals("IsSimple-1: ", false, multiLS.IsSimple());

            //now try it with a null geometry collection
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            multiLS = gf.CreateMultiLineString(null);

            Assertion.AssertEquals("IsSimple-2: ", true, multiLS.IsSimple());

            //now try it with a different geometry collection
            multiLS = CreateMLS1();

            //TODO: This is really slow!!!!!!!!!  Why?
            //Assertion.AssertEquals("IsSimple-3: ", false, multiLS.IsSimple());

            //now try it with a mixed geometry collection
            multiLS = nonSimpleMLS();

            Assertion.AssertEquals("IsSimple-4: ", false, multiLS.IsSimple());

            //now try it with a closed geometry collection
            multiLS = closedMLS();

            //TODO: Uncomment when IsSimple is working.
            Assertion.AssertEquals("IsSimple-5: ", true, multiLS.IsSimple());
        }
Beispiel #7
0
        public void test_Geometry()
        {
            LineString[] linestrings = new LineString[2];
            Coordinates coords1 = new Coordinates();
            Coordinate coord = new Coordinate(5,3);
            coords1.Add(coord);
            coord = new Coordinate(4,5);
            coords1.Add(coord);
            coord = new Coordinate(3,4);
            coords1.Add(coord);

            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            LineString ls = gf.CreateLineString(coords1);
            linestrings[0] = ls;

            Coordinates coords2 = new Coordinates();
            coord = new Coordinate(2,7);
            coords2.Add(coord);
            coord = new Coordinate(9,2);
            coords2.Add(coord);
            coord = new Coordinate(7,9);
            coords2.Add(coord);

            ls = gf.CreateLineString(coords2);
            linestrings[1] = ls;

            MultiLineString mls = gf.CreateMultiLineString(linestrings);

            Assertion.AssertEquals("Geometry-1: ", "LineString:(5, 3, NaN),(4, 5, NaN),(3, 4, NaN)", mls.GetGeometryN(0).ToString());
            Assertion.AssertEquals("Geometry-2: ", "LineString:(2, 7, NaN),(9, 2, NaN),(7, 9, NaN)", mls.GetGeometryN(1).ToString());
        }
Beispiel #8
0
        public void test_GetBoundaryDimension()
        {
            //create a multilinestring
            MultiLineString multiLS = CreateMLS();

            //this returns a zero because it is not closed
            Assertion.AssertEquals("GetBoundaryDimension-1: ", 0, multiLS.GetBoundaryDimension());

            //now try it with a null multilinestring
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            multiLS = gf.CreateMultiLineString(null);

            //this returns a zero because it is not closed
            Assertion.AssertEquals("GetBoundaryDimension-2: ", 0, multiLS.GetBoundaryDimension());

            //now try it with a closed multilinestring
            multiLS = closedMLS();

            //this returns a -1 because it is closed
            Assertion.AssertEquals("GetBoundaryDimension-3: ", -1, multiLS.GetBoundaryDimension());
        }
Beispiel #9
0
        public void test_EqualExact()
        {
            //create a geomerty collection
            MultiLineString multiLS1 = CreateMLS();
            //create another geometry collection that is null
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            MultiLineString multiLS2 = gf.CreateMultiLineString(null);
            //create another geometry collection that is different
            MultiLineString multiLS3 = CreateMLS1();
            //create another geometry collection that is different
            MultiLineString multiLS4 = closedMLS();
            //create another geometry collection that is the same as the first
            MultiLineString multiLS5 = CreateMLS();

            Assertion.AssertEquals("Equals-1: ", true , multiLS1.Equals(multiLS5));
            Assertion.AssertEquals("Equals-2: ", false, multiLS1.Equals(multiLS2));
            Assertion.AssertEquals("Equals-3: ", false, multiLS1.Equals(multiLS3));
            Assertion.AssertEquals("Equals-4: ", false, multiLS1.Equals(multiLS4));
        }
Beispiel #10
0
        public void test_Envelope()
        {
            //create a new collection
            MultiLineString multiLS = CreateMLS();

            //put the envelope into a geometry
            Geometry env = multiLS.GetEnvelope() as Geometry;

            //make sure there is something in the envelope
            Assertion.AssertEquals("Envelope-1: ", false, env.IsEmpty());

            Coordinates coords = env.GetCoordinates();
            //check the first set of coordinates (minX, minY)
            Assertion.AssertEquals("Envelope-2: ", 0.0, coords[0].X);
            Assertion.AssertEquals("Envelope-3: ", 5.0, coords[0].Y);

            //check the second set of coordinates (maxX, minY)
            Assertion.AssertEquals("Envelope-4: ", 18.0, coords[1].X);
            Assertion.AssertEquals("Envelope-5: ", 5.0, coords[1].Y);

            //check the third set of coordinates (maxX, maxY)
            Assertion.AssertEquals("Envelope-6: ", 18.0, coords[2].X);
            Assertion.AssertEquals("Envelope-7: ", 23.0, coords[2].Y);

            //check the forth set of coordinates (minX, maxY)
            Assertion.AssertEquals("Envelope-8: ", 0.0, coords[3].X);
            Assertion.AssertEquals("Envelope-9: ", 23.0, coords[3].Y);

            //check the fifth set of coordinates (minX, minY)
            Assertion.AssertEquals("Envelope-10: ", 0.0, coords[4].X);
            Assertion.AssertEquals("Envelope-11: ", 5.0, coords[4].Y);

            //create a null collection
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            multiLS = gf.CreateMultiLineString(null);

            //put the envelope into a geometry
            env = multiLS.GetEnvelope() as Geometry;

            //make sure there is something in the envelope
            Assertion.AssertEquals("Envelope-12: ", true, env.IsEmpty());
        }
Beispiel #11
0
        public void test_Coordinates()
        {
            //create a geomerty collection
            MultiLineString multiLS = CreateMLS();

            //this geometry conatins 10 sets of coordinates
            Assertion.AssertEquals("Coordinates-1: ", 100, multiLS.GetCoordinates().Count);

            //now try it with a null geometry collection
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
            multiLS = gf.CreateMultiLineString(null);

            Assertion.AssertEquals("Coordinates-2: ", 0, multiLS.GetCoordinates().Count);

            //now try it with a different geometry collection
            multiLS = CreateMLS1();

            //1000 sets of coordinates
            Assertion.AssertEquals("Cordinates-3: ", 1000, multiLS.GetCoordinates().Count);
        }
		/// <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 Geometry Read(BigEndianBinaryReader file, GeometryFactory geometryFactory)
		{
			int shapeTypeNum = file.ReadInt32();
			ShapeType shapeType = (ShapeType)Enum.Parse(typeof(ShapeType),shapeTypeNum.ToString());
			if (shapeType != ShapeType.Arc)
			{
				throw new ShapefileException("Attempting to load a non-arc as arc.");
			}
			//read and for now ignore bounds.
			double[] box = new double[4];
			for (int i = 0; i < 4; i++) 
			{
				double d= file.ReadDouble();
				box[i] =d;
			}


        
			int numParts = file.ReadInt32();
			int numPoints = file.ReadInt32();
			int[] partOffsets = new int[numParts];
			for (int i = 0; i < numParts; i++)
			{
				partOffsets[i] = file.ReadInt32();
			}
			
			LineString[] lines = new LineString[numParts];
			int start, finish, length;
			for (int part = 0; part < numParts; part++)
			{
				start = partOffsets[part];
				if (part == numParts - 1)
				{
					finish = numPoints;
				}
				else 
				{
					finish = partOffsets[part + 1];
				}
				length = finish - start;
				Coordinates points = new Coordinates();
				points.Capacity=length;
				Coordinate external;
				for (int i = 0; i < length; i++)
				{
					external = new Coordinate(file.ReadDouble(),file.ReadDouble());
					points.Add( geometryFactory.PrecisionModel.ToInternal(external));
				}
				lines[part] = geometryFactory.CreateLineString(points);

			}
			return geometryFactory.CreateMultiLineString(lines);
		}
		private MultiPolygon CreateMP1()
		{
			Polygon[] polygons = new Polygon[2];
			LineString[] rings = new LineString[2];

			Coordinates coords = new Coordinates();
			Coordinate coord = new Coordinate(5, 1);
			coords.Add(coord);
			coord = new Coordinate(6, 2);
			coords.Add(coord);
			coord = new Coordinate(7, 3);
			coords.Add(coord);
			coord = new Coordinate(6, 4);
			coords.Add(coord);
			coord = new Coordinate(5, 5);
			coords.Add(coord);
			coord = new Coordinate(4, 4);
			coords.Add(coord);
			coord = new Coordinate(3, 3);
			coords.Add(coord);
			coord = new Coordinate(4, 2);
			coords.Add(coord);
			coord = new Coordinate(5, 1);
			coords.Add(coord);

			GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            LinearRing exterior1 = gf.CreateLinearRing(coords);
			polygons[0] = gf.CreatePolygon(exterior1);
			rings[0] = exterior1 as LineString;

			coords = new Coordinates();
			coord = new Coordinate(5, 1);
			coords.Add(coord);
			coord = new Coordinate(6, 2);
			coords.Add(coord);
			coord = new Coordinate(7, 3);
			coords.Add(coord);
			coord = new Coordinate(6, 4);
			coords.Add(coord);
			coord = new Coordinate(5, 5);
			coords.Add(coord);
			coord = new Coordinate(4, 4);
			coords.Add(coord);
			coord = new Coordinate(3, 3);
			coords.Add(coord);
			coord = new Coordinate(4, 2);
			coords.Add(coord);
			coord = new Coordinate(5, 1);
			coords.Add(coord);

			LinearRing exterior2 = gf.CreateLinearRing(coords);
			polygons[1] = gf.CreatePolygon(exterior2);
			rings[1] = exterior2;

			_mls1 = gf.CreateMultiLineString(rings);

			return gf.CreateMultiPolygon(polygons);
		}