Beispiel #1
0
        public void CreateLinealShapeFile()
        {
            var fdt = CreateLinealFeatureDataTable(_geometryFactory);

            using (var sfp = ShapeFileProvider.Create(".", "Lineal", ShapeType.PolyLine, fdt, _geometryFactory, new GeometryServices().CoordinateSystemFactory))
            {
                sfp.Open(WriteAccess.ReadWrite);
                foreach (FeatureDataRow row in fdt.Rows)
                {
                    sfp.Insert(row);
                }
            }


            int number = 0;
            var gs     = new GeometryServices();

            using (var sfp = new ShapeFileProvider("Lineal.shp", gs.DefaultGeometryFactory, gs.CoordinateSystemFactory))
            {
                sfp.IsSpatiallyIndexed = false;
                sfp.Open(WriteAccess.ReadOnly);
                using (var p = sfp.ExecuteFeatureQuery(FeatureQueryExpression.Intersects(sfp.GetExtents())))
                {
                    while (p.Read())
                    {
                        Assert.True(((FeatureDataRow)fdt.Rows[number]).Geometry.Equals(p.Geometry));
                        number++;
                        Console.WriteLine(string.Format("{0}; {1}; {2}", p.GetOid(), p.Geometry.GeometryTypeName, p.Geometry));
                    }
                }
            }
            Assert.True(number == 100);
        }
Beispiel #2
0
        public void TestSqLite()
        {
            GeometryServices services = new GeometryServices();

            SpatiaLite2Provider search = new SpatiaLite2Provider(services.DefaultGeometryFactory,
                                                                 ConfigurationManager.ConnectionStrings["sqLite"].
                                                                 ConnectionString,
                                                                 "main",
                                                                 "regions", "OID", "XGeometryX");

            search.SpatiaLiteIndexType = SpatiaLite2IndexType.MBRCache;

            BinaryExpression binaryExpression =
                new BinaryExpression(new PropertyNameExpression("VHG5"),
                                     BinaryOperator.GreaterThan, new LiteralExpression <int>(6));

            ProviderPropertiesExpression providerProps =
                new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[] { });


            ProviderQueryExpression prov = new ProviderQueryExpression(providerProps, new AllAttributesExpression(),
                                                                       binaryExpression);

            object obj = search.ExecuteQuery(prov);

            Assert.IsNotNull(obj);
        }
        private static void setupShapefile(HttpContext context, Map m)
        {
            GeometryServices geometryServices = new GeometryServices();

            string[] layernames = new[]
            {
                "Countries",
                "Rivers"                          /*,
                                                   * "Cities"*/
            };

            foreach (string s in layernames)
            {
                ShapeFileProvider shapeFile =
                    new ShapeFileProvider(context.Server.MapPath(string.Format("~/App_Data/Shapefiles/{0}.shp", s)),
                                          geometryServices.DefaultGeometryFactory,
                                          geometryServices.CoordinateSystemFactory, false);
                shapeFile.IsSpatiallyIndexed = false;

                AppStateMonitoringFeatureProvider provider = new AppStateMonitoringFeatureProvider(shapeFile);

                GeoJsonGeometryStyle style = RandomStyle.RandomGeometryStyle();
                /* include GeoJson styles */
                style.IncludeAttributes            = false;
                style.IncludeBBox                  = true;
                style.PreProcessGeometries         = false;
                style.CoordinateNumberFormatString = "{0:F}";

                GeometryLayer geometryLayer = new GeometryLayer(s, style, provider);
                geometryLayer.Features.IsSpatiallyIndexed = false;
                m.AddLayer(geometryLayer);
                provider.Open();
            }
        }
Beispiel #4
0
        public void TestGetFeatureByOid()
        {
            GeometryServices services = new GeometryServices();

            MsSqlServer2008Provider <long> search = new MsSqlServer2008Provider <long>(services.DefaultGeometryFactory,
                                                                                       ConfigurationManager.
                                                                                       ConnectionStrings["sql2008"].
                                                                                       ConnectionString,
                                                                                       "dbo",
                                                                                       "vw_iMARS_BRANCH", "ACSId", "Geom")
            {
                DefaultProviderProperties
                    = new ProviderPropertiesExpression(
                          new ProviderPropertyExpression[]
                {
                    new WithNoLockExpression(true),
                    new ForceIndexExpression(true)
                })
            };


            IFeatureDataRecord record = search.GetFeatureByOid(1);

            Assert.IsNotNull(record);
        }
