Beispiel #1
0
        public void Overlaps()
        {
            var rnd     = new Random();
            var pg      = new Polygon[50];
            var pgcheck = new GeoAPI.Geometries.IPolygon[50];
            var gf      = new NetTopologySuite.Geometries.GeometryFactory();
            var center  = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            for (var i = 0; i < 50; i++)
            {
                var coord       = new Coordinate[36];
                var coordscheck = new GeoAPI.Geometries.Coordinate[36];
                for (var ii = 0; ii < 36; ii++)
                {
                    coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
                    var x = coord[ii].X;
                    var y = coord[ii].Y;
                    var c = new GeoAPI.Geometries.Coordinate(x, y);
                    coordscheck[ii] = c;
                }
                coord[35]       = new Coordinate(coord[0].X, coord[0].Y);
                coordscheck[35] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
                GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck);
                pgcheck[i] = gf.CreatePolygon(ring, null);
                pg[i]      = new Polygon(coord);
            }
            for (var t = 0; t < 49; t++)
            {
                var g      = pg[t].Overlaps(pg[t + 1]);
                var gcheck = pgcheck[t].Overlaps(pgcheck[t + 1]);
                Assert.AreEqual(g, gcheck);
            }
        }
Beispiel #2
0
        public void PolygonEnvelopeArea()
        {
            var coords      = new Coordinate[20];
            var rnd         = new Random();
            var center      = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
            var coordscheck = new GeoAPI.Geometries.Coordinate[20];

            for (var i = 0; i < 19; i++)
            {
                coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10);
                var x = coords[i].X;
                var y = coords[i].Y;
                var c = new GeoAPI.Geometries.Coordinate(x, y);
                coordscheck[i] = c;
            }
            coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y);
            coords[19]      = new Coordinate(coords[0].X, coords[0].Y);
            var gf = new NetTopologySuite.Geometries.GeometryFactory();

            GeoAPI.Geometries.ILinearRing ring    = gf.CreateLinearRing(coordscheck);
            GeoAPI.Geometries.IPolygon    pgcheck = gf.CreatePolygon(ring, null);
            var pg   = new Polygon(coords);
            var area = pg.Envelope.Area();

            AssertExt.AreEqual15(area, pgcheck.Envelope.Area);
        }
Beispiel #3
0
        public void Multipg()
        {
            var rnd     = new Random();
            var pg      = new Polygon[50];
            var pgcheck = new GeoAPI.Geometries.IPolygon[50];
            var gf      = new NetTopologySuite.Geometries.GeometryFactory();

            for (var i = 0; i < 50; i++)
            {
                var center      = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
                var coord       = new Coordinate[36];
                var coordscheck = new GeoAPI.Geometries.Coordinate[36];
                for (var ii = 0; ii < 36; ii++)
                {
                    coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
                    var x = coord[ii].X;
                    var y = coord[ii].Y;
                    var c = new GeoAPI.Geometries.Coordinate(x, y);
                    coordscheck[ii] = c;
                }
                coord[35]       = new Coordinate(coord[0].X, coord[0].Y);
                coordscheck[35] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
                var ring = gf.CreateLinearRing(coordscheck);
                pgcheck[i] = gf.CreatePolygon(ring, null);
                pg[i]      = new Polygon(coord);
            }
            var mpg      = new MultiPolygon(pg);
            var mpgcheck = gf.CreateMultiPolygon(pgcheck);

            for (var ii = 0; ii < mpg.Coordinates.Count; ii++)
            {
                Assert.AreEqual(mpg.Coordinates[ii].X, mpgcheck.Coordinates[ii].X);
                Assert.AreEqual(mpg.Coordinates[ii].Y, mpgcheck.Coordinates[ii].Y);
            }
        }
Beispiel #4
0
        public void PolygonCentroid()
        {
            var coords      = new Coordinate[20];
            var rnd         = new Random();
            var center      = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
            var coordscheck = new GeoAPI.Geometries.Coordinate[20];

            for (var i = 0; i < 19; i++)
            {
                coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10);
                var x = coords[i].X;
                var y = coords[i].Y;
                var c = new GeoAPI.Geometries.Coordinate(x, y);
                coordscheck[i] = c;
            }
            coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y);
            coords[19]      = new Coordinate(coords[0].X, coords[0].Y);
            var gf           = new NetTopologySuite.Geometries.GeometryFactory();
            var ring         = gf.CreateLinearRing(coordscheck);
            var polygonCheck = gf.CreatePolygon(ring, null);
            var pg           = new Polygon(coords);
            var x1           = pg.Centroid.X;
            var x2           = polygonCheck.Centroid.X;

            AssertExt.AreEqual15(x1, x2);
            var y1 = pg.Centroid.Y;
            var y2 = polygonCheck.Centroid.Y;

            AssertExt.AreEqual15(y1, y2);
        }
Beispiel #5
0
        public void PolygonArea()
        {
            var coords      = new Coordinate[20];
            var rnd         = new Random();
            var center      = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
            var coordscheck = new GeoAPI.Geometries.Coordinate[20];

            for (var i = 0; i < 19; i++)
            {
                coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10);
                var x = coords[i].X;
                var y = coords[i].Y;
                var c = new GeoAPI.Geometries.Coordinate(x, y);
                coordscheck[i] = c;
            }
            coordscheck[19] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
            coords[19]      = new Coordinate(coords[0].X, coords[0].Y);
            var gf           = new NetTopologySuite.Geometries.GeometryFactory();
            var ring         = gf.CreateLinearRing(coordscheck);
            var polygonCheck = gf.CreatePolygon(ring, null);
            var pg           = new Polygon(coords);
            var areaCheck    = polygonCheck.Area;
            var area         = pg.Area;

            Assert.IsTrue(Math.Abs(area - areaCheck) < 1e-6);
        }
