Пример #1
0
        private static IFeatureClass BuildQueryFeatureClass(string connection, string query, string name, string oidFields, int?srid, esriGeometryType?geometryType)
        {
            var factory   = new SqlWorkspaceFactoryClass();
            var workspace = factory.OpenFromString(connection, 0);
            //var workspace = factory.OpenFromFile(@"c:\tmp\AnimalMovement.sde", 0);
            var sqlWorkspace     = (ISqlWorkspace)workspace;
            var queryDescription = sqlWorkspace.GetQueryDescription(query);

            if (!String.IsNullOrEmpty(oidFields))
            {
                queryDescription.OIDFields = oidFields;
            }
            if (srid.HasValue)
            {
                queryDescription.Srid = srid.Value.ToString(CultureInfo.InvariantCulture);
                var srEnv = new SpatialReferenceEnvironmentClass();
                queryDescription.SpatialReference = srEnv.CreateSpatialReference(srid.Value);
            }
            if (geometryType.HasValue)
            {
                queryDescription.GeometryType = geometryType.Value;
            }
            sqlWorkspace.CheckDatasetName(name, queryDescription, out name);
            var queryClass   = sqlWorkspace.OpenQueryClass(name, queryDescription);
            var featureClass = (IFeatureClass)queryClass;

            return(featureClass);
        }
Пример #2
0
 private static IFeatureClass BuildQueryFeatureClass(string connection, string query, string name, string oidFields, int? srid, esriGeometryType? geometryType)
 {
     var factory = new SqlWorkspaceFactoryClass();
     var workspace = factory.OpenFromString(connection, 0);
     //var workspace = factory.OpenFromFile(@"c:\tmp\AnimalMovement.sde", 0);
     var sqlWorkspace = (ISqlWorkspace)workspace;
     var queryDescription = sqlWorkspace.GetQueryDescription(query);
     if (!String.IsNullOrEmpty(oidFields))
         queryDescription.OIDFields = oidFields;
     if (srid.HasValue)
     {
         queryDescription.Srid = srid.Value.ToString(CultureInfo.InvariantCulture);
         var srEnv = new SpatialReferenceEnvironmentClass();
         queryDescription.SpatialReference = srEnv.CreateSpatialReference(srid.Value);
     }
     if (geometryType.HasValue)
         queryDescription.GeometryType = geometryType.Value;
     sqlWorkspace.CheckDatasetName(name, queryDescription, out name);
     var queryClass = sqlWorkspace.OpenQueryClass(name, queryDescription);
     var featureClass = (IFeatureClass)queryClass;
     return featureClass;
 }