Beispiel #5
0
        public void TestMsSqlServer2008OrderBy()
        {
            GeometryServices services = new GeometryServices();

            MsSqlServer2008Provider <long> search = new MsSqlServer2008Provider <long>(services.DefaultGeometryFactory,
                                                                                       ConfigurationManager.
                                                                                       ConnectionStrings["sql2008"].
                                                                                       ConnectionString,
                                                                                       "dbo",
                                                                                       "vwGeoCustomers", "OID", "Geom")
            {
                DefaultProviderProperties
                    = new ProviderPropertiesExpression(
                          new ProviderPropertyExpression[]
                {
                    new WithNoLockExpression(true),
                    new ForceIndexExpression(true)
                })
            };

            //var binaryExpression =
            //    new CollectionBinaryExpression(new PropertyNameExpression("PostCode"), CollectionOperator.In, new CollectionExpression(new[] { 3, 4, 5, 6 }));


            AttributeBinaryStringExpression binaryExpression = new AttributeBinaryStringExpression("PostCode",
                                                                                                   BinaryStringOperator.
                                                                                                   StartsWith, "W");


            IGeometry testPoint = new GeometryServices()["EPSG:27700"].CreatePoint2D(500000, 180000);
            ProviderPropertiesExpression providerProps =
                new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[]
            {
                new WithNoLockExpression(true),
                //new OrderByCollectionExpression(
                //    new []
                //        {
                //            new OrderByExpression(
                //                new SpatialAnalysisDistanceExpression(new GeometryExpression(null),new GeometryExpression(testPoint) ),SortOrder.Ascending),
                //        }),

                new DataPageSizeExpression(10),
                new DataPageNumberExpression(0)
            });


            ProviderQueryExpression prov = new ProviderQueryExpression(providerProps, new AllAttributesExpression(),
                                                                       binaryExpression,
                                                                       new SortExpressionCollectionExpression(
                                                                           new[] { new SortExpression(
                                                                                       new SpatialAnalysisDistanceExpression(
                                                                                           new GeometryExpression(null),
                                                                                           new GeometryExpression(testPoint)), SortOrder.Ascending) }));

            object obj = search.ExecuteQuery(prov);

            Assert.IsNotNull(obj);
        }
Beispiel #6
0
        public override IFeatureProvider GetProvider()
        {
            if (!EnsureTables())
            {
                return(null);
            }

            string oidColumn, oidType, geometryColumn, schema, tableName;

            string[] prts = ((string)cbTable.SelectedItem).Split('|');
            oidColumn      = prts[3];
            oidType        = prts[2];
            geometryColumn = prts[1];
            prts           = prts[0].Split('.');
            schema         = prts[0];
            tableName      = prts[1];
            IGeometryFactory f = new GeometryServices().DefaultGeometryFactory;

            SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(this.ServerConnectionString);

            sb.InitialCatalog = cbDataBases.SelectedItem.ToString();
            string conn = sb.ToString();

            switch (oidType)
            {
            case "bigint":
                return(new MsSqlServer2008Provider <long>(f, conn, schema, tableName, oidColumn, geometryColumn));

            case "decimal":
                return(new MsSqlServer2008Provider <decimal>(f, conn, schema, tableName, oidColumn, geometryColumn));

            case "int":
            case "smallint":
                return(new MsSqlServer2008Provider <int>(f, conn, schema, tableName, oidColumn, geometryColumn));

            case "float":
            case "numeric":
            case "real":
                return(new MsSqlServer2008Provider <double>(f, conn, schema, tableName, oidColumn, geometryColumn));

            case "tinyint":
                return(new MsSqlServer2008Provider <byte>(f, conn, schema, tableName, oidColumn, geometryColumn));

            case "uniqueidentifier":
                return(new MsSqlServer2008Provider <Guid>(f, conn, schema, tableName, oidColumn, geometryColumn));

            case "nvarchar":
            case "varchar":
                return(new MsSqlServer2008Provider <string>(f, conn, schema, tableName, oidColumn, geometryColumn));
            }
            return(null);
        }
Beispiel #7
0
        public void TestTOWGS84Conversion()
        {
            string fromWkt =
                "PROJCS[\"LGD2006 / UTM zone 32N\",GEOGCS[\"LGD2006\",DATUM[\"Libyan_Geodetic_Datum_2006\",SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]],TOWGS84[-87,-98,-121,0,0,0,0],AUTHORITY[\"EPSG\",\"6754\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4754\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",9],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",-4000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"3199\"]]";
            string toWkt =
                "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]";

            GeometryServices          gs  = new GeometryServices();
            ICoordinateSystem         srs = gs.CoordinateSystemFactory.CreateFromWkt(fromWkt);
            ICoordinateSystem         dst = gs.CoordinateSystemFactory.CreateFromWkt(toWkt); //WGS84
            ICoordinateTransformation ics = gs.CoordinateTransformationFactory.CreateFromCoordinateSystems(srs, dst);

            Assert.IsNotNull(ics);
        }