Beispiel #6
0
        /// <summary>
        /// Get an array of parcels within the specified filter.
        /// Will not return sensitive parcels unless the user has the `sensitive-view` claim and belongs to the owning agency.
        /// </summary>
        /// <param name="neLat"></param>
        /// <param name="neLong"></param>
        /// <param name="swLat"></param>
        /// <param name="swLong"></param>
        /// <returns></returns>
        public IEnumerable <Parcel> Get(double neLat, double neLong, double swLat, double swLong)
        {
            this.User.ThrowIfNotAuthorized(Permissions.PropertyView);
            // Check if user has the ability to view sensitive properties.
            var userAgencies  = this.User.GetAgenciesAsNullable();
            var viewSensitive = this.User.HasPermission(Security.Permissions.SensitiveView);
            var isAdmin       = this.User.HasPermission(Permissions.AdminProperties);

            // Users may only view sensitive properties if they have the `sensitive-view` claim and belong to the owning agency.
            var query = this.Context.Parcels.AsNoTracking().Where(p =>
                                                                  (isAdmin ||
                                                                   p.IsVisibleToOtherAgencies ||
                                                                   ((!p.IsSensitive || viewSensitive) &&
                                                                    userAgencies.Contains(p.AgencyId))));

            var pfactory = new NetTopologySuite.Geometries.GeometryFactory();
            var ring     = new NetTopologySuite.Geometries.LinearRing(
                new[] {
                new NetTopologySuite.Geometries.Coordinate(neLong, neLat),
                new NetTopologySuite.Geometries.Coordinate(swLong, neLat),
                new NetTopologySuite.Geometries.Coordinate(swLong, swLat),
                new NetTopologySuite.Geometries.Coordinate(neLong, swLat),
                new NetTopologySuite.Geometries.Coordinate(neLong, neLat)
            });
            var poly = pfactory.CreatePolygon(ring);

            poly.SRID = 4326;
            query     = query.Where(p => poly.Contains(p.Location));

            return(query.ToArray());
        }
Beispiel #7
0
        public void PolygonHoles()
        {
            var coords = new Coordinate[20];
            var rnd    = new Random();
            var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            // Shell Coordinates
            var coordscheck = new GeoAPI.Geometries.Coordinate[20];

            for (var i = 0; i < 19; i++)
            {
                var x = center.X + Math.Cos((i * 10) * Math.PI / 10);
                var y = center.Y + (i * 10) * Math.PI / 10;
                coords[i]      = new Coordinate(x, y);
                coordscheck[i] = new GeoAPI.Geometries.Coordinate(x, y);
            }
            coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y);
            coords[19]      = new Coordinate(coords[0].X, coords[0].Y);


            // Shell Rings
            var ring      = new LinearRing(coords);
            var gf        = new NetTopologySuite.Geometries.GeometryFactory();
            var ringCheck = gf.CreateLinearRing(coordscheck);


            // Hole Coordinates
            var coordsholecheck = new GeoAPI.Geometries.Coordinate[20];
            var coordshole      = new Coordinate[20];

            for (var i = 0; i < 20; i++)
            {
                var x = center.X + Math.Cos((i * 10) * Math.PI / 20);
                var y = center.Y + (i * 10) * Math.PI / 20;
                coordshole[i]      = new Coordinate(x, y);
                coordsholecheck[i] = new GeoAPI.Geometries.Coordinate(x, y);
            }
            coordshole[19]      = new Coordinate(coordshole[0].X, coordshole[0].Y);
            coordsholecheck[19] = new GeoAPI.Geometries.Coordinate(coordshole[0].X, coordshole[0].Y);

            // Hole LinearRing Arrays
            var hole       = new LinearRing(coordshole);
            var holes      = new ILinearRing[1];
            var holeCheck  = gf.CreateLinearRing(coordsholecheck);
            var holescheck = new GeoAPI.Geometries.ILinearRing[1];

            holes[0]      = hole;
            holescheck[0] = holeCheck;


            var pg           = new Polygon(ring, holes);
            var polygonCheck = gf.CreatePolygon(ringCheck, holescheck);
            var areaCheck    = polygonCheck.Area;
            var area         = pg.Area;

            Assert.IsTrue(Math.Abs(area - areaCheck) < 1e-6);
        }
Beispiel #8
0
        public void Intersection()
        {
            var rnd = new Random();
            var pg = new Polygon[50];
            var pgcheck = new GeoAPI.Geometries.IPolygon[50];
            var gf = new NetTopologySuite.Geometries.GeometryFactory();
            var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            for (var i = 0; i < 50; i++)
            {

                var coord = new Coordinate[36];
                var coordscheck = new GeoAPI.Geometries.Coordinate[36];
                for (var ii = 0; ii < 36; ii++)
                {
                    coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
                    var x = coord[ii].X;
                    var y = coord[ii].Y;
                    var c = new GeoAPI.Geometries.Coordinate(x, y);
                    coordscheck[ii] = c;
                }
                coord[35] = new Coordinate(coord[0].X, coord[0].Y);
                coordscheck[35] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
                GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck);
                pgcheck[i] = gf.CreatePolygon(ring, null);
                pg[i] = new Polygon(coord);

            }
            for (var t = 0; t < 49; t++)
            {
                var g = pg[t].Intersection(pg[t + 1]);
                var gcheck = pgcheck[t].Intersection(pgcheck[t + 1]);
                for (var j = 0; j < g.Coordinates.Count; j++)
                {
                    Assert.AreEqual(g.Coordinates[j].X, gcheck.Coordinates[j].X);
                    Assert.AreEqual(g.Coordinates[j].Y, gcheck.Coordinates[j].Y);
                }
            }
        }
 public void PolygonArea()
 {
     var coords = new Coordinate[20];
     var rnd = new Random();
     var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
     var coordscheck = new GeoAPI.Geometries.Coordinate[20];
     for (var i = 0; i < 19; i++)
     {
         coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10);
         var x = coords[i].X;
         var y = coords[i].Y;
         var c = new GeoAPI.Geometries.Coordinate(x, y);
         coordscheck[i] = c;
     }
     coordscheck[19] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
     coords[19] = new Coordinate(coords[0].X, coords[0].Y);
     var gf = new NetTopologySuite.Geometries.GeometryFactory();
     var ring = gf.CreateLinearRing(coordscheck);
     var polygonCheck = gf.CreatePolygon(ring, null);
     var pg = new Polygon(coords);
     var areaCheck = polygonCheck.Area;
     var area = pg.Area;
     Assert.IsTrue(Math.Abs(area - areaCheck) < 1e-6);
 }