Beispiel #8
0
        public void TestMsSqlSpatialPaged()
        {
            GeometryServices services = new GeometryServices();

            MsSqlSpatialProvider search = new MsSqlSpatialProvider(services.DefaultGeometryFactory,
                                                                   ConfigurationManager.ConnectionStrings["mssqlspatial"
                                                                   ].
                                                                   ConnectionString,
                                                                   "ST",
                                                                   "dbo",
                                                                   "BRoads", "OID", "the_geom")
            {
                DefaultProviderProperties
                    = new ProviderPropertiesExpression(
                          new ProviderPropertyExpression[]
                {
                    new WithNoLockExpression(true),
                    new ForceIndexExpression(true)
                })
            };

            //var binaryExpression =
            //    new CollectionBinaryExpression(new PropertyNameExpression("PostCode"), CollectionOperator.In, new CollectionExpression(new[] { 3, 4, 5, 6 }));


            AttributeBinaryStringExpression binaryExpression = new AttributeBinaryStringExpression("NAME",
                                                                                                   BinaryStringOperator.
                                                                                                   StartsWith, "W");


            ProviderPropertiesExpression providerProps =
                new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[]
            {
                new WithNoLockExpression(true),
                //new OrderByCollectionExpression(new[] {"NAME"}),
                new ForceIndexExpression(true),
                new IndexNamesExpression(new[] { "Index1", "Index2" }),
                new DataPageSizeExpression(10),
                new DataPageNumberExpression(5)
            });


            ProviderQueryExpression prov = new ProviderQueryExpression(providerProps, new AllAttributesExpression(),
                                                                       binaryExpression);

            object obj = search.ExecuteQuery(prov);

            Assert.IsNotNull(obj);
        }
Beispiel #9
0
        public void TestSqlServer2008Paged()
        {
            GeometryServices services = new GeometryServices();

            MsSqlServer2008Provider <long> search = new MsSqlServer2008Provider <long>(services.DefaultGeometryFactory,
                                                                                       ConfigurationManager.
                                                                                       ConnectionStrings["sql2008"].
                                                                                       ConnectionString,
                                                                                       "dbo",
                                                                                       "vw_iMARS_BRANCH", "ACSId", "Geom")
            {
                DefaultProviderProperties
                    = new ProviderPropertiesExpression(
                          new ProviderPropertyExpression[]
                {
                    new WithNoLockExpression(true),
                    new ForceIndexExpression(true)
                })
            };

            //var binaryExpression =
            //    new CollectionBinaryExpression(new PropertyNameExpression("PostCode"), CollectionOperator.In, new CollectionExpression(new[] { 3, 4, 5, 6 }));


            AttributeBinaryStringExpression binaryExpression = new AttributeBinaryStringExpression("PostCode",
                                                                                                   BinaryStringOperator.
                                                                                                   StartsWith, "W");


            ProviderPropertiesExpression providerProps =
                new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[]
            {
                new WithNoLockExpression(true),
                //new OrderByCollectionExpression(new[] {"PostCode"}),
                new ForceIndexExpression(true),
                new IndexNamesExpression(new[] { "Index1", "Index2" }),
                new DataPageSizeExpression(10),
                new DataPageNumberExpression(5)
            });


            ProviderQueryExpression prov = new ProviderQueryExpression(providerProps, new AllAttributesExpression(),
                                                                       binaryExpression);

            object obj = search.ExecuteQuery(prov);

            Assert.IsNotNull(obj);
        }
Beispiel #10
0
        public IFeatureProvider GetProvider()
        {
            IGeometryServices svc = new GeometryServices();

            if (File.Exists(tbPath.Text))
            {
                return(new ShapeFileProvider(tbPath.Text, svc.DefaultGeometryFactory, svc.CoordinateSystemFactory, false)
                {
                    IsSpatiallyIndexed = false,
                    ForceCoordinateOptions = (ForceCoordinateOptions)cbForceCoordinate.SelectedItem,
                    ReadStrictness = (ShapeFileReadStrictness)cbStrictness.SelectedItem
                });
            }
            return(null);
        }
        private ICoordinateTransformation SetCoordinateTransfromation(ICoordinateSystem spatialReference)
        {
            if (spatialReference != null)
            {
                string lastTargetCS = string.IsNullOrEmpty(Settings.Default.TargetSrid)
                                          ?
                                      "(e.g. 'EPSG:4326'). Otherwise just press Enter."
                                          :
                                      string.Format(
                    "(Last time you used: '{0}'). Only press Enter to do again or \n'{1}' to omit coordinat transformation.",
                    Settings.Default.TargetSrid, spatialReference.AuthorityCode);

                Console.WriteLine(string.Format(
                                      "\nThe Srid Authority Code of the sources' coordinate system is '{0}'.\n" +
                                      "If you wish to apply a coordinate transformation supply Srid Authority Code.\n" +
                                      "{1}.",
                                      spatialReference.AuthorityCode));

                string targetCS = Console.ReadLine();
                if (string.IsNullOrEmpty(targetCS))
                {
                    targetCS = Settings.Default.TargetSrid;
                }
                if (string.Equals(targetCS, spatialReference.AuthorityCode))
                {
                    targetCS = "";
                }

                if (!string.IsNullOrEmpty(targetCS))
                {
                    ICoordinateSystem csTo = SridMap.DefaultInstance.Process(targetCS, (ICoordinateSystem)null);
                    if (csTo != null)
                    {
                        ICoordinateTransformation ct = new GeometryServices().CoordinateTransformationFactory
                                                       .CreateFromCoordinateSystems(spatialReference, csTo);

                        return(ct);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Cannot access the following coordinate system: {0}", targetCS));
                    }
                }
            }
            return(null);
        }
Beispiel #12
0
        public void TestSqlServer2008Distance()
        {
            GeometryServices services = new GeometryServices();

            MsSqlServer2008Provider <long> search = new MsSqlServer2008Provider <long>(services.DefaultGeometryFactory,
                                                                                       ConfigurationManager.
                                                                                       ConnectionStrings["sql2008"].
                                                                                       ConnectionString,
                                                                                       "dbo",
                                                                                       "GeoPlaces", "OId", "Geom")
            {
                DefaultProviderProperties
                    = new ProviderPropertiesExpression(
                          new ProviderPropertyExpression[]
                {
                    new WithNoLockExpression(true),
                    new ForceIndexExpression(true)
                })
            };

            IGeometry point = services["EPSG:27700"].CreatePoint2D(500000, 180000);

            SpatialAnalysisExpression analysisExpresssion =
                new SpatialAnalysisDistanceExpression(new GeometryExpression(null),
                                                      new GeometryExpression(point));


            BinaryExpression expression = new BinaryExpression(analysisExpresssion, BinaryOperator.LessThanOrEqualTo,
                                                               new LiteralExpression <double>(2000.00));
            ProviderPropertiesExpression providerProps =
                new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[]
            {
                new WithNoLockExpression(true),
                new ForceIndexExpression(true)
            });


            ProviderQueryExpression prov = new ProviderQueryExpression(providerProps, new AllAttributesExpression(),
                                                                       expression);

            object obj = search.ExecuteQuery(prov);

            Assert.IsNotNull(obj);
        }
Beispiel #13
0
        public void TestGeometryProvider()
        {
            string           wkt;
            GeometryServices g = new GeometryServices();
            GeometryProvider prov;

            IGeometry geom = g.DefaultGeometryFactory.WktReader.Read(File.ReadAllText("D:\\geometries.txt"));

            prov = new GeometryProvider(new[] { geom });


            using (IFeatureDataReader fdr =
                       prov.ExecuteFeatureQuery(new FeatureQueryExpression(geom.Extents, SpatialOperation.Intersects)))
            {
                while (fdr.Read())
                {
                    Debug.WriteLine(fdr.Geometry.AsText());
                }
            }
        }
Beispiel #14
0
        public void CreateLinealShapeFileZ()
        {
            var fdt = CreateLinealFeatureDataTableZ(_geometryFactory);

            using (var sfp = ShapeFileProvider.Create(".", "LinealZ", ShapeType.PolyLineZ, fdt, _geometryFactory, new GeometryServices().CoordinateSystemFactory))
            {
                sfp.Open(WriteAccess.ReadWrite);
                foreach (FeatureDataRow row in fdt.Rows)
                {
                    sfp.Insert(row);
                }
            }


            int number = 0;
            var gs     = new GeometryServices();

            using (var sfp = new ShapeFileProvider("LinealZ.shp", gs.DefaultGeometryFactory, gs.CoordinateSystemFactory))
            {
                sfp.IsSpatiallyIndexed = false;
                sfp.Open(WriteAccess.ReadOnly);
                using (var p = sfp.ExecuteFeatureQuery(FeatureQueryExpression.Intersects(sfp.GetExtents())))
                {
                    while (p.Read())
                    {
                        var geom = ((FeatureDataRow)fdt.Rows[number]).Geometry;
                        Assert.True(geom.AsText().Equals(p.Geometry.AsText()),
                                    string.Format("\n{0}\nis not equal to\n{1}", geom.AsText(), p.Geometry.AsText()));
                        number++;
                        Assert.True(p.Geometry.Coordinates[0].ContainsOrdinate(Ordinates.Z), "Geometry's coordinates should have Z values");
                        Assert.True(p.Geometry.Coordinates[0].ContainsOrdinate(Ordinates.M), "Geometry's coordinates should have M values");
                        Assert.False(p.Geometry.Coordinates[0].ContainsOrdinate(Ordinates.W), "Geometry's coordinates should not have W values");
                        Console.WriteLine(string.Format("{0}; {1}; {2}", p.GetOid(), p.Geometry.GeometryTypeName, p.Geometry));
                    }
                }
            }
            Assert.True(number == 100);
        }