Beispiel #10
0
        public static void Test()
        {
            string s1 = "POLYGON((7.5999034 47.5506347,7.5997595 47.5507183,7.5998959 47.5508256,7.5999759 47.5508885,7.6001195 47.550805,7.5999034 47.5506347))";
            string s2 = "POLYGON((7.6003356 47.5509754,7.6001195 47.550805,7.5999759 47.5508885,7.6000322 47.5509328,7.6001926 47.551059,7.6003356 47.5509754))";

            s1 = "POLYGON((7.5999034 47.5506347,7.6001195 47.550805,7.5999759 47.5508885,7.5998959 47.5508256,7.5997595 47.5507183,7.5999034 47.5506347))";
            s2 = "POLYGON((7.6003356 47.5509754,7.6001926 47.551059,7.6000322 47.5509328,7.5999759 47.5508885,7.6001195 47.550805,7.6003356 47.5509754))";


            // NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory
            // GeoAPI.Geometries.IGeometryFactory geoFactory = new NetTopologySuite.Geometries.GeometryFactory();


            NetTopologySuite.IO.WKTReader wr = new NetTopologySuite.IO.WKTReader();

            Wgs84Coordinates[] coords1 = PolygonParsingExtensions.PolygonStringToCoordinates(s1);
            Wgs84Coordinates[] coords2 = PolygonParsingExtensions.PolygonStringToCoordinates(s2);

            var lr = new NetTopologySuite.Geometries.LinearRing(coords1.ToNetTopologyCoordinates());

            System.Console.WriteLine(lr.IsValid);

            var x = new NetTopologySuite.Geometries.Polygon(new NetTopologySuite.Geometries.LinearRing(coords1.ToNetTopologyCoordinates()));

            System.Console.WriteLine(x.IsValid);

            NetTopologySuite.Geometries.GeometryFactory geomFactory = new NetTopologySuite.Geometries.GeometryFactory();

            GeoAPI.Geometries.IPolygon poly1 = geomFactory.CreatePolygon(coords1.ToNetTopologyCoordinates());
            GeoAPI.Geometries.IPolygon poly2 = geomFactory.CreatePolygon(coords2.ToNetTopologyCoordinates());



            /*
             * GeoAPI.Geometries.IPolygon poly1 = (GeoAPI.Geometries.IPolygon)wr.Read(s1);
             * GeoAPI.Geometries.IPolygon poly2 = (GeoAPI.Geometries.IPolygon)wr.Read(s2);
             */

            poly1.SRID = 4326;
            poly2.SRID = 4326;



            CalculateArea2(coords1);
            CalculateArea2(coords2);


            System.Console.WriteLine(poly1.Area);
            System.Console.WriteLine(poly2.Area);


            GeoAPI.Geometries.IPolygon poly3quick = (GeoAPI.Geometries.IPolygon)poly1.Union(poly2);
            System.Console.WriteLine(poly3quick.IsValid);

            // https://gis.stackexchange.com/questions/209797/how-to-get-geometry-points-using-geo-api
            System.Console.Write(poly1.IsValid);
            System.Console.Write(poly2.IsValid);


            System.Collections.Generic.List <GeoAPI.Geometries.IGeometry> lsPolygons =
                new System.Collections.Generic.List <GeoAPI.Geometries.IGeometry>();

            lsPolygons.Add(poly1);
            lsPolygons.Add(poly2);


            GeoAPI.Geometries.IGeometry ig = NetTopologySuite.Operation.Union.CascadedPolygonUnion.Union(lsPolygons);
            System.Console.WriteLine(ig.GetType().FullName);

            GeoAPI.Geometries.IPolygon poly3 = (GeoAPI.Geometries.IPolygon)ig;
            System.Console.WriteLine(poly3);

            // POLYGON ((7.5997595 47.5507183, 7.5999034 47.5506347, 7.6001195 47.550805, 7.6003356 47.5509754
            // , 7.6001926 47.551059, 7.6000322 47.5509328, 7.5999759 47.5508885
            // , 7.5998959 47.5508256, 7.5997595 47.5507183))

            System.Console.WriteLine(poly3.Shell.Coordinates);


            /*
             * // GeoAPI.Geometries.IPolygon poly3 = (GeoAPI.Geometries.IPolygon)ig;
             * NetTopologySuite.Geometries.MultiPolygon poly3a = (NetTopologySuite.Geometries.MultiPolygon)ig;
             * GeoAPI.Geometries.IGeometry ig2 = poly3a.ConvexHull();
             * System.Console.WriteLine(ig2.GetType().FullName);
             */

            // GeoAPI.Geometries.IPolygon poly4 = (GeoAPI.Geometries.IPolygon)ig2;
            // System.Console.WriteLine(poly4);


            System.Console.WriteLine("--- Press any key to continue --- ");
            System.Console.ReadKey();
        } // End Sub Test