Beispiel #15
0
        /// <summary>
        /// Sets the blocks faces. Called whenever the BlockShape changes
        /// </summary>
        public void SetFaces()
        {
            TEMPMinPoint = position + new Vector3(-0.5f, -0.5f, -0.5f);
            TEMPMaxPoint = position + new Vector3(0.5f, 0.5f, 0.5f);

            faces.Clear();
            //Y-up world
            SetVertices();



            // Texture2D tex = BlockTextures[Direction.Up];
            Vector2 textureTopLeft     = new Vector2(0, 0);
            Vector2 textureTopRight    = new Vector2(1, 0);
            Vector2 textureBottomLeft  = new Vector2(0, 1);
            Vector2 textureBottomRight = new Vector2(1, 1);


            // Normal vectors for block faces (will be different for different shapes)
            Vector3 normalNorth  = new Vector3(1.0f, 0.0f, 0.0f);
            Vector3 normalSouth  = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 normalTop    = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 normalBottom = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 normalEast   = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 normalWest   = new Vector3(0.0f, 0.0f, -1.0f);



            if (blockShape == BlockShape.Cube)
            {
                // UV texture coordinates. TextureID is the index of the texture, from 0 to 15 (4x4 square texture atlas)

                /*    Texture2D tex = BlockTextures[BlockFace.Top];
                 *  Vector2 textureTopLeft = new Vector2(0, 0);
                 *  Vector2 textureTopRight = new Vector2(tex.Bounds.Width, 0);
                 *  Vector2 textureBottomLeft = new Vector2(0, tex.Bounds.Height);
                 *  Vector2 textureBottomRight = new Vector2(tex.Bounds.Width, tex.Bounds.Height);*/

                //Create 6 faces of cube
                //create bottom Face

                //Create Top Face
                if (ActiveFaces[Direction.Up])
                {
                    Vector3[] quad = { topVertices[1], topVertices[2], topVertices[3], topVertices[0] };
                    faces.AddRange(GeometryServices.BuildQuad(quad, true, normalTop, BlockTextures[Direction.Up], BlockTextures[Direction.Up]));
                }

                if (ActiveFaces[Direction.Down])
                {
                    Vector3[] quad = { bottomVertices[1], bottomVertices[0], bottomVertices[3], bottomVertices[2] };
                    faces.AddRange(GeometryServices.BuildQuad(quad, true, normalBottom, BlockTextures[Direction.Down], BlockTextures[Direction.Down]));
                }


                //Create West Face
                if (ActiveFaces[Direction.West])
                {
                    Vector3[] quad = { topVertices[1], topVertices[0], bottomVertices[0], bottomVertices[1] };
                    faces.AddRange(GeometryServices.BuildQuad(quad, true, normalWest, BlockTextures[Direction.West], BlockTextures[Direction.West]));
                }

                //Create South Face
                if (ActiveFaces[Direction.South])
                {
                    Vector3[] quad = { topVertices[0], topVertices[3], bottomVertices[3], bottomVertices[0] };
                    faces.AddRange(GeometryServices.BuildQuad(quad, true, normalSouth, BlockTextures[Direction.South], BlockTextures[Direction.South]));
                }

                //Create North Face
                if (ActiveFaces[Direction.North])
                {
                    Vector3[] quad = { topVertices[2], topVertices[1], bottomVertices[1], bottomVertices[2] };
                    faces.AddRange(GeometryServices.BuildQuad(quad, true, normalNorth, BlockTextures[Direction.North], BlockTextures[Direction.North]));
                }

                //Create East Face
                if (ActiveFaces[Direction.East])
                {
                    Vector3[] quad = { topVertices[3], topVertices[2], bottomVertices[2], bottomVertices[3] };
                    faces.AddRange(GeometryServices.BuildQuad(quad, true, normalEast, BlockTextures[Direction.East], BlockTextures[Direction.East]));
                }
            }
            else if (blockShape == BlockShape.Slope)
            {
                //NOTE: Slope normal will need to be changed
                int w = 0, x = 0, y = 0, z = 0;
                //NOTE: Must also flip texture coords

                //NOTE: Facing is the direction of the downwards slope
                if (blockFacing == Direction.West)
                {
                    w = 0;
                    x = 1;
                    y = 2;
                    z = 3;
                }
                else if (blockFacing == Direction.South)
                {
                    w = 3;
                    x = 0;
                    y = 1;
                    z = 2;
                }
                else if (blockFacing == Direction.East)
                {
                    w = 2;
                    x = 3;
                    y = 0;
                    z = 1;
                }

                else if (blockFacing == Direction.North)
                {
                    w = 1;
                    x = 2;
                    y = 3;
                    z = 0;
                }

                Vector2[] textureCoordinates = new Vector2[4];
                textureCoordinates[0] = textureBottomLeft;
                textureCoordinates[1] = textureTopLeft;
                textureCoordinates[2] = textureTopRight;
                textureCoordinates[3] = textureBottomRight;

                //  normalTop = new Vector3(1.0f, 1.0f, 0.0f);
                //create Top Face
                if (ActiveFaces[Direction.Up])
                {
                    /*  faces.Add(new VertexPositionNormalTexture(bottomVertices[w], normalTop, textureCoordinates[w]));
                     * faces.Add(new VertexPositionNormalTexture(bottomVertices[x], normalTop, textureCoordinates[x]));
                     * faces.Add(new VertexPositionNormalTexture(topVertices[y], normalTop, textureCoordinates[y]));
                     * faces.Add(new VertexPositionNormalTexture(topVertices[y], normalTop, textureCoordinates[y]));
                     * faces.Add(new VertexPositionNormalTexture(topVertices[z], normalTop, textureCoordinates[z]));
                     * faces.Add(new VertexPositionNormalTexture(bottomVertices[w], normalTop, textureCoordinates[w]));*/
                }



                /*   faces.Add(new VertexPositionNormalTexture(topVertices[z], normalSouth, textureTopRight));
                 * faces.Add(new VertexPositionNormalTexture(bottomVertices[z], normalSouth, textureBottomRight));
                 * faces.Add(new VertexPositionNormalTexture(bottomVertices[w], normalSouth, textureBottomLeft));
                 *
                 * faces.Add(new VertexPositionNormalTexture(topVertices[y], normalNorth, textureTopRight));
                 * faces.Add(new VertexPositionNormalTexture(bottomVertices[x], normalNorth, textureBottomLeft));
                 * faces.Add(new VertexPositionNormalTexture(bottomVertices[y],normalNorth, textureBottomRight));*/
            }
            BuildBuffers(faces);
        }