Beispiel #11
0
        public static void TestUnion()
        {
            string s1 = "POLYGON((8.3038582 47.0506309,8.3038611 47.050588,8.3038772 47.0504833,8.3041581 47.0505083,8.3041532 47.0506229,8.303965 47.0506089,8.3039616 47.0506342,8.3038582 47.0506309))";
            string s2 = "POLYGON((8.3041532 47.0506229,8.3041581 47.0505083,8.3042898 47.0505392,8.3042879 47.050571,8.3042854 47.0506139,8.3041532 47.0506229))";
            string s3 = "POLYGON((8.3042879 47.050571,8.30442 47.05058,8.3044327 47.0507439,8.3043001 47.0507637,8.3042885 47.0506777,8.3042854 47.0506139,8.3042879 47.050571))";
            string s4 = "POLYGON((8.304174 47.050784,8.3041695 47.0507507,8.3041592 47.0506835,8.3041585 47.0506448,8.3042166 47.0506438,8.3042225 47.0506777,8.3042885 47.0506777,8.3043001 47.0507637,8.304174 47.050784))";


            Wgs84Coordinates[] coords1 = PolygonParsingExtensions.PolygonStringToCoordinates(s1);
            Wgs84Coordinates[] coords2 = PolygonParsingExtensions.PolygonStringToCoordinates(s2);
            Wgs84Coordinates[] coords3 = PolygonParsingExtensions.PolygonStringToCoordinates(s3);
            Wgs84Coordinates[] coords4 = PolygonParsingExtensions.PolygonStringToCoordinates(s4);


            NetTopologySuite.Geometries.GeometryFactory geomFactory = new NetTopologySuite.Geometries.GeometryFactory();

            GeoAPI.Geometries.IPolygon poly1 = geomFactory.CreatePolygon(coords1.ToNetTopologyCoordinates());
            GeoAPI.Geometries.IPolygon poly2 = geomFactory.CreatePolygon(coords2.ToNetTopologyCoordinates());
            GeoAPI.Geometries.IPolygon poly3 = geomFactory.CreatePolygon(coords3.ToNetTopologyCoordinates());
            GeoAPI.Geometries.IPolygon poly4 = geomFactory.CreatePolygon(coords4.ToNetTopologyCoordinates());



            System.Collections.Generic.List <GeoAPI.Geometries.IGeometry> lsPolygons =
                new System.Collections.Generic.List <GeoAPI.Geometries.IGeometry>();

            lsPolygons.Add(poly1);
            lsPolygons.Add(poly2);
            lsPolygons.Add(poly3);
            lsPolygons.Add(poly4);


            GeoAPI.Geometries.IGeometry ig = NetTopologySuite.Operation.Union.CascadedPolygonUnion.Union(lsPolygons);
            System.Console.WriteLine(ig.GetType().FullName);

            GeoAPI.Geometries.IPolygon unionPolygon = (GeoAPI.Geometries.IPolygon)ig;
            System.Console.WriteLine(poly3);
            System.Console.WriteLine(unionPolygon.Shell.Coordinates);


            System.Collections.Generic.List <Wgs84Coordinates> coords = new System.Collections.Generic.List <Wgs84Coordinates>();

            for (int i = 0; i < unionPolygon.Shell.Coordinates.Length; ++i)
            {
                coords.Add(new Wgs84Coordinates(unionPolygon.Shell.Coordinates[i].X, unionPolygon.Shell.Coordinates[i].Y));
            }


            coords = PolygonParsingExtensions.ToCounterClockWise(coords);


            // Close polygon if unclosed
            if (coords[0].Latitude != coords[coords.Count - 1].Latitude || coords[0].Longitude != coords[coords.Count - 1].Longitude)
            {
                coords.Add(coords[0]);
            }

            string insertString = @"
DECLARE @GB_UID AS uniqueidentifier;
DECLARE @SO_UID AS uniqueidentifier;

SET @GB_UID = NULLIF('abc', '');
SET @SO_UID = NULLIF('', '');


DELETE FROM T_ZO_Objekt_Wgs84Polygon WHERE ZO_OBJ_WGS84_GB_UID = @GB_UID; 


/*
INSERT INTO T_ZO_Objekt_Wgs84Polygon
(
     ZO_OBJ_WGS84_UID
    ,ZO_OBJ_WGS84_GB_UID
    ,ZO_OBJ_WGS84_SO_UID
    ,ZO_OBJ_WGS84_Sort
    ,ZO_OBJ_WGS84_GM_Lat
    ,ZO_OBJ_WGS84_GM_Lng
)
*/";


            for (int i = 0; i < coords.Count; ++i)
            {
                if (i != 0)
                {
                    insertString += " \r\n\r\n\r\nUNION ALL \r\n\r\n";
                }



                insertString += $@"
SELECT
     NEWID() AS ZO_OBJ_WGS84_UID
    ,CAST(@GB_UID AS uniqueidentifier) AS ZO_OBJ_WGS84_GB_UID
    ,CAST(@SO_UID AS uniqueidentifier) AS ZO_OBJ_WGS84_SO_UID
    ,CAST({i.ToString(System.Globalization.CultureInfo.InvariantCulture)} AS integer) + 1 AS ZO_OBJ_WGS84_Sort
    ,{coords[i].Latitude.ToString(System.Globalization.CultureInfo.InvariantCulture)} AS ZO_OBJ_WGS84_GM_Lat -- decimal(23, 20)
    ,{coords[i].Longitude.ToString(System.Globalization.CultureInfo.InvariantCulture)} AS ZO_OBJ_WGS84_GM_Lng -- decimal(23, 20) ";
            }



            insertString += " \r\n; \r\n\r\n";
            System.Console.WriteLine(insertString);

            System.Console.WriteLine("--- Press any key to continue --- ");
            System.Console.ReadKey();
        }
 public void PolygonShellEndPoint()
 {
     var coords = new Coordinate[20];
     var rnd = new Random();
     var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
     var coordscheck = new GeoAPI.Geometries.Coordinate[20];
     for (var i = 0; i < 19; i++)
     {
         coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10);
         var x = coords[i].X;
         var y = coords[i].Y;
         var c = new GeoAPI.Geometries.Coordinate(x, y);
         coordscheck[i] = c;
     }
     coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y);
     coords[19] = new Coordinate(coords[0].X, coords[0].Y);
     var gf = new NetTopologySuite.Geometries.GeometryFactory();
     var ring = gf.CreateLinearRing(coordscheck);
     var polygonCheck = gf.CreatePolygon(ring, null);
     var pg = new Polygon(coords);
     AssertExt.AreEqual15(pg.Shell.EndPoint.X, polygonCheck.Shell.EndPoint.X);
     AssertExt.AreEqual15(pg.Shell.EndPoint.Y, polygonCheck.Shell.EndPoint.Y);
 }
Beispiel #13
0
        /// <summary>
        /// Generate a query for the specified 'filter'.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="user"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public static IQueryable <Entity.Views.Property> GenerateQuery(this PimsContext context, ClaimsPrincipal user, Entity.Models.AllPropertyFilter filter)
        {
            filter.ThrowIfNull(nameof(filter));
            filter.ThrowIfNull(nameof(user));

            // Check if user has the ability to view sensitive properties.
            var userAgencies  = user.GetAgenciesAsNullable();
            var viewSensitive = user.HasPermission(Permissions.SensitiveView);
            var isAdmin       = user.HasPermission(Permissions.AdminProperties);

            // Users may only view sensitive properties if they have the `sensitive-view` claim and belong to the owning agency.
            var query = context.Properties
                        .AsNoTracking()
                        .Where(p => p.ClassificationId != 4); // Disposed properties are not visible.

            // Only allowed to see user's own agency properties.
            if (!isAdmin)
            {
                query = query.Where(p => p.IsVisibleToOtherAgencies || userAgencies.Contains(p.AgencyId));
            }
            if (!viewSensitive)
            {
                query = query.Where(p => !p.IsSensitive);
            }

            if (filter.PropertyType.HasValue)
            {
                query = query.Where(p => p.PropertyTypeId == filter.PropertyType);
            }

            if (filter.NELatitude.HasValue && filter.NELongitude.HasValue && filter.SWLatitude.HasValue && filter.SWLongitude.HasValue)
            {
                var pfactory = new NetTopologySuite.Geometries.GeometryFactory();
                var ring     = new NetTopologySuite.Geometries.LinearRing(
                    new[] {
                    new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.NELatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.SWLongitude.Value, filter.NELatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.SWLongitude.Value, filter.SWLatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.SWLatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.NELatitude.Value)
                });
                var poly = pfactory.CreatePolygon(ring);
                poly.SRID = 4326;
                query     = query.Where(p => poly.Contains(p.Location));
            }

            if (filter.Agencies?.Any() == true)
            {
                // Get list of sub-agencies for any agency selected in the filter.
                var filterAgencies = filter.Agencies.Select(a => (int?)a);
                var agencies       = filterAgencies.Concat(context.Agencies.AsNoTracking().Where(a => filterAgencies.Contains(a.Id)).SelectMany(a => a.Children.Select(ac => (int?)ac.Id)).ToArray()).Distinct();
                query = query.Where(p => agencies.Contains(p.AgencyId));
            }
            if (filter.ParcelId.HasValue)
            {
                query = query.Where(p => p.ParcelId == filter.ParcelId);
            }
            if (filter.ClassificationId.HasValue)
            {
                query = query.Where(p => p.ClassificationId == filter.ClassificationId);
            }
            if (!String.IsNullOrWhiteSpace(filter.ProjectNumber))
            {
                query = query.Where(p => EF.Functions.Like(p.ProjectNumber, $"{filter.ProjectNumber}%"));
            }
            if (filter.IgnorePropertiesInProjects == true)
            {
                query = query.Where(p => p.ProjectNumber == null);
            }
            if (filter.InSurplusPropertyProgram == true)
            {
                query = query.Where(p => !String.IsNullOrWhiteSpace(p.ProjectNumber));
            }
            if (!String.IsNullOrWhiteSpace(filter.Description))
            {
                query = query.Where(p => EF.Functions.Like(p.Description, $"%{filter.Description}%"));
            }

            if (!String.IsNullOrWhiteSpace(filter.PID))
            {
                var pidValue = filter.PID.Replace("-", "").Trim();
                if (Int32.TryParse(pidValue, out int pid))
                {
                    query = query.Where(p => p.PID == pid || p.PIN == pid);
                }
            }
            if (!String.IsNullOrWhiteSpace(filter.AdministrativeArea))
            {
                query = query.Where(p => EF.Functions.Like(p.AdministrativeArea, $"%{filter.AdministrativeArea}%"));
            }
            if (!String.IsNullOrWhiteSpace(filter.Zoning))
            {
                query = query.Where(p => EF.Functions.Like(p.Zoning, $"%{filter.Zoning}%"));
            }
            if (!String.IsNullOrWhiteSpace(filter.ZoningPotential))
            {
                query = query.Where(p => EF.Functions.Like(p.ZoningPotential, $"%{filter.ZoningPotential}%"));
            }

            if (filter.ConstructionTypeId.HasValue)
            {
                query = query.Where(p => p.BuildingConstructionTypeId == filter.ConstructionTypeId);
            }
            if (filter.PredominateUseId.HasValue)
            {
                query = query.Where(p => p.BuildingPredominateUseId == filter.PredominateUseId);
            }
            if (filter.FloorCount.HasValue)
            {
                query = query.Where(p => p.BuildingFloorCount == filter.FloorCount);
            }
            if (!String.IsNullOrWhiteSpace(filter.Tenancy))
            {
                query = query.Where(p => EF.Functions.Like(p.BuildingTenancy, $"%{filter.Tenancy}%"));
            }

            if (!String.IsNullOrWhiteSpace(filter.Address))
            {
                query = query.Where(p => EF.Functions.Like(p.Address, $"%{filter.Address}%") || EF.Functions.Like(p.AdministrativeArea, $"%{filter.Address}%"));
            }

            if (filter.MinLandArea.HasValue)
            {
                query = query.Where(p => p.LandArea >= filter.MinLandArea);
            }
            if (filter.MaxLandArea.HasValue)
            {
                query = query.Where(b => b.LandArea <= filter.MaxLandArea);
            }

            if (filter.MinRentableArea.HasValue)
            {
                query = query.Where(p => p.RentableArea >= filter.MinRentableArea);
            }
            if (filter.MaxRentableArea.HasValue)
            {
                query = query.Where(b => b.RentableArea <= filter.MaxRentableArea);
            }

            if (filter.MinEstimatedValue.HasValue)
            {
                query = query.Where(p => p.Estimated >= filter.MinEstimatedValue);
            }
            if (filter.MaxEstimatedValue.HasValue)
            {
                query = query.Where(p => p.Estimated <= filter.MaxEstimatedValue);
            }

            if (filter.MinAssessedValue.HasValue)
            {
                query = query.Where(p => p.Assessed >= filter.MinAssessedValue);
            }
            if (filter.MaxAssessedValue.HasValue)
            {
                query = query.Where(p => p.Assessed <= filter.MaxAssessedValue);
            }

            if (filter.InEnhancedReferralProcess.HasValue && filter.InEnhancedReferralProcess.Value)
            {
                var statuses = context.Workflows.Where(w => w.Code == "ERP")
                               .SelectMany(w => w.Status).Where(x => !x.Status.IsTerminal)
                               .Select(x => x.StatusId).Distinct().ToArray();

                query = query.Where(property =>
                                    context.Projects.Any(project =>
                                                         statuses.Any(st => st == project.StatusId) &&
                                                         project.ProjectNumber == property.ProjectNumber));
            }

            if (filter.Sort?.Any() == true)
            {
                query = query.OrderByProperty(filter.Sort);
            }
            else
            {
                query = query.OrderBy(p => p.AgencyCode).ThenBy(p => p.PID).ThenBy(p => p.PIN).ThenBy(p => p.PropertyTypeId);
            }


            return(query);
        }