Beispiel #16
0
        public IFeatureProvider GetProvider()
        {
            if (EnsureTables())
            {
                string conn = ServerConnectionString;

                conn += string.Format("Database={0};", cbDataBases.SelectedItem);

                DataRowView drv              = (DataRowView)cbTables.SelectedItem;
                string      schema           = (string)drv["Schema"];
                string      tableName        = (string)drv["TableName"];
                string      oidColumnName    = (string)drv["OID"];
                string      geomColumn       = (string)drv["GeometryColumn"];
                int         coordDimension   = (int)drv["Dimension"];
                string      srid             = (string)drv["SRID"]; //((int)).ToString();
                string      spatialReference = (string)drv["SpatialReference"];

                IGeometryFactory gf    = null;
                GeometryServices gserv = new GeometryServices();
                if (spatialReference == "UNSPECIFIED" || spatialReference == "")
                {
                    gf = gserv[srid];
                }
                else
                {
                    gf = gserv[spatialReference];
                    if (string.IsNullOrEmpty(gf.Srid))
                    {
                        gf.Srid = srid;
                    }
                }


                IFeatureProvider prov = null;

                switch ((String)drv["OIDType"])
                {
                case "BIGINT":
                    prov = new DB2SpatialExtenderProvider <long>(gf, conn, schema, tableName, oidColumnName,
                                                                 geomColumn);
                    break;

                case "INTEGER":
                    prov = new DB2SpatialExtenderProvider <int>(gf, conn, schema, tableName, oidColumnName,
                                                                geomColumn);
                    break;

                case "VARCHAR":
                case "CLOB":
                    prov = new DB2SpatialExtenderProvider <string>(gf, conn, schema, tableName, oidColumnName,
                                                                   geomColumn);
                    break;

                case "REAL":
                    prov = new DB2SpatialExtenderProvider <Single>(gf, conn, schema, tableName, oidColumnName,
                                                                   geomColumn);
                    break;

                case "DOUBLE":
                    prov = new DB2SpatialExtenderProvider <Double>(gf, conn, schema, tableName, oidColumnName,
                                                                   geomColumn);
                    break;

                default:
                    return(null);
                }

                //prov.CoordinateTransformation = gserv.CoordinateTransformationFactory.CreateFromCoordinateSystems(
                //    gf.SpatialReference,
                //    gserv["EPSG:31467"].SpatialReference);

                //jd commented temporarily to get a build
                //((ISpatialDbProvider)prov).DefinitionQuery =
                //    new ProviderQueryExpression(ppe, ape, null);

                return(prov);
            }
            return(null);
        }
Beispiel #17
0
        public void SetFaces()
        {
            faces.Clear();
            SetVertices();

            Texture2D tex                = wallTextures[0];//NOTE: Will need to change per wall face
            Vector2   textureTopLeft     = new Vector2(0, 0);
            Vector2   textureTopRight    = new Vector2(1, 0);
            Vector2   textureBottomLeft  = new Vector2(0, 1);
            Vector2   textureBottomRight = new Vector2(1, 1);


            //NOTE: May be facing incorrect directions
            Vector3 normalNorth  = new Vector3(1.0f, 0.0f, 0.0f);
            Vector3 normalSouth  = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 normalTop    = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 normalBottom = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 normalEast   = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 normalWest   = new Vector3(0.0f, 0.0f, -1.0f);

            //Create Top Face
            Vector3[] quad1 = { topVertices[1], topVertices[2], topVertices[3], topVertices[0] };
            faces.AddRange(GeometryServices.BuildQuad(quad1, true, normalTop, TextureName.Stone, TextureName.Stone));

            /*  faces.Add(new VertexPositionNormalTexture(topVertices[0], normalTop, textureBottomLeft));
             * faces.Add(new VertexPositionNormalTexture(topVertices[1], normalTop, textureTopLeft));
             * faces.Add(new VertexPositionNormalTexture(topVertices[2], normalTop, textureTopRight));
             * faces.Add(new VertexPositionNormalTexture(topVertices[2], normalTop, textureTopRight));
             * faces.Add(new VertexPositionNormalTexture(topVertices[3], normalTop, textureBottomRight));
             * faces.Add(new VertexPositionNormalTexture(topVertices[1], normalTop, textureBottomLeft));*/

            //Bottom face
            Vector3[] quad2 = { bottomVertices[1], bottomVertices[0], bottomVertices[3], bottomVertices[2] };
            faces.AddRange(GeometryServices.BuildQuad(quad2, true, normalBottom, TextureName.Stone, TextureName.Stone));

            /*   faces.Add(new VertexPositionNormalTexture(bottomVertices[2], normalBottom, textureTopRight));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[0], normalBottom, textureTopLeft));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[1], normalBottom, textureBottomLeft));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[1], normalBottom, textureBottomLeft));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[3], normalBottom, textureBottomRight));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[2], normalBottom, textureTopRight));*/

            Vector3[] quad3 = { topVertices[1], topVertices[0], bottomVertices[0], bottomVertices[1] };
            faces.AddRange(GeometryServices.BuildQuad(quad3, true, normalWest, TextureName.Stone, TextureName.Stone));

            /* faces.Add(new VertexPositionNormalTexture(bottomVertices[0], normalWest, textureBottomRight));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[1], normalWest, textureBottomLeft));
             * faces.Add(new VertexPositionNormalTexture(topVertices[1], normalWest, textureTopLeft));
             * faces.Add(new VertexPositionNormalTexture(topVertices[1], normalWest, textureTopLeft));
             * faces.Add(new VertexPositionNormalTexture(topVertices[0], normalWest, textureTopRight));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[0], normalWest, textureBottomRight));*/


            Vector3[] quad4 = { topVertices[0], topVertices[3], bottomVertices[3], bottomVertices[0] };
            faces.AddRange(GeometryServices.BuildQuad(quad4, true, normalSouth, TextureName.Stone, TextureName.Stone));

            /* faces.Add(new VertexPositionNormalTexture(bottomVertices[0], normalSouth, textureBottomLeft));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[2], normalSouth, textureTopLeft));
             * faces.Add(new VertexPositionNormalTexture(topVertices[2], normalSouth, textureTopRight));
             * faces.Add(new VertexPositionNormalTexture(topVertices[2], normalSouth, textureTopRight));
             * faces.Add(new VertexPositionNormalTexture(topVertices[0], normalSouth, textureBottomRight));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[0], normalSouth, textureBottomLeft));*/

            Vector3[] quad5 = { topVertices[2], topVertices[1], bottomVertices[1], bottomVertices[2] };
            faces.AddRange(GeometryServices.BuildQuad(quad5, true, normalNorth, TextureName.Stone, TextureName.Stone));

            /* faces.Add(new VertexPositionNormalTexture(bottomVertices[1], normalNorth, textureBottomRight));
             * faces.Add(new VertexPositionNormalTexture(topVertices[1], normalNorth, textureBottomLeft));
             * faces.Add(new VertexPositionNormalTexture(topVertices[3], normalNorth, textureTopLeft));
             * faces.Add(new VertexPositionNormalTexture(topVertices[3], normalNorth, textureTopLeft));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[3], normalNorth, textureTopRight));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[1], normalNorth, textureBottomRight));*/

            Vector3[] quad6 = { topVertices[3], topVertices[2], bottomVertices[2], bottomVertices[3] };
            faces.AddRange(GeometryServices.BuildQuad(quad6, true, normalEast, TextureName.Stone, TextureName.Stone));

            /* faces.Add(new VertexPositionNormalTexture(bottomVertices[2], normalEast, textureBottomRight));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[3], normalEast, textureBottomLeft));
             * faces.Add(new VertexPositionNormalTexture(topVertices[3], normalEast, textureTopLeft));
             * faces.Add(new VertexPositionNormalTexture(topVertices[3], normalEast, textureTopLeft));
             * faces.Add(new VertexPositionNormalTexture(topVertices[2], normalEast, textureTopRight));
             * faces.Add(new VertexPositionNormalTexture(bottomVertices[2], normalEast, textureBottomRight));*/


            BuildBuffers(faces);
        }