Beispiel #14
0
        /// <summary>
        /// Get an array of parcels within the specified filter.
        /// Will not return sensitive parcels unless the user has the `sensitive-view` claim and belongs to the owning agency.
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public Paged <Parcel> Get(ParcelFilter filter)
        {
            filter.ThrowIfNull(nameof(filter));
            this.User.ThrowIfNotAuthorized(Permissions.SystemAdmin, Permissions.AgencyAdmin);

            if (filter.Page < 1)
            {
                throw new ArgumentException("Argument must be greater than or equal to 1.", nameof(filter.Page));
            }
            if (filter.Quantity < 1)
            {
                throw new ArgumentException("Argument must be greater than or equal to 1.", nameof(filter.Quantity));
            }

            // Check if user has the ability to view sensitive properties.
            var userAgencies  = this.User.GetAgenciesAsNullable();
            var viewSensitive = this.User.HasPermission(Security.Permissions.SensitiveView);

            // Users may only view sensitive properties if they have the `sensitive-view` claim and belong to the owning agency.
            var query = this.Context.Parcels.AsNoTracking();

            if (filter.NELatitude.HasValue && filter.NELongitude.HasValue && filter.SWLatitude.HasValue && filter.SWLongitude.HasValue)
            {
                var pfactory = new NetTopologySuite.Geometries.GeometryFactory();
                var ring     = new NetTopologySuite.Geometries.LinearRing(
                    new[] {
                    new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.NELatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.SWLongitude.Value, filter.NELatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.SWLongitude.Value, filter.SWLatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.SWLatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.NELatitude.Value)
                });
                var poly = pfactory.CreatePolygon(ring);
                poly.SRID = 4326;
                query     = query.Where(p => poly.Contains(p.Location));
            }

            if (filter.Agencies?.Any() == true)
            {
                var filterAgencies = filter.Agencies.Select(a => (int?)a);
                query = query.Where(p => filterAgencies.Contains(p.AgencyId));
            }
            if (filter.ClassificationId.HasValue)
            {
                query = query.Where(p => p.ClassificationId == filter.ClassificationId);
            }
            if (!String.IsNullOrWhiteSpace(filter.ProjectNumber))
            {
                query = query.Where(p => EF.Functions.Like(p.ProjectNumber, $"{filter.ProjectNumber}%"));
            }
            if (!String.IsNullOrWhiteSpace(filter.Description))
            {
                query = query.Where(p => EF.Functions.Like(p.Description, $"%{filter.Description}%"));
            }
            if (!String.IsNullOrWhiteSpace(filter.AdministrativeArea))
            {
                query = query.Where(p => EF.Functions.Like(p.Address.AdministrativeArea, $"%{filter.AdministrativeArea}%"));
            }
            if (!String.IsNullOrWhiteSpace(filter.Zoning))
            {
                query = query.Where(p => EF.Functions.Like(p.Zoning, $"%{filter.Zoning}%"));
            }
            if (!String.IsNullOrWhiteSpace(filter.ZoningPotential))
            {
                query = query.Where(p => EF.Functions.Like(p.ZoningPotential, $"%{filter.ZoningPotential}%"));
            }

            // TODO: Parse the address information by City, Postal, etc.
            if (!String.IsNullOrWhiteSpace(filter.Address))
            {
                query = query.Where(p => EF.Functions.Like(p.Address.Address1, $"%{filter.Address}%") || EF.Functions.Like(p.Address.AdministrativeArea, $"%{filter.Address}%"));
            }

            if (filter.MinLandArea.HasValue)
            {
                query = query.Where(p => p.LandArea >= filter.MinLandArea);
            }
            if (filter.MaxLandArea.HasValue)
            {
                query = query.Where(p => p.LandArea <= filter.MaxLandArea);
            }

            // TODO: Review performance of the evaluation query component.
            if (filter.MinEstimatedValue.HasValue)
            {
                query = query.Where(p =>
                                    filter.MinEstimatedValue <= p.Fiscals
                                    .FirstOrDefault(e => e.FiscalYear == this.Context.ParcelFiscals
                                                    .Where(pe => pe.ParcelId == p.Id && e.Key == FiscalKeys.Estimated)
                                                    .Max(pe => pe.FiscalYear))
                                    .Value);
            }
            if (filter.MaxEstimatedValue.HasValue)
            {
                query = query.Where(p =>
                                    filter.MaxEstimatedValue >= p.Fiscals
                                    .FirstOrDefault(e => e.FiscalYear == this.Context.ParcelFiscals
                                                    .Where(pe => pe.ParcelId == p.Id && e.Key == FiscalKeys.Estimated)
                                                    .Max(pe => pe.FiscalYear))
                                    .Value);
            }

            // TODO: Review performance of the evaluation query component.
            if (filter.MinAssessedValue.HasValue)
            {
                query = query.Where(p =>
                                    filter.MinAssessedValue <= p.Evaluations
                                    .FirstOrDefault(e => e.Date == this.Context.ParcelEvaluations
                                                    .Where(pe => pe.ParcelId == p.Id && e.Key == EvaluationKeys.Assessed)
                                                    .Max(pe => pe.Date))
                                    .Value);
            }
            if (filter.MaxAssessedValue.HasValue)
            {
                query = query.Where(p =>
                                    filter.MaxAssessedValue >= p.Evaluations
                                    .FirstOrDefault(e => e.Date == this.Context.ParcelEvaluations
                                                    .Where(pe => pe.ParcelId == p.Id && e.Key == EvaluationKeys.Assessed)
                                                    .Max(pe => pe.Date))
                                    .Value);
            }

            if (filter.Sort?.Any() == true)
            {
                query = query.OrderByProperty(filter.Sort);
            }

            var pagedEntities = query.Skip((filter.Page - 1) * filter.Quantity).Take(filter.Quantity);

            return(new Paged <Parcel>(pagedEntities, filter.Page, filter.Quantity, query.Count()));
        }
Beispiel #15
0
        /// <summary>
        /// Generate a query for the specified 'filter'.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="user"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public static IQueryable <Entity.Parcel> GenerateQuery(this PimsContext context, ClaimsPrincipal user, Entity.Models.ParcelFilter filter)
        {
            filter.ThrowIfNull(nameof(user));
            filter.ThrowIfNull(nameof(filter));

            // Check if user has the ability to view sensitive properties.
            var userAgencies  = user.GetAgenciesAsNullable();
            var viewSensitive = user.HasPermission(Permissions.SensitiveView);
            var isAdmin       = user.HasPermission(Permissions.AdminProperties);

            // Users may only view sensitive properties if they have the `sensitive-view` claim and belong to the owning agency.
            var query = context.Parcels.AsNoTracking();

            if (!isAdmin)
            {
                query = query.Where(p =>
                                    p.IsVisibleToOtherAgencies ||
                                    ((!p.IsSensitive || viewSensitive) &&
                                     userAgencies.Contains(p.AgencyId)));
            }

            if (filter.NELatitude.HasValue && filter.NELongitude.HasValue && filter.SWLatitude.HasValue && filter.SWLongitude.HasValue)
            {
                var pfactory = new NetTopologySuite.Geometries.GeometryFactory();
                var ring     = new NetTopologySuite.Geometries.LinearRing(
                    new[] {
                    new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.NELatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.SWLongitude.Value, filter.NELatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.SWLongitude.Value, filter.SWLatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.SWLatitude.Value),
                    new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.NELatitude.Value)
                });
                var poly = pfactory.CreatePolygon(ring);
                poly.SRID = 4326;
                query     = query.Where(p => poly.Contains(p.Location));
            }

            if (filter.Agencies?.Any() == true)
            {
                // Get list of sub-agencies for any agency selected in the filter.
                var filterAgencies = filter.Agencies.Select(a => (int?)a);
                var agencies       = filterAgencies.Concat(context.Agencies.AsNoTracking().Where(a => filterAgencies.Contains(a.Id)).SelectMany(a => a.Children.Select(ac => (int?)ac.Id)).ToArray()).Distinct();
                query = query.Where(p => agencies.Contains(p.AgencyId));
            }
            if (filter.ClassificationId.HasValue)
            {
                query = query.Where(p => p.ClassificationId == filter.ClassificationId);
            }
            if (!String.IsNullOrWhiteSpace(filter.ProjectNumber))
            {
                query = query.Where(p => EF.Functions.Like(p.ProjectNumber, $"{filter.ProjectNumber}%"));
            }
            if (!String.IsNullOrWhiteSpace(filter.Description))
            {
                query = query.Where(p => EF.Functions.Like(p.Description, $"%{filter.Description}%"));
            }
            if (!String.IsNullOrWhiteSpace(filter.AdministrativeArea))
            {
                query = query.Where(p => EF.Functions.Like(p.Address.AdministrativeArea, $"%{filter.AdministrativeArea}%"));
            }
            if (!String.IsNullOrWhiteSpace(filter.Zoning))
            {
                query = query.Where(p => EF.Functions.Like(p.Zoning, $"%{filter.Zoning}%"));
            }
            if (!String.IsNullOrWhiteSpace(filter.ZoningPotential))
            {
                query = query.Where(p => EF.Functions.Like(p.ZoningPotential, $"%{filter.ZoningPotential}%"));
            }

            // TODO: Parse the address information by City, Postal, etc.
            if (!String.IsNullOrWhiteSpace(filter.Address))
            {
                query = query.Where(p => EF.Functions.Like(p.Address.Address1, $"%{filter.Address}%") || EF.Functions.Like(p.Address.AdministrativeArea, $"%{filter.Address}%"));
            }

            if (filter.MinLandArea.HasValue)
            {
                query = query.Where(p => p.LandArea >= filter.MinLandArea);
            }
            if (filter.MaxLandArea.HasValue)
            {
                query = query.Where(p => p.LandArea <= filter.MaxLandArea);
            }

            // TODO: Review performance of the evaluation query component.
            if (filter.MinEstimatedValue.HasValue)
            {
                query = query.Where(p =>
                                    filter.MinEstimatedValue <= p.Fiscals
                                    .FirstOrDefault(e => e.FiscalYear == context.ParcelFiscals
                                                    .Where(pe => pe.ParcelId == p.Id && pe.Key == Entity.FiscalKeys.Estimated)
                                                    .Max(pe => pe.FiscalYear))
                                    .Value);
            }
            if (filter.MaxEstimatedValue.HasValue)
            {
                query = query.Where(p =>
                                    filter.MaxEstimatedValue >= p.Fiscals
                                    .FirstOrDefault(e => e.FiscalYear == context.ParcelFiscals
                                                    .Where(pe => pe.ParcelId == p.Id && pe.Key == Entity.FiscalKeys.Estimated)
                                                    .Max(pe => pe.FiscalYear))
                                    .Value);
            }

            // TODO: Review performance of the evaluation query component.
            if (filter.MinAssessedValue.HasValue)
            {
                query = query.Where(p =>
                                    filter.MinAssessedValue <= p.Evaluations
                                    .FirstOrDefault(e => e.Date == context.ParcelEvaluations
                                                    .Where(pe => pe.ParcelId == p.Id && pe.Key == Entity.EvaluationKeys.Assessed)
                                                    .Max(pe => pe.Date))
                                    .Value);
            }
            if (filter.MaxAssessedValue.HasValue)
            {
                query = query.Where(p =>
                                    filter.MaxAssessedValue >= p.Evaluations
                                    .FirstOrDefault(e => e.Date == context.ParcelEvaluations
                                                    .Where(pe => pe.ParcelId == p.Id && pe.Key == Entity.EvaluationKeys.Assessed)
                                                    .Max(pe => pe.Date))
                                    .Value);
            }

            if (filter.Sort?.Any() == true)
            {
                query = query.OrderByProperty(filter.Sort);
            }
            else
            {
                query = query.OrderBy(p => p.Id);
            }

            return(query);
        }