Beispiel #18
0
        public IFeatureProvider GetProvider()
        {
            if (EnsureTables())
            {
                string conn = ServerConnectionString;

                conn += string.Format("Database={0};", cbDataBases.SelectedItem);
                conn += "Enlist=true;";

                DataRowView drv       = (DataRowView)cbTables.SelectedItem;
                string      schema    = (string)drv["Schema"];
                string      tableName = (string)drv["TableName"];
                ;
                string geomColumn     = (string)drv["GeometryColumn"];
                int    coordDimension = (int)drv["Dimension"];
                string srid           = (string)drv["SRID"]; //((int)).ToString();

                GeometryServices gs = new GeometryServices();
                IGeometryFactory gf = gs[srid]; //, coordDimension];
                //if (!string.IsNullOrEmpty(spatialReference))
                //    gf.SpatialReference = gs.CoordinateSystemFactory.CreateFromWkt(spatialReference);

                string oidColumnName = (String)dgvColumns.Rows[oidcolumn].Cells["ColumnName"].Value;

                List <String> columns = new List <string>();
                //List<OrderByExpression> orderby = new List<OrderByExpression>();
                foreach (DataGridViewRow dgvr in dgvColumns.Rows)
                {
                    if ((bool)dgvr.Cells["Include"].Value)
                    {
                        columns.Add((String)dgvr.Cells["ColumnName"].Value);
                    }
                    //if (dgvr.Cells["SortOrder"].Value != null)
                    //    orderby.Add(new OrderByExpression((String) dgvr.Cells[1].Value,
                    //                                      (SortOrder) dgvr.Cells["SortOrder"].Value));
                }

                if (!columns.Contains(oidColumnName))
                {
                    columns.Insert(0, oidColumnName);
                }

                columns.Add(geomColumn);

                ProviderPropertiesExpression ppe = null;

                //if (orderby.Count == 0)
                //{
                //    ppe = new ProviderPropertiesExpression(
                //        new ProviderPropertyExpression[]
                //            {
                //                new AttributesCollectionExpression(columns)
                //            });
                //}
                //else
                //{
                ppe = new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[]
                {
                    //new OrderByCollectionExpression(orderby),
                    new AttributesCollectionExpression(columns)
                });
                //}

                IFeatureProvider prov = null;

                switch ((String)dgvColumns.Rows[oidcolumn].Cells["DataType"].Value)
                {
                case "bigint":
                    prov = new PostGisProvider <long>(gf, conn, schema, tableName, oidColumnName, geomColumn,
                                                      gs.CoordinateTransformationFactory)
                    {
                        DefaultProviderProperties = ppe
                    };
                    break;

                case "integer":
                    prov = new PostGisProvider <int>(gf, conn, schema, tableName, oidColumnName, geomColumn,
                                                     gs.CoordinateTransformationFactory)
                    {
                        DefaultProviderProperties = ppe
                    };
                    break;

                case "character varying":
                case "text":
                    prov = new PostGisProvider <string>(gf, conn, schema, tableName, oidColumnName, geomColumn,
                                                        gs.CoordinateTransformationFactory)
                    {
                        DefaultProviderProperties = ppe
                    };
                    break;

                case "uuid":
                    prov = new PostGisProvider <Guid>(gf, conn, schema, tableName, oidColumnName, geomColumn,
                                                      gs.CoordinateTransformationFactory)
                    {
                        DefaultProviderProperties = ppe
                    };
                    break;

                default:
                    return(null);
                }

                //jd commented temporarily to get a build
                //((ISpatialDbProvider)prov).DefinitionQuery =
                //    new ProviderQueryExpression(ppe, ape, null);

                return(prov);
            }
            return(null);
        }
Beispiel #19
0
        public IFeatureProvider GetProvider()
        {
            if (EnsureTables())
            {
                string conn = ServerConnectionString;

                DataRowView drv       = (DataRowView)cbTables.SelectedItem;
                string      schema    = (string)drv["Schema"];
                string      tableName = (string)drv["TableName"];
                ;
                string geomColumn       = (string)drv["GeometryColumn"];
                int    coordDimension   = (int)(long)drv["Dimension"];
                string srid             = drv["SRID"].ToString();
                string spatialReference = drv["SpatialReference"] == DBNull.Value
                                              ?
                                          ""
                                              :
                                          (string)drv["SpatialReference"];

                GeometryServices gs = new GeometryServices();
                IGeometryFactory gf = gs[srid]; //, coordDimension];
                //if (!string.IsNullOrEmpty(spatialReference))
                //    gf.SpatialReference = gs.CoordinateSystemFactory.CreateFromWkt(spatialReference);

                string oidColumnName = (String)dgvColumns.Rows[oidcolumn].Cells[2].Value;

                List <String> columns = new List <string>();
                //List<OrderByExpression> orderby = new List<OrderByExpression>();
                foreach (DataGridViewRow dgvr in dgvColumns.Rows)
                {
                    if ((bool)dgvr.Cells["Include"].Value)
                    {
                        columns.Add((String)dgvr.Cells[2].Value);
                    }
                    //if (dgvr.Cells["SortOrder"].Value != null)
                    //    orderby.Add(new OrderByExpression((String) dgvr.Cells[1].Value,
                    //                                      (SortOrder) dgvr.Cells["SortOrder"].Value));
                }

                if (!columns.Contains(oidColumnName))
                {
                    columns.Insert(0, oidColumnName);
                }
                columns.Insert(1, geomColumn);

                ProviderPropertiesExpression ppe = null;

                //if (orderby.Count == 0)
                //{
                //    ppe = new ProviderPropertiesExpression(
                //        new ProviderPropertyExpression[]
                //            {
                //                new AttributesCollectionExpression(columns)
                //            });
                //}
                //else
                //{
                ppe = new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[]
                {
                    //new OrderByCollectionExpression(orderby),
                    new AttributesCollectionExpression(columns)
                });
                //}

                IFeatureProvider prov =
                    new SpatiaLite2Provider(gf, conn, schema, tableName, oidColumnName, geomColumn,
                                            gs.CoordinateTransformationFactory)
                {
                    DefaultProviderProperties = ppe
                };

                //jd commented temporarily to get a build
                //((ISpatialDbProvider)prov).DefinitionQuery =
                //    new ProviderQueryExpression(ppe, ape, null);

                return(prov);
            }
            return(null);
        }