Beispiel #16
0
        public void Multipg()
        {
            var rnd = new Random();
            var pg = new Polygon[50];
            var pgcheck = new GeoAPI.Geometries.IPolygon[50];
            var gf = new NetTopologySuite.Geometries.GeometryFactory();
            for (var i = 0; i < 50; i++)
            {
                var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
                var coord = new Coordinate[36];
                var coordscheck = new GeoAPI.Geometries.Coordinate[36];
                for (var ii = 0; ii < 36; ii++)
                {
                    coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
                    var x = coord[ii].X;
                    var y = coord[ii].Y;
                    var c = new GeoAPI.Geometries.Coordinate(x, y);
                    coordscheck[ii] = c;
                }
                coord[35] = new Coordinate(coord[0].X, coord[0].Y);
                coordscheck[35] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
                var ring = gf.CreateLinearRing(coordscheck);
                pgcheck[i] = gf.CreatePolygon(ring, null);
                pg[i] = new Polygon(coord);

            }
            var mpg = new MultiPolygon(pg);
            var mpgcheck = gf.CreateMultiPolygon(pgcheck);
            for (var ii = 0; ii < mpg.Coordinates.Count; ii++)
            {
                Assert.AreEqual(mpg.Coordinates[ii].X, mpgcheck.Coordinates[ii].X);
                Assert.AreEqual(mpg.Coordinates[ii].Y, mpgcheck.Coordinates[ii].Y);
            }
        }
 public void PolygonEnvelopeMaxMin()
 {
     var coords = new Coordinate[20];
     var rnd = new Random();
     var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
     var coordscheck = new GeoAPI.Geometries.Coordinate[20];
     for (var i = 0; i < 19; i++)
     {
         coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10);
         var x = coords[i].X;
         var y = coords[i].Y;
         var c = new GeoAPI.Geometries.Coordinate(x, y);
         coordscheck[i] = c;
     }
     coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y);
     coords[19] = new Coordinate(coords[0].X, coords[0].Y);
     var gf = new NetTopologySuite.Geometries.GeometryFactory();
     GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck);
     GeoAPI.Geometries.IPolygon pgcheck = gf.CreatePolygon(ring, null);
     var pg = new Polygon(coords);
     AssertExt.AreEqual15(pg.Envelope.Maximum.X, pgcheck.EnvelopeInternal.MaxX);
     AssertExt.AreEqual15(pg.Envelope.Maximum.Y, pgcheck.EnvelopeInternal.MaxY);
     AssertExt.AreEqual15(pg.Envelope.Minimum.X, pgcheck.EnvelopeInternal.MinX);
     AssertExt.AreEqual15(pg.Envelope.Minimum.Y, pgcheck.EnvelopeInternal.MinY);
 }
        public void PolygonHoles()
        {
            var coords = new Coordinate[20];
            var rnd = new Random();
            var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            // Shell Coordinates
            var coordscheck = new GeoAPI.Geometries.Coordinate[20];
            for (var i = 0; i < 19; i++)
            {
                var x = center.X + Math.Cos((i * 10) * Math.PI / 10);
                var y = center.Y + (i * 10) * Math.PI / 10;
                coords[i] = new Coordinate(x, y);
                coordscheck[i] = new GeoAPI.Geometries.Coordinate(x, y);
            }
            coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y);
            coords[19] = new Coordinate(coords[0].X, coords[0].Y);


            // Shell Rings
            var ring = new LinearRing(coords);
            var gf = new NetTopologySuite.Geometries.GeometryFactory();
            var ringCheck = gf.CreateLinearRing(coordscheck);


            // Hole Coordinates
            var coordsholecheck = new GeoAPI.Geometries.Coordinate[20];
            var coordshole = new Coordinate[20];
            for (var i = 0; i < 20; i++)
            {
                var x = center.X + Math.Cos((i * 10) * Math.PI / 20);
                var y = center.Y + (i * 10) * Math.PI / 20;
                coordshole[i] = new Coordinate(x, y);
                coordsholecheck[i] = new GeoAPI.Geometries.Coordinate(x, y);
            }
            coordshole[19] = new Coordinate(coordshole[0].X, coordshole[0].Y);
            coordsholecheck[19] = new GeoAPI.Geometries.Coordinate(coordshole[0].X, coordshole[0].Y);

            // Hole LinearRing Arrays
            var hole = new LinearRing(coordshole);
            var holes = new ILinearRing[1];
            var holeCheck = gf.CreateLinearRing(coordsholecheck);
            var holescheck = new GeoAPI.Geometries.ILinearRing[1];
            holes[0] = hole;
            holescheck[0] = holeCheck;


            var pg = new Polygon(ring, holes);
            var polygonCheck = gf.CreatePolygon(ringCheck, holescheck);
            var areaCheck = polygonCheck.Area;
            var area = pg.Area;
            Assert.IsTrue(Math.Abs(area - areaCheck) < 1e-6);
        }
 public static IPolygon CreatePolygon(ILinearRing shell, ILinearRing[] holes)
 {
     return(geomFactory.CreatePolygon(shell, holes));
 }
        /// <summary>
        /// Converts the given OsmSharp feature into an NTS feature.
        /// </summary>
        /// <param name="feature"></param>
        /// <returns></returns>
        public static Feature Convert(OsmSharp.Geo.Features.Feature feature)
        {
            if (feature == null) { throw new ArgumentNullException("feature"); }

            var geometryFactory = new NetTopologySuite.Geometries.GeometryFactory();
            if(feature.Geometry is OsmSharp.Geo.Geometries.Polygon)
            { // a polygon.
                var polygon = (feature.Geometry as OsmSharp.Geo.Geometries.Polygon);
                var holes = polygon.Holes.Select((hole) => {
                    return (ILinearRing)geometryFactory.CreateLinearRing(hole.Coordinates.Select((coordinate) => {
                        return new Coordinate(coordinate.Longitude, coordinate.Latitude);
                    }).ToArray());
                }).ToArray();
                var shell = geometryFactory.CreateLinearRing(polygon.Ring.Coordinates.Select((coordinate) => {
                    return new Coordinate(coordinate.Longitude, coordinate.Latitude);
                }).ToArray());
                return new Feature(geometryFactory.CreatePolygon(shell, holes),
                    OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes));
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.LineairRing)
            { // a lineair ring.
                var lineairRing = (feature.Geometry as OsmSharp.Geo.Geometries.LineairRing);
                var coordinates = lineairRing.Coordinates.Select((coordinate) => {
                    return new Coordinate(coordinate.Longitude, coordinate.Latitude);
                });
                return new Feature(geometryFactory.CreateLinearRing(coordinates.ToArray()),
                    OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes));
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.LineString)
            { // a line string.
                var lineString = (feature.Geometry as OsmSharp.Geo.Geometries.LineString);
                var coordinates = lineString.Coordinates.Select((coordinate) =>
                {
                    return new Coordinate(coordinate.Longitude, coordinate.Latitude);
                });
                return new Feature(geometryFactory.CreateLineString(coordinates.ToArray()),
                    OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes));
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.Point)
            { // a point.
                var point = (feature.Geometry as OsmSharp.Geo.Geometries.Point);
                return new Feature(geometryFactory.CreatePoint(new Coordinate(point.Coordinate.Longitude, point.Coordinate.Latitude)),
                    OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes));
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.MultiLineString)
            { // a multi line string.
                throw new NotSupportedException("A MultiLineString is not supported.");
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.MultiPoint)
            { // a multi point.
                throw new NotSupportedException("A MultiPoint is not supported.");
            }
            else if (feature.Geometry is OsmSharp.Geo.Geometries.MultiPolygon)
            { // a multi polygon.
                throw new NotSupportedException("A MultiPolygon is not supported.");
            }
            throw new ArgumentOutOfRangeException("Geometry not recognized: {0}", feature.ToString());
